开发者

cuda header files .cuh private host functions

开发者 https://www.devze.com 2023-04-11 10:41 出处:网络
In cuda we can create header files with .cuh extension and we can call the functions from anywhere like,

In cuda we can create header files with .cuh extension and we can call the functions from anywhere like,

   __device__ void doSomething()
  {
    .........开发者_如何学编程...........
  }

  void doSomthingOnHost()
  {
    ....................
  }

these two functions are public. How can i make the host function to private?


I find that what works best for me is to

  1. Make .CU files with my CUDA kernels, their public C/C++ wrappers and any private/encapsulated C/C++ functions I need to make the device code work.
  2. Make .H files which provide access to the C/C++ wrappers inside my .CU files, #including them in the .CU files and any .C/.CPP files I need to call the device code from
  3. Make .C/.CPP files which handle the high-level application logic and which invoke device code through interfaces supplied through the header files described in step 2.

To make host functions private in this scheme, just don't put prototypes for them in the header... a pretty neat scheme if you ask me.


Strictly speaking, there's no way to make a free function private in C++ -- any client which can see a function's signature can call it.

Instead, you could make doSomethingOnHost a private, static member function of some class:

class my_class
{
  private:
    static void doSomethingOnHost(); // only my_class or friends of my_class may use this function
};
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号