get opencl information

int get_device_info(cl_device_id deviceID)
{
    char param_value[1024];
    size_t ret_size;
    //get device Type
/* /usr/include/CL/cl.h
#define CL_DEVICE_TYPE_DEFAULT                      (1 << 0)
#define CL_DEVICE_TYPE_CPU                          (1 << 1)
#define CL_DEVICE_TYPE_GPU                          (1 << 2)
#define CL_DEVICE_TYPE_ACCELERATOR                  (1 << 3)
#define CL_DEVICE_TYPE_CUSTOM                       (1 << 4)
#define CL_DEVICE_TYPE_ALL                          0xFFFFFFFF
*/
    clGetDeviceInfo(deviceID, CL_DEVICE_TYPE, 1024, param_value, &ret_size);
    long long *pType =(long long*)param_value;
    printf("ret size %d, device type: %ld\n", ret_size, *pType);

    //get device name
    clGetDeviceInfo(deviceID, CL_DEVICE_NAME, 1024, param_value, &ret_size);
    printf("ret size %d, device name: %s\n", ret_size, param_value);

    //get device  vendor
    clGetDeviceInfo(deviceID, CL_DEVICE_VENDOR, 1024, param_value, &ret_size);
    printf("ret size %d, device vendor: %s\n", ret_size, param_value);

    //get device  version
    clGetDeviceInfo(deviceID, CL_DEVICE_VERSION, 1024, param_value, &ret_size);
    printf("ret size %d, device version: %s\n", ret_size, param_value);

    //get device profile 
    clGetDeviceInfo(deviceID, CL_DEVICE_PROFILE, 1024, param_value, &ret_size);
    printf("ret size %d, device profile: %s\n", ret_size, param_value);

    //get device opencl c info 
    clGetDeviceInfo(deviceID, CL_DEVICE_OPENCL_C_VERSION, 1024, param_value, &ret_size);
    printf("ret size %d, device opencl c version: %s\n", ret_size, param_value);

    //get device parallel units
    clGetDeviceInfo(deviceID, CL_DEVICE_VENDOR_ID, 1024, param_value, &ret_size);
    unsigned int *pTypeUint =(unsigned int*)param_value;
    printf("ret size %d, parrallel units: %d\n", ret_size, *pTypeUint);

    //get device work dimensions 
    clGetDeviceInfo(deviceID, CL_DEVICE_MAX_WORK_ITEM_DIMENSIONS, 1024, param_value, &ret_size); 
    pTypeUint =(unsigned int*)param_value;
    printf("ret size %d, work dimensions: %d\n", ret_size, *pTypeUint);

    //get device max working-entry per dimension
    clGetDeviceInfo(deviceID, CL_DEVICE_MAX_WORK_ITEM_SIZES, 1024, param_value, &ret_size); 
    size_t *pTypeSize_t =(size_t*)param_value;
    printf("ret size %d, work dimensions 0 workSize: %d, work dimensions 1 workSize: %d, work dimensions 2 workSize: %d\n", 
                ret_size, *pTypeSize_t, *(pTypeSize_t+1), *(pTypeSize_t+2));

    //get device max working-entry per group of one compute unit
    clGetDeviceInfo(deviceID, CL_DEVICE_MAX_WORK_GROUP_SIZE, 1024, param_value, &ret_size); 
    pTypeSize_t =(size_t*)param_value;
    printf("ret size %d, work-entry max num per group in one compute unit : %d\n", ret_size, *pTypeSize_t );

    //check if or not gpu support the vector data type, if return value is 0, not support;else return value is the width of that data type.
    clGetDeviceInfo(deviceID, CL_DEVICE_PREFERRED_VECTOR_WIDTH_CHAR, 1024, param_value, &ret_size); 
    pTypeUint =(unsigned int*)param_value;
    printf("ret size %d, preferred vector char: %d\n", ret_size, *pTypeUint);
    clGetDeviceInfo(deviceID, CL_DEVICE_PREFERRED_VECTOR_WIDTH_SHORT, 1024, param_value, &ret_size); 
    pTypeUint =(unsigned int*)param_value;
    printf("ret size %d, preferred vector short: %d\n", ret_size, *pTypeUint);
    clGetDeviceInfo(deviceID, CL_DEVICE_PREFERRED_VECTOR_WIDTH_INT, 1024, param_value, &ret_size); 
    pTypeUint =(unsigned int*)param_value;
    printf("ret size %d, preferred vector int: %d\n", ret_size, *pTypeUint);
    clGetDeviceInfo(deviceID, CL_DEVICE_PREFERRED_VECTOR_WIDTH_LONG, 1024, param_value, &ret_size); 
    pTypeUint =(unsigned int*)param_value;
    printf("ret size %d, preferred vector long: %d\n", ret_size, *pTypeUint);
    clGetDeviceInfo(deviceID, CL_DEVICE_PREFERRED_VECTOR_WIDTH_FLOAT, 1024, param_value, &ret_size); 
    pTypeUint =(unsigned int*)param_value;
    printf("ret size %d, preferred vector float: %d\n", ret_size, *pTypeUint);
    clGetDeviceInfo(deviceID, CL_DEVICE_PREFERRED_VECTOR_WIDTH_DOUBLE, 1024, param_value, &ret_size); 
    pTypeUint =(unsigned int*)param_value;
    printf("ret size %d, preferred vector double: %d\n", ret_size, *pTypeUint);
    clGetDeviceInfo(deviceID, CL_DEVICE_PREFERRED_VECTOR_WIDTH_HALF, 1024, param_value, &ret_size); 
    pTypeUint =(unsigned int*)param_value;
    printf("ret size %d, preferred vector half: %d\n", ret_size, *pTypeUint);

    //get native instruction vetor width
    clGetDeviceInfo(deviceID, CL_DEVICE_NATIVE_VECTOR_WIDTH_CHAR, 1024, param_value, &ret_size); 
    pTypeUint =(unsigned int*)param_value;
    printf("ret size %d, native vector char: %d\n", ret_size, *pTypeUint);
    clGetDeviceInfo(deviceID, CL_DEVICE_NATIVE_VECTOR_WIDTH_SHORT, 1024, param_value, &ret_size); 
    pTypeUint =(unsigned int*)param_value;
    printf("ret size %d, native vector short: %d\n", ret_size, *pTypeUint);
    clGetDeviceInfo(deviceID, CL_DEVICE_NATIVE_VECTOR_WIDTH_INT, 1024, param_value, &ret_size); 
    pTypeUint =(unsigned int*)param_value;
    printf("ret size %d, native vector int: %d\n", ret_size, *pTypeUint);
    clGetDeviceInfo(deviceID, CL_DEVICE_NATIVE_VECTOR_WIDTH_LONG, 1024, param_value, &ret_size); 
    pTypeUint =(unsigned int*)param_value;
    printf("ret size %d, native vector long: %d\n", ret_size, *pTypeUint);
    clGetDeviceInfo(deviceID, CL_DEVICE_NATIVE_VECTOR_WIDTH_DOUBLE, 1024, param_value, &ret_size); 
    pTypeUint =(unsigned int*)param_value;
    printf("ret size %d, native vector double: %d\n", ret_size, *pTypeUint);
    clGetDeviceInfo(deviceID, CL_DEVICE_NATIVE_VECTOR_WIDTH_HALF, 1024, param_value, &ret_size); 
    pTypeUint =(unsigned int*)param_value;
    printf("ret size %d, native vector half: %d\n", ret_size, *pTypeUint);

    //get max clock frequency in MHz
    clGetDeviceInfo(deviceID, CL_DEVICE_MAX_CLOCK_FREQUENCY, 1024, param_value, &ret_size); 
    pTypeUint =(unsigned int*)param_value;
    printf("ret size %d, max clock frequency: %d MHz\n", ret_size, *pTypeUint);

    //get address space bits
    clGetDeviceInfo(deviceID, CL_DEVICE_ADDRESS_BITS, 1024, param_value, &ret_size); 
    pTypeUint =(unsigned int*)param_value;
    printf("ret size %d, address space bits: %d\n", ret_size, *pTypeUint);

    //get the max bytes of mem objects allocated
    clGetDeviceInfo(deviceID, CL_DEVICE_MAX_MEM_ALLOC_SIZE, 1024, param_value, &ret_size); 
    unsigned long *pTypeUlong =(unsigned long*)param_value;
    printf("ret size %d, max  bytes of one mem object: %ld\n", ret_size, *pTypeUlong);

    //get if or not support image
    clGetDeviceInfo(deviceID, CL_DEVICE_IMAGE_SUPPORT, 1024, param_value, &ret_size); 
    pTypeUint=(unsigned int*)param_value;
    printf("ret size %d, image support: %d\n", ret_size, *pTypeUint);

    //get max number of readonly image objects
    clGetDeviceInfo(deviceID, CL_DEVICE_MAX_READ_IMAGE_ARGS, 1024, param_value, &ret_size); 
    pTypeUint=(unsigned int*)param_value;
    printf("ret size %d, max number of readonly image objects: %d\n", ret_size, *pTypeUint);

    //get max number of writeonly image objects
    clGetDeviceInfo(deviceID, CL_DEVICE_MAX_WRITE_IMAGE_ARGS, 1024, param_value, &ret_size); 
    pTypeUint=(unsigned int*)param_value;
    printf("ret size %d, max number of writeonly image objects: %d\n", ret_size, *pTypeUint);

    //get max number of readwrite image objects
    clGetDeviceInfo(deviceID, CL_DEVICE_MAX_READ_WRITE_IMAGE_ARGS, 1024, param_value, &ret_size); 
    pTypeUint=(unsigned int*)param_value;
    printf("ret size %d, max number of readwrite image objects: %d\n", ret_size, *pTypeUint);

    //get max width of image2D 
    clGetDeviceInfo(deviceID, CL_DEVICE_IMAGE2D_MAX_WIDTH, 1024, param_value, &ret_size); 
    pTypeSize_t =(size_t*)param_value;
    printf("ret size %d, max width of image2D: %d\n", ret_size, *pTypeSize_t);

    //get max height of image2D 
    clGetDeviceInfo(deviceID, CL_DEVICE_IMAGE2D_MAX_HEIGHT, 1024, param_value, &ret_size); 
    pTypeSize_t =(size_t*)param_value;
    printf("ret size %d, max height of image2D: %d\n", ret_size, *pTypeSize_t);

    //get max buffer size of image1D 
    clGetDeviceInfo(deviceID, CL_DEVICE_IMAGE_MAX_BUFFER_SIZE, 1024, param_value, &ret_size); 
    pTypeSize_t =(size_t*)param_value;
    printf("ret size %d, max buffer size of image1D: %d\n", ret_size, *pTypeSize_t);

    //get max image number of image group, also named array size
    clGetDeviceInfo(deviceID, CL_DEVICE_IMAGE_MAX_ARRAY_SIZE, 1024, param_value, &ret_size); 
    pTypeSize_t =(size_t*)param_value;
    printf("ret size %d, max image number of image group, also named array size: %d\n", ret_size, *pTypeSize_t);

    //get the global cacheline size in bytes
    clGetDeviceInfo(deviceID, CL_DEVICE_GLOBAL_MEM_CACHELINE_SIZE, 1024, param_value, &ret_size); 
    pTypeUint=(unsigned int*)param_value;
    printf("ret size %d, the global cacheline size in bytes: %d\n", ret_size, *pTypeUint);

    //get the global cache size in bytes
    clGetDeviceInfo(deviceID, CL_DEVICE_GLOBAL_MEM_CACHE_SIZE, 1024, param_value, &ret_size); 
    pTypeUlong=(unsigned long*)param_value;
    printf("ret size %d, the global cache size in bytes: %d\n", ret_size, *pTypeUlong);

    //get the global mem size in bytes
    clGetDeviceInfo(deviceID, CL_DEVICE_GLOBAL_MEM_SIZE, 1024, param_value, &ret_size); 
    pTypeUlong=(unsigned long*)param_value;
    printf("ret size %d, the global mem size in bytes: %ld\n", ret_size, *pTypeUlong);

    //get the local mem size in bytes
    clGetDeviceInfo(deviceID, CL_DEVICE_LOCAL_MEM_SIZE, 1024, param_value, &ret_size); 
    pTypeUlong=(unsigned long*)param_value;
    printf("ret size %d, the local mem size in bytes: %d\n", ret_size, *pTypeUlong);

    //get the preferred queue number of device
    clGetDeviceInfo(deviceID, CL_DEVICE_QUEUE_ON_DEVICE_PREFERRED_SIZE, 1024, param_value, &ret_size); 
    pTypeUint =(unsigned int*)param_value;
    printf("ret size %d, preferred queue number of device: %d\n", ret_size, *pTypeUint);

    //get the max queue number of device
    clGetDeviceInfo(deviceID, CL_DEVICE_QUEUE_ON_DEVICE_MAX_SIZE, 1024, param_value, &ret_size); 
    pTypeUint =(unsigned int*)param_value;
    printf("ret size %d,  max queue number of device: %d\n", ret_size, *pTypeUint);

    return 0;
}
 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值