Accessing class data members from within cuda kernel - how to design proper host/device interaction?

前端 未结 2 1301
死守一世寂寞
死守一世寂寞 2021-02-10 04:03

I\'ve been trying to transform some cuda/C code into a more OO code, but my goal doesn\'t seem to be easy to achieve for my current understanding of the cuda functionin

2条回答
  •  闹比i
    闹比i (楼主)
    2021-02-10 04:32

    What has worked best for me is to only put regular CUDA functions, kernels and kernel launches in CUDA C (.cu) files, and then build an object oriented interface on top of that, with classes in C++ (.cpp) files.

    So, in your class constructor, you call functions in your .cu file that allocate and initialize memory and in your methods, you call functions that launch kernels, etc.

    This can also make development turnaround faster because you can often change your classes without incurring recompile of .cu files, which is much slower than compiling pure .cpp files.

提交回复
热议问题