opencl(二)----平臺、設備、上下文的獲取

一、獲取平臺

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

cl_int clGetPlatformIDs(    
     cl_uint num_entries, //想要獲取的平臺數量
     cl_platform_id *platforms,  // cl_platform_id 指針,獲取的平臺會保存在這個地址中
     cl_uint *num_platforms  //環境中存在的平臺數量
)
返回值小於0表示獲取平臺失敗

獲取平臺信息app

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   // 實際信息的數據大小
)

信息類型ide

cl_platform_info Return Type Description
CL_PLATFORM_PROFILE char[]

確認平臺是支持徹底版本的opencl仍是嵌入式版本的ui

FULL_PROFILEthis

EMBEDDED_PROFILE spa

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.

二、獲取設備

// 獲取設備
cl_int clGetDeviceIDs(    
        cl_platform_id platform,
     cl_device_type device_type,   //設備類型
     cl_uint num_entries,              // 想要獲取的數量
     cl_device_id *devices,           // 保存設備的地址
     cl_uint *num_devices            //  總設備數
)

獲取設備信息scala

// 獲取設備信息
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_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_info Return Type Information 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

管理上下文的引用code

// 引用計數加1
cl_int clRetainContext (cl_context context)

// 引用計數減1
cl_int clReleaseContext (cl_context context)

// 建立時,計數爲1,當爲0時釋放

 

 

 

 

 

 

cl_int clGetPlatformIDs( cl_uint num_entries
相關文章
相關標籤/搜索