cuda文件组织的有效方法:.cpp .h .cu .cuh .curnel文件 [英] efficient way of cuda file organization: .cpp .h .cu .cuh .curnel files
问题描述
什么是cuda最容易理解/高效的代码组织。经过一些调查,我发现cuda函数声明应该在.cuh文件中,实现驻留在.cu文件和.curnel文件中的内核函数实现。其他c ++的东西在.cpp和.h文件通常。最近我发布了一个问题 visual studio .cu文件显示语法错误但编译成功。这个组织是正确的吗?其中.cpp调用.cu并调用.curnel中的内核函数。
What is the most easy to understand/efficient etc. code organization for cuda. After some investigation i found that cuda function declarations should be in .cuh file and implementations reside in .cu file and kernel function implementations in .curnel files. Other c++ stuff in .cpp and .h files ordinarily. Recently i posted a question visual studio .cu file shows syntax error but compile successfully . Is this organization correct? where .cpp calls .cu and it calls kernel function that in .curnel.
推荐答案
- h , cpp , c , hpp , inc C代码(例如__ device __和其他关键字,内核调用等),不要做任何cuda运行时调用(cuda ...函数)。从这些文件调用CUDA驱动程序API(cu ...)函数是完全正确的。请注意,可以使用除NVCC之外的编译器来编译这些文件。
- cu - CUDA C源文件。这些文件传递到NVCC编译器,以便编译为可链接(主机/设备)对象。
- cuh , cuinc 包括在.cu文件中。这些文件可以包含CUDA C关键字和/或调用CUDA运行时函数。
- h, cpp, c, hpp, inc - files that don't contain CUDA C code (e.g. __device__ and other keywords, kernel calls, etc.) and do not make any cuda runtime calls (cuda... functions). It is perfectly fine to call CUDA driver API (cu...) functions from these files. Note that it is possible to compile these files with compilers other then NVCC.
- cu - CUDA C source files. These files are passed to the NVCC compiler to be compiled into linkable (host/device) objects.
- cuh, cuinc - files that are included in .cu files. These files can have CUDA C keywords and/or call CUDA runtime functions.
这篇关于cuda文件组织的有效方法:.cpp .h .cu .cuh .curnel文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!