3 Replies Latest reply on Jun 16, 2012 9:33 PM by nathan1986

    OpenCL and Code::Blocks (win32/64)

    agenthex

      EDIT:  Figured it out.  The clGetPlatformIDs was limited to a single entry.  I changed platforms to an array of 2 elements because &available was returning 2 platforms, not 3 devices on 1 platform.  Code updated to add second platform and change num_entries to 2.

       

      -- Original Message --

       

      I am new to OpenCL programming, and I have configured my compiler with proper headers and link libraries.  I can compile sample code found on the Internet (with the addition of a few C headers), but despite compiling with the OpenCL files from the AMD APP SDK, the only device recognized is an nVidia 9500GT in the last PCI-E slot.

       

      I have run GPUCaps, and it can see all my hardware fine (I have a FX-8120 and a Radeon HD 5870).  The function clGetDeviceIDs() takes a pointer to a cl_uint (or just passed by reference), and returns only 1 detected device.  Am I doing something wrong?  I've attached the sample OCL code I'm using to poll GPUs.  Please let me know if I've missed something.

       

      Thanks.

       

      -- Modified Code as per EDIT --

       

      #include <CL/cl.h>

      #include <string.h>

      #include <stdio.h>

       

      using namespace std;

       

      typedef struct DeviceDesc

      {

          cl_device_id    deviceId;

          cl_device_type  deviceType;

          char*           deviceTypeString;

          char*           deviceName;

      } DeviceDesc;

       

      int main(void)

      {

          unsigned int        i;

          unsigned int        maxDevices = 5;

          cl_device_id*       deviceIDs = new cl_device_id[maxDevices];

          cl_platform_id*     platforms = new cl_platform_id[2];

          cl_int              err;

          cl_uint             num_entries = 2;

          cl_uint             available;

          cl_uint             numDevices;

          DeviceDesc*         devices;

       

          //Get available platforms (we will use the first result, I think most of the time we have

          //one platform on personnal computers)

          cl_int result = clGetPlatformIDs(num_entries, platforms, &available);

       

          for (unsigned int j(0); j < available; ++j)

          {

              err = clGetDeviceIDs(platforms[j], CL_DEVICE_TYPE_ALL, maxDevices, deviceIDs, &numDevices);

       

              devices = new DeviceDesc[numDevices];

       

              for(i=0 ; i<numDevices ; i++)

              {

                  devices[i].deviceId = deviceIDs[i];

                  size_t actualSize;

       

                  //Getting the device type (processor, graphics card, accelerator)

                  result = clGetDeviceInfo(

                               deviceIDs[i],

                               CL_DEVICE_TYPE,

                               sizeof(cl_device_type),

                               &devices[i].deviceType,

                               &actualSize);

       

                  //Getting the human readable device type

                  switch(devices[i].deviceType)

                  {

                  case CL_DEVICE_TYPE_CPU:

                      devices[i].deviceTypeString = "CPU";

                      break;

                  case CL_DEVICE_TYPE_GPU:

                      devices[i].deviceTypeString = "GPU";

                      break;

                  case CL_DEVICE_TYPE_ACCELERATOR:

                      devices[i].deviceTypeString = "APU";

                      break;

                  default:

                      devices[i].deviceTypeString = "???";

                      break;

                  }

       

                  //Getting the device name

                  size_t deviceNameLength = 4096;

                  char* tempDeviceName = new char[4096];

                  result |= clGetDeviceInfo(

                                deviceIDs[i],

                                CL_DEVICE_NAME,

                                deviceNameLength,

                                tempDeviceName,

                                &actualSize);

                  if(result == CL_SUCCESS)

                  {

                      devices[i].deviceName = new char[actualSize];

                      memcpy(devices[i].deviceName, tempDeviceName, actualSize);

                      delete [] tempDeviceName;

                  }

       

                  //If an error occured

                  if(result != CL_SUCCESS)

                  {

                      printf("Error while getting device info.\n");

                      return 1;

                  }

              }

       

              //And finally we print the information we wanted to have

              for(i=0 ; i<numDevices ; i++)

              {

                  printf("Device %s is of type %s.\n", devices[i].deviceName, devices[i].deviceTypeString);

              }

          }

       

          //Free memory

          delete [] deviceIDs;

          delete platforms;

       

          return 0;

      }

        • Re: OpenCL and Code::Blocks (win32/64)
          nathan1986

          hi, agenthex,

               It seems that you have installed two SDKs(NVIDIA and AMD) on your computer, so you got 2 available platform. Is the devices you see on NVIDIA platform? you can use clGetPlatromInfo() to check the platform vendor after each clGetPlatformIDs().

               It is still amazing me  that you have printed all the devices on the two platforms, but you can't see AMD devices. Maybe on AMD platform, you didn't get any devices available, please try to re-install the AMD Catalyst driver to see if the problem is solved.