Getting Started

I am completely new to GPU computing and have downloaded and read the NVIDIA OpenCL Jump Start Guide and the OpenCL Programming Guide for the CUDA Architecture. I have the NVIDIA GPU Computing SDK installed and the example code compiles and runs just fine.

I am running into a problem where I don’t know how to actually compile the code and link it into an executable. I have been digging through the tree of make files in the example directory and have had no success at figuring out how any of it works. If anyone has a simple example of a stand alone program with an easily understood make file it would be greatly appreciated.

assuming you have the gnu toolchain (gcc, make etc) and opencl driver (190.29) installed properly, the only thing you need to do is to navigate into an example folder and type “make”. here is an example based on the path on my machine

cd ~/openclsdk/OpenCL/src/oclDeviceQuery



you can compile all of the examples by typing “make” in the ~/openclsdk/OpenCL folder.

hope that helps

Thank you for your response, doing this works fine but I am trying to figure out how to compile something I write myself assuming that I already have the host code as a cpp and h file and the .cl kernel code.

use build-in string constant to specify the path to your .cl source file in your host code, or use argument (argv) to specify it at run-time.

compile each unit of your code with g++ -c unit1.cpp, and with “g++ -lOpenCL *.o -o binary” to link. then it should be ready to run (given the path to the .cl file is specified). Nothing really special, opencl is just a library with an additional .cl source file.

While trying to compile using this method I get an error that oclUtils.h does not exist in the compiling stage (g++ -c unit1.cpp) is there something else that I need to do here to get this to link to the header file? All I am trying to do here is compile the oclMatrixmultiply in the example directory to narrow down this issue to not being a problem with my code. The whole directory compiles with the make file that came with it with no errors.

use the standard gcc/g++ -I/path/to/find/header syntax. If your libOpenCL is not in the /usr/lib folder, you should do -L/path/to/find/libopencl/ when linking.