Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 537
Ian Decks Avatar asked Mar 05 '13 10:03

Ian Decks


2 Answers

  • 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.
like image 175
Eugene Avatar answered Nov 12 '22 21:11

Eugene


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.
like image 1
Vitality Avatar answered Nov 12 '22 21:11

Vitality