Given that I am making heavy use of float2, float3 etc. datatypes on the GPU side, I want to mirror some of it on the CPU side, i.e., in host code. Upon doing so, I have run into problems when using g++/gcc to compile the host side, whereas everything is fine when using nvcc. Consider the following example of pure host code
#include <stdlib.h>
#include <stdio.h>
#include <cuda_runtime.h> // for gcc/g++
float2 sqrt(float2 a) {
return make_float2(sqrt(a.x),sqrt(a.y));
}
int main ()
{
double value,sqrtvalue;
float valuef,sqrtvaluef;
float2 value2,sqrtvalue2;
printf("Enter a floating point number:\n");
scanf("%lf",&value);
valuef=value;
value2=make_float2(value,2.*value);
sqrtvalue=sqrt(value);
sqrtvaluef=sqrt(valuef);
sqrtvalue2=sqrt(value2);
printf("values: %f %f %f %f\n",value,valuef,value2.x,value2.y);
printf("sqrts : %f %f %f %f\n",sqrtvalue,sqrtvaluef,sqrtvalue2.x,sqrtvalue2.y);
}
If this is saved as test.cu and compiled with “nvcc test.cu” everything works as expected. If however I rename the file to test.cpp and compile with “g++ -I /usr/local/cuda/include/ test.cpp”, I get various errors “conversion from ‘float’ to non-scalar type ‘float2’ requested”. What am I overlooking? Can I get g++ to compile the above snippet? Am I just missing an include file (I thought that cuda_runtime.h pulls in all relevant include files …)
Thanks,
Stefan