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

前端 未结 2 1765
迷失自我
迷失自我 2020-11-28 15:32

I am currently developing a GPU version of a CPU function (e.g. function Calc(int a, int b, double* c, souble* d, CalcInvFunction GetInv )), in which a host function is pass

2条回答
  •  失恋的感觉
    2020-11-28 16:12

    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.

提交回复
热议问题