6 Replies Latest reply: Nov 3, 2013 10:39 PM by nou RSS

OpenCL do not detect the number of APU CL_DEVICE_MAX_COMPUTE_UNITS correctly

ssuarezbe Newbie
Currently Being Moderated

Hi.

 

I'm just a novice in the OpenCL world and before start coding real programs I have just do some basic code to detect the available devices in my computer.

To do that I wrote this code.

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

#define __CL_ENABLE_EXCEPTIONS

#include <CL/cl.hpp>

#include <iostream>

 

// Get device type as string

char* getDevTypeString(cl_device_type type)

{

          switch(type)

          {

          case CL_DEVICE_TYPE_CPU:

                    return "CPU";

                    break;

          case CL_DEVICE_TYPE_GPU:

                    return "GPU";

                    break;

          case CL_DEVICE_TYPE_ACCELERATOR:

                    return "ACCELERATOR";

                    break;

          default:

                    return "DEFAULT";

                    break;

          }

}

 

int main()

{

 

    /* Host/device data structures */

    cl_platform_id platform;

    cl_device_id *devices;

    cl_uint num_devices, addr_data,comp_units;

    cl_int err;

    cl_device_type deviceType;

    char name_data[48];

 

    /* Identify a platform */

    err = clGetPlatformIDs(1, &platform, NULL);

    if(err < 0)

    {

        std::cerr<<"Couldn't find any platforms "<<err;

        exit(1);

    }

 

    /* Determine number of connected devices */

    err = clGetDeviceIDs(platform, CL_DEVICE_TYPE_ALL, (cl_uint)0, NULL, &num_devices);

    if(err < 0)

    {

        std::cerr<<"Couldn't find any devices "<<err;

        exit(1);

    }

 

    /* Access connected devices */

    devices = (cl_device_id*)malloc(sizeof(cl_device_id) * num_devices);

    clGetDeviceIDs(platform, CL_DEVICE_TYPE_ALL,num_devices, devices, NULL);

 

    /* Obtain data for each connected device */

    for (int i=0;i<num_devices;i++){

        /*Device proporties list

           http://www.khronos.org/registry/cl/sdk/1.0/docs/man/xhtml/clGetDeviceInfo.html

        */

        err = clGetDeviceInfo(devices[i], CL_DEVICE_NAME,sizeof(name_data), name_data, NULL);

        if(err < 0) {

            std::cerr<<"Couldn't read extension data";

            exit(1);

        }

        clGetDeviceInfo(devices[i], CL_DEVICE_ADDRESS_BITS,sizeof(addr_data), &addr_data, NULL);

        clGetDeviceInfo(devices[i], CL_DEVICE_EXTENSIONS,sizeof(ext_data), ext_data, NULL);

        clGetDeviceInfo(devices[i], CL_DEVICE_MAX_COMPUTE_UNITS,sizeof(comp_units), &comp_units, NULL);

        clGetDeviceInfo(devices[i], CL_DEVICE_TYPE,sizeof(deviceType), &deviceType, NULL);

        std::cout<<"NAME: "<<name_data<<"\nType: "<<getDevTypeString(deviceType)

                <<"\nADDRESS_WIDTH:"<<addr_data<<"\nCompute Units:"<<comp_units<<std::endl;

        std::cout<<"--------------------------------------------------------------------------------"<<std::endl;

    }

    free(devices);

    return 0;

}

 

 

 

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

***** The problem is that the program returns:

 

NAME: Devastator

Type: GPU

ADDRESS_WIDTH:32

Compute Units:4

--------------------------------------------------------------------------------

NAME: AMD A8-5600K APU with Radeon(tm) HD Graphics  

Type: CPU

ADDRESS_WIDTH:64

Compute Units:4

--------------------------------------------------------------------------------

 

Which is wrong because the number of "Compute Units" for the GPU should be 256.

I have already update the driver  to Catalyst 13.04 and installed the AMD SDK 2.8.1 .

My operating System is Ubuntu 12.04.

 

Did I do something wrong? Please help!!

More Like This

Legend

  • Correct Answers - 4 points
  • Helpful Answers - 2 points