HOWTO NetBeans and CUDA tutorial for working on CUDA with NetBeans

Hi,

I’ve made some small HOWTO for using CUDA with NetBeans, primary I did it for documentation of my Bachelor thesis, but I thought it could be usefull for others.

Here is the link

Lucas

Thanks。 It is useful。

I edited the HOWTO to work with the cuda-gdb and using g++ for linking instead of nvcc.
Some additional hints for using the debug mode without emulation.

Follow the link from the first post.

Hi Lucas, Thanks a lot for posting this. This is exactly what system I am running on my personal machine. I seem to have missed something, however. I think I have followed your instructions to a “T”, but I am still having problems with NetBeans flagging some Cuda Specific terms.

In the template_kernal.cu this code returns “cannot find include file”

[codebox]#include <vector_functions.h>

#include <device_launch_parameters.h>

#include <device_functions.h>[/codebox]

Then subseqent Cuda terms are flagged.

Any ideas?

Hi afspear,

Check Tools->Options->C/C++

  1. Is NVCC set as default ? [Tab “Build Tools”]

  2. Did you added all “Macro Definitions”, maybe “CUDACC” is missing, this enables for me __syncthreads() and other functions. [Tab “Code Assistance”]

  3. Are all include directorys added ? for special purpose “…/cuda/include” and “…/C/common/inc”

  4. NetBeans is buged, from time to time I have simmilar errors. Comment the includes, and then comment them out, for me it helps.

  5. In the template.cu I added this includes, too.

#include <cuda_runtime.h>

#include <cutil_inline.h>

#include <cutil.h>
  1. right-click on the project->Properties, is under the categorie “Build” the “Tool Collection” “NVCC” choosen?

Hope this helps,

Lucas

Hello,

Thanks for the guide, it really helped in starting off with CUDA on Netbeans. I wanted to make C/C++ Dynamic Library with CUDA, but getting some errors with gcc++ and gmake. How is procedure to be modified to be able to make shared library (.so) files?

Hello,

Thanks for the guide, it really helped in starting off with CUDA on Netbeans. I wanted to make C/C++ Dynamic Library with CUDA, but getting some errors with gcc++ and gmake. How is procedure to be modified to be able to make shared library (.so) files?

In your howto, you state “Because of duplicating the “Tool Collection” the settings in “Code Assistance” will be still there.”. This doesn’t happen on my system…as soon as I change the C/C++ compiler from gcc/g++ to nvcc/nvcc, the settings in code assistance disappear.

Darkmav, my company has made a plugin available that makes NetBeans 6.9.1 aware of the CUDA compiler under Linux. It is free. You can find it by searching for “cuda” at the NetBeans Plugin Portal or from our website.

Hi,

try to duplicate the “GNU” Tool Collection and open again the “Code Assistance” tab.

Maybe it helps.

Lucas

Hi jux, thanks. Your plugin was very useful, along with the attached README. However, when I execute CUDA code from within Netbeans, I get the following errors

"/usr/bin/make" -f nbproject/Makefile-CUDA-Toolkit.mk QMAKE= SUBPROJECTS= .build-conf

make[2]: *** No rule to make target `/tmp/tmpxft_000040d1_00000000-12_main.ii', needed by `build/CUDA-Toolkit/GNU+CUDA-Linux-x86/main.o'.  Stop.

make[1]: Entering directory `/home/vivek/netbeansprojects/CudaTemplate3'

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

"/usr/bin/make"  -f nbproject/Makefile-CUDA-Toolkit.mk dist/CUDA-Toolkit/GNU+CUDA-Linux-x86/cudatemplate3

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

make[2]: Entering directory `/home/vivek/netbeansprojects/CudaTemplate3'

make[2]: Leaving directory `/home/vivek/netbeansprojects/CudaTemplate3'

make[1]: Leaving directory `/home/vivek/netbeansprojects/CudaTemplate3'

When I compile, I get no errors

"/usr/bin/make" -f nbproject/Makefile-CUDA-Toolkit.mk QMAKE= SUBPROJECTS= .clean-conf

make[1]: Entering directory `/home/vivek/netbeansprojects/CudaTemplate3'

rm -f -r build/CUDA-Toolkit

rm -f dist/CUDA-Toolkit/GNU+CUDA-Linux-x86/cudatemplate3

make[1]: Leaving directory `/home/vivek/netbeansprojects/CudaTemplate3'

CLEAN SUCCESSFUL (total time: 52ms)

"/usr/bin/make" -f nbproject/Makefile-CUDA-Toolkit.mk QMAKE= SUBPROJECTS= .build-conf

make[1]: Entering directory `/home/vivek/netbeansprojects/CudaTemplate3'

"/usr/bin/make"  -f nbproject/Makefile-CUDA-Toolkit.mk dist/CUDA-Toolkit/GNU+CUDA-Linux-x86/cudatemplate3

make[2]: Entering directory `/home/vivek/netbeansprojects/CudaTemplate3'

mkdir -p build/CUDA-Toolkit/GNU+CUDA-Linux-x86

rm -f build/CUDA-Toolkit/GNU+CUDA-Linux-x86/main.o.d

nvcc -m64   -c -O2 -I../../NVIDIA_GPU_Computing_SDK/C/common/inc -Xcompiler "-MMD -MP -MF build/CUDA-Toolkit/GNU+CUDA-Linux-x86/main.o.d" -o build/CUDA-Toolkit/GNU+CUDA-Linux-x86/main.o main.cu

mkdir -p dist/CUDA-Toolkit/GNU+CUDA-Linux-x86

nvcc -m64    -o dist/CUDA-Toolkit/GNU+CUDA-Linux-x86/cudatemplate3 build/CUDA-Toolkit/GNU+CUDA-Linux-x86/main.o -L../../NVIDIA_GPU_Computing_SDK/C/lib -L../../NVIDIA_GPU_Computing_SDK/shared/lib -lcudart 

make[2]: Leaving directory `/home/vivek/netbeansprojects/CudaTemplate3'

make[1]: Leaving directory `/home/vivek/netbeansprojects/CudaTemplate3'

BUILD SUCCESSFUL (total time: 1s)

I should point out that a few minutes ago, when I ran the same code after compiling it from Netbeans, I got the error message “libcudart.so not found” (sorry I don’t quite remember the exact message now). I know this is the error you get if your LD_LIBRARY_PATH isn’t set right, so I checked that in my ~/.bashrc file. Not only is it set correctly, but I am also able to compile, execute and run CUDA code from the terminal.

FYI, here’s the code…just an innocuous hello world program.

#include <cuda_runtime.h>

#include <cutil.h>

#include <stdio.h>

int main(int argc, char **argv)

{

    printf("Hello, world\n");

    return 0;

}

So I’m guessing I need to do something more?

Hi darkmav. I’m happy to here that the plugin was useful for you.

I have copied your code into my IDE at it compiles+runs just fine from the NetBeans IDE. This isn’t surprising though, since I’ve been compiling CUDA in NetBeans without a problem for some time. I’ll see if I can find a workstation that isn’t set up and walk through the install process myself to see if I can replicate your problem. I will let you know what I learn. Otherwise, my initial thoughts are:

  1. Check that you have actioned step 1.4.4 in readme.txt. NetBeans should not be attempting to rebuild your project when you click run.

  2. I am only aware of 2 situations that would have you encounter the “libcudart.so not found” message. The first is as you suggest: if LD_LIBRARY_PATH is not set up correctly. Have you set your library paths in /etc/ld.so.conf (i.e. added lines for /usr/local/cuda/lib and/or /usr/local/cuda/lib64, and run $ldconfig)? I seem to recall there being something about exporting LD_LIBRARY_PATH versus updating your ldconfig that leads to the libcudart.so problem. My system uses the latter approach only. You might also check that your project config in NetBeans is is set correctly for your host architecture as this would also produce the same error message.

Hi Supsurge. Your approach would appear not to work for NetBeans 6.9.1 users. This is because from version 6.8 changing the compiler triggers a Code Assistance update which attempts to call the compiler with flags “-x c -E -v” to get the include paths and “-x c -E -dM” to get the macros. nvcc does not understand these. They need to passed directly to the compiler with -Xcompiler and nvcc won’t do this without a source file. This is what has been implemented in the CUDA-plugin.