Question about compiling cuda code in linux

Hi, I am a newbie for both linux and cuda, yet I have to write cuda code in linux. The question I want to ask is how to compile cuda coda in linux. Do I need to generate a Makefile? And how to link those library functions?

Thanks a lot! oh, BTW, is this same as ordinary compilation (not cuda) in linux?

Thanks again!

Hi,

you need to install nvcc for your distro (I assume you are able to do this). Then you have to export path containing bin and library. To do this in a Debian-based OS (like Ubuntu for example), if you give a standard installation, I suggest you to open a shell and type:

nano ~/.bashrc
export PATH=$PATH:/usr/local/cuda/bin

export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/cuda/lib

Or maybe:

export PATH=$PATH:/usr/local/cuda/bin

export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/cuda/lib64

Anyway you can find the right code lines at the end of your nvcc installation. These cause to export to the OS information about where are both bins and libraries.

Compiling a CUDA file is the same of compile, for example, a C/C++ file. But you use nvcc instead of, for example, gcc or g++.

Anyway, to compile a file open a shell, move to the right directory (using cd) and type:

nvcc your_file.cu -o the_exe_name

Note that you can omit the option -o.

I suggest you to read nvcc help:

nvcc -h

Cheers,

luca

P.S.: note that you have to add the lines beginning with export to your bashrc. To exit nano type ctrl+x.
Cheers,

luca

Thanks a lot!I appreciate it.