title: CUDA errors: identifier "(global/device)" is undefined, no suitable conversion,
body: <p>Im doing a project on Photon mapping. I coded raytracer part and it ran successfully on CPU. Now im doing the same on GPU(through ssh).</p>
  
  <p>im getting the following errors</p>
  
  <blockquote>
  <pre><code>    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
  </code></pre>
    
    <p>"Float3" to "void *" exists</p>
  
  <pre><code>gpuRayTracer.cu(55): error: no suitable conversion function from
  </code></pre>
    
    <p>"Float3" to "void *" exists</p>
  
  <pre><code>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
  </code></pre>
    
    <p><strong>device</strong>/_<em>global</em>_ function is not allowed</p>
  
  <pre><code>gpuRayTracer.cu(90): error: identifier "GPUmul" is undefined
  
  gpuRayTracer.cu(95): error: calling a host function from a
  </code></pre>
    
    <p><strong>device</strong>/_<em>global</em>_ function is not allowed</p>
  
  <pre><code>gpuRayTracer.cu(95): error: identifier "GPUadd" is undefined
  
  gpuRayTracer.cu(192): error: calling a host function from a
  </code></pre>
    
    <p><strong>device</strong>/_<em>global</em>_ function is not allowed</p>
  
  <pre><code>15 errors detected in the compilation of
  </code></pre>
    
    <p>"/tmp/tmpxft_0000432c_00000000-4_gpuRayTracer.cpp1.ii"
        .
        make: <em>*</em> [gpuRayTracer.o] Error 2</p>
  </blockquote>
  
  <p><strong><em>gpuRayTracer.cu</em></strong>
   line 44,53, 55(errors) are marked in the below code</p>
  
  <p>Float3 used below is a structure containing 3 float variables(x,y,z coordinates)</p>
  
  <pre><code>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(&amp;d_eye,size1);
  cudaMalloc(&amp;d_lookAt,size1);
  cudaMemcpy(d_eye,&amp;this-&gt;eye,size1,cudaMemcpyHostToDevice);
  
  cudaMemcpy(d_lookAt,&amp;this-&gt;lookAt,size1,cudaMemcpyHostToDevice);
  
  
  cudaMalloc(&amp;d_objectCount,size2);
  cudaMemcpy(d_objectCount,&amp;this-&gt;objectCount,size2,cudaMemcpyHostToDevice);
  
  
  
  cudaMalloc(&amp;d_Width,size2);
  cudaMalloc(&amp;d_Height,size2);
  cudaMemcpy(d_Width,&amp;this-&gt;screenWidth,size2,cudaMemcpyHostToDevice);
  
  cudaMemcpy(d_Height,&amp;this-&gt;screenHeight,size2,cudaMemcpyHostToDevice);
  
  
  cudaMalloc(&amp;d_pixels,size3);
  cudaMemcpy(d_pixels,&amp;this-&gt;pixels,size3,cudaMemcpyHostToDevice);
  
  
  cudaMalloc((void **)&amp;d_objectList,
  (sizeof(this-&gt;objectList)));
  cudaMemcpy(d_objectList,
  &amp;this-&gt;objectList,
  sizeof(this-&gt;objectList),cudaMemcpyHostToDevice);
  
  line 44:raytracer&lt;&lt;&lt;1,500&gt;&gt;&gt;(d_pixels,d_Width,d_Height,
  d_objectList,d_eye,d_lookAt);
  
  cudaMemcpy((this-&gt;objectList),&amp;d_objectList,sizeof(this-
  &gt;objectList),cudaMemcpyDeviceToHost);
  cudaMemcpy(this-&gt;pixels,&amp;d_pixels,size3,cudaMemcpyDeviceToHost);
  
  
  cudaMemcpy((int *)this-&gt;screenWidth,&amp;d_Width,size2,cudaMemcpyDeviceToHost);
  
  cudaMemcpy((int *)this-&gt;screenHeight,&amp;d_Height,size2,cudaMemcpyDeviceToHost);
  
  cudaMemcpy((int *)this-&gt;objectCount,&amp;d_objectCount,size2,cudaMemcpyDeviceToHost);
  
  cudaMemcpy(
  
  
  line:53   (void *)this-&gt;eye,
  (void *)&amp;d_eye,sizeof(d_eye),cudaMemcpyDeviceToHost);
  line:55  cudaMemcpy(this-&gt;lookAt,(void *)&amp;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&lt;b)
          return a;
  
  return b;
  
  
  }
  
  
  
  __device__ float GPUffmaxf(float a, float b){
  
  
          if(a&gt;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;
  
  }
  </code></pre>
  
  <p>wats wrong in the code??</p>
  
  <p>apart from this i have few questions</p>
  
  <p>*<strong>The order in which .cu/.cpp files are compiled..is it matter??
  *Should the kernel be invoked only from main.cpp??
  *If so, should a .cu file consists of only global/device functions ??</strong> </p>