Advertisement
Guest User

Untitled

a guest
Mar 21st, 2021
160
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.82 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #ifdef __APPLE__
  4. #include <OpenCL/opencl.h>
  5. #else
  6. #include <CL/cl.h>
  7. #endif
  8. //using namespace std;
  9.  
  10. int main() {
  11.     printf("hi\n");
  12.    
  13.     cl_int errcode;
  14.     cl_uint num_platforms;
  15.     errcode = clGetPlatformIDs(0, NULL, &num_platforms);
  16.     //return 0;
  17.     printf("Platforms count: %d\n", num_platforms);
  18.    
  19.     cl_platform_id *platforms;    
  20.     platforms = (cl_platform_id*) malloc(sizeof(cl_platform_id) * num_platforms);
  21.     //platforms = new cl_platform_id[num_platforms];
  22.     errcode = clGetPlatformIDs(num_platforms, platforms, NULL);
  23.    
  24.     for (int i = 0; i < num_platforms; ++i) {
  25.         size_t ret_size;
  26.         errcode = clGetPlatformInfo(platforms[i], CL_PLATFORM_NAME, 0, NULL, &ret_size);
  27.         //char* plat_name = (char*)malloc(ret_size);
  28.         char* plat_name = new char[ret_size];
  29.         errcode = clGetPlatformInfo(platforms[i], CL_PLATFORM_NAME, ret_size, plat_name, NULL);
  30.         printf("%d. %s\n", platforms[i], plat_name);
  31.         //delete[] plat_name;
  32.         free(plat_name);
  33.     }        
  34.    
  35.     for (int i = 0; i < num_platforms; ++i) {
  36.         cl_uint num_devices;
  37.         errcode = clGetDeviceIDs(platforms[i], CL_DEVICE_TYPE_GPU, 0, NULL, &num_devices);
  38.         cl_device_id *devices = (cl_device_id*) malloc(sizeof(cl_device_id) * num_devices);
  39.         errcode = clGetDeviceIDs(platforms[i], CL_DEVICE_TYPE_GPU, num_devices, devices, NULL);
  40.         printf("::%d\n", errcode);
  41.        
  42.         //printf("devices %u\n", num_devices);
  43.         //continue;
  44.         char *driver_version;
  45.         size_t valueSize;
  46.         for (int j = 0; j < num_devices; ++j) {
  47.             errcode = clGetDeviceInfo(devices[j], CL_DEVICE_OPENCL_C_VERSION, 0, NULL, &valueSize);
  48.             printf("::%d\n", errcode);
  49.             printf("ok %u\n", valueSize);
  50.             //valueSize = 50;
  51.             driver_version = (char*) malloc(valueSize);
  52.             errcode = clGetDeviceInfo(devices[j], CL_DEVICE_OPENCL_C_VERSION, valueSize, driver_version, NULL);
  53.             printf("::%d\n", errcode);
  54.             printf("%d. %s\n", devices[j], driver_version);
  55.             free(driver_version);
  56.         }
  57.         free(devices);
  58.     }
  59.     free(platforms);
  60.     //delete[] platforms;
  61.    
  62.     /*char *driver_version;
  63.     size_t valueSize;
  64.     //printf("ok\n");
  65.     for (int i = 0; i < num_platforms; ++i) {
  66.         //clGetDeviceInfo(0, CL_DRIVER_VERSION, sizeof(char*), &driver_version, NULL);
  67.         clGetDeviceInfo(platforms[i], CL_DRIVER_VERSION, 0, NULL, &valueSize);
  68.         printf("ok %u\n", valueSize);
  69.         //valueSize = 50;
  70.         driver_version = (char*) malloc(valueSize);
  71.         clGetDeviceInfo(0, CL_DRIVER_VERSION, valueSize, driver_version, NULL);
  72.         printf("%d. %s\n", platforms[i], driver_version);
  73.     }*/
  74.     return 0;
  75. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement