cancel
Showing results for 
Search instead for 
Did you mean: 

Archives Discussions

agenthex
Adept I

OpenCL and Code::Blocks (win32/64)

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, CL_DEVICE_TYPE_ALL, maxDevices, deviceIDs, &numDevices);

        devices = new DeviceDesc[numDevices];

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

        {

            devices.deviceId = deviceIDs;

            size_t actualSize;

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

            result = clGetDeviceInfo(

                         deviceIDs,

                         CL_DEVICE_TYPE,

                         sizeof(cl_device_type),

                         &devices.deviceType,

                         &actualSize);

            //Getting the human readable device type

            switch(devices.deviceType)

            {

            case CL_DEVICE_TYPE_CPU:

                devices.deviceTypeString = "CPU";

                break;

            case CL_DEVICE_TYPE_GPU:

                devices.deviceTypeString = "GPU";

                break;

            case CL_DEVICE_TYPE_ACCELERATOR:

                devices.deviceTypeString = "APU";

                break;

            default:

                devices.deviceTypeString = "???";

                break;

            }

            //Getting the device name

            size_t deviceNameLength = 4096;

            char* tempDeviceName = new char[4096];

            result |= clGetDeviceInfo(

                          deviceIDs,

                          CL_DEVICE_NAME,

                          deviceNameLength,

                          tempDeviceName,

                          &actualSize);

            if(result == CL_SUCCESS)

            {

                devices.deviceName = new char[actualSize];

                memcpy(devices.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.deviceName, devices.deviceTypeString);

        }

    }

    //Free memory

    delete [] deviceIDs;

    delete platforms;

    return 0;

}

0 Likes
3 Replies
nathan1986
Adept II

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.

0 Likes

Sorry, no.  I did figure it out.  It shows AMD and nVidia as two different platforms.  The AMD platform shows two devices: Cypress and FX-8120.

The sample code I acquired online did not account for multiple platforms in the same machine, but OpenCL does.

0 Likes

So you can get 3 devices now? what's the question now? I don't find any issue from your code. you can select one platform for develop.

0 Likes