【问题标题】:CUDA errors: identifier "(global/device)" is undefined, no suitable conversion,CUDA 错误:标识符“(全局/设备)”未定义,没有合适的转换,
【发布时间】:2011-02-20 11:10:58
【问题描述】:

我正在做一个关于光子映射的项目。我编写了光线追踪器部分,它在 CPU 上成功运行。现在我在 GPU 上做同样的事情(通过 ssh)。

我收到以下错误

    nvcc -c -lSDL -lGL -lGLU AntTweakBar.a gpuRayTracer.cu
gpuRayTracer.cu(44): error: identifier "raytracer" is undefined

gpuRayTracer.cu(53): error: no suitable conversion function from

“Float3”到“void *”存在

gpuRayTracer.cu(55): error: no suitable conversion function from

“Float3”到“void *”存在

gpuRayTracer.cu(76): error: identifier "GPUsub" is undefined

gpuRayTracer.cu(77): error: identifier "GPUnormalize" is undefined

gpuRayTracer.cu(78): error: identifier "GPUcross" is undefined

gpuRayTracer.cu(80): error: calling a host function from a

设备/_全局_函数不允许

gpuRayTracer.cu(90): error: identifier "GPUmul" is undefined

gpuRayTracer.cu(95): error: calling a host function from a

设备/_全局_函数不允许

gpuRayTracer.cu(95): error: identifier "GPUadd" is undefined

gpuRayTracer.cu(192): error: calling a host function from a

设备/_全局_函数不允许

15 errors detected in the compilation of

"/tmp/tmpxft_0000432c_00000000-4_gpuRayTracer.cpp1.ii" . make: * [gpuRayTracer.o] 错误 2

gpuRayTracer.cu 第 44,53、55 行(错误)标记在下面的代码中

下面使用的Float3是一个包含3个浮点变量(x,y,z坐标)的结构

void Scene::GPUrayTracer(){

Object *d_objectList[OBJ_MAX];
GLubyte         * d_pixels;
int *d_Width, *d_Height;
Float3 *d_eye,*d_lookAt;
int *d_objectCount;
size_t size1=sizeof(Float3);
size_t size2=sizeof(int);
size_t size3=sizeof(GLubyte);
//size_t size4=sizeof(Object);

cudaMalloc(&d_eye,size1);
cudaMalloc(&d_lookAt,size1);
cudaMemcpy(d_eye,&this->eye,size1,cudaMemcpyHostToDevice);

cudaMemcpy(d_lookAt,&this->lookAt,size1,cudaMemcpyHostToDevice);


cudaMalloc(&d_objectCount,size2);
cudaMemcpy(d_objectCount,&this->objectCount,size2,cudaMemcpyHostToDevice);



cudaMalloc(&d_Width,size2);
cudaMalloc(&d_Height,size2);
cudaMemcpy(d_Width,&this->screenWidth,size2,cudaMemcpyHostToDevice);

cudaMemcpy(d_Height,&this->screenHeight,size2,cudaMemcpyHostToDevice);


cudaMalloc(&d_pixels,size3);
cudaMemcpy(d_pixels,&this->pixels,size3,cudaMemcpyHostToDevice);


cudaMalloc((void **)&d_objectList,
(sizeof(this->objectList)));
cudaMemcpy(d_objectList,
&this->objectList,
sizeof(this->objectList),cudaMemcpyHostToDevice);

line 44:raytracer<<<1,500>>>(d_pixels,d_Width,d_Height,
d_objectList,d_eye,d_lookAt);

cudaMemcpy((this->objectList),&d_objectList,sizeof(this-
>objectList),cudaMemcpyDeviceToHost);
cudaMemcpy(this->pixels,&d_pixels,size3,cudaMemcpyDeviceToHost);


cudaMemcpy((int *)this->screenWidth,&d_Width,size2,cudaMemcpyDeviceToHost);

cudaMemcpy((int *)this->screenHeight,&d_Height,size2,cudaMemcpyDeviceToHost);

cudaMemcpy((int *)this->objectCount,&d_objectCount,size2,cudaMemcpyDeviceToHost);

cudaMemcpy(


line:53   (void *)this->eye,
(void *)&d_eye,sizeof(d_eye),cudaMemcpyDeviceToHost);
line:55  cudaMemcpy(this->lookAt,(void *)&d_lookAt,sizeof(d_lookAt),cudaMemcpyDeviceToHost);


}



__global__ void raytracer( unsigned char *out_data,const int screenWidth,const int screenHeight,Object * objectList,Float3 eye,Float3 lookAt,int objectCount)
{
int x = blockDim.x * BLOCK_SIZE + threadIdx.x;
        int y = blockDim.y * BLOCK_SIZE + threadIdx.y;

        [b]//code goes here[/b]
}

__device__ float GPUffminf(float a, float b){



if(a<b)
        return a;

return b;


}



__device__ float GPUffmaxf(float a, float b){


        if(a>b)

        return a;

return b;

}





__device__ float GPUmag(Float3 a){

float res;

res=a.x*a.x+a.y*a.y+a.z*a.z;

res=sqrt(res);

return res;

}



__device__ Float3 GPUnormalize(Float3 a){

Float3 res;

float magn=mag(a);

if(magn!=0){

magn=(float)1.0/magn;

res.x=a.x*magn;

res.y=a.y*magn;

res.z=a.z*magn;

return res;

}

return a;



}

__device__ Float3 GPUcross(Float3 a ,Float3 b){

Float3 res;

res.x=a.y*b.z-a.z*b.y;

res.y=a.z*b.x-a.x*b.z;

res.z=a.x*b.y-a.y*b.x;

return res;

}

__device__  float GPUdot(Float3 a,Float3 b){

return (float)(a.x*b.x + a.y*b.y + a.z*b.z);

}



__device__  Float3 GPUsub(Float3 a,Float3 b){

Float3 res;

res.x=a.x-b.x;

res.y=a.y-b.y;

res.z=a.z-b.z;

return res;

}

__device__ Float3 GPUadd(Float3 a,Float3 b){

Float3 res;

res.x=a.x+b.x;

res.y=a.y+b.y;

res.z=a.z+b.z;

return res;

}





__device__ Float3 GPUmul(Float3 a,float b){

Float3 res;

res.x=a.x*b;

res.y=a.y*b;

res.z=a.z*b;

return res;

}

代码有问题吗??

除此之外我还有几个问题

*.cu/.cpp文件的编译顺序..有关系吗?? *是否应该只从 main.cpp 调用内核?? *如果是这样,.cu 文件应该只包含全局/设备函数吗?

【问题讨论】:

  • 首先,首先在文件顶部定义所有设备功能的原型,如下所示:“__global__ void raytracer(unsigned char,int,int,Object*,Float3,Float3,int) ;"

标签: cuda device global


【解决方案1】:

好的,首先,你可以放任何 .cu 文件中的 C/C++ 函数 其他 比全局/设备功能。两者都不 编译顺序是否重要。

  1. 对于这个错误:没有合适的转换函数从“Float3”到 “无效*”存在

    你需要做 (无效**)

而不是

(无效*)

对于此类错误:gpuRayTracer.cu(76): error: identifier

“GPUsub”未定义

你需要定义 GPUsub 函数 在调用它的函数之前 .cu 文件。只需移动功能 文件顶部的定义。

对于这样的错误:从设备/全局函数调用主机函数不是 允许

好的,你不能调用任何函数 在 CPU 上执行(没有 deviceglobal 标识符)来自设备或全局函数。

这是你需要做的 生活轻松。

在单独的 .cu 中定义每个函数 文件并为其使用头文件 减速。你应该有一个主机 执行所有的函数 管道,它可以调用 gpu 以及 cpu 函数。

【讨论】:

    猜你喜欢
    • 2020-10-21
    • 1970-01-01
    • 2013-10-05
    • 1970-01-01
    • 2014-06-05
    • 2015-05-12
    • 2012-02-26
    • 2011-10-23
    相关资源
    最近更新 更多