问题描述
我正在尝试编译一个CUDA项目,当我尝试运行在单独的.cu文件中定义的函数时,该项目将产生255错误
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
这是定义主内核的地方
#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;
}
这是scene.cuh
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
还有scene.cu
And scene.cu
#include "Scene.cuh"
Scene::Scene() {
}
__host__ __device__ float3 Scene::computeRayFromIndex(int pixelIndex) {
float3 test;
return test;
}
我正在使用Visual Studio 2013,并且像往常一样从菜单中将cuda文件添加到我的项目中
I'm using visual studio 2013 and I'm adding the cuda files to my project as usual from the menu
这是编译错误
Error 10 error MSB3721: The command ""C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v8.0\bin\nvcc.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.0\VC\bin\x86_amd64" -I"C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v8.0\include" -I"C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v8.0\include" -G --keep-dir x64\Debug -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 x64\Debug\fillRandomTexture.cu.obj "D:\CUDA\projects\vRay\vRay\fillRandomTexture.cu"" exited with code 255.
如果我注释掉,该项目将构建并正常运行
The project builds and runs fine if I comment out
float3 result = scene->computeRayFromIndex(index);
在主内核文件中
推荐答案
在CUDA中,当我们要从另一个设备代码函数调用一个设备代码函数,并且这两个设备代码函数位于单独的编译单元中时,有必要启用可重定位的设备代码编译此类项目时生成和链接.
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.
在Visual Studio中,可以从项目属性页为整个项目进行设置,如此处:
In visual studio, this can be set for the entire project from the project properties page, as indicated here:
此外,在使用Visual Studio和CUDA时,错误"MSB3721"是Visual Studio的非特定错误,指示我运行nvcc
并且返回了错误".但是,来自nvcc
的实际错误应在此之前发生.如果您在"MSB3721"错误之前的编译输出窗口中没有看到它,则您的详细程度太低.您可以增加它,并且这样做的确切方法会因VS版本而略有不同,因此我建议针对您的特定版本进行搜索.
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错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!