从命令行运行nvcc时出现问题

问题描述 投票:6回答:2

我需要从命令行使用nvcc编译cuda .cu文件。该文件是“vectorAdd_kernel.cu”并包含以下代码:

extern "C" __global__ void VecAdd_kernel(const float* A, const float* B, float* C, int N)
{
    int i = blockDim.x * blockIdx.x + threadIdx.x;
    if (i < N)
        C[i] = A[i] + B[i];
}

我使用以下命令(我需要获取.cubin文件):

nvcc --cubin --use-local-env --cl-version 2010 -keep -I "C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include" vectorAdd_kernel.cu

编译器创建文件vectorAdd_kernel.cpp4.ii和vectorAdd_kernel.cpp1.ii然后它使用以下输出停止:

C:\Users\Massimo\Desktop\Pluto>nvcc --cubin --use-local-env --cl-version 2010 vectorAdd_kernel.cu -keep -I "C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include"

vectorAdd_kernel.cu

vectorAdd_kernel.cu

c:\program files (x86)\microsoft visual studio 10.0\vc\include\codeanalysis\sourceannotations.h(29): error: invalid redeclaration of type name "size_t"

C:/Program Files (x86)/Microsoft Visual Studio 10.0/VC/include\new(51): error: first parameter of allocation function must be of type "size_t"

C:/Program Files (x86)/Microsoft Visual Studio 10.0/VC/include\new(55): error: first parameter of allocation function must be of type "size_t"

你能帮我解决这个问题吗?

干杯,

马西莫

visual-c++ cuda nvcc
2个回答
3
投票

我刚刚在Visual Studio 2017和Cuda v9.0中尝试使用nvcc从命令行编译。经过漫长的会议后,我意识到我的Visual Studio命令行工具设置为使用cl.exe导演的x86而不是x64。有许多方法可以解决它,一种方法是覆盖它查找其编译器工具的目录 - 例如:

nvcc -ccbin "C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\VC\Tools\MSVC\14.11.25503\bin\HostX86\x64"  -o add_cuda add_cuda.cu

它工作得很好。

我还要提到我使用git工具中的which.exe实用程序来确定它访问的cl.exe的版本,但where命令 - 原生于windows - 也可以。

Update:

处理此问题的另一种方法 - 可能是更好的方法 - 只需将Visual Studio环境变量正确设置为64位,就像企业版一样:

"C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\VC\Auxiliary\Build\vcvarsall.bat" x64

对于社区版,在路径中用“社区”代替“企业”。

您还可以使用(例如)--vcvars_ver=14.0选择工具集,该工具集选择14.0工具集,这是使用15.5版本的Visual Studio编译CUDA 9.1所必需的。

然后你可以用这个简单地构建:

nvcc  -o add_cuda add_cuda.cu

2
投票

我有类似的问题。

SourceAnnotations.h中构建中断的代码:

#ifdef  _WIN64
typedef unsigned __int64    size_t;
#else
typedef _W64 unsigned int   size_t;
#endif

我已经用这个_WIN64添加了--compiler-options "-D _WIN64"编译器符号。我的nvcc构建字符串看起来像这样:

nvcc kernel.cu --cubin --compiler-options "-D _WIN64"
© www.soinside.com 2019 - 2024. All rights reserved.