无法从Cuda中的内核调用设备代码

时间:2019-08-20 14:44:00

标签: cuda

由于在我的cuda代码中进行了一些重组,当我尝试从内核调用设备函数时,出现以下错误“ Unresolved extern function”。

test.cuh看起来像这样:

#include "cuda_runtime.h"

class TestKernel
{
  public:
    int number;
    TestKernel(int number);
    __device__ __host__
    void run();
};

test.cu看起来像这样。

#include"testkernel.cuh"
#include "stdio.h"

TestKernel::TestKernel(int number)
{
   this->number = number;
}
void TestKernel::run()
{
    printf("%d", this->number);
} 

我的主文件是这样的。

#include "device_launch_parameters.h"
#include "testkernel.cuh"


__global__ void kernel(TestKernel * testKernel)
{
    testKernel[blockIdx.x * blockDim.x + threadIdx.x].run();
}

int main()
{
    TestKernel * testKernel;
    cudaMallocManaged(&testKernel, 10 * sizeof(*testKernel));
    for (int i = 0; i < 10; i++)
    {
       testKernel[i] = TestKernel(i);
    }
    kernel << <1, 10 >> > (testKernel);

    return 0;
}

我发现建议可以通过在构建过程中添加-dc来解决,但是当我这样做时,我遇到了其他一些错误:

“严重性代码描述项目文件行抑制状态 错误LNK2019无法解析的外部符号__cudaRegisterLinkedBinary_45_tmpxft_00007118_00000000_7_TestKernel_cpp1_ii_aa56518f在函数“ void __cdecl __nv_cudaEntityRegisterCallback(void * *)”中引用(?__ nv_cudaEntityRegisterCallX @@ YAXPEAP “

我正在尝试使用Visual Studio 2017和CUDA 10.1来构建它。

0 个答案:

没有答案
相关问题