Hi,
Does OpenCL support some kind of C++ virtual functions or C function pointers as kernel arguments?
The idea is to call functions compiled from other .cl file.
For example, I have a file called MyCustomAdd.cl
__device int MyCustomAdd ( const int a, const int b)
{
return a+b;
}
and I have this kernel.cl file
__device int (*deviceFunctionPointer) ( const int a, const int b );
__kernel __device void MyOpenCLKernel ( deviceFunctionPointer *p )
{
//Do some things...
//Now call the user-defined function pointer
const int result = deviceFunctionPointer(1,2);
}
in my CPU code I could do this:
void main ()
{
//init OpenCL, etc...
//load the user-defined shader function/interface
clModule *mod = clCompileModule("MyCustomAdd.cl");
void *MyCustomAddPtr = clGetDeviceFunction(mod,"MyCustomAdd");
//load my kernel
clModule *krnMod = clCompileModule("kernel.cl");
//fire my kernel
array<void*> krnParams;
krnParams.push_back(MyCustomAdd);
clExecuteKernel ( krnMod, "MyOpenCLKernel", 256_threads_per_block, krnParams );
}
Thanks