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

19,017

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

Solution 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.
Share:
19,017

Related videos on Youtube

Ian Decks
Author by

Ian Decks

Updated on June 05, 2022

Comments

  • Ian Decks
    Ian Decks almost 2 years

    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.

    • talonmies
      talonmies about 11 years
      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....
  • Yola
    Yola about 6 years
    Could you provide bodies for the files with empty functions implementations? Thanks!
  • polwel
    polwel over 3 years
    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?
  • BiMo
    BiMo about 2 years
    what is FDTD ? is it the name of your project or something else in CUDA? sorry to ask, new in CUDA.