Passing Host Function as a function pointer in __global__ OR __device__ function in CUDA

Yes, for a GPU implementation of Calc, you should pass the GetInv as a __device__ function pointer.

It is possible, here are some worked examples:

Ex. 1

Ex. 2

Ex. 3

Most of the above examples demonstrate bringing the device function pointer all the way back to the host code. This may not be necessary for your particular case. But it should be fairly obvious from above how to grab a __device__ function pointer (in device code) and use it in a kernel.

Leave a Comment