zoukankan      html  css  js  c++  java
  • opencl(二)----平台、设备、上下文的获取

    1、获取平台

    参考:https://www.khronos.org/registry/OpenCL/sdk/1.0/docs/man/xhtml/clGetPlatformInfo.html

    cl_int clGetPlatformIDs(    
         cl_uint num_entries, //想要获取的平台数量
         cl_platform_id *platforms,  // cl_platform_id 指针,获取的平台会保存在这个地址中
         cl_uint *num_platforms  //环境中存在的平台数量
    )
    返回值小于0表示获取平台失败

    获取平台信息

    cl_int clGetPlatformInfo(    
         cl_platform_id platform,  // cl_platform_id 平台
         cl_platform_info param_name,  // 信息类型
         size_t param_value_size,          // 所要保存的字节数
         void *param_value,                 // 所要保存的地址
         size_t *param_value_size_ret   // 实际信息的数据大小
    )

    信息类型

    cl_platform_infoReturn TypeDescription
    CL_PLATFORM_PROFILE char[]

    确认平台是支持完全版本的opencl还是嵌入式版本的

    FULL_PROFILE

    EMBEDDED_PROFILE 

    CL_PLATFORM_VERSION char[]

     

    CL_PLATFORM_NAME char[] Platform name string.
    CL_PLATFORM_VENDOR char[] 返回和平台相关的厂商
    CL_PLATFORM_EXTENSIONS char[] Returns a space-separated list of extension names (the extension names themselves do not contain any spaces) supported by the platform. Extensions defined here must be supported by all devices associated with this platform.

    2、获取设备

    // 获取设备
    cl_int clGetDeviceIDs(    
            cl_platform_id platform,
         cl_device_type device_type,   //设备类型
         cl_uint num_entries,              // 想要获取的数量
         cl_device_id *devices,           // 保存设备的地址
         cl_uint *num_devices            //  总设备数
    )

    获取设备信息

    // 获取设备信息
    cl_int clGetDeviceInfo(    
            cl_device_id device,
         cl_device_info param_name,     // 信息类型
         size_t param_value_size,          //所要保存的信息字节数
         void *param_value,                  // 信息保存的地址
         size_t *param_value_size_ret   //信息应有的字节数
    )
    
    // 几个重要的设备信息类型参数
    
    参数名                                        类型                  含义
    CL_DEVICE_EXTENSIONS                         char[]              支持的扩展类型
    CL_DEVICE_GLOBAL_MEM_SIZE                    cl_ulong            全局设备内存大小
    CL_DEVICE_ADDRESS_BITS                       cl_uint             设备地址空间大小

    CL_DEVICE_PREFERRED_VECTOR_WIDTH_CHAR
    cl_uint 向量长度
    
    

    CL_DEVICE_PREFERRED_VECTOR_WIDTH_SHORT

    CL_DEVICE_PREFERRED_VECTOR_WIDTH_INT

    CL_DEVICE_PREFERRED_VECTOR_WIDTH_LONG

    CL_DEVICE_PREFERRED_VECTOR_WIDTH_FLOAT

    CL_DEVICE_PREFERRED_VECTOR_WIDTH_DOUBLE

    3、创建上下文

    //  创建上下文,根据设备列表
    cl_context clCreateContext(    
         cl_context_properties *properties,  //属性列表
         cl_uint num_devices,                     //  设备数量 
         const cl_device_id *devices,           //  设备列表
         void *pfn_notify (
                    const char *errinfo, 
                    const void *private_info, 
                    size_t cb, 
                    void *user_data
                    ),
         void *user_data,            //提供报错信息
         cl_int *errcode_ret        //错误信息大小
    )
    
    // 创建上下文,根据设备类型
    cl_context clCreateContextFromType (    
         cl_context_properties   *properties,
         cl_device_type  device_type,
         void  (*pfn_notify) (
                    const char *errinfo,
                 const void  *private_info,
                 size_t  cb,
                 void  *user_data),
         void  *user_data,
         cl_int  *errcode_ret
    )

    // 返回结果是上下文

    获取上下文信息

    // 获取上下文信息
    cl_int clGetContextInfo (    
            cl_context context,     // 上下文
         cl_context_info param_name,   // 信息参数名称
         size_t param_value_size,         // 所要保存的大小
         void *param_value,                 //  保存的地址
         size_t param_value_size_ret     // 信息的大小
    )
    cl_context_infoReturn TypeInformation returned in param_value
    CL_CONTEXT_REFERENCE_COUNT cl_uint Return the context reference count. The reference count returned should be considered immediately stale. It is unsuitable for general use in applications. This feature is provided for identifying memory leaks.
    CL_CONTEXT_DEVICES cl_device_id[] Return the list of devices in context.
    CL_CONTEXT_PROPERTIES cl_context_properties[] Return the properties argument specified in clCreateContext

    管理上下文的引用

    // 引用计数加1
    cl_int clRetainContext (cl_context context)
    
    // 引用计数减1
    cl_int clReleaseContext (cl_context context)
    
    // 创建时,计数为1,当为0时释放
    cl_int clGetPlatformIDs( cl_uint num_entries
  • 相关阅读:
    WPF 窗口图标与背景
    WPF Convert和RelativeSource
    属性更改通知(INotifyPropertyChanged)——针对ObservableCollection
    WPF 输入异常提示
    WPF 异常处理
    WPF DataGrid 触发器
    拉格朗日乘子法(Lagrange multiplier)和KKT条件
    在同一台电脑上添加多个ssh key
    重积分的换元法
    Matlab之显示输出
  • 原文地址:https://www.cnblogs.com/feihu-h/p/12081019.html
Copyright © 2011-2022 走看看