OpenCL运行时:内存#
- class pyopencl.MemoryObject#
-
- hostbuf#
- release()#
- get_host_array(shape, dtype, order='C')#
将内存对象的关联主机内存区域作为
numpy.ndarray
给定的 形状 , D型 和 秩序 .
- static from_int_ptr(int_ptr_value: int, retain: bool = True) object #
(静态方法)返回引用C-Level的新的Python对象
cl_mem
对象指向的位置上的 int_ptr_value 。相关的clRetain*
函数将在以下情况下被调用 retain 为真。如果对象的前一个所有者将 not 释放引用, retain 应设置为 False ,以有效地将所有权转移到pyopencl
。在 2013.2 版本加入.
在 2016.1 版本发生变更: retain 添加了。
- int_ptr#
返回一个整数,该整数与基础
cl_mem
。使用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.
内存迁移#
- pyopencl.enqueue_migrate_mem_objects(queue, mem_objects, flags=0, wait_for=None)#
- 参数:
flags -- 从
mem_migration_flags
在 2011.2 版本加入.
仅适用于CL 1.2。
缓冲区#
- class pyopencl.Buffer(context, flags, size=0, hostbuf=None)#
创建一个
Buffer
. 见mem_flags
对于价值 旗帜 .如果 霍斯特布夫 已指定, size 如果指定的缓冲区作为零传递,则默认为该缓冲区的大小。Buffer
继承自MemoryObject
.备注
Python还定义了一种 buffer object ,并且PyOpenCL也作为的宿主端目标与这些对象交互
enqueue_copy()
。确保始终清楚地说明是否存在Buffer
或者需要一个Python缓冲区对象。请注意,OpenCL中的实际内存分配可能会延迟。缓冲器连接到
Context
只有在设备上使用了缓冲区后,才会将和移动到该设备。这也是发生内存不足错误的时间点。如果您想确保有足够的内存用于分配,可以使用enqueue_migrate_mem_objects()
(如果可用)或只是执行一个小的传输到缓冲区。另请参见pyopencl.tools.ImmediateAllocator
.- get_sub_region(origin, size, flags=0)#
仅在OpenCL1.1及更新版本中可用。
- __getitem__(slc)#
slc 是一个
slice
对象,指示要从哪个字节索引范围创建子缓冲区。这个 旗帜 的参数get_sub_region()
设置为与 self 创建。
- pyopencl.enqueue_fill_buffer(queue, mem, pattern, offset, size, wait_for=None)[源代码]#
- 参数:
mem -- 在设备上
Buffer
pattern -- 缓冲区对象(可能是
numpy.ndarray
,例如。np.uint32(0)
)。与以下内容关联的内存 pattern 可以在函数完成后重新使用或释放。size -- 要填充的区域的大小(字节)。必须是图案大小的倍数。
offset -- 正在填充的区域的位置(以字节为单位) mem . 必须是图案大小的倍数。
用提供的模式填充缓冲区
Returns a new
pyopencl.Event
. wait_for may either be None or a list ofpyopencl.Event
instances for whose completion this command waits before starting exeuction.仅适用于CL 1.2。
在 2011.2 版本加入.
图像#
- class pyopencl.ImageFormat([channel_order, channel_type])#
- channel_order#
见
channel_order
对于可能的值。
- channel_data_type#
见
channel_type
对于可能的值。
- channel_count#
在 0.91.5 版本加入.
- dtype_size#
在 0.91.5 版本加入.
- itemsize#
在 0.91.5 版本加入.
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.
在 0.91 版本发生变更: 已添加构造函数参数。
在 2013.2 版本发生变更:
ImageFormat
使之具有可比性和可散列性
- pyopencl.get_supported_image_formats(context, flags, image_type)#
见
mem_flags
对于可能的值 旗帜 和mem_object_type
对于可能的值 image_type .
- class pyopencl.Image(context, flags, format, shape=None, pitches=None, hostbuf=None, is_array=False, buffer=None)#
见
mem_flags
对于价值 旗帜 . 形状 是2元组或3元组。 格式 是的实例ImageFormat
. 投球 是用于2D图像的1元组和用于3D图像的2元组,以字节表示从一个扫描线到下一个扫描线以及从一个2D图像切片到下一个扫描线的距离。如果 hostbuf 被给予并且被给予 shape 是 None ,那么 hostbuf.shape 被用作 shape 参数。
Image
继承自MemoryObject
.备注
如果要从加载图像
numpy.ndarray
实例或将图像读回实例中,请注意OpenCL图像期望 x 尺寸变化最快,而在默认(C)顺序numpy
数组中,最后一个索引变化最快。如果数组在内存中的排列顺序错误,则有两种可能的解决方法:使用将数组转换为Fortran(列主)顺序
numpy.asarray()
.通过 副本() 图像创建功能。
在 0.91 版本加入.
在 2011.2 版本发生变更: 补充 is_array 和 缓冲区 ,仅在CL 1.2及更新版本上可用。
- info#
的小写版本
mem_info
和image_info
常量可以用作此类实例上的属性,以直接查询信息属性。
- get_image_info(param)#
见
image_info
对于价值 param .
- release()#
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.image_from_array(ctx, ary, num_channels=None, mode='r', norm_int=False)[源代码]#
Build a 2D or 3D
Image
from thenumpy.ndarray
ary. If num_channels is greater than one, the last dimension of ary must be identical to num_channels. ary must be in C order. If num_channels is not given, it defaults to 1 for scalar types and the number of entries for 向量类型.这个
ImageFormat
被选为第一个 num_channels “RGBA”的组成部分。- 参数:
mode -- “r”或“w”表示读/写
备注
从图像对象读取时,传递给
read_imagef
的顺序与访问时的顺序相反 ary 来自 Python 。如果 norm_int 是 True ,则在读取时将整数值归一化为浮点小数位数0..1。
在 2011.2 版本加入.
- pyopencl.enqueue_fill_image(queue, mem, color, origin, region, wait_for=None)#
- 参数:
color -- 缓冲对象(可能是
numpy.ndarray
)
Returns a new
pyopencl.Event
. wait_for may either be None or a list ofpyopencl.Event
instances for whose completion this command waits before starting exeuction.仅适用于CL 1.2。
在 2011.2 版本加入.
转移#
- pyopencl.enqueue_copy(queue, dest, src, **kwargs)[源代码]#
复制自
Image
,Buffer
或主机以Image
,Buffer
或者是主人。(注意:不支持主机到主机拷贝。)以下关键字参数可用:
- 参数:
wait_for -- (可选,默认为空)
is_blocking -- 等待完成。默认为 True 。(在涉及主机内存的任何副本上可用)
- 返回:
A
NannyEvent
如果传输涉及主机端缓冲区,则引发Event
。
备注
请注意,删除
NannyEvent
如果涉及主机端缓冲区的传输将被阻塞,直到传输完成,则由函数返回,因此请确保保留对此的引用Event
直到转账完成。备注
此函数的参数中出现两种类型的“缓冲区”,
Buffer
和‘主机端缓冲区’。后者由Python定义,通常称为 buffer objects 。numpy
数组是一个非常常见的例子。确保始终清楚地说明是否存在Buffer
或者需要一个Python缓冲区对象。转接
Buffer
↔主机- 参数:
src_offset -- 偏移量(以字节为单位)(可选)只有在设备端应用时才能为非零值。
dst_offset -- 偏移量(以字节为单位)(可选)只有在设备端应用时才能为非零值。
备注
传输的大小由主机端缓冲区的大小控制。如果主机端缓冲区是
numpy.ndarray
,您可以通过转换到目标数组的较小“视图”来控制传输大小,如下所示:cl.enqueue_copy(queue, large_dest_numpy_array[:15], src_buffer)
- 参数:
byte_count -- (可选)如果未指定,则默认为2012.x及更低版本中的源大小,并从2013.1开始默认为源和目标的最小大小。
src_offset -- (可选)
dst_offset -- (可选)
长方形
Buffer
↔主机传输(CL1.1及更高版本)- 参数:
长方形
Buffer
↔Buffer
传输(CL 1.1及更高版本)- 参数:
转接
Image
↔主机- 参数:
- 参数:
转接
SVMPointer
/主机↔SVMPointer
/主机- 参数:
byte_count -- (可选)如果未指定,则默认为2012.x及更低版本中的源大小,并从2013.1开始默认为源和目标的最小大小。
Returns a new
pyopencl.Event
. wait_for may either be None or a list ofpyopencl.Event
instances for whose completion this command waits before starting exeuction.在 2011.1 版本加入.
- pyopencl.enqueue_copy_buffer_p2p_amd(platform, queue, src, dest, size=None, wait_for=None)#
AMD扩展,用于在两个不同设备上的两个缓冲区之间执行对等复制。这两个设备必须处于不同的环境中。队列必须位于源缓冲区所在的位置。
- 参数:
platform -- 一个
Platform
实例queue -- 一个
CommandQueue
实例src -- 一个
Buffer
实例dest -- 一个
Buffer
实例size -- 要复制的字节数。如果 None ,则使用两个缓冲区的最小大小。
Returns a new
pyopencl.Event
. wait_for may either be None or a list ofpyopencl.Event
instances for whose completion this command waits before starting exeuction.仅在AMD平台上可用。
在 2023.1.2 版本加入.
将内存映射到主机地址空间#
- class pyopencl.MemoryMap#
此类还可以用作
with
陈述。删除此对象时,将取消映射与此对象对应的内存,或者release()
被称为。- release(self: pyopencl._cl.MemoryMap, queue: pyopencl._cl.CommandQueue = None, wait_for: object = None) pyopencl._cl.Event #
- pyopencl.enqueue_map_buffer(queue, buf, flags, offset, shape, dtype, order='C', strides=None, wait_for=None, is_blocking=True)#
wait_for may either be None or a list of
pyopencl.Event
instances for whose completion this command waits before starting exeuction. 形状 , D型 和 秩序 与中的含义相同numpy.empty()
. 见map_flags
对于可能的值 旗帜 . 大步 ,如果给定,则重写 秩序 .- 返回:
元组 (数组,事件) . 数组 是一个
numpy.ndarray
表示地图的主机端。它 .底座 成员包含MemoryMap
.
在 2011.1 版本发生变更: is_blocking 现在默认为True。
在 2013.1 版本发生变更: 秩序 现在默认为“C”。
在 2013.2 版本发生变更: 补充 大步 争论。
样品使用情况:
mapped_buf = cl.enqueue_map_buffer(queue, buf, ...) with mapped_buf.base: # work with mapped_buf ... # memory will be unmapped here
- pyopencl.enqueue_map_image(queue, buf, flags, origin, region, shape, dtype, order='C', strides=None, wait_for=None, is_blocking=True)#
wait_for may either be None or a list of
pyopencl.Event
instances for whose completion this command waits before starting exeuction. 形状 , D型 和 秩序 与中的含义相同numpy.empty()
. 见map_flags
对于可能的值 旗帜 . 大步 ,如果给定,则重写 秩序 .- 返回:
元组 (数组,事件) . 数组 是一个
numpy.ndarray
表示地图的主机端。它 .底座 成员包含MemoryMap
.
在 2011.1 版本发生变更: is_blocking 现在默认为True。
在 2013.1 版本发生变更: 秩序 现在默认为“C”。
在 2013.2 版本发生变更: 补充 大步 争论。
采样器#
- class pyopencl.Sampler#
- __init__(context, normalized_coords, addressing_mode, filter_mode)#
normalized_coords 是一个
bool
指示是否使用0和1之间的坐标( True )或者纹理的自然像素大小( 假 )见addressing_mode
和filter_mode
可能的参数值。还支持备用签名
(context, properties)
.- 参数:
properties -- 来自的键和值的序列
sampler_properties
已被接受clCreateSamplerWithProperties()
(有关详细信息,请参见OpenCL规范)。尾随 0 是自动添加的,不需要包括在内。
此签名需要OpenCL 2或更新版本。
在 2018.2 版本发生变更: 添加了基于属性的签名。
- info#
的小写版本
sampler_info
常量可以用作此类实例上的属性,以直接查询信息属性。
- get_info(param)#
见
sampler_info
对于价值 param .
- static from_int_ptr(int_ptr_value: int, retain: bool = True) pyopencl._cl.Sampler #
(静态方法)返回引用C-Level的新的Python对象
cl_sampler
对象指向的位置上的 int_ptr_value 。相关的clRetain*
函数将在以下情况下被调用 retain 为真。如果对象的前一个所有者将 not 释放引用, retain 应设置为 False ,以有效地将所有权转移到pyopencl
。在 2013.2 版本加入.
在 2016.1 版本发生变更: retain 添加了。
- int_ptr#
返回一个整数,该整数与基础
cl_sampler
。使用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.Pipe(context, flags, packet_size, max_packets, properties=())#
见
mem_flags
对于价值 旗帜 .- 参数:
properties -- 中的键和值的序列
pipe_properties
按照以下方式接受clCreatePipe()
。拖后腿 0 是自动添加的,不需要包括在内。(此参数当前必须为空。)
此功能需要OpenCL 2或更高版本。
在 2020.3 版本加入.
在 2021.1.7 版本发生变更: properties 现在默认为空元组。
类型别名#
- class pyopencl._cl.Buffer#
看见
pyopencl.Buffer
。