0

好的,我已经在 VS2012 中从 Python 切换到 C++,以努力让这个项目再次滚动。在了解其中的来龙去脉时,我遇到了很多障碍和头痛。这是我最新的,最令人沮丧的一个,以及随之而来的编译错误。

1>  C:\Users\Karsten Chu\New Google Drive\Research\Visual Studio 2012\Projects\Dynamic Parallelism Test\Dynamic Parallelism Test>"C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v5.5\bin\nvcc.exe" -dlink -o "x64\Debug\Dynamic Parallelism Test.device-link.obj" -Xcompiler "/EHsc /W3 /nologo /Od /Zi /RTC1 /MDd  " -L"C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v5.5\lib\x64" cuda.lib cudart.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib -lcudadevrt  -gencode=arch=compute_35,code=sm_35 -G --machine 64 "x64\Debug\CUDA Test 2.cu.obj" "x64\Debug\CUDA Test.cu.obj" 
1>Dynamic Parallelism Test.device-link.obj : error LNK2001: unresolved external symbol __fatbinwrap_54_tmpxft_00000634_00000000_8_cuda_device_runtime_cpp1_ii_5f6993ef
1>C:\Users\Karsten Chu\New Google Drive\Research\Visual Studio 2012\Projects\Dynamic Parallelism Test\x64\Debug\Dynamic Parallelism Test.exe : fatal error LNK1120: 1 unresolved externals
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

还有我的代码。

#include <cuda.h>
#include <cuda_runtime.h>
#include <device_launch_parameters.h>
#include <stdio.h>
#include <iostream>
using namespace std;

__global__ void rkf5(double*, int*);
__global__ void k1(double*);

int main2(int argc, char** argv)
{
    const int max_length = 5;
    double concs[max_length];
    for (int i=0; i<max_length; i++)
    {
        concs[i]=0;
        //std::cout<<concs[i];
    }

    double *d_concs;
    int *d_max_length;
    size_t size_concs = sizeof(concs);
    size_t size_max_length = sizeof(max_length);
    cudaMalloc((void**)&d_concs, size_concs);
    cudaMemcpy(d_concs, concs, size_concs, cudaMemcpyHostToDevice);
    cudaMalloc((void**)&d_max_length, size_max_length);
    cudaMemcpy(d_concs, concs, size_concs, cudaMemcpyHostToDevice);
    rkf5<<<1,max_length>>>(d_concs, d_max_length);
    cudaMemcpy(concs, d_concs, size_concs, cudaMemcpyDeviceToHost);

    for (int i=0; i<max_length; i++)
    {
        std::cout<<concs[i];
    }
    return 0;
}

__global__ void rkf5(double* concs, int* max_length)
{
    int idx = blockIdx.x * blockDim.x + threadIdx.x;
    concs[idx]=idx;
    //dim3 threads = dim3(max_length);
    k1<<< 1, *max_length >>>(concs);
}
__global__ void k1(double* concs)
{
    int idx = blockIdx.x * blockDim.x + threadIdx.x;
    concs[idx]=0;
}

请在这里帮助我,我花了很多时间谷歌搜索这个问题,我发现的每一条线索都没有发布解决方案。

4

2 回答 2

3

用于编译和链接的命令行:

nvcc.exe -dlink -o "x64\Debug\Dynamic Parallelism Test.device-link.obj" 
-Xcompiler "/EHsc /W3 /nologo /Od /Zi /RTC1 /MDd  " 
-L"C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v5.5\lib\x64" 
cuda.lib cudart.lib kernel32.lib user32.lib gdi32.lib winspool.lib  
comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib 
odbc32.lib odbccp32.lib -lcudadevrt -gencode=arch=compute_35,code=sm_35 -G 
--machine 64 "x64\Debug\CUDA Test 2.cu.obj" "x64\Debug\CUDA Test.cu.obj"

您正在尝试链接 cudadevrt linux 风格 ( -lcudadevrt)。这在 Windows 上不起作用,调用的链接器是 VS 形式的。添加cudadevrt.lib到您的链接器输入中,例如cudart.lib.

于 2013-10-18T16:51:38.080 回答
3

我已通过以下方式成功编译并运行您的代码:

  1. 使用在 Visual Studio 2010 中使用 CUDA 动态并行中的过程;
  2. 更改main2main;

程序输出0123:-)

于 2013-10-18T16:56:57.593 回答