I managed to make whole thing with function pointers work and now I want to dynamically load such a kernel. My code:
cuh:
ifndef customkernel_cuh
define customkernel_cuh
extern "C" pfunctionWhere __declspec(dllexport) getHostPointer();
endif
cu:
__device__
bool myWhere2(PapayaColumnValue *values)
{
return ((int)values[1]) == 1 || ((int)values[1]) == 3;
}
__device__ pfunctionWhere pMyWhere2 = myWhere2;
pfunctionWhere __declspec(dllexport) getHostPointer()
{
cudaError_t cudaStatus;
pfunctionWhere h_pMyWhere2;
cudaStatus = cudaMemcpyFromSymbol(&h_pMyWhere2, pMyWhere2, sizeof(pfunctionWhere));
cudaDeviceSynchronize();
return h_pMyWhere2;
}
main.cpp:
HINSTANCE hGetProcIDDLL = LoadLibrary("xxx.dll");
if (hGetProcIDDLL == NULL) {
std::cout << "could not load the dynamic library" << std::endl;
}
dll_func dll_getHostPointer = (dll_func)GetProcAddress(hGetProcIDDLL, "getHostPointer");
DWORD dw = GetLastError();
if (!dll_getHostPointer) {
std::cout << "could not locate the function" << std::endl;
}
pfunctionWhere h_pMyWhere2 = (*dll_getHostPointer)();
And if I debug into dll cudaStatus = cudaSuccess
, but pointer to function is null and it is returned from dll invocation. My question is: is it possible to write kernel functions in DLL and then get pointer to such kernels and pass it to main program? I need it to be able to change the kernel while main program is working.