Reply to comment

  1.         //Get an OpenCL platform
  2.         cl_platform_id cpPlatform;
  3.         clGetPlatformIDs(1, &cpPlatform, NULL);
  4.  
  5.         //Get a GPU device
  6.         cl_uint ciDeviceCount;
  7.         cl_int ciErrNum;
  8.         ciErrNum = clGetDeviceIDs (cpPlatform, CL_DEVICE_TYPE_GPU, 0, NULL, &ciDeviceCount);
  9.         if (ciDeviceCount == 0 || ciErrNum != CL_SUCCESS){
  10.                 printf("No opencl devices!\n");
  11.                 return 0;
  12.         }
  13.  
  14.         //get devices ID
  15.         cl_device_id *devices;
  16.         devices = (cl_device_id*)malloc(sizeof(cl_device_id) * ciDeviceCount);
  17.         clGetDeviceIDs (cpPlatform, CL_DEVICE_TYPE_GPU, ciDeviceCount, devices, &ciDeviceCount);
  18.  
  19.         //get device with maximum number of SMs
  20.     char dev_buf[256];
  21.     size_t szReturn;
  22.         int n_Max_Units = 0;
  23.         cl_device_id cdDevice;
  24.         for (size_t i=0; i<ciDeviceCount; i++){
  25.                 cl_int status = clGetDeviceInfo(devices[i], CL_DEVICE_MAX_COMPUTE_UNITS,  sizeof(dev_buf), dev_buf, &szReturn );
  26.                 int n_Compute_Units = *(int*)dev_buf;
  27.                 if (n_Compute_Units > n_Max_Units){
  28.                         cdDevice = devices[i];
  29.                         n_Max_Units = n_Compute_Units;
  30.                 }
  31.         }
  32.         printf("Units count: %d \n", n_Max_Units);
  33.         cl_int status = clGetDeviceInfo(cdDevice, CL_DEVICE_MAX_MEM_ALLOC_SIZE,  sizeof(dev_buf), dev_buf, &szReturn );
  34.         size_t maxMemorySize = *(int*)dev_buf;
  35.         printf("max memory allocated: %u\n", maxMemorySize);
  36.  
  37.         //free device buffer
  38.         free(devices);
  39.  
  40.         //from ati opencl sample
  41.         cl_int err;
  42.     std::vector< cl::Platform > platformList;
  43.     cl::Platform::get(&platformList);
  44.     //checkErr(platformList.size()!=0 ? CL_SUCCESS : -1, "cl::Platform::get");
  45.         std::cout << "Platform number is: " << platformList.size() << std::endl;
  46.         std::string platformVendor;
  47.     platformList[0].getInfo(CL_PLATFORM_VENDOR, &platformVendor);
  48.     std::cout << "Platform is by: " << platformVendor << "\n";

Units count: 9
Max memory allocated: 268435456
Platform number is: 1
Platform is by: Advanced Micro Devices, Inc.

Reply

The content of this field is kept private and will not be shown publicly.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd> <i> <table> <td> <tr> <th>
  • Lines and paragraphs break automatically.
  • You can enable syntax highlighting of source code with the following tags: <code>, <blockcode>. The supported tag styles are: <foo>, [foo].
  • Images can be added to this post.

More information about formatting options

Copyright © 2008-2011 Alex Tutubalin