cancel
Showing results for 
Search instead for 
Did you mean: 

Archives Discussions

thedl
Journeyman III

Sample program not requiring any SDK?

Is there some very basic opencl program I can compile and run out there (with instructions) that doesn't depend on an SDK implementation? I have an nvidia card but when I try to build and run the samples from the AMD SDK it reports No GPU was found and reverts to the CPU. I heard if I use the nvidia SDK to develop that it requires an nvidia card to run, but I want it to to be cross platform since my project is to convert a CUDA program that's in development to OpenCL so that it's not just restricted to nvidia cards.

Thanks

0 Likes
16 Replies
notyou
Adept III

thedl wrote:

Is there some very basic opencl program I can compile and run out there (with instructions) that doesn't depend on an SDK implementation? I have an nvidia card but when I try to build and run the samples from the AMD SDK it reports No GPU was found and reverts to the CPU. I heard if I use the nvidia SDK to develop that it requires an nvidia card to run, but I want it to to be cross platform since my project is to convert a CUDA program that's in development to OpenCL so that it's not just restricted to nvidia cards.

Thanks

In order to run any OpenCL program, you don't need the SDK. You do however need the runtime which is typically bundled with the GPU drivers. As for some basic program, try this hello world one: http://www.google.ca/url?sa=t&rct=j&q=opencl%20hello%20world&source=web&cd=10&ved=0CGcQFjAJ&url=http...

The reason you're getting an "error" about not finding a GPU and falling back to the CPU is because you're using AMD's runtime (supporting their GPUs and all SSE2 supporting and up CPUs [if I recall correctly]). You need to install and use Nvidia's runtime in order to get the program to run on their GPU. What you're hearing about the Nvidia SDK is that it only supports Nvidia GPUs, that is, it doesn't even have a fallback mode like AMD's where it can go to the CPU, for Nvidia, it's the GPU or nothing. Note: this makes no difference regarding the portability of the code (unless you use manufacturer specific extensions like AMD has done for their SDK samples), all that needs to be done is to change the runtime.

0 Likes

Thanks, that provided a lot of clarity.

For the sample program, is there special command line options I have to input when compiling? When I just do "gcc opencl_hello_world.c" I get

In file included from opencl_hello_world.c:6:0:

OpenCL/opencl.h:42:19: fatal error: CL/cl.h: No such file or directory

compilation terminated.

I included the OpenCL folder along with all its files I got from the AMD SDK install in my folder the sample is located in.

0 Likes

That's because what you're doing is trying to build a regular program, not an OpenCL one. What you need to do is add in the parameters to link in the OpenCL libraries, start here: http://stackoverflow.com/questions/4059676/compiling-opencl-on-ubuntu. If you still can't get it working, let me know and I can dig up the commands I use and you can modify them to suit your installation.

0 Likes

Yeah that would be helpful, this is what I currently get.

g++ opencl_hello_world.c -IOpenCL

opencl_hello_world.c:19:1: warning: deprecated conversion from string constant to ‘char*’

/tmp/ccVjJQRv.o: In function `main':

opencl_hello_world.c:(.text+0x6e): undefined reference to `clGetDeviceIDs'

opencl_hello_world.c:(.text+0x95): undefined reference to `clCreateContext'

opencl_hello_world.c:(.text+0xb3): undefined reference to `clCreateCommandQueue'

opencl_hello_world.c:(.text+0xda): undefined reference to `clCreateBuffer'

opencl_hello_world.c:(.text+0xff): undefined reference to `clCreateProgramWithSource'

opencl_hello_world.c:(.text+0x12a): undefined reference to `clBuildProgram'

opencl_hello_world.c:(.text+0x140): undefined reference to `clCreateKernel'

opencl_hello_world.c:(.text+0x161): undefined reference to `clSetKernelArg'

opencl_hello_world.c:(.text+0x1b9): undefined reference to `clEnqueueNDRangeKernel'

opencl_hello_world.c:(.text+0x1f9): undefined reference to `clEnqueueReadBuffer'

opencl_hello_world.c:(.text+0x205): undefined reference to `clReleaseMemObject'

opencl_hello_world.c:(.text+0x211): undefined reference to `clReleaseKernel'

opencl_hello_world.c:(.text+0x21d): undefined reference to `clReleaseProgram'

opencl_hello_world.c:(.text+0x229): undefined reference to `clReleaseCommandQueue'

opencl_hello_world.c:(.text+0x235): undefined reference to `clReleaseContext'

collect2: ld returned 1 exit status

0 Likes

I'm going from memory here since I'm not at my Linux box right now. I can give you the exact build commands I use in a few hours. But this page should help: http://stackoverflow.com/questions/7657660/opencl-undefined-reference-but-lib-files-in-the-right-pla....

0 Likes

Yeah I already tried using the std=c99 and -std=gnu99 commands but no luck.

0 Likes

OK, if I remember, you've got the linker but you haven't included the CL.hpp file. You should add -I <path to CL.hpp> (made up example: -I /usr/lib/CL/CL.hpp ) to the command line. If this doesn't finish it, I'll post back when I'm at my Linux machine.

0 Likes

Yeah, no luck. I greatly appreciate your help though.

0 Likes

This is what I used to compile the hello world program here:

http://www.thebigblob.com/getting-started-with-opencl-and-gpu-computing/

 

Copy the CL and lib folders into your project folder. // just so I can always use the same path

 

Then use "g++ -c -I /home/ideas/Downloads/ main.cpp -o main.o" and

              "g++ -L /home/ideas/Downloads/lib/x86/ -l OpenCL main.o -o host" to compile the program.

// obviously, replace the path with your own location.

Then run the program using ./host.

0 Likes

Still not working:

g++ -c -I /home/dl/test  opencl_hello_world.c -o main.o

opencl_hello_world.c:19:1: warning: deprecated conversion from string constant to ‘char*’

g++ -L /home/dl/test/lib/x86_64 -I OpenCL main.o -o host

main.o: In function `main':

opencl_hello_world.c:(.text+0x6e): undefined reference to `clGetDeviceIDs'

opencl_hello_world.c:(.text+0x95): undefined reference to `clCreateContext'

opencl_hello_world.c:(.text+0xb3): undefined reference to `clCreateCommandQueue'

opencl_hello_world.c:(.text+0xda): undefined reference to `clCreateBuffer'

opencl_hello_world.c:(.text+0xff): undefined reference to `clCreateProgramWithSource'

opencl_hello_world.c:(.text+0x12a): undefined reference to `clBuildProgram'

opencl_hello_world.c:(.text+0x140): undefined reference to `clCreateKernel'

opencl_hello_world.c:(.text+0x161): undefined reference to `clSetKernelArg'

opencl_hello_world.c:(.text+0x1b9): undefined reference to `clEnqueueNDRangeKernel'

opencl_hello_world.c:(.text+0x1f9): undefined reference to `clEnqueueReadBuffer'

opencl_hello_world.c:(.text+0x205): undefined reference to `clReleaseMemObject'

opencl_hello_world.c:(.text+0x211): undefined reference to `clReleaseKernel'

opencl_hello_world.c:(.text+0x21d): undefined reference to `clReleaseProgram'

opencl_hello_world.c:(.text+0x229): undefined reference to `clReleaseCommandQueue'

opencl_hello_world.c:(.text+0x235): undefined reference to `clReleaseContext'

collect2: ld returned 1 exit status

I have included both the CL and lib folders into the test folder.

0 Likes

Actually it compiles since I thought -I was a capitalized i and not an l.

But when I try to run it, it just seg faults.

0 Likes

Then all I can guess is that something in youur environment isn't set up properly. Unless you want to put printfs through the program to see where it's segfaulting.

0 Likes
notzed
Challenger

The SDK is only required to compile code: code compiled on any SDK should run with any vendor's driver.   Originally AMD's driver was only available in the SDK, but now it's in the catalyst drivers too.

However:

a) The vendor driver software must be installed correctly, including the ICD stuff (e.g. /etc/OpenCL/vendors/* on linux)

b) The application software need to query available platforms for devices properly.  If it just tries to get a GPU device from the first platform it finds, it will fail if it defaults to the AMD platform where no AMD GPU exists.

e.g. when i had an nvidia card i also had amd's sdk installed, and just chose whether to use a gpu or the cpu backend by changing the device selection code.

0 Likes

notzed wrote:

e.g. when i had an nvidia card i also had amd's sdk installed, and just chose whether to use a gpu or the cpu backend by changing the device selection code.

Out of curiosity, I haven't dealt with cross-manufacturer solutions before, is there a problem using AMD's runtime driver (instead of Nvidia's) with an Nvidia GPU (and choosing to use a GPU device)? Does it automatically fall back to the CPU or does it run correctly?

0 Likes

notyou,

AMD does not have access to Nvidia drivers, so our software cannot work on their drivers/devices. The only reason it works on the CPU is that x86 execution does not require a specialized driver to access it.

0 Likes

It doesn't need 'fall back', it just doesn't find any GPU devices in that case.  Obviously AMD isn't going to include an Nvidia driver in their software even if they had enough information to do it; OpenCL has explicit support for multiple vendors via the platform abstraction.

So the AMD platform would just list the CPU driver by itself if there was no AMD GPU installed.

I use this scenario for testing inside virtualbox so I don't have to reboot into microsoft's  os just to check the code will run on the client's machine.

0 Likes