OpenCL运行时:平台、设备和上下文#

Platform#

pyopencl.get_platforms()#

返回的列表 Platform 实例。

class pyopencl.Platform#
info#

的小写版本 platform_info 常量可以用作此类实例上的属性,以直接查询信息属性。

get_info(param)#

platform_info 对于价值 param .

get_devices(device_type=device_type.ALL)#

返回匹配的设备列表 device_type . 见 device_type 对于价值 device_type .

在 2013.2 版本发生变更: 如果找不到匹配的设备,则会引发异常。现在,它只返回一个空列表。

static from_int_ptr(int_ptr_value: int, retain: bool = True) pyopencl._cl.Platform#

(静态方法)返回引用C-Level的新的Python对象 cl_platform_id 对象指向的位置上的 int_ptr_value 。相关的 clRetain* 函数将在以下情况下被调用 retain 为真。如果对象的前一个所有者将 not 释放引用, retain 应设置为 False ,以有效地将所有权转移到 pyopencl

在 2013.2 版本加入.

在 2016.1 版本发生变更: retain 添加了。

int_ptr#

返回一个整数,该整数与基础 cl_platform_id 。使用 from_int_ptr() 以转回为一个Python对象。

在 2013.2 版本加入.

Instances of this class are hashable, and two instances of this class may be compared using "==" and "!=". (Hashability was added in version 2011.2.) Two objects are considered the same if the underlying OpenCL object is the same, as established by C pointer equality.

装置#

class pyopencl.Device#

此类的两个实例可以使用 ==""!=" .

info#

的小写版本 device_info 常量可以用作此类实例上的属性,以直接查询信息属性。

get_info(param)#

device_info 对于价值 param .

static from_int_ptr(int_ptr_value: int, retain: bool = True) pyopencl._cl.Device#

(静态方法)返回引用C-Level的新的Python对象 cl_device_id 对象指向的位置上的 int_ptr_value 。相关的 clRetain* 函数将在以下情况下被调用 retain 为真。如果对象的前一个所有者将 not 释放引用, retain 应设置为 False ,以有效地将所有权转移到 pyopencl

在 2013.2 版本加入.

在 2016.1 版本发生变更: retain 添加了。

int_ptr#

返回一个整数,该整数与基础 cl_device_id 。使用 from_int_ptr() 以转回为一个Python对象。

在 2013.2 版本加入.

hashable_model_and_version_identifier#

一种未指定的数据类型,可用于(尽可能精确地,给定OpenCL中可用的标识信息)标识计算设备的给定模型和软件堆栈版本。请注意,此标识符不区分安装在单个主机中的同一设备的不同实例。

返回的数据类型是可哈希的。

在 2020.1 版本加入.

create_sub_devices(properties)#

性质 是一个(或多个)形式的数组:

[ dpp.EQUALLY, 8]
[ dpp.BY_COUNTS, 5, 7, 9, dpp.PARTITION_BY_COUNTS_LIST_END]
[ dpp.BY_NAMES, 5, 7, 9, dpp.PARTITION_BY_NAMES_LIST_END]
[ dpp.BY_AFFINITY_DOMAIN, dad.L1_CACHE]

哪里 dpp 表示 device_partition_propertydad 表示 device_affinity_domain

PROPERTIES_LIST_END_EXT 是自动添加的。

仅适用于CL 1.2。

在 2011.2 版本加入.

device_and_host_timer()#
返回:

元组 (device_timestamp, host_timestamp) .

仅适用于CL 2.0。

在 2020.3 版本加入.

host_timer()#

仅适用于CL 2.0。

在 2020.3 版本加入.

语境#

class pyopencl.Context(devices=None, properties=None, dev_type=None, cache_dir=None)#

创建新的上下文。 properties 是键-值元组的列表,其中每个键必须是 context_properties 。最多只有一个 devicesdev_type 可能不是 None ,在哪里 devices 是一份 Device 实例,以及 dev_typedevice_type 常量。如果两者都未指定,则具有 dev_typedevice_type.DEFAULT 被创造出来了。

如果 cache_dir 不是 None -它将用作默认设置 cache_dir 对于它所有的一切 Program 实例构建(另请参阅 Program.build() )。

备注

对于支持OpenCL ICD的最新CL驱动程序,调用不带参数的构造函数将失败。如果你想要类似的,只是给我一个上下文已经行为,我们建议 create_some_context() 。看到了吗,例如这个 explanation by AMD

备注

由于OpenCL如何改变以支持opencl1.1中的可安装客户机驱动程序(icd),下面将 look 合理但通常不起作用:

import pyopencl as cl
ctx = cl.Context(dev_type=cl.device_type.ALL)

相反,在按类型选择设备时,请确保选择平台:

import pyopencl as cl

platforms = cl.get_platforms()
ctx = cl.Context(
        dev_type=cl.device_type.ALL,
        properties=[(cl.context_properties.PLATFORM, platforms[0])])

备注

为了 context_properties.CL_GL_CONTEXT_KHRcontext_properties.CL_EGL_DISPLAY_KHRcontext_properties.CL_GLX_DISPLAY_KHRcontext_properties.CL_WGL_HDC_KHRcontext_properties.CL_CGL_SHAREGROUP_KHR context_properties.CL_CGL_SHAREGROUP_APPLE 键值对中的值是PyOpenGL上下文或显示实例。

在 0.91.2 版本发生变更: 构造函数参数 dev_type 补充。

info#

的小写版本 context_info 常量可以用作此类实例上的属性,以直接查询信息属性。

get_info(param)#

context_info 对于价值 param .

static from_int_ptr(int_ptr_value: int, retain: bool = True) pyopencl._cl.Context#

(静态方法)返回引用C-Level的新的Python对象 cl_context 对象指向的位置上的 int_ptr_value 。相关的 clRetain* 函数将在以下情况下被调用 retain 为真。如果对象的前一个所有者将 not 释放引用, retain 应设置为 False ,以有效地将所有权转移到 pyopencl

在 2013.2 版本加入.

在 2016.1 版本发生变更: retain 添加了。

int_ptr#

返回一个整数,该整数与基础 cl_context 。使用 from_int_ptr() 以转回为一个Python对象。

在 2013.2 版本加入.

set_default_device_command_queue(dev, queue)#

Instances of this class are hashable, and two instances of this class may be compared using "==" and "!=". (Hashability was added in version 2011.2.) Two objects are considered the same if the underlying OpenCL object is the same, as established by C pointer equality.

pyopencl.create_some_context(interactive=True, answers=None, cache_dir=None)[源代码]#

创建一个 Context “不知怎么的”。

如果存在平台和/或设备的多个选择, 互动式 是真的,而且 系统标准isatty() 如果为True,则会询问用户应该选择哪个设备。否则,以实现定义的方式选择设备。