16 Replies Latest reply on Feb 25, 2012 9:50 AM by notyou

    Sample program not requiring any SDK?

    thedl

      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

        • Re: Sample program not requiring any SDK?
          notyou

          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%3A%2F%2Fwww.it.uu.se%2Fkatalog%2Fdavbl791%2Fpresentations%2Fopencl_hello_world.c&ei=ibxFT4bKNYqZgwe96OWvBA&usg=AFQjCNE3wOWKG-01jCo0F1V1XEFS4bpNpA

           

          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.

            • Re: Sample program not requiring any SDK?
              thedl

              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.

                • Re: Sample program not requiring any SDK?
                  notyou

                  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.

                    • Re: Sample program not requiring any SDK?
                      thedl

                      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

                • Re: Sample program not requiring any SDK?
                  notzed

                  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.

                    • Re: Sample program not requiring any SDK?
                      notyou

                      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?

                        • Re: Sample program not requiring any SDK?
                          MicahVillmow

                          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.

                          • Re: Sample program not requiring any SDK?
                            notzed

                            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.