IDE for CUDA Using Netbeans C/C++ IDE with CUDA

Installing CUDA compiler/debugger for NetBeans IDE on Linux Ubuntu
Hi everyone,

I use Netbeans everyday as my main IDE for Java and C++ projects, and here is my experience using it for CUDA. With it you have everything you need compile projects with colored syntax and auto-complete and also debug step by step, view variables… I use Ubuntu 7.10 but it should be about the same for Windows except the “path” and “lib”.
I think it could be interesting for users who don’t already have an IDE and it’s FREE!

How to install?

After installing CUDA toolkit, SDK, video driver…

download nebeans 6.0 on http://www.netbeans.org/ all or C++ only
install

launch netbeans
open new project c/c++ application

how to have the keywords colored for a .cu file extension?
in the menu tool–>option button advanced
open “IDE Configuration” folder on the left tree
open “System” folder
open “Object Types” folder
select “C Data Object” and add “,cu” at the end of “Extensions and MIME type”
close the option box

how to create a source file?
on the left project tree, right click on “Source Files”
New–>Other create an “empty file” and name it whatever.cu
the next time the menu will show the New–>Empty file right away

how to create a kernel source file that is used with #include from the main .cu file?
same as a .cu file except at the end, right click on the file and “properties”
and in the General category, check the box “Excluded from build”

how to compile?
Right click on your project and “properties”
In the General tab, uncheck both “C compiler required” and “C++ compiler required”, select “Generic” in the list box of “Platform”
On the tree select “C/C++”–>“C Compiler”–>“General”
and change the include directories to somewhat like that:
.:/usr/local/cuda/include:/home/patrick/NVIDIA_CUDA_SDK/common/inc
modify to your very path.
and in the “Tool” type nvcc
noe in the “C/C++”–>“C Compiler”–>“Command Line” set these options -v -deviceemu --compile -G0
do exactly the same for the “C/C++”–>“C++ Compiler”
now set the linker, in the same properties box, select “Linker”–>“General”, change “Tool” to nvcc
in the “Linker”–>“Libraries” add “cudart” and cutil with th e"Add Library button" select .a and get the library for your “NVIDIA_CUDA_SDK/lib/libcuda.a”
same for cudart but select dynamic library “.so” and get it from /usr/local/cuda/libcudart.so
put “–link” in the “Linker”–>“Command Line”
and “OK” the project properties box

everything should work well if you have the right path for lib and nvcc in your system environment
I couldn’t find an easy way to set the LD_LIBRARY_PATH on Ubuntu, so if you know… anyway I have modified the /etc/ld.so.conf.d/libc.conf and add the cuda lib at the end, it require to restart the machine, I know it’s bad but works well :">

libc default configuration

/usr/local/lib
/usr/local/cuda/lib

Same for the path to nvcc
I have modified the /etc/environment
to that:
PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/u
sr/local/cuda/bin"
LANG=“en_US.UTF-8”

I will appreciate if you have some info (step by step) how to set up the 169 driver on Ubuntu 7.10 in order to run CUDA 1.1. I am using CUDA 1.0 with 100.xx driver but have no success to install the new driver.

I don’t know what is the 169 driver where to find it?

I have downloaded the install package from Nvidia

NVIDIA-Linux-x86-96.43.01-pkg1.run

the latest one should work the same way (NVIDIA-Linux-x86-100.14.11-pkg1.run)

then logout Ubuntu

from the login panel “Ctrl” “Alt” “F2” opens a text console

login as an administrator, yourself by default, not root

to kill the Xorg process

search for process id with ps -e | more

4564 tty7 00:03:54 Xorg

“sudo killl processid#” (e.g. kill 4564)

go to ring 3 level

“sudo /sbin/init 3”

cd where you have the package

cd /home/you/downloads

sudo chmod +x NVIDIA-Linux-x86-96.43.01-pkg1.run

sudo ./NVIDIA-Linux-x86-96.43.01-pkg1.run

accept the license

sudo reboot

that’s it

but sometimes when you kill the X.org your console is logout, so redo again and it works

I found it on the same download page, my screen is maybe not big enough <img src=‘http://hqnveipbwb20/public/style_emoticons/<#EMO_DIR#>/crying.gif’ class=‘bbc_emoticon’ alt=’:’(’ />

Tanks a lot :) I upgraded successfully. Probably ENVY set the all files previous time (e.g. removing the nv driver), so now upgrade to new driver manually is as just you described.

Thanks for the setup. I have set up a project including C++ and CUDA where the CUDA code is called from a C++ main. I configured the C compiler to use nvcc and the left the c++ compiler as is (g++). As linker I also use g++.

However, I am unable to step through the code. I insert a breakpoint in the cpp and cu files, but the program just runs straight through. Is there anything special I have to do to make debugging work?

  • Atle

I personally use nvcc for any files even to compile and link C++ ( the nvcc calls g++ ). I use the regular gdb debugger, I am able to debug (CTRL + F5) any code even the kernel (in Debug Emu mode only), except the the step in (F7) doesn’t go it the kernel code, to step in I have to first put a break point in the kernel source code and step over(F8). May be it’s ok to use g++ to compile but I guess the nvcc is required to link in emulation mode. But even if you link with g++ you should be able to stop on a break set in the c++ file.

Have you tried to debug in a terminal with the gdb or with kDbg ?

Hi,

I am starting to learn CUDA and I would like to continue using Netbeans as IDE. So far the steps I have to do are clear, however I have a question about the make file (which so far I have never touched, so I don’t really know much about it). Do I have to change the make file? Should I copy one makefile from the CUDA examples or can I continue using the standard make file from netbeans?

tom

I have never made any complicate project that require a make file, my projects are simple, 10-20 files of C/C++. I think Netbeans generates the basic make for your project during the build.

OK, to finish another project I had to interrupt my CUDA learning process, but now I am starting again and I have a problem getting CUDA run on Netbeans.

Following message I get if I want to compile a program:

Running "/usr/bin/make  -f Makefile CONF=Debug" in /l/thofel/NetBeansProjects/Cuda_test

/usr/bin/make -f nbproject/Makefile-Debug.mk SUBPROJECTS= .build-conf

make[1]: Entering directory `/l/thofel/NetBeansProjects/Cuda_test'

mkdir -p dist/Debug/GNU-Linux-x86

nvcc -o dist/Debug/GNU-Linux-x86/cuda_test build/Debug/GNU-Linux-x86/moveArrays.o -lcudart -lcutil 

/usr/bin/ld: cannot find -lcutil

collect2: ld returned 1 exit status

make[1]: *** [dist/Debug/GNU-Linux-x86/cuda_test] Error 255

make[1]: Leaving directory `/l/thofel/NetBeansProjects/Cuda_test'

make: *** [.build-impl] Error 2

Build failed. Exit value 2.

I saw in the release note that a similar problem occured with Linux Redhat 4.3 (which I use) with the “usr/bin/ld: cannot find -lglut” file, however there is nothing mentioned about the cudart library. I followed all the steps to integrate CUDA in netbeans as explained above.

I am using CUDA 1.1 on Cientific Linux 4.3 (based on Redhat Enterprise 4.3).

Anyone an idea what is going wrong here?

I couldnt get CUDA - netbeans to work in the way described it kept giving me the error

couldnt find -lcutil

however i did manage to get netbeens to compile stuff using the template file from the sdk projects folder, you can rename the template and all of the source files, and modify the Makefile variables accordingly

you can now add that project using the “add from existing makefile” button when starting a project in net beans (you have to add the .cu extension as before)

i seem to be only able to biuld the project if i have it in the ~/NVIDIA_CUDA_SDK/projects/myproject/ folder. otherwise it throws up the same error that:
-lcutil or
cutil.h can not be found

any explination as to why it can only find the literary when in a specific path? i think it must be defined directory relative in the template makefile, or in the file /home/**********/NVIDIA_CUDA_SDK/common/common.mk
and cant be found in the PATH and LD_LIBRARY_PATH variables
i have set both of these correctly btw you have to put

CUDA stuff

PATH=$PATH:/usr/local/cuda/bin:
LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/cuda/lib:/home/richard/pool/lib:
export PATH
export LD_LIBRARY_PATH
into ~/.bashrc

also you can add the path “/usr/local/cuda/bin” to the netbeans environment
“Tools->options->C/C++”
current path

i had to do this for netbeans to see nvcc, but then i got these errors about libcutil

anyway, its good to know there is a second way

I’m guessing you’re using the “template” project and modified it. The make file there contains a relative reference to your SDK folder, where the cutil header in lib are located, which is why it works in the projects folder but not any other. To solve your you have to link the lib and common/inc from your SDK directory to your project in Netbeans.

dear patrick,

thanks for sharing this. i downloaded the recent version which happens to be 6.5. i dont see any menu tool–>option button advanced, etc…

This is really cool, and probably the only tutorial which might make cuda work with an ide on linux. i would be really grateful to you if you could spare some more time and be a little clearer as to what to do, step by step… we are a bunch of students here, and it would benifit all of us.

hoping your kind help!
arjun

Hello,

Good news, the Netbeans 6.5 is working again with the .cu files, unfortunately the 6.1 was not able to colorize the syntax of the .cu files and for this and other reasons (WxWidgets integration) I switched to codelite.org IDE, more configurable because targeted for C/C++.
But the Netbeans 6.5 seems to resolve these issues nicely.

To create a project with 6.5, follow the same steps as 6.1 except for the cu mime type and compiler options.

How to colorize the source code of a .cu file:
Menu->Tools->Options
Click on the button “Miscellaneous”
Select the tab note “Files”
New…
enter “cu” int the input field
and choose the mime for C Files (text/x-c)

How to add the nvcc compiler in Netbeans:
Menu->Tools->Options
Click on the button “C/C++”
Select the tab note “Other”
Click new…
Type “cu” (without quotes) int the field and click “Add”
OK

Menu->Tools->Options
Click on the button “C/C++”
Select the tab note “Build Tools”
On the “Tool Collection” list click on “Add…”
Browse the Base Directory to where you have installed nvcc (usually /usr/local/cuda/bin )
Select GCC for type of compiler
Type nvcc for Tool collection name
OK

[attachment=10148:Screenshot_Options.png]

How to set the compiler in your project:
On the left hand tree, right click on your project and “Properties”
On the “Build” panel, un-check the “Enable Make Dependency Checking” otherwise this add -MDD -M to the nvcc command line and the compiler doesn’t understand.
On the “C Compiler” tab choose the Toll “nvcc”

Patrick

Hello,

Good news, the Netbeans 6.5 is working again with the .cu files, unfortunately the 6.1 was not able to colorize the syntax of the .cu files and for this and other reasons (WxWidgets integration) I switched to codelite.org IDE, more configurable because targeted for C/C++.
But the Netbeans 6.5 seems to resolve these issues nicely.

To create a project with 6.5, follow the same steps as 6.1 except for the cu mime type and compiler options.

How to colorize the source code of a .cu file:
Menu->Tools->Options
Click on the button “Miscellaneous”
Select the tab note “Files”
New…
enter “cu” int the input field
and choose the mime for C Files (text/x-c)

How to add the nvcc compiler in Netbeans:
Menu->Tools->Options
Click on the button “C/C++”
Select the tab note “Other”
Click new…
Type “cu” (without quotes) int the field and click “Add”
OK

Menu->Tools->Options
Click on the button “C/C++”
Select the tab note “Build Tools”
On the “Tool Collection” list click on “Add…”
Browse the Base Directory to where you have installed nvcc (usually /usr/local/cuda/bin )
Select GCC for type of compiler
Type nvcc for Tool collection name
OK

[attachment=7862:Screenshot_Options.png]

How to set the compiler in your project:
On the left hand tree, right click on your project and “Properties”
On the “Build” panel, un-check the “Enable Make Dependency Checking” otherwise this add -MDD -M to the nvcc command line and the compiler doesn’t understand.
On the “C Compiler” tab choose the Toll “nvcc”

Patrick

Hi,

I just start with netbeans and cuda. I am not familiar with c language.

I could find only the cuda and cudart and so the cuda language is not recognized ie " global""

I do I fixed this

conf window vista 64 , netbeans 6.5

I followed the instructions for Netbeans 6.5 in Ubuntu and everything went fine. I then copied the code from the deviceQuery example and pasted into my file in Netbeans. When I try to build I get the following error:

[codebox]Running “/usr/bin/make -f Makefile CONF=Debug” in /home/agerlach/NetBeansProjects/try

/usr/bin/make -f nbproject/Makefile-Debug.mk SUBPROJECTS= .build-conf

make[1]: Entering directory `/home/agerlach/NetBeansProjects/try’

/usr/bin/make -f nbproject/Makefile-Debug.mk dist/Debug/nvcc-Linux-x86/try

make[2]: Entering directory `/home/agerlach/NetBeansProjects/try’

mkdir -p dist/Debug/nvcc-Linux-x86

nvcc --link -o dist/Debug/nvcc-Linux-x86/try build/Debug/nvcc-Linux-x86/main.o -lcudart -lcublas -lcublasemu -lcufft -lcufftemu -lcuda -lcutil

/usr/bin/ld: cannot find -lcutil

collect2: ld returned 1 exit status

make[2]: *** [dist/Debug/nvcc-Linux-x86/try] Error 255

make[2]: Leaving directory `/home/agerlach/NetBeansProjects/try’

make[1]: *** [.build-conf] Error 2

make[1]: Leaving directory `/home/agerlach/NetBeansProjects/try’

make: *** [.build-impl] Error 2

Build failed. Exit value 2.[/codebox]

So it says that it cannot find -lcutil but if I check my linker the cutil library is being included. I also know this because if I remove it it finds other errors in the program. Does anybody have any Ideas on this? I also tried adding …/NVIDIA_CUDA_SDK to the LD_LIBRARY_PATH but it did not help.

In the project properties , add the cutil.a library

Clean And Build

the command line should look like

nvcc --link -o dist/Debug/nvcc-Linux-x86/try build/Debug/nvcc-Linux-x86/main.o “-L/usr/local/cuda/lib/” -lcudart -lcublas -lcublasemu -lcufft -lcufftemu -lcuda -lcutil

I added the cutil.a library by using the “Add Library” button. I also had to add “/usr/local/cuda/lib” to the "additional library directories in order to get the “-L/usr/local/cuda/lib” that you show.

I still get the following error[codebox]nvcc --link -o dist/Debug/nvcc-Linux-x86/try build/Debug/nvcc-Linux-x86/main.o -L/usr/local/cuda/lib -lcudart -lcutil

/usr/bin/ld: cannot find -lcutil[/codebox]

I also noticed that in your picture it looks like you added the library using the “Add library file” button. I tried that but it still did not work and the command line looked completely different from yours.

I thought that something may have went wrong when I compiled the cutil.a library so I went back and ran make and got the following error.

[codebox] error: GL/glu.h: No such file or directory

[/codebox]

I’m assuming the cutil.a library was built correctly though. Since I don’t see why it would depend on OpenGL and that the library exists.

Hi,

Could you help me?

I am using your guidelines to install CUDA on netbeans6.5. THANKS FOR THAT!!! :rolleyes:

I am trying to run cuda sdk code samples, but when I tried to build the project, I got the following error:

/usr/bin/make -f nbproject/Makefile-Default.mk SUBPROJECTS= .build-conf

make[1]: Entering directory `/home/liliana/NVIDIA_CUDA_SDK/projects/matrixMul/matrixMul_1'

/usr/bin/make  -f nbproject/Makefile-Default.mk dist/Default/nvcc-Linux-x86/matrixmul_1

make[2]: Entering directory `/home/liliana/NVIDIA_CUDA_SDK/projects/matrixMul/matrixMul_1'

mkdir -p build/Default/nvcc-Linux-x86/_ext/home/liliana/NVIDIA_CUDA_SDK/projects/matrixMul/matrixMul_1/..

g++	-c -g -o build/Default/nvcc-Linux-x86/_ext/home/liliana/NVIDIA_CUDA_SDK/projects/matrixMul/matrixMul_1/../matrixMul_gold.o ../matrixMul_gold.cpp

mkdir -p build/Default/nvcc-Linux-x86/_ext/home/liliana/NVIDIA_CUDA_SDK/projects/matrixMul/matrixMul_1/..

gcc	-c -g -o build/Default/nvcc-Linux-x86/_ext/home/liliana/NVIDIA_CUDA_SDK/projects/matrixMul/matrixMul_1/../matrixMul.o ../matrixMul.cu

gcc: ../matrixMul.cu: linker input file unused because linking not done

mkdir -p build/Default/nvcc-Linux-x86/_ext/home/liliana/NVIDIA_CUDA_SDK/projects/matrixMul/matrixMul_1/..

gcc	-c -g -o build/Default/nvcc-Linux-x86/_ext/home/liliana/NVIDIA_CUDA_SDK/projects/matrixMul/matrixMul_1/../matrixMul_kernel.o ../matrixMul_kernel.cu

gcc: ../matrixMul_kernel.cu: linker input file unused because linking not done

mkdir -p dist/Default/nvcc-Linux-x86

nvcc -o dist/Default/nvcc-Linux-x86/matrixmul_1 build/Default/nvcc-Linux-x86/_ext/home/liliana/NVIDIA_CUDA_SDK/projects/matrixMul/matrixMul_1/../matrixMul_gold.o build/Default/nvcc-Linux-x86/_ext/home/liliana/NVIDIA_CUDA_SDK/projects/matrixMul/matrixMul_1/../matrixMul.o build/Default/nvcc-Linux-x86/_ext/home/liliana/NVIDIA_CUDA_SDK/projects/matrixMul/matrixMul_1/../matrixMul_kernel.o -L../../../common/lib/linux -L/usr/local/cuda/lib -lcutil -lcudpp -lcudpp -lcudart -lcublas -lcufft 

g++: build/Default/nvcc-Linux-x86/_ext/home/liliana/NVIDIA_CUDA_SDK/projects/matrixMul/matrixMul_1/../matrixMul.o: No such file or directory

g++: build/Default/nvcc-Linux-x86/_ext/home/liliana/NVIDIA_CUDA_SDK/projects/matrixMul/matrixMul_1/../matrixMul_kernel.o: No such file or directory

make[2]: *** [dist/Default/nvcc-Linux-x86/matrixmul_1] Error 255

make[2]: Leaving directory `/home/liliana/NVIDIA_CUDA_SDK/projects/matrixMul/matrixMul_1'

make[1]: *** [.build-conf] Error 2

make[1]: Leaving directory `/home/liliana/NVIDIA_CUDA_SDK/projects/matrixMul/matrixMul_1'

make: *** [.build-impl] Error 2

Build failed. Exit value 2.

Thank you!