Integration of CUDA code and a C source

Hi

Im trying to integrate a CUDA module (.c code which I modified for GPU processing into a .cu code) back in its original source code, but the CPU functions written in that module are not being linked. I’m getting an “Undefined reference” error for the functions written in the .cu file which are being called from other functions.
I’m compiling the source using the template makefile available with the examples. The examples are being compiled properly and a personal-test-standalone .cu file compiled in this manner also gave a working executable.
I have tried generating an object file through nvcc and linking it to the source which also proved futile giving the same error. In both cases if the symbols in the object file are listed using nm, the function names which are giving the error are missing, rather they have a certain prefix and suffix of some sort due to which the linking is not happening.
Any suggestions on the right procedure I’ve to follow to solve my problem?

Thanks in advance

Hi

Im trying to integrate a CUDA module (.c code which I modified for GPU processing into a .cu code) back in its original source code, but the CPU functions written in that module are not being linked. I’m getting an “Undefined reference” error for the functions written in the .cu file which are being called from other functions.
I’m compiling the source using the template makefile available with the examples. The examples are being compiled properly and a personal-test-standalone .cu file compiled in this manner also gave a working executable.
I have tried generating an object file through nvcc and linking it to the source which also proved futile giving the same error. In both cases if the symbols in the object file are listed using nm, the function names which are giving the error are missing, rather they have a certain prefix and suffix of some sort due to which the linking is not happening.
Any suggestions on the right procedure I’ve to follow to solve my problem?

Thanks in advance

Use extern C.

Use extern C.

It worked…

Thanks a ton…

I had another problem when using double in the nvcc compiled code. After a lot of debugging I realized that the nvcc compiled code was changing values of a double variable in a structure assuming that it is float, hence when using the same structure elsewhere all the values had been shifted by 4 bytes. Is it possible to avoid this in any other way than avoiding double completely? Is there a way to use a datatype similar to float with the same precision but of the size of a double?

It worked…

Thanks a ton…

I had another problem when using double in the nvcc compiled code. After a lot of debugging I realized that the nvcc compiled code was changing values of a double variable in a structure assuming that it is float, hence when using the same structure elsewhere all the values had been shifted by 4 bytes. Is it possible to avoid this in any other way than avoiding double completely? Is there a way to use a datatype similar to float with the same precision but of the size of a double?

You need to tell the compiler that you want to use double:

nvcc -arch sm_13 ( or -arch sm_20) file.cu

This is something annoying, but it is a legacy of the original G80 GPU generation that was unable to support double.
The compiler was demoting all doubles to floats.

You need to tell the compiler that you want to use double:

nvcc -arch sm_13 ( or -arch sm_20) file.cu

This is something annoying, but it is a legacy of the original G80 GPU generation that was unable to support double.
The compiler was demoting all doubles to floats.