12

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.

Community
  • 1
  • 1
Ian Decks
  • 211
  • 1
  • 5
  • 13
  • 4
    `curnel` files? I count myself as reasonably experienced with CUDA and have looked at lot of other peoples projects, and I can't *ever* remember seeing a single `curnel` file extension. It certainly isn't anything NVCC understands or has a predefined trajectory for.... – talonmies Mar 05 '13 at 11:35
  • It depends on you, you can group files by functionality, by type (.cu, .h, .cpp) or other or combine them (in functionality groups you can keep .cu file together). – Tomasz Dzięcielewski Mar 05 '13 at 12:20

2 Answers2

8
  • 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.
Eugene
  • 8,611
  • 2
  • 26
  • 28
  • Why would the driver API be allowed but not the runtime? AFAICT the runtime just a set of regular C functions that I have to link to. Why would any code calling them need to be passed through a special compilation step? – polwel Oct 08 '20 at 07:20
1

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.
Vitality
  • 18,557
  • 4
  • 87
  • 129
  • Could you provide bodies for the files with empty functions implementations? Thanks! – Yola Feb 02 '18 at 11:22