Writing small programs in CUDA could be done simply in any text editor. But as I was working on slightly bigger application, I tried to find good IDE, which allows to develop applications with CUDA support. Unfortunately I was working on Ubuntu so I couldn't just use Parallel Nsight, which comes as a plugin for Visual Studio only. I have tried different IDEs, but Eclipse was the most flexible. So here are the hints which may be useful when we want to use CUDA in Eclipse.
First of all we should install CUDA SDK and download Eclipse with C/C++ support. After downloading and setting all up properly we should create just empty C/C++ project in Eclipse or just use existing one. I always try to separate CUDA source files from ordinary C/C++ sources in project.
The next steps will set necessary global properties for our project. We should create some build variables (just select "Project"->"Properties") and make new variables for selected build configuration as presented below:
Four variables should be set:
- CUDA_INCLUDE - path for CUDA header files, which are installed with CUDA SDK
- CUDA_LIB - path for libraries installed with CUDA SDK. Notice that you should point to directory with libraries compiled for our system (in my case 64bit architecture)
- NVCC - CUDA compiler which will be used to compile our CUDA sources
- NVCC_ARCH - this one is for additional compiler flags. We don't have to set this one. I have used it for setting target compute architecture (double precision)
Next we should tell Eclipse, that our CUDA source should be considered as C source files.
Now everything is ready to use. When we create new file with *.cu extension, in which we put all CUDA specific code, we need to compile this sources with nvcc compiler. In order to do that, we should select "Properties" for that specific file and set custom build step.
The last figure shows how to set custom build step for integrate_2d_cuda.cu example file. This build step creates integrate_2d_cuda.o file, by using nvcc compiler, which then will be used by gcc/g++ linker to build application.
There is one thing we should do to prevent Eclipse from complaining about unknown keywords in CUDA source files. At the very beginning of each *.cu we just add following lines:
//Only for eclipse parsers #ifdef __CDT_PARSER__ #define __global__ #define __device__ #define __shared__ #define __const__ #endif
That is all. Now we can develop application as ordinary C/C++ project. We should only remember that for each CUDA source file we have to set custom build step. Happy coding!
1 comments:
Thanks a lot! It saved my day.
Post a Comment