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.html
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
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