Thursday, July 24, 2008

Using Eclipse for CUDA Development

Here is how I got Eclipse (Ganymede) working with CUDA in Ubuntu 8.04. This includes syntax highlighting and having Eclipse use NVidia's makefiles. After setting up CUDA in Ubuntu, Installing Eclipse, setting up Eclipse for graphics programming, here's what I did:

Syntax Highlighting for .cu Files:
Window -> Preferences -> in C/C++ -> File Types -> New -> enter "*.cu" and select "C++ Source File"

Working with NVidia's Makefiles:
Here we'll make a copy of NVidia's template project and set it up in Eclipse.
cd NVIDIA_CUDA_SDK/projects/
cp -r template/ foobar/

In Eclipse:
New -> C++ Project ->
  • Project Name: "Foobar"
  • uncheck "Use default location"
  • Location: "/home/yourusername/NVIDIA_CUDA_SDK/projects/foobar"
  • Project types: Executable -> Empty Project
-> Next -> uncheck "Debug", select "Release" -> Advanced Settings ->
in "C/C++ build" ->
  • in "Builder Settings" tab -> uncheck "Generate Makefiles"
  • Build Directory: "${workspace_loc:/foobar}"
  • in "Behaviour" tab -> Build (incremental build):"" (delete "all")
in C/C++ build -> Environment ->
  • Add -> Name: "PATH" Value: "/usr/local/cuda/bin" -> OK
  • Select PATH -> Edit -> Value: change ";/usr/local/cuda/bin" to ":/usr/local/cuda/bin"
-> Ok -> Finish

Ctrl+b to build should work now.

In Makefile, replace "EXECUTABLE := template" with "EXECUTABLE := foobar" so it puts the executable in the right place.

To set up Eclipse to run it:
Run -> Run Configurations -> select "C/C++ Local Application" -> "New launch configuration (click the leftmost icon on the top) ->
  • Name: "Foobar Release"
  • Project: Foobar
  • C/C++ Application: "/home/yourusername/NVIDIA_CUDA_SDK/bin/linux/release/foobar"
-> Apply -> Close

Try Ctrl+F11 to run.

At this point I got:
error while loading shared libraries: libcudart.so: cannot open shared object file: No such file or directory

Solution: (thanks to this guy)
sudo sh -c "echo /usr/local/cuda/lib >> /etc/ld.so.conf; ldconfig"

Ctrl+F11 works! Finally!!

I am trying to use FindCuda.cmake, but I haven't been able to get it working. Please post if you have figured out another way to use Eclipse with CUDA, or if this post helped, or if you see something unnecessary or which could be done more elegantly. Thanks!

Links:
FindCuda.cmake
NVidia Sample Makefiles working in Eclipse (on a Mac)
NVidia Forum thread asking for a CDT CUDA plugin

49 comments:

Aquarin said...

It works for me now. Thanks. I used to do some of the steps differently.
Eclipse: 3.2.2
1) ld.conf set and ldconfig executed dirung the CUDA intallation.
2) created Standart C++ project.
3) set project name and changed default location as described.
4) next, on Make builder tab removed "all" target.
5) after the project creation right click on project and open properties menu and in "Include paths and symbols" add external include path /usr/local/cuda/bin
6) Run -> Run...->
C/C++ Local Application as you described add path do the binary.

Now it should work.

curran said...

Sweet! Thanks for posting your steps.

Andres said...

RUN CUDA programs in eclipse under OS X 10.5.5

For CUDA 2.0, eclipse and macbook pro

Do all the previous settings (For compilation, etc), then

Right click on the project, open

Properties -> Run/Debug Settings

Edit the settings, go to "Environment"

add the following variable

"DYLD_LIBRARY_PATH"

with value "/usr/local/cuda/lib"

the run should work now.

Roy said...

Thanks a lot your post saved me so much time

Janis said...

Thanks for the great tips! Just a note for newbie OS X programmers (such as myself) - with Andres' tip, don't confuse "Environment Variables" under "C/C++ Build" with "Environment" under Run/Debug settings.

All the best!

Sergio said...

Thanks. The post is great! Do you know how to run a CUDA project from Eclipse in emulation mode? where should we indicate the -deviceemu flag?

curran said...

You're welcome! Sorry, I never did get CUDA emulation mode in Eclipse working. Please let me know if you do.

Sergio said...

Sure! I got it

In the makefile you need to set

# Rules and targets#
emu=1
include ../../common/common.mk

This will build the project to an "emurelease" folder. Then you have to make sure that in "Run configurations" you take the program from this folder!

curran said...

Sweet! Thanks for posting the solution!

LostL said...

Thanks a lot for your work!

Patricia said...

Hi, I haven't found the folder /home/yourusername/NVIDIA_CUDA_SDK/bin/linux/release/foobar. Do I have to create one on /bin?
Thanks!

Rajendra said...

Thank you for the codes..
Its rocks!!!

@Patrica::
home/yourusername/NVIDIA_CUDA_SDK/bin/linux/release/foobar is the place for build file.
Please see the makefile which and edit the file name. Rename as foobar if there is template..which u may have copied from NVIDIA_CUDA_SDK projects

So you dont have to create any files inside release.. it comes after successful make..

Mario said...

Thanks for this little how to. I just started with CUDA and want to use eclipse for developing. I have done all your changes and copied the template to a folder called foobar. but when I try to strg+b i get an error, that there are no targets and no makefile... but the makefile is in my project inside the folger template...

any idea?

curran said...

hmmm.. I'm not sure. I'm not set up with CUDA at the moment so I'm not in a position to investigate. ..But if/when you do figure out a solution, I'd be grateful if you posted it here. Thanks!

Anonymous said...

I use the FindCuda.cmake (svn branch 1171) without any problems in eclipse. Configure it with cmake to build an eclipse project file worked out of the box for me.

However, there is a drawback:
NVCC errors are not parsed correct, only cmake errors are reported.

Now my question:
Do you get the NVCC errors parsed the way you created your eclipse project?

likejie said...

hello guys, i got this


**** Build of configuration Release for project cuda_test ****

make
/bin/sh: /bin/sh: grep: not found
uname: not found
/bin/sh: uname: not found
/bin/sh: grep: not found
/bin/sh: tr: not found
/bin/sh: tr: not found
make: mkdir: Command not found
make: *** [makedirectories] Error 127

I following exactly the instruction. And I am using Eclipse 3.5 and CUDA 2.3.

TIA!

goozez said...

Dear likejie,
I made it working but this ain't the best way to do it (I'm sure;p).

Go to Project properties->
in C/C++ build -> Environment ->
Select PATH -> Edit -> Value: change ":/usr/local/cuda/bin" to ":/usr/bin"
and Apply everything

(if you now try to build you will get only "make: mkdir: Command not found")

Now take out the console and
cd /usr/bin
sudo ln -s /bin/mkdir
(we created a symlink to mkdir in your "PATH" folder)
now go back to eclipse and ctrl-b :)
It should only type "make"

I hope it did work. I dont thing it's the best way to do it, because I dont like changing things in system folder (security problems)

If you want the F11 (quick-run) button
not to trigger the debugger on program startup, there is an option in run configurations =>debugger-> uncheck stop on startup.

Curran : thnx for your tutorials :)

Exhodus said...

Hi

does any of you make it work on windows? im trying to set up an eclipse on windows for cuda, without success so far, I can't remove the tick from the "generate makefiles automatically" its all gray...

Michael Zwenger said...

Using 64bitOS you may use 'lib64' instead of 'lib':
sudo sh -c "echo /usr/local/cuda/lib64 >> /etc/ld.so.conf; ldconfig"
MIC

LeMoulle said...

Has anyone got debugging working in eclipse?

123 123 said...

Great blog as for me. I'd like to read a bit more concerning this theme. Thanks for posting that data.
Sexy Lady
UK escorts

KiM said...

Perfect !!!

Thanks !!!

daniel said...

Hello,

we developed a plugin for eclipse which comfortably allows CUDA (and QT) development with some additional features... Check:

http://www.ai3.uni-bayreuth.de/software/eclipsecudaqt/index.php

albert said...

Looking 4 any suggesion


**** Build of configuration Release for project cudates ****

make
make: *** empty string invalid as file name. Stop.

albert said...

whatever...

i make mistakes following the steps

Clément said...

It s work! Thanks you for this nice explaination. But compiling my project take rely a lot of time :o

Anonymous said...

Hi, thats exactly what I was searching in this time...

I'm really interested in this post...I would like to know more about "Using Eclipse for CUDA Development".

Thanks!!!

niz said...

Hello .. firstly I would like to send greetings to all readers. After this, I recognize the content so interesting about this article. For me personally I liked all the information. I would like to know of cases like this more often. In my personal experience I might mention a book called Generic Viagra in this book that I mentioned have very interesting topics, and also you have much to do with the main theme of this article.

Gaurav Kalra said...

Hi.
I successfully configured Eclipse with CUDA following your instructions.

On the other hand, I was also trying to configure Eclipse with OpenCV for the same project which is configured with CUDA.

The instructions are over here:
http://www.jestinstoffel.com/?q=node/112

But this image:
http://www.jestinstoffel.com/files/images/Screenshot-Properties%20for%20OpenCVDemo%20.preview.png

doesn't appear because with CUDA we have unchecked "Automatically generate makefile".

Can you please throw some light on CUDA+OpenCV on eclipse ?

eastsky said...

In case of using cuda library, you can add cuda library directory in eclipse...
it's easier than your solution...
Really easy and it's standard solution when you using eclipse.

When you make...
C/C++ General->Paths and Symbols.
you can 'Add'
usr/local/cuda/lib

That's all you should do for library load for your project.

Although your suggestion was helpful to me thanks.

Maverick said...
This comment has been removed by the author.
Maverick said...

I'm trying to follow the instructions given in your post, but I get this error from Eclipse:

[code]make:***No targets specified and no makefile found. Stop[/code]

My SDK is installed in ~/NVIDIA_GPU_Computing_SDK. I don't see any directory named projects in it, so I assumed you meant the directory folder named 'C'.

Here's my tree structure: http://forums.nvidia.com/index.php?showtopic=186125&view=findpost&p=1185876

Cialis Generico said...

Nice post....thanks for sharing!!

Jack Paul Aster said...

I develop CUDA plug in for eclipse if you are interesting..!

ant.polastri@gmail.com

lesbian bondage said...

Great website, looks very clean and organized. Keep up the good work!

bondage sex said...

Great website, looks very clean and organized. And very interesting to read Your the article!

muebles madrid said...

Goodness, there's really much effective info here!

Anonymous said...

do you still doubt about my words? you can try right now enterprise application integration

Louis Bush said...

Last spring I enormously looked for resume writing assistance. Subsequent to extraordinarily lengthy exploration I saw College research papers for sale who did just the things I required. therefore guys you truly ought to examine where to buy essays

Reviews of pharmacy said...

you have a very informative site.
and i must say you have use very truly words on your website.
Reviews of pharmacy

online propecia said...

hi..
its james scott,
how may i get more information from your website.
GENERIC PROPECIA

lawyers directory said...

this is the best blog i have ever seen.
find a lawyer

ShamsRock said...

You have a very nice and informative site.
saudi airlines tickets

suzan said...

You do seem to have a lot going on, but I know you really like all of them. How would you ever choose what to provide up? And I would skip following your success.
Compra Oro Plata

Alex Edward said...
This comment has been removed by the author.
Andrew Smith said...
This comment has been removed by the author.
Andrew Smith said...

Completely a wonderful article. You did a marvelous job. Thank you for taking this demand connected with previously mentioned reviewed theme. We are happy that we found ones article as well as the information which you talk about from the article within is fantastic. These records they can be handy for anybody. Keep the good work going.
james bond midnight blue tuxedo

Noman Khan said...

Thanks for this post.We current service offerings include Software Development,Web & Graphic Development ,Online Marketing , Hosting & IT Management ,Telecom & Network Services,provider of Business Process Outsourcing,Wordpress,php web application,Joomla,Software Design & Development Bangladesh,Web Development. We have serviced and continuing to service countless businesses in Middle East and across the globe.

Regional College Of Pharmacy said...

Your blog is very informative and gracefully
your guideline is very good.Thank you
Engineering college
Best engineering college in india
Private engineering college
pharmacy college
pharmacy college in india
top pharmacy college
Polytechnic college
Top polytechnic college
Top private polytechnic college
Top polytechnic colleges in India
Techanical colleges
Polytechnic college in india
Leading call center
Outbound call center india
Cheap Seo services india