Pointers 将内核编译为DLL并使用它

Pointers 将内核编译为DLL并使用它,pointers,dll,cuda,Pointers,Dll,Cuda,我设法使整个函数指针工作,现在我想动态加载这样一个内核。 我的代码: cuh: 特写: main.cpp: HINSTANCE hGetProcIDDLL = LoadLibrary("xxx.dll"); if (hGetProcIDDLL == NULL) { std::cout << "could not load the dynamic library" << std::endl; } dll_func dll_getHos

我设法使整个函数指针工作,现在我想动态加载这样一个内核。 我的代码:

cuh:

特写:

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)();
HINSTANCE hGetProcIDDLL=LoadLibrary(“xxx.dll”);
如果(hGetProcIDDLL==NULL){

std::cout整个代码没有意义

首先,您没有检查
cudaStatus

其次,您正在从常量内存复制,但为什么?您肯定没有更新内核中的常量内存。您可能正在查找
cudaMemcpy
而不是
cudamemcpyfromsmbol


在“固定内存”上使用Google,这可能对您的情况很有用。

您可以将内核代码编译为PTX,并使用CUDA驱动程序API运行它,请参阅


如果您使用
-ptx
选项而不是
-compile
调用
nvcc
,它将生成ptx文件。它不与exe程序链接,您可以随时更改ptx文件。

这是基于第一个答案:我正在通过调试器检查cudaStatus。通过cudaMemcpyFromSymbol从常量内存复制是或者将指向设备函数的指针传递给内核。您可以在上面的链接中找到它。我正在尝试加载一些代码,这些代码可以在编译主程序后进行编译,然后进行更改和重新加载。是否可以使用PTX?是的,您可以将PTX文件与cpu程序分开编译。
__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;
}
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)();