浅谈OpenCL之Platform API(2)
OpenCL Contexts
context是贯串 opencl 程序的核心,也是host 与device 交互的唯一通道,是内存申请维护,命令队列的创建等功能的基础。
不同的plaform,可以申请不同的context,不同的context内的内存不能直接共享,在同一个context下的 不同device的内存是相同的,可以相互访问。
创建Contexts API 有两个:
cl_context clCreateContext (const cl_context_properties *properties,cl_uint num_devices,const cl_device_id *devices,void (CL_CALLBACK *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 (const cl_context_properties *properties,cl_device_type device_type,void (CL_CALLBACK *pfn_notify)(const char *errinfo,const void *private_info,size_t cb,void *user_data),void *user_data,cl_int *errcode_ret)
第二个创建context API是可以根据所需要的设备类型选择创建context.
参数:
const cl_context_properties *properties :
context 属性,创建context一般为:
cl_context_properties contextProperties[] = {CL_CONTEXT_PLATFORM, (cl_context_properties)platformId, 0};
cl_device_type device_type:
设备类型
cl_uint num_devices:
为该platform device数量
const cl_device_id *devices:
platform下的device id
void (CL_CALLBACK *pfn_notify) (const char *errinfo, const void *private_info, size_t cb, void *user_data):
用于注册回调,opencl通知错误信息
void *user_data:
为用户数据
cl_int *errcode_ret:
返回错误码
使用范例:
cl_context_properties contextProperties[] = {CL_CONTEXT_PLATFORM, (cl_context_properties)platformId, 0};ocl->context = clCreateContextFromType(contextProperties, deviceType, NULL, NULL, &err);if ((CL_SUCCESS != err) || (NULL == ocl->context)){LogError("Couldn't create a context, clCreateContextFromType() returned '%s'.\n", TranslateOpenCLError(err));return err;}
创建完成context之后,就可以获取conext 属性,其API为:
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 context: 为context
cl_context_info param_name: 参数名称
size_t param_value_size:输出param_value的长度
void * param_value:获取参数值
size_t * param_value_size_ret:错误码返回值
其用法和之前的API类似,先获取长度,然后再次调用获取到参数的值
cl_context_info param_name 列表如下:
cl_context_info | Return Type | Description |
CL_CONTEXT_REFERENCE_COUNT | cl_uint | Returns the context reference count. |
CL_CONTEXT_NUM_DEVICES | cl_uint | Returns the number of devices in context. |
CL_CONTEXT_DEVICES | cl_device_id[] | Returns the list of devices in context. |
CL_CONTEXT_PROPERTIES | cl_context_properties[] |
Returns the properties argument specified in clCreateContext or clCreateContextFromType.If the properties argument specified in clCreateContext or clCreateContextFrom-Type used to create context is not NULL, the implementation must return the values specified in the properties argument. If the properties argument specified in clCreateContext or clCreateContextFrom-Type used to create context is NULL, the imple-mentation may return either a param_value_size_ret of 0 (that is, there is no context property |
使用范例:
// Query for OpenCL device which was used for context creationerr = clGetContextInfo(ocl->context, CL_CONTEXT_DEVICES, sizeof(cl_device_id), &ocl->device, NULL);if (CL_SUCCESS != err){LogError("Error: clGetContextInfo() to get list of devices returned %s.\n", TranslateOpenCLError(err));return err;}
自此platform API讲完,主要包括platform, device ,context
浅谈OpenCL之Platform API(2)相关推荐
- 浅谈OpenCL之Platform API(1)
Platform API 为opencl 初始化首先要使用的API,主要是获取到platform 以及device. OpenCL Platforms opencl 应用程序第一步首先就是要查询ope ...
- 浅谈OpenCL之API分类
OpenCL为应用开发提供了丰富的API,按照其四大模型其API主要分为以下三类: Platform API 平台API主要是由HOST调用,可以用来查询opencl plaftform, devic ...
- 浅谈Opencl四大模型之Platform model
Opencl是一种典型的异构架构,可以很好的实施并发性,为了简化并行计算复杂度以及兼容各个芯片差异性,opencl将其抽象为四大模型(Platform model, Execution model,M ...
- 浅谈opencl之错误码
opencl采用了统一的错误码,各个API通用 Error Description CL_SUCCESS Command executed successfully without error. CL ...
- 浅谈OpenCL四大模型之Execution Model
OpenCL执行模型(Execution Model)解释了opencl程序是如何运行的,是理解opencl的基础. OpenCL程序 Opencl应用程序一般分为host部分和kernel部分组成, ...
- 浅谈OpenCL之 应用程序总体步骤思路
一般Opencl 应用程序步骤,为了保证原英文意思 没有翻译中文: 1:Query which platforms are present. 2: Query the set of devices ...
- 浅谈Opencl四大模型之Memory Model
运行模型(execution model)讲述了一个kernel怎么样在opencl平台运行,host喝kernel如何交互的,kernel代码如何编译的等等,但是没有涉及到opencl内存的管理方式 ...
- 浅谈opencl之整体框架
结合四大模型,以CPU和GPU平台为例子,opencl整体框架如下: CPU为host端, GPU为device端, host和device端的交互是以context为主.context贯穿到整个op ...
- 浅谈Opencl四大模型之Programming Model
Opencl 平台模型解决了 硬件兼容问题,将各种硬件抽象成了模型:执行模型解决了opencl程序如何运行的问题:内存模型解决了opencl 内存管理 问题,而编程模型(programming mod ...
最新文章
- mysql8.0.12最小化安装_简述MySql8.0编译安装过程
- 给大忙人看的Java核心技术笔记(8、Stream)
- XML引入多scheme文件约束简单示例
- 【C++ 学习笔记】 MFC CEdit
- java中位运算传参_java基础之位运算讲解于实战
- 计算机体系、语言的基础认识
- nginx 和 php超时设置
- 博弈论(Game Theory)入门学习笔记(持续更新)
- No buffer space available问题解决
- 什么app可以绘制路线图_为什么大多数路线图都会不可避免地带来糟糕的结果
- NGUI-动画Tween
- uIP TCP/IP协议栈在51系列单片机上的应用
- 好消息!想入深户的伙伴们赶紧看过来!
- 一篇文章让你掌握HTML+CSS
- request的setAttribute()用法及request.sendRedirect 与 request.getRequestDispatcher.forward 的区别
- 对数函数定义域和值域_对数函数的定义域,值域是怎么求的
- 【电子基础】总结·嵌入式硬件基础
- EJBCA证书平台-管理员及用户使用指南
- CKPlayer播放M3U8文件 (加载失败)问题
- HTML特殊字符编码对照表 —— (一)
热门文章
- JEECG 3.6.3版本发布 企业级JAVA快速开发平台
- 如何不用鼠标操作电脑
- 微服务技术栈:常见注册中心组件,对比分析
- Rails Security (上)
- Android NDK调试出错Unknown Application ABI, Unable to detect application ABI#39;s的解决方式...
- jQuery之ajax错误调试分析
- Unity3D-RPG项目实战(1):发动机的特殊文件夹
- 二分查找:在有序数组中搜索大于等于x的数的最小下标
- 信息学奥赛一本通(1102:与指定数字相同的数的个数)
- permutation 1(HDU-6628)