Visual Studio MSB3721 error when compiling a __device__ function call from another file(从另一个文件编译 __device__ 函数调用时出现 Visual Studio MSB3721 错误)
问题描述
我正在尝试编译一个 CUDA 项目,一旦我尝试运行在单独的 .cu 文件中定义的函数,就会出现 255 错误
这是定义主内核的地方
#include <curand_kernel.h>#include <ctime>#include <stdio.h>#include "场景.cuh"__global__ void fill(float *c, Scene* 场景){整数索引 = blockIdx.y * blockDim.x * blockDim.y * gridDim.x +threadIdx.y * blockDim.x * gridDim.x +blockIdx.x * blockDim.x + threadIdx.x;//这是给出编译错误的行float3 结果 = 场景->computeRayFromIndex(index);c[索引 * 4 + 0] += 1.0f;c[索引 * 4 + 1] += 1.0f;c[索引 * 4 + 2] += 1.0f;c[索引 * 4 + 3] += 1.0f;}
这里是scene.cuh
#ifndef Scene_h#define 场景_h#include cuda_runtime.h"类场景{上市:场景();__host__ __device__ float3 computeRayFromIndex(int);整数宽度;整数高度;int 相机类型;私人的:};#万一
还有scene.cu
#include "Scene.cuh"场景::场景() {}__host__ __device__ float3 Scene::computeRayFromIndex(int pixelIndex) {float3 测试;返回测试;}
我正在使用 Visual Studio 2013,并且像往常一样从菜单中将 cuda 文件添加到我的项目中
这是编译错误
Error 10 error MSB3721: The command ""C:Program FilesNVIDIA GPU Computing ToolkitCUDAv8.0in
vcc.exe" -gencode=arch=compute_20,code="sm_20,compute_20" --use-local-env --cl-version 2013 -ccbin "C:Program Files (x86)Microsoft Visual Studio 12.0VCinx86_amd64" -I"C:Program FilesNVIDIAGPU 计算工具包CUDAv8.0include" -I"C:Program FilesNVIDIA GPU 计算工具包CUDAv8.0include" -G --keep-dir x64Debug -maxrregcount=0 --machine 64 --compile -cudart static -g -DWIN32 -DWIN64 -D_DEBUG -D_CONSOLE -D_MBCS -Xcompiler "/EHsc/W3/nologo/Od/FS/Zi/RTC1/MDd " -o x64DebugfillRandomTexture.cu.obj "D:CUDAprojectsvRayvRayfillRandomTexture.cu"" 以代码 255 退出.
如果我注释掉,项目构建并运行良好
float3 result = scene->computeRayFromIndex(index);
在主内核文件中
在CUDA中,当我们要从另一个设备代码函数中调用一个设备代码函数,而这两个设备代码函数在不同的编译单元中时,需要启用
此外,在使用 Visual Studio 和 CUDA 时,错误MSB3721"是来自 Visual Studio 的非特定错误,指示我运行 nvcc
并返回错误".但是,来自 nvcc
的实际错误应该在此之前发生.如果您在MSB3721"错误之前的编译输出窗口中没有看到它,那么您的详细级别太低了.您可以增加它,并且这样做的确切方法会因 VS 版本而略有不同,因此我建议您针对您的特定版本搜索如何做到这一点.
I'm trying to compile a CUDA project which gives a 255 error as soon as I try to run a function defined in a separate .cu file
This is where the main kernel is defined
#include <curand_kernel.h>
#include <ctime>
#include <stdio.h>
#include "Scene.cuh"
__global__ void fill(float *c, Scene* scene)
{
int index = blockIdx.y * blockDim.x * blockDim.y * gridDim.x +
threadIdx.y * blockDim.x * gridDim.x +
blockIdx.x * blockDim.x + threadIdx.x;
// this is the line which gives the compilation error
float3 result = scene->computeRayFromIndex(index);
c[index * 4 + 0] += 1.0f;
c[index * 4 + 1] += 1.0f;
c[index * 4 + 2] += 1.0f;
c[index * 4 + 3] += 1.0f;
}
Here is scene.cuh
#ifndef Scene_h
#define Scene_h
#include "cuda_runtime.h"
class Scene {
public:
Scene();
__host__ __device__ float3 computeRayFromIndex(int);
int width;
int height;
int cameraType;
private:
};
#endif
And scene.cu
#include "Scene.cuh"
Scene::Scene() {
}
__host__ __device__ float3 Scene::computeRayFromIndex(int pixelIndex) {
float3 test;
return test;
}
I'm using visual studio 2013 and I'm adding the cuda files to my project as usual from the menu
This is the compilation error
Error 10 error MSB3721: The command ""C:Program FilesNVIDIA GPU Computing ToolkitCUDAv8.0in
vcc.exe" -gencode=arch=compute_20,code="sm_20,compute_20" --use-local-env --cl-version 2013 -ccbin "C:Program Files (x86)Microsoft Visual Studio 12.0VCinx86_amd64" -I"C:Program FilesNVIDIA GPU Computing ToolkitCUDAv8.0include" -I"C:Program FilesNVIDIA GPU Computing ToolkitCUDAv8.0include" -G --keep-dir x64Debug -maxrregcount=0 --machine 64 --compile -cudart static -g -DWIN32 -DWIN64 -D_DEBUG -D_CONSOLE -D_MBCS -Xcompiler "/EHsc /W3 /nologo /Od /FS /Zi /RTC1 /MDd " -o x64DebugfillRandomTexture.cu.obj "D:CUDAprojectsvRayvRayfillRandomTexture.cu"" exited with code 255.
The project builds and runs fine if I comment out
float3 result = scene->computeRayFromIndex(index);
In the main kernel file
In CUDA, when we want to call a device code function from another device code function, and those two device code functions are in separate compilation units, it's necessary to enable relocatable device code generation and linking when compiling such a project.
In visual studio, this can be set for the entire project from the project properties page, as indicated here:
Also, when working with visual studio and CUDA, the error "MSB3721" is a non-specific error from visual studio indicating "I ran nvcc
and it returned an error". However, the actual error from nvcc
should occur prior to this. If you don't see it in the compile output window immediately prior to the "MSB3721" error, then your verbosity level is too low. You can increase it, and the exact method to do so will vary slightly by VS version so I recommend doing a search for how to do that, for your specific version.
这篇关于从另一个文件编译 __device__ 函数调用时出现 Visual Studio MSB3721 错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:从另一个文件编译 __device__ 函数调用时出现 Visual Studio MSB3721 错误
基础教程推荐
- 如何使图像调整大小以在 Qt 中缩放? 2021-01-01
- 如何在不破坏 vtbl 的情况下做相当于 memset(this, ...) 的操作? 2022-01-01
- 如何“在 Finder 中显示"或“在资源管理器中显 2021-01-01
- 管理共享内存应该分配多少内存?(助推) 2022-12-07
- 在 C++ 中循环遍历所有 Lua 全局变量 2021-01-01
- Windows Media Foundation 录制音频 2021-01-01
- 为 C/C++ 中的项目的 makefile 生成依赖项 2022-01-01
- 使用从字符串中提取的参数调用函数 2022-01-01
- 从 std::cin 读取密码 2021-01-01
- 为什么语句不能出现在命名空间范围内? 2021-01-01