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

Re: Sample program not requiring any SDK?

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
notzed
Challenger

Re: Sample program not requiring any SDK?

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
notyou
Adept III

Re: Sample program not requiring any SDK?

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
MicahVillmow
Staff
Staff

Re: Sample program not requiring any SDK?

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
thedl
Journeyman III

Re: Sample program not requiring any SDK?

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
notyou
Adept III

Re: Sample program not requiring any SDK?

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
thedl
Journeyman III

Re: Sample program not requiring any SDK?

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
notyou
Adept III

Re: Sample program not requiring any SDK?

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
thedl
Journeyman III

Re: Sample program not requiring any SDK?

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

0 Likes