compiling *.c with __CUDACC__

i don’t know why but if we compile with nvcc a file with .c extension don’t create the default this EV CUDACC like say in the nvcc compile. I check that is created when the file is *.cu

is this normal??? i think that is a mistake. what do u think???

.....

//

// IMPLEMENTACION DE FUNCIONES EXTERNAS

//

extern vector * Crear_Vec (int n_row){

  vector *vect = (vector *) malloc (sizeof(vector));

vect->len = n_row;

  vect->PTR = (double *) malloc (n_row * sizeof(TIPO));

#ifdef __CUDACC__

  cudaError_t status = cudaMalloc ((void**)&vect->d_ptr, vect->len * sizeof (TIPO));

  if (status != OK_CUDA){

    printf("ERROR: al reservar memoria para el fichero en la GPU\n");

    free (vect->PTR);

    free (vect);

    return NULL;

  }

  printf ("cuda flag\n");

#endif

  printf ("created \n");

return vect;

}

.........

if i compile *.c with nvcc I only get the message of “created” and if i compile *.cu with nvcc i get the 2 messages

it’s enought with this example???

What happens if you compile with [font=“Courier New”]nvcc -x cu[/font]?

Ohhhhhhhhhhhhhhhhh it’s works

ok thx u very much i understand now, sorry i didn’t read the help text of nvcc

in addition i had another problem the execution and this have solved it :S:S. Look i compiled with this way

nvcc -G -g -arch=sm_20 -O3 -Xcompiler -Wall -x cu vector.cu matrix.cu -I../include/ -c ###to generate data structures

nvcc -G -g -arch=sm_20 -O3 -Xcompiler -Wall -Xcompiler -fPIC -x cu  -I../include/ grad_conj.cu -c ###to generate function

nvcc -shared -Xlinker -soname,libgrad_conj_cublas.so.1  grad_conj.o -o ../lib/libgrad_conj_cublas.so.1.0 -lcublas ###to generate shared lib of function

ln -sf libgrad_conj_cublas.so.1.0 ../lib/libgrad_conj_cublas.so.1

ln -sf libgrad_conj_cublas.so.1 ../lib/libgrad_conj_cublas.so

<b>gcc main.c -Wall -g -O3  -I../include -c -o main.o</b> ###to generate the main program (only prepare the structures and call to library function)

gcc -Wall -g -O3  main.o estructuras/vector.o estructuras/matrix.o -L../lib -lgrad_conj_cublas -o ../bin/grad_conj_cublas ###to link all parts

and now …

nvcc -G -g -arch=sm_20 -O3 -Xcompiler -Wall -x cu vector.cu matrix.cu -I../include/ -c ###to generate data structures

nvcc -G -g -arch=sm_20 -O3 -Xcompiler -Wall -Xcompiler -fPIC -x cu  -I../include/ grad_conj.cu -c ###to generate function

nvcc -shared -Xlinker -soname,libgrad_conj_cublas.so.1  grad_conj.o -o ../lib/libgrad_conj_cublas.so.1.0 -lcublas ###to generate shared lib of function

ln -sf libgrad_conj_cublas.so.1.0 ../lib/libgrad_conj_cublas.so.1

ln -sf libgrad_conj_cublas.so.1 ../lib/libgrad_conj_cublas.so

<b>nvcc main.c -G -g -arch=sm_20 -O3 -x cu -I../include -c -o main.o</b> ###to generate the main program (only prepare the structures and call to library function)

gcc -Wall -g -O3  main.o estructuras/vector.o estructuras/matrix.o -L../lib -lgrad_conj_cublas -o ../bin/grad_conj_cublas ###to link all parts

In the first case the program crash at moment to call function of cublas and free memory (all in grad_conj.cu) and in the second case works perfectly

calling to cublasDdot on grad_conj.cu:

the cublasStatus_t (error) was :EXECUTION FAILED

for this reason (error) i started to free the local variables and …

calling to cudaFree of local variables on grad_conj.cu:

the error was cudaErrorLaunchFailure

the description of cudaGetErrorString(error[0]) was unspecified launch failure

:S:S:S

so… THANK YOU VERY MUCH for the tell me the option -x cu. i don’t know why works now but works hahaha

[font=“Courier New”]-x cu[/font] tells [font=“Courier New”]nvcc[/font] to compile your code as CUDA code. Otherwise nvcc deduces the language from the file extension, thus compiling your code as ordinary C code.