efficient way of cuda file organization: .cpp .h .cu .cuh .curnel files

守給你的承諾、 提交于 2019-12-03 17:15:51

问题


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.


回答1:


  • 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.



回答2:


As an example, suppose to have a GPU-based FDTD code. I usually do the following (Visual Studio 2010).

  • main.cpp file, including CPU-GPU memory transfers;
  • FDTD.cu, including an extern "C" void E_update(...) function which contains the kernel <<< >>> call;
  • main.h file, including the extern "C" void E_update(...) prototype;
  • FDTD.cuh, including the __global__ void E_update_kernel(...) function.


来源:https://stackoverflow.com/questions/15222071/efficient-way-of-cuda-file-organization-cpp-h-cu-cuh-curnel-files

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!