Hi,
sorry to disturb you, but I need your help. I have a .cc file and I want to use a cuda function in this file.
Here is the code:
//Sphere.cc
#include "Sphere.hh"
#include <float.h>
#include <cuda.h>
#include <cuda_runtime_api.h>
#include <vector_types.h>
#include <vector_functions.h>
__global__ void intersect(float *a,double radius, Vec3d direction, Vec3d origin, Vec3d center)
{
a[0]=0.0;
Vec3d roc =(origin-center);
// | compute scalar product with another vector of same type (siehe VectorT.hh);
double z= -(roc|direction);
//pow returns base raised to the power exponent:
double d= pow( -z, 2.0)-((roc|roc) - (radius*radius));
if(d>0.0){
if((z-sqrt(d))>1e-5)
{
a[0]=1.0;
}
}
else
a[0]=0.0;
}
bool
Sphere::
intersect(const Scene::Ray& _ray,
Vec3d& _intersection,
Vec3d& _normal,
double& _t ) const
{
const int bla =1;
float *a_h, *a_d;
size_t size = bla * sizeof(float);
a_h = (float *)malloc(size); // Allocate array on host
cudaMalloc((void **) &a_d, size); // Allocate array on device
// Initialize host array and copy it to CUDA device
for (int i=0; i<bla; i++) a_h[i] = (float)i;
cudaMemcpy(a_d, a_h, size, cudaMemcpyHostToDevice);
dim3 block(8);
dim3 grid(8);
intersect<<<grid,block>>>(a_d,radius,_ray.direction,_ray.origin,center);
cudaMemcpy(a_h, a_d, sizeof(float)*bla, cudaMemcpyDeviceToHost);
if(a_h[0]==1.0){
return true;
}
else return false;
//free(a_h);
cudaFree(a_d);
}
The problem is, that the compiler dosnt acept the intersect<<<grid,block>>>(a_d,radius,_ray.direction,_ray.origin,center); line.
Do you know, how to solve this?
Here the output from the commandline:
[i]
g++ -I/usr/local/cuda/include -Wall -O3 -funroll-loops -DNDEBUG -fopenmp -MMD -MF release/Mesh.d -c Mesh.cc -o release/Mesh.o
g++ -I/usr/local/cuda/include -Wall -O3 -funroll-loops -DNDEBUG -fopenmp -MMD -MF release/Scene.d -c Scene.cc -o release/Scene.o
g++ -I/usr/local/cuda/include -Wall -O3 -funroll-loops -DNDEBUG -fopenmp -MMD -MF release/Sphere.d -c Sphere.cc -o release/Sphere.o
Sphere.cc: In member function ‘virtual bool Sphere::intersect(const Scene::Ray&, Vec3d&, Vec3d&, double&) const’:
Sphere.cc:48: error: expected primary-expression before ‘<’ token
Sphere.cc:48: error: expected primary-expression before ‘>’ token
Sphere.cc:48: warning: left-hand operand of comma has no effect
Sphere.cc:48: warning: right-hand operand of comma has no effect
Sphere.cc:48: warning: right-hand operand of comma has no effect
Sphere.cc:48: warning: right-hand operand of comma has no effect
make[1]: *** [release/Sphere.o] Fehler 1
make[1]: Verlasse Verzeichnis ‘/home/swalter/Ubuntu One/cg/CG-exercises/src/05-RayTracing Cuda’
make: *** [rel] Fehler 2
[/i]
I have really no idea, how to fix this problem. I just started in the last days with Cuda an I only finished the nvidia exersises yet. But beacause its realy fun to work with cuda, I am triing to change some of my normal .cc files, to use cuda.
Iam glad about every hint or solution.
Thanks a lot!