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 passes as a function pointer(e.g. in above example GetInv is the host function of CalcInvFunction type). My question is, if i have to put Calc() function entirely in GPU, i have to pass the GetInv function as a function pointer argument in device function/kernel function, and is that possible?
相关问题
- Achieving the equivalent of a variable-length (loc
- The behavior of __CUDA_ARCH__ macro
- Setting Nsight to run with existing Makefile proje
- Usage of anonymous functions in arrayfun with GPU
- AMD CPU versus Intel CPU openCL
相关文章
- How to downgrade to cuda 10.0 in arch linux?
- What's the relation between nvidia driver, cud
- How can I use 100% of VRAM on a secondary GPU from
- Running LSTM with multiple GPUs gets “Input and hi
- NVidia CUDA toolkit 7.5.27 failing to install on O
- How can I find row to all rows distance matrix bet
- thrust: fill isolate space
- How to get the real and imaginary parts of a compl
Yes, for a GPU implementation of
Calc
, you should pass theGetInv
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.Finally, i have been able to pass a host function as a function pointer in cuda kernel function (__global__ function). Thanks to Robert Crovella and njuffa for the answer. I have been able to pass a class member function(cpu function) as a function pointer to a cuda kernel. But, the main problem is, i can only pass the static class member function. I am not being able to pass the function not declared as static. For Example:
/**/ __host__ __device__ static int CellfunPtr( void*ptr, int a ); /**/
The above function work because this member function is declared as static member function. If i do not declare this member function as a static member as ,
/**/ __host__ __device__ int CellfunPtr( void*ptr, int a ); /**/
then it doesnt work.
The complete code has four files.
/*start of fundef.h file*/
typedef int (*pFunc_t)(void* ptr, int N);
/*end of fundef.h file*/
/*start of solver.h file*/
/*end of solver.h file*/
/*start of solver.cu file*/
/*end of solver.cu file*/
/*start of main.cpp file*/
/*end of main.cpp file*/