好的,我已经在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;
}
请在这里帮助我,我花了很多时间搜索这个问题,我找到的每个线索都没有发布解决方案。
答案 0 :(得分: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
。
答案 1 :(得分:3)
我已成功编译并运行您的代码:
main2
更改为main
; 程序输出0123
: - )