2011-02-20 3 views
0

광자 매핑에 관한 프로젝트를 수행 중입니다. raytracer 부분을 코딩했고 CPU에서 성공적으로 실행되었습니다. 이제 GPU (ssh를 통해)에서 동일한 작업을 수행합니다.CUDA 오류 : "(글로벌/장치)"식별자가 정의되지 않았으며 적절한 변환이 없습니다.

IM지고 다음의 에러

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" to "void *" exists

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

"Float3" to "void *" exists

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 

device/_global_ function is not allowed

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

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

device/_global_ function is not allowed

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

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

device/_global_ function is not allowed

15 errors detected in the compilation of 

"/tmp/tmpxft_0000432c_00000000-4_gpuRayTracer.cpp1.ii" . make: * [gpuRayTracer.o] Error 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; 

} 

코드에서 잘못된 wats ??

는이 외에도에서 나는 몇 가지 질문

* .CU/.CPP 파일이 문제가 compiled..is이되는 순서가 ?? * main.cpp에서만 커널을 호출해야합니까 ?? * 그렇다면 .cu 파일은 전역/장치 기능으로 만 구성되어야합니까 ?? gpuRayTracer.cu (76) : 오류 :

+0

1 식별자, 장치의 모든 기능에 대한 프로토 타입을 정의함으로써 시작 "\ _ \ _ global \ _ \ _ void raytracer (unsigned char, int, int, Object *, Float3, Float3, int);" –

답변

1

Okay first of all, you can put any C/C++ function in .cu files other than global/device functions. Neither does the order of compilation matter.

  1. For this error: no suitable conversion function from "Float3" to "void *" exists

    you need to do (void**)

대신에 이런 오류의

(void*)

"GPUsub" is undefined

you need to define GPUsub function before the functions that calls it in the .cu file. Just move the function definition on top of the file.

For errors like this: calling a host function from a device/global function is not allowed

okay, you can't call any function that executes on CPU (doesn't have a device or global identifier in it) from a device or global function.

Here's what you need to do to make life easy.

Define each function in a separate .cu file and use header file for their decelerations. You should have one HOST function that executes all the pipeline, it can call gpu as well as cpu functions.

관련 문제