cuda header files .cuh private host functions
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
- 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.
- 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
- 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
};
精彩评论