我正在写一个 CUDA Raytracer,似乎遇到了一个奇怪的问题。我在我的 Mac OS X 上使用 CUDA 5.5 和 GCC4.2.1,并且正在使用 GLM 0.9.4.4。每当我调用我的 raycastFromCameraKernel 函数时,我都会收到此错误:
Cuda 错误:内核失败!:操作系统调用失败或此操作系统不支持操作。
经过一些调试,我想我已经将问题缩小到glm::normalize(temp)
功能上。如果我通过编写自己的 normalize 函数来代替它,则代码可以正常工作。有趣的是,当我使用 glm::normalize 编写示例程序以查看它是否正常工作时,它编译并正常运行!
这是有问题的函数的代码:
__host__ __device__ ray raycastFromCameraKernel(glm::vec2 resolution, float time, int x, int y, glm::vec3 eye, glm::vec3 view, glm::vec3 up, glm::vec2 fov)
{
glm::vec3 eyePoint = eye;
glm::vec3 V = up;
glm::vec3 W = view;
glm::vec3 U = glm::cross(V,W); // Perter Sherley page 74 (Creating orthonormal vectors)
float fovY = fov.y;
//d is the near clip plane
float distance = (resolution.y / 2.0f) / tan(fovY);
float left = -resolution.x/2;
float right = resolution.x/2;
float top = resolution.y/2;
float bottom = -resolution.y/2;
float u = left + (right - left)*(x + 0.5)/resolution.x;
float v = bottom + (top - bottom)*(y + 0.5)/resolution.y;
ray r;
r.origin = eyePoint;
glm::vec3 temp = -1*distance*W + u*U + v*V;
r.direction = glm::normalize(temp);
return r;
}
有人可以帮忙吗?