AnsweredAssumed Answered

about clGetDeviceInfo()

Question asked by kalab1998 on Jul 20, 2013
Latest reply on Jul 23, 2013 by kalab1998

I'm studying OpenCL now. I'd like to program like clinfo command. And I write code as follows on AMDAPP 2.8.1. but this code is wrong running.


Concretely, I get an information when this program call clGetDeviceInfo() on core i5-430UM and no GPU machine at first time,



ret = clGetDeviceInfo( device_id[dv], CL_DEVICE_TYPE, MAX_MSG_SIZE, (void*)(&msg_uint), &msglen);
printf( "  ret = %d, msg = %d\n", ret, msg_uint);



ret = 0, msg = 2


but I don't get any information and return code -33 when this program call clGetDeviceInfo() at second time.



ret = clGetDeviceInfo( device_id[dv], CL_DEVICE_VENDOR, MAX_MSG_SIZE, (void*)msg, &msglen);
printf( "  ret = %d, msg = %s\n, ret, msg);



ret = -33, msg = ...(depends memory status)


Please teach me where is my code wrong.


Program Code:

#include <stdio.h>
#include <stdlib.h>


#ifdef __APPLE__
#include <OpenCL/opencl.h>
#include <CL/cl.h>


#define MAX_MSG_SIZE 256
#define MAX_PLATFORMS 16
#define MAX_DEVICES 256


int main()
  cl_platform_id platform_id[ MAX_PLATFORMS];
  cl_platform_info platform_info;
  cl_uint platforms_num;


  cl_device_id device_id[ MAX_DEVICES];
  cl_uint devices_num;


  cl_uint dummy;
  cl_int ret;
  char msg[ MAX_MSG_SIZE];
  size_t msglen;
  cl_uint msg_uint;
  cl_ulong msg_ulong;
  size_t msg_dim[ MAX_MSG_SIZE];
  ret = clGetPlatformIDs( MAX_PLATFORMS, platform_id, &platforms_num);


  for ( int pf = 0; pf < platforms_num; pf++) {
    printf( "Platform %d:\n", pf);
    ret = clGetPlatformInfo( platform_id[pf], CL_PLATFORM_PROFILE,
                 MAX_MSG_SIZE, (void*)msg, &msglen);
    printf( "  PLATFORM_PROFILE\t%s\n", msg);
    ret = clGetPlatformInfo( platform_id[pf], CL_PLATFORM_VERSION,
                 MAX_MSG_SIZE, (void*)msg, &msglen);
    printf( "  PLATFORM_VERSION\t%s\n", msg);
    ret = clGetPlatformInfo( platform_id[pf], CL_PLATFORM_NAME,
                 MAX_MSG_SIZE, (void*)msg, &msglen);
    printf( "  PLATFORM_NAME\t\t%s\n", msg);
    ret = clGetPlatformInfo( platform_id[pf], CL_PLATFORM_VENDOR,
                 MAX_MSG_SIZE, (void*)msg, &msglen);
    printf( "  PLATFORM_VENDOR\t%s\n", msg);
    ret = clGetPlatformInfo( platform_id[pf], CL_PLATFORM_EXTENSIONS,
                 MAX_MSG_SIZE, (void*)msg, &msglen);
    printf( "  PLATFORM_EXTENTIONS\t%s\n", msg);
    ret = clGetDeviceIDs( platform_id[pf], CL_DEVICE_TYPE_ALL, MAX_DEVICES,
              device_id, &devices_num);


    for ( int dv = 0; dv < devices_num; dv++) {
      printf( "platform %d: device %d:\n", pf, dv);
      ret = clGetDeviceInfo( device_id[dv], CL_DEVICE_TYPE,
                 MAX_MSG_SIZE, (void*)(&msg_uint), &msglen);
      printf( "  ret = %d, dvid = %d\n", ret, device_id[dv]);
      printf( "  DEVICE_TYPE\t%d ", msg_uint);
      switch ( msg_uint) {
      case CL_DEVICE_TYPE_CPU:
    printf( "CPU\n");
      case CL_DEVICE_TYPE_GPU:
    printf( "GPU\n");
    printf( "ACCELERATOR\n");
    printf( "CUSTOM\n");
    printf( "\n");


      ret = clGetDeviceInfo( device_id[dv], CL_DEVICE_VENDOR,
                 MAX_MSG_SIZE, (void*)msg, &msglen);
      printf( "  ret = %d, dvid = %d\n", ret, device_id[dv]);
      printf( "  DEVICE_VENDOR\t%s\n", msg);
      ret = clGetDeviceInfo( device_id[dv], CL_DEVICE_NAME,
                 MAX_MSG_SIZE, (void*)msg, &msglen);
      printf( "  DEVICE_NAME\t%s\n", msg);
      ret = clGetDeviceInfo( device_id[dv], CL_DRIVER_VERSION,
                 MAX_MSG_SIZE, (void*)msg, &msglen);
      printf( "  DRIVER_VERSION\t%s\n", msg);
      ret = clGetDeviceInfo( device_id[dv], CL_DEVICE_PROFILE,
                 MAX_MSG_SIZE, (void*)msg, &msglen);
      printf( "  DEVICE_PROFILE\t%s\n", msg);
      ret = clGetDeviceInfo( device_id[dv], CL_DEVICE_VERSION,
                 MAX_MSG_SIZE, (void*)msg, &msglen);
      printf( "  DEVICE_VERSION\t%s\n", msg);
      ret = clGetDeviceInfo( device_id[dv], CL_DEVICE_OPENCL_C_VERSION,
                 MAX_MSG_SIZE, (void*)msg, &msglen);
      printf( "  DEVICE_OPENCL_C_VERSION\t%s\n", msg);
      ret = clGetDeviceInfo( device_id[dv], CL_DEVICE_EXTENSIONS,
                 MAX_MSG_SIZE, (void*)msg, &msglen);
      printf( "  DEVICE_EXTENSIONS\t%s\n", msg);


    ret = clGetDeviceIDs( platform_id[ pf], CL_DEVICE_TYPE_ALL, 1,
              &device_id, &devices_num);
    ret = clGetDeviceIDs( platform_id[ pf], CL_Device_TYPE_ALL, devices_num,
              &device_id, &dummy);
  return 0;