构造函数调用时出现GLM cuda错误

GLM cuda error on constructor call

本文关键字:GLM cuda 错误 函数调用      更新时间:2023-10-16

已解决

我正在尝试创建一个使用GLM数学库的CUDA程序。我有一个相机和光线的类/结构定义为:

class Camera
{
public:
    vec3 pos;
    vec3 lookat;
    vec3 up;
    float fov;
    Camera(vec3& p, vec3& la, vec3& u, float f) : pos(p), lookat(la), up(u), fov(f) {}
    Camera() : pos(vec3(0.0f, 0.0f, 10.0f)), lookat(vec3(0.0f, 0.0f, -1.0f)), up(vec3(0.0f, 1.0f, 0.0f)), fov(60.0f*0.0174532925f) {}
};
typedef struct Ray
{
    vec3 pos;
    vec3 dir;
    __device__ __host__ Ray(vec3& p, vec3& d) : pos(p), dir(d) {}
    __device__ __host__ Ray() {}
} Ray;

当我试图创建一个使用相机和光线的函数时,问题来了:

__device__ __host__ void calculateRay(int x, int y, int width, int height, Camera& camera)
{
float xoff = (x + 0.5f) / width;
float yoff = ((height - y) + 0.5f) / height;
vec3 dir = normalize(camera.lookat);
vec3 right = normalize(cross(dir, camera.up)) * (xoff - 0.5f);
vec3 down = -camera.up * (yoff - 0.5f);
dir += down + right;
vec3 rayDir = normalize(dir);
Ray ray(camera.pos, rayDir); //Error here
/*
Ray ray;
ray.pos.x = camera.pos.x;
ray.pos.y = camera.pos.y;
ray.pos.z = camera.pos.z;
ray.dir.x = rayDir.x;
ray.dir.y = rayDir.y;
ray.dir.z = rayDir.z;
*/
}

如果我注释掉"Ray Ray(camera.pos,rayDir(;"这一行,它编译得很好。如果我把它注释掉并取消注释下面的部分,它也会编译

编译器给出的错误是

error MSB3721: The command ""F:devCUDAbinnvcc.exe" 
-gencode=arch=compute_50,code="sm_52,compute_50" --use-local-env 
--cl-version 2013 -ccbin "F:programsMicrosoft Visual Studio 12.0VCbin"  
-IG:oldthingsincludeglm -IF:devCUDAinclude -IF:devCUDAinclude  
-G   --keep-dir Debug -maxrregcount=0  --machine 32 --compile 
-cudart static  -g   -DWIN32 -D_DEBUG -D_CONSOLE -D_MBCS -Xcompiler 
"/EHsc /W3 /nologo /Od /Zi /RTC1 /MDd " -o Debugkernel.cu.obj 
"C:UsersaDocumentsVisual Studio 2013ProjectsRayTracerkernel.cu""
 exited with code 255.

虽然我似乎找不到任何关于错误代码255 的原因

编辑:已解决-原来是由GLM中的一个错误引起的,返回9.6.2版本修复了这个问题。

这个问题是由GLM中的一个错误引起的,回到9.6.2版本为我修复了这个问题。它也应该在最新版本(此时为9.7.1(中修复。