【发布时间】:2013-06-10 22:48:31
【问题描述】:
我设法用函数指针使整个事情工作,现在我想动态加载这样的内核。 我的代码:
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)();
如果我调试到 dll cudaStatus = cudaSuccess,但指向函数的指针为空,并且它是从 dll 调用返回的。我的问题是:是否可以在 DLL 中编写内核函数,然后获取指向此类内核的指针并将其传递给主程序?我需要它能够在主程序运行时更改内核。
【问题讨论】: