terça-feira, 2 de março de 2010

[LINUX] Preparing Eclipse for OpenCL Development

Hello Everyone,

As I said in last post, preparing all the IDE to start programming and debugging OpenCL apps in Linux, can be a hard work. No so hard, but still you can get some headaches:P
To share my experience, I'll share with you some configurations that I've used to configure Eclipse IDE to starting C++ OpenCL dev.

I've used Nvidia drivers and API, but for AMD I think that would be very similiar.

Please NOTE to future references to this constants:
$(NVIDIA_SDK_INSTALATION) --> Refers to place in you file system where have installed your OpenCL SDK

Let's start:
1. You need to download and install the lastest drivers for your GPU. For NVidia you can get drivers and SDK here: http://developer.nvidia.com/object/opencl-download.htmlLink
For AMD cards get it here: http://developer.amd.com/gpu/ATIStreamSDK/Pages/default.aspx

Installing drivers is the most difficult one, you can have some problems, but usually it goes well if you follow the instructions. For SDK you only need to unpack it in any folder and run the .sh file.

2. Pay attention to log generated by Nvidia SDK instalation :
* Please make sure your PATH includes /usr/local/cuda/bin
* Please make sure your LD_LIBRARY_PATH includes /usr/local/cuda/lib

you can make sure if they are setted, using:
$ echo PATH
(you must see many path and one must be "/usr/local/cuda/bin")
$ echo LD_LIBRARY_PATH
(same from PATH)

In my fedora I needed to set LD_LIBRARY_PATH. just write:
$ set LD_LIBRARY_PATH = "$LD_LIBRARY_PATH;/usr/local/cuda/lib"

take care, sometimes this syntax can change from system to system. Assure that everythings was right setted, using echo command.

3. Test If installation was succeed. Pick a terminal and go to:
$(NVIDIA_SDK_INSTALATION)/OpenCL/

and do:
$make

if you didn't get errors, now make:

$make runall

and all samples will start running. Try to see if you got so TEST PASSED.
Sometime you get some test failed or segmentation fault, no worry, if some of them work, the installation is working.

---
Setting Up a Eclipse Project
---
Let's start our adventure on Eclipse.
1. Now runs eclipse.

NOTE: Make sure that you make your OpenCL workspace goes to: $(NVIDIA_SDK_INSTALATION)/OpenCL/src

Tip: If you need to run eclipse remotely, you can redirect X-Server output to your windows connecting through ssh in this way:

$ ssh -X @ eclipse

2. Lets create a New Project:

File-> New -> C++ Project

Now in New Project Window, choose "Executable->Empty Project -> Linux GCC"

Give that name to project: "HelloBlogCL"

and make sure you default location is $(NVIDIA_SDK_INSTALATION)/OpenCL/src

It will be, if your workspace is correct setted, as mentioned above.


Press NEXT.

3. Now on "Select Configurations" window, we will set our debugger and make commands.

Go to: Advanced Settings

Now on "HelloBlogCL Configurations", choose C/C++ Build:
You need to change make for Debug configuration, to run command: make dbg=1.

See image:




For each configuration (Release and Debug), go to Behaviour Tab and disable Build Incremental, because our makefile wont get an "all" target.







4. Now, you need to replicate files from one sample from SDK. I'll use oclBandwithTest, you can found samples at:

$(NVIDIA_SDK_INSTALATION)/OpenCL/src

I get makefile and oclBandwithTest.cpp and drag to my HelloBlogCL project in Eclipse. Feel free to use your own way.

5. Rename oclBandwithTest.cpp (in eclipse, pressing F2 key) to HelloBlogCL.cpp.

Open makefile and make a find/Replace by: Find= oclBandwithTest --> Replace = HelloWorldCL

Do Replace all:)

6. At this time, we are only missing the run configuration. First we will need to compile our project at hand, to generate binaries.

go to: $(NVIDIA_SDK_INSTALATION)/OpenCL/src in a terminal and make:

$make dbg=1
$make

Make sure you don't have errors, it will compile all samples including yours. After compilation you can make sure that your project was successful compiled looking at:
$(NVIDIA_SDK_INSTALATION)/OpenCL/bin/linux/debug
and
$(NVIDIA_SDK_INSTALATION)/OpenCL/bin/linux/release

for HelloBlogCL binary. Try to run it, it should run without any problems.

7. Now you have all binaries we will make our run configuration points to it.

Right Mouse Button on Project Name -> Debug As -> Debug Configurations

Now in Debug Configurations Window you can give a name to for your run. For debug configuration, I'll give HelloBlogCL_Debug.

And in C/C++ Application you must point to binary created in previous step:

$(NVIDIA_SDK_INSTALATION)/OpenCL/bin/linux/debug/HelloBlogCL

Now make the same for release configuration, changing the binary path to:
$(NVIDIA_SDK_INSTALATION)/OpenCL/bin/linux/relaease/HelloBlogCL

8. Try to Run using Debug configuration and now you can debug your OpenCL code as usual :)

NOTE: This only have capacity to debug Host Code, for Device code you need wait for future developments or take a look at this page:
http://samritmaity.wordpress.com/2009/11/20/debugging-opencl-program-with-gdb/

FINAL NOTE: At this time you don't have Eclipse auto-completion for OpenCL libs, you can add it in usual way, but for those who are not familiarized with it, it will be part of my next blog post.

Next Blog Post: Putting OpenCL C++ Bindings and Auto Completion working on Eclipse


If you need help or you find some error here, please leave a comment

quarta-feira, 24 de fevereiro de 2010

Starting OpenCL Dev on Linux

Hello Everyone,

I'm just starting my Master Thesis on "Discrete Events Simulation On GPU" and I'm using OpenCL. So, in order to share all my experiences with this new language I've created this blog:)

Let's present me, I'm Portuguese and my name is Vando Pereira, I'm 22 years old and I'm just finishing my Computer Science and Engineering Master. I've a lot of limitation in my written English, so this blog will help me improve that too :)

I'm making my master in OpenCL in NVidia CUDA platform, so the code that will be posted here will be tested on this GPUs (Multiple GPU Config: Gforce 8400 + Gforce 9800 GTX+ and a Single GPU config: Gforce GTX260) The CPU of both machines are a Intel Core 2 E8400 3.0GHz.
In these two machines, we have two important differences, GPU Compute capabilities is 1.1 on 8800 and 1.2 on GTX260. I don't know all diferences yet, but I know that a huge difference exists on Coalesced Access to Global Memory. So I'll explore that in future.

For now, I'm setting up everything that I'll need in linux Environment and I'll post some kind of guide to everyone. First, in Windows setting a new project using VS2008 and debugging looks like peace of cake, but in Linux with remote machines and a IDE with visual debugging (I'll use eclipse) it is giving me a lot of work and time wasted, so I'll share to everyone what I did:)

I'll start tweeting very soon, later I'll post all info where you can find me:)
Hope that future posts can help somebody.

Thank you and be welcome:)