AnsweredAssumed Answered

OpenCL and Code::Blocks (win32/64)

Question asked by agenthex on Jun 16, 2012
Latest reply on Jun 16, 2012 by nathan1986

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.




-- 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(







            //Getting the human readable device type



            case CL_DEVICE_TYPE_CPU:

                devices[i].deviceTypeString = "CPU";


            case CL_DEVICE_TYPE_GPU:

                devices[i].deviceTypeString = "GPU";



                devices[i].deviceTypeString = "APU";



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




            //Getting the device name

            size_t deviceNameLength = 4096;

            char* tempDeviceName = new char[4096];

            result |= clGetDeviceInfo(






            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;