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

我们两清 提交于 2019-12-03 06:22:06
  • 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.

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