CUDA 链接错误 - Visual Express 2008 - 由于(空)配置文件导致 nvcc 致命

发布于 2024-09-04 07:29:37 字数 3846 浏览 6 评论 0原文

在过去的两周里,我一直在广泛寻找可能的解决方案来解决我的错误。我已经成功安装了Cuda 64位编译器(工具)和SDK以及64位版本的Visual Studio Express 2008和带有Framework 3.5的Windows 7 SDK。我使用的是 Windows XP 64 位。我已确认 VSE 能够以 64 位进行编译,因为我使用以下网站上的步骤获得了所有可用的 64 位选项:(因为 Visual Express 本身并不包含 64 位软件包)

http://jenshuebel .wordpress.com/2009/02/12/visual-c-2008-express-edition-and-64-bit-targets/

64 位安装的注册表更新可在用户评论中找到页面如上面的链接。

我已经确认了 64 位编译能力,因为“x64”可从“工具 -> 选项 -> VC++ 目录”下的下拉菜单中找到,并且在 64 位中编译不会导致整个项目为“跳过”。我已经包含了 64 位 cuda 工具、64 SDK 和 Visual Express (\VC\bin\amd64) 所需的所有目录。

这是我尝试在 64 位中编译时收到的错误消息:

1>------ Build started: Project: New, Configuration: Release x64 ------
1>Compiling with CUDA Build Rule...
1>"C:\CUDA\bin64\nvcc.exe"    -arch sm_10 -ccbin "C:\Program Files (x86)\Microsoft    Visual Studio 9.0\VC\bin"    -Xcompiler "/EHsc /W3 /nologo /O2 /Zi   /MT  "  -maxrregcount=32  --compile -o "x64\Release\template.cu.obj" "c:\Documents and Settings\All Users\Application Data\NVIDIA Corporation\NVIDIA GPU Computing SDK\C\src\CUDA_Walkthrough_DeviceKernels\template.cu" 
1>nvcc fatal   : Visual Studio configuration file '(null)' could not be found for installation at 'C:/Program Files (x86)/Microsoft Visual Studio 9.0/VC/bin/../..'
1>Linking...
1>LINK : fatal error LNK1181: cannot open input file '.\x64\Release\template.cu.obj'
1>Build log was saved at "file://c:\Documents and Settings\Administrator\My Documents\Visual Studio 2008\Projects\New\New\x64\Release\BuildLog.htm"
1>New - 1 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

这是我尝试在 64 位中编译/运行的简单代码:

#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <math.h>

#include <cuda.h>

void mypause () 
{ 
  printf ( "Press [Enter] to continue . . ." );
  fflush ( stdout );
  getchar();
} 

__global__ void VecAdd1_Kernel(float* A, float* B, float* C, int N)
{
 int i = blockDim.x*blockIdx.x+threadIdx.x;
 if (i<N)
  C[i] = A[i] + B[i]; //result should be a 16x1 array of 250s
} 

__global__ void VecAdd2_Kernel(float* B, float* C, int N)
{
 int i = blockDim.x*blockIdx.x+threadIdx.x;
 if (i<N)
  C[i] = C[i] + B[i]; //result should be a 16x1 array of 400s
}

int main()
{
 int N = 16;
 float A[16];float B[16];
 size_t size = N*sizeof(float);

 for(int i=0; i<N; i++) 
 {
  A[i] = 100.0;
  B[i] = 150.0;
 }

 // Allocate input vectors h_A and h_B in host memory
 float* h_A = (float*)malloc(size);
        float* h_B = (float*)malloc(size);
        float* h_C = (float*)malloc(size);

 //Initialize Input Vectors
 memset(h_A,0,size);memset(h_B,0,size);
 h_A = A;h_B = B;

 printf("SUM = %f\n",A[1]+B[1]); //simple check for initialization

 //Allocate vectors in device memory
 float* d_A;
 cudaMalloc((void**)&d_A,size);
 float* d_B;
 cudaMalloc((void**)&d_B,size);
 float* d_C;
 cudaMalloc((void**)&d_C,size);

 //Copy vectors from host memory to device memory
 cudaMemcpy(d_A,h_A,size,cudaMemcpyHostToDevice);
 cudaMemcpy(d_B,h_B,size,cudaMemcpyHostToDevice);

 //Invoke kernel
 int threadsPerBlock = 256;
 int blocksPerGrid = (N+threadsPerBlock-1)/threadsPerBlock;
 VecAdd1(blocksPerGrid, threadsPerBlock,d_A,d_B,d_C,N);
 VecAdd2(blocksPerGrid, threadsPerBlock,d_B,d_C,N);

 //Copy results from device memory to host memory
 //h_C contains the result in host memory
 cudaMemcpy(h_C,d_C,size,cudaMemcpyDeviceToHost);

 for(int i=0; i<N; i++) //output result from the kernel "VecAdd"
 {
  printf("%f ", h_C[i] );
  printf("\n");
 }
 printf("\n");

 cudaFree(d_A); 
 cudaFree(d_B); 
 cudaFree(d_C);
 free(h_A);
 free(h_B);
 free(h_C);

 mypause();
 return 0;
}

I've been searching extensively for a possible solution to my error for the past 2 weeks. I have successfully installed the Cuda 64-bit compiler (tools) and SDK as well as the 64-bit version of Visual Studio Express 2008 and Windows 7 SDK with Framework 3.5. I'm using windows XP 64-bit. I have confirmed that VSE is able to compile in 64-bit as I have all of the 64-bit options available to me using the steps on the following website: (since Visual Express does not inherently include the 64-bit packages)

http://jenshuebel.wordpress.com/2009/02/12/visual-c-2008-express-edition-and-64-bit-targets/

The registry updates for 64-bit installation are found in a user comment on the same page as the above link.

I have confirmed the 64-bit compile ability since the "x64" is available from the pull-down menu under "Tools->Options->VC++ Directories" and compiling in 64-bit does not result in the entire project being "skipped". I have included all the needed directories for 64-bit cuda tools, 64 SDK and Visual Express (\VC\bin\amd64).

Here's the error message I receive when trying to compile in 64-bit:

1>------ Build started: Project: New, Configuration: Release x64 ------
1>Compiling with CUDA Build Rule...
1>"C:\CUDA\bin64\nvcc.exe"    -arch sm_10 -ccbin "C:\Program Files (x86)\Microsoft    Visual Studio 9.0\VC\bin"    -Xcompiler "/EHsc /W3 /nologo /O2 /Zi   /MT  "  -maxrregcount=32  --compile -o "x64\Release\template.cu.obj" "c:\Documents and Settings\All Users\Application Data\NVIDIA Corporation\NVIDIA GPU Computing SDK\C\src\CUDA_Walkthrough_DeviceKernels\template.cu" 
1>nvcc fatal   : Visual Studio configuration file '(null)' could not be found for installation at 'C:/Program Files (x86)/Microsoft Visual Studio 9.0/VC/bin/../..'
1>Linking...
1>LINK : fatal error LNK1181: cannot open input file '.\x64\Release\template.cu.obj'
1>Build log was saved at "file://c:\Documents and Settings\Administrator\My Documents\Visual Studio 2008\Projects\New\New\x64\Release\BuildLog.htm"
1>New - 1 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

Here's the simple code I'm trying to compile/run in 64-bit:

#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <math.h>

#include <cuda.h>

void mypause () 
{ 
  printf ( "Press [Enter] to continue . . ." );
  fflush ( stdout );
  getchar();
} 

__global__ void VecAdd1_Kernel(float* A, float* B, float* C, int N)
{
 int i = blockDim.x*blockIdx.x+threadIdx.x;
 if (i<N)
  C[i] = A[i] + B[i]; //result should be a 16x1 array of 250s
} 

__global__ void VecAdd2_Kernel(float* B, float* C, int N)
{
 int i = blockDim.x*blockIdx.x+threadIdx.x;
 if (i<N)
  C[i] = C[i] + B[i]; //result should be a 16x1 array of 400s
}

int main()
{
 int N = 16;
 float A[16];float B[16];
 size_t size = N*sizeof(float);

 for(int i=0; i<N; i++) 
 {
  A[i] = 100.0;
  B[i] = 150.0;
 }

 // Allocate input vectors h_A and h_B in host memory
 float* h_A = (float*)malloc(size);
        float* h_B = (float*)malloc(size);
        float* h_C = (float*)malloc(size);

 //Initialize Input Vectors
 memset(h_A,0,size);memset(h_B,0,size);
 h_A = A;h_B = B;

 printf("SUM = %f\n",A[1]+B[1]); //simple check for initialization

 //Allocate vectors in device memory
 float* d_A;
 cudaMalloc((void**)&d_A,size);
 float* d_B;
 cudaMalloc((void**)&d_B,size);
 float* d_C;
 cudaMalloc((void**)&d_C,size);

 //Copy vectors from host memory to device memory
 cudaMemcpy(d_A,h_A,size,cudaMemcpyHostToDevice);
 cudaMemcpy(d_B,h_B,size,cudaMemcpyHostToDevice);

 //Invoke kernel
 int threadsPerBlock = 256;
 int blocksPerGrid = (N+threadsPerBlock-1)/threadsPerBlock;
 VecAdd1(blocksPerGrid, threadsPerBlock,d_A,d_B,d_C,N);
 VecAdd2(blocksPerGrid, threadsPerBlock,d_B,d_C,N);

 //Copy results from device memory to host memory
 //h_C contains the result in host memory
 cudaMemcpy(h_C,d_C,size,cudaMemcpyDeviceToHost);

 for(int i=0; i<N; i++) //output result from the kernel "VecAdd"
 {
  printf("%f ", h_C[i] );
  printf("\n");
 }
 printf("\n");

 cudaFree(d_A); 
 cudaFree(d_B); 
 cudaFree(d_C);
 free(h_A);
 free(h_B);
 free(h_C);

 mypause();
 return 0;
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

岁月打碎记忆 2024-09-11 07:29:37

我通过

  1. 安装 Windows SDK 解决了这个问题(不要忘记为 64 位操作系统选择所有 x64 选项),
  2. 中包含“c:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\bin\amd64”
  3. 在 PATH创建文件 vcvars64 目录“c:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\bin\amd64”内的 .bat 包含以下内容:
    调用 "C:\Program Files\Microsoft SDKs\Windows\v7.1\Bin\SetEnv.cmd" /x64

注意:我这样做是因为:

  1. 我使用的是 VC++ Express 2010
  2. 我在任何目录中都没有“vcvars64.bat”? ?

I solved the problem by

  1. installing Windows SDK (don't forget to choose all x64 options for 64 bit OS)
  2. include "c:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\bin\amd64" in PATH
  3. create file vcvars64.bat inside directory "c:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\bin\amd64" with following content:
    call "C:\Program Files\Microsoft SDKs\Windows\v7.1\Bin\SetEnv.cmd" /x64

Note: I did this because:

  1. I am using VC++ Express 2010
  2. I dont have "vcvars64.bat" in any directory ??
苦妄 2024-09-11 07:29:37

更新 06/04/2010:

好的,我找到了问题的解决方案。代码没问题。按照上面原始链接中的步骤操作并添加所需的注册表项后,通过从开始菜单启动 Windows SDK 配置工具,确保 Windows SDK 面向正确的版本 (7.0),选择正确的版本 (v7.0),并单击“设为当前”。

确保包含以下用于 x64 编译的目录(在“工具 -> 选项 -> 项目和解决方案 -> VC++ 目录”下):
C:\CUDA\bin64
C:\CUDA\lib64
C:\CUDA\包含
C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\bin\amd64

现在,对于 64 位系统,还有一件事需要更改。显然,cuda 编译器在 Visual Express 2008 上有一个针对 64 位编译器的“硬编码”目录。要进行修复,请复制所需的文件“vcvars64.bat”并将其重命名为“vcvarsamd64.bat”,如下所示:

C: \Program Files (x86)\Microsoft Visual Studio 9.0\VC\bin\vcvars64.bat

C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\bin\amd64\vcvarsamd64.bat

更改后,程序编译并成功运行。

我已经在网络上阅读了“其他”帖子,以了解错误的其他解决方案:“nvcc fatal:Visual Studio 配置文件 '(null)'”,但很少有人将上述内容指定为让 nvcc 找到必要的 Visual Studio 配置文件。

免责声明:我安装到干净的机器和操作系统。

希望这可以帮助其他有类似问题的人。

UPDATE 06/04/2010:

Ok, I found the solution to the problem. The code is fine. After following the steps from the original link above and adding in the needed registry key make sure that Windows SDK is targeting the correct version (7.0) by launching the Windows SDK Configuration Tool from start menu, choose the right version (v7.0), and click "Make Current".

Make sure to include the following directories for x64 compiling (under "Tools->Options->Projects And Solutions->VC++ Directories):
C:\CUDA\bin64
C:\CUDA\lib64
C:\CUDA\include
C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\bin\amd64

Now there's one other thing to change for a 64-bit system. Apparently the cuda compiler has a "hard-coded" directory for 64-bit compilers on Visual Express 2008. To make the fix, copy the needed file "vcvars64.bat" and rename it to "vcvarsamd64.bat" as follows:

C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\bin\vcvars64.bat

to

C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\bin\amd64\vcvarsamd64.bat

Upon the change, the program compiled and ran successfully.

I've read 'other' postings all over the web for other solutions to the error: "nvcc fatal: Visual Studio configuration file '(null)'", but very few have specified the above as a requirement to get nvcc to find the necessary visual studio configuration file.

Disclaimer: I installed to a clean machine and OS.

Hopefully this helps others with similar problems.

习惯成性 2024-09-11 07:29:37

相同的错误消息,但解决方案又不同。我试图在 64 位机器上编译 32 位 CUDA 库。
我必须将 --machine 32 参数添加到 nvcc 调用中,正如 Imperian 在评论中所建议的那样:从命令提示符编译 CUDA 时出错

希望这对某人有帮助

Same error message, but different solution yet again. I was trying to compile 32 bits CUDA libs on a 64bits machine.
I had to add --machine 32 argument to nvcc call, as suggested by Imperian in a comment, here : Error compiling CUDA from Command Prompt

in hope this helps someone

难忘№最初的完美 2024-09-11 07:29:37

我发现我还必须更改 CUDA_PATH 和 CUDA_LIB_PATH 环境变量,因为它们指向 x86 工具链(我在 x64 工具之后安装了它)。

经过一些链接器错误的处理后,我成功构建了一个 x64 CUDA 应用程序!

I found that I also had to change the CUDA_PATH and CUDA_LIB_PATH environment variables, because they were pointing to the x86 toolchain (which I had installed after the x64 tools).

After some faffing around with some linker errors, I managed to build a x64 CUDA app!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文