OpenCL运行时:内存#

class pyopencl.MemoryObject#
info#

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

hostbuf#
get_info(param)#

mem_info 对于价值 param .

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 of pyopencl.Event instances for whose completion this command waits before starting exeuction.

仅适用于CL 1.2。

在 2011.2 版本加入.

共享虚拟内存(SVM)#

共享虚拟内存允许主机和计算设备共享地址空间,因此主机和设备上的指针可能具有相同的含义。此外,它允许主机和设备访问相同的内存。 Coarse-grain SVM要求在主机上访问缓冲区之前映射缓冲区, fine-grain SVM取消了这个要求。

警告

与.相比 Buffer S,支持向量机带来了一个新的问题:内存释放的同步。与OpenCL中的其他对象不同,支持向量机由普通(C语言)指针表示,因此没有引用计数的能力。

因此,完全合法地分配 Buffer ,将其上的操作排队,然后释放缓冲区,而无需担心操作是否已完成。OpenCL实现将使缓冲区保持活动状态,直到操作完成。这是 not 支持向量机的情况:除非另有指定,否则在请求时立即执行内存释放,因此只要Python垃圾收集器认为合适,就会释放支持向量机,即使操作尚未完成,也会立即导致未定义的行为(即,通常,内存损坏,不久后会崩溃)。

2022.2版的PyOpenCL提供了显著改进的工具来处理此问题。特别是,所有用于分配支持向量机的方法都允许指定 CommandQueue ,以便在先前入队的操作完成后排入队列并执行释放。

SVM需要OpenCL2.0。

不透明且被“包裹” -numpy “引用支持向量机的风格#

当尝试将支持向量机指针传递给 pyopencl ,支持两种样式:

  • 第一,不透明的风格。这种风格最接近于 Buffer -OpenCL 1.x中提供的基于分配。支持向量机指针保存在不透明的“句柄”对象中,例如 SVMAllocation

  • 第二,被包裹的 -numpy 风格。在本例中,一个 numpy.ndarray (或另一个实现 Python buffer protocol )作为支持向量机的一个区域的参考。此样式允许将内存区域与 pyopencl 的支持向量机接口,即使它们被分配到 pyopencl

    由于传递了一个 numpy.ndarray (或遵循缓冲区接口的另一种类型的对象)在中的大多数设置中已经具有现有的语义 pyopencl (例如,将参数传递给内核或调用 enqueue_copy() ),则存在包装器对象, SVM ,这可能是“包裹”这些对象,以将它们标记为支持向量机。

这两种样式的共同点在于,它们最终都实现了 SVMPointer 接口,该接口 pyopencl 用于获取实际的支持向量机指针。

请注意,很容易获得一个 numpy.ndarray 以不透明样式显示的支持向量机区域的视图,请参见 SVMPointer.buf ,允许从不透明过渡到包裹 -numpy 风格。相反的过渡(从包装 -numpy 不透明)不一定很简单,因为它需要从 numpy.ndarray.base 属性(或类似的,取决于充当主要支持向量机参考的实际对象)。

看见 帮助器函数 numpy 基于支持向量机的分配 用于简化设置包装的帮助器函数 -numpy 结构。

包好 -numpy 支持向量机往往非常适合细粒度支持向量机,因为直接主机端访问很容易,但创建使这成为可能的嵌套结构与一定的成本相关联。

相比之下,不透明的支持向量机访问往往非常适合粗粒度支持向量机,因为如果不映射阵列,直接主机访问是不可能的,而且设置成本较低。当然,将不透明的支持向量机访问与细粒度支持向量机一起使用是完全可能的。

在 2022.2 版本发生变更: 这个版本增加了不透明的支持向量机访问风格。

将支持向量机与数组结合使用#

而所有类型的支持向量机都可以用作记忆备份 pyopencl.array.Array 对象,确保由数组操作(例如算术)返回的新数组也使用支持向量机,这是最容易实现的,方法是将 SVMAllocator (或 SVMPool )作为 allocator 返回新数组的函数中的参数。

支持向量机指针、分配和映射#

class pyopencl.SVMPointer#

可以传递给允许支持向量机指针的函数的事物的基类,例如内核入队和内存副本。

此类型的对象目前不能在Python中直接创建或实现。若要获取实现此类型的对象,请考虑其子类型 SVMAllocationSVM

property svm_ptr#

将支持向量机指针作为 int

property size#

一个 int 以字节为单位表示大小,或 None ,如果所指向的支持向量机的大小未知。

Most 此类型的对象(例如 SVMAllocationSVM 知道它们的大小,这样,例如 enqueue_copy 将自动复制整个 SVMAllocation 未明确指定大小时。

map(queue: CommandQueue, *, flags: int, is_blocking: bool = True, wait_for: Sequence[Event] | None = None, size: Event | None = None) SVMMap[源代码]#
参数:
  • is_blocking -- 如果 False ,后续代码必须等待 SVMMap.event 在访问映射内存之前,在返回的对象中。

  • flags -- 一种组合 pyopencl.map_flags

  • size -- 映射的大小(以字节为单位)。如果未提供,则默认为 size

Returns a new pyopencl.Event. wait_for may either be None or a list of pyopencl.Event instances for whose completion this command waits before starting exeuction.

map_ro(queue: CommandQueue, *, is_blocking: bool = True, wait_for: Sequence[Event] | None = None, size: int | None = None) SVMMap[源代码]#

喜欢 map() ,但与 flags 为只读地图设置。

map_rw(queue: CommandQueue, *, is_blocking: bool = True, wait_for: Sequence[Event] | None = None, size: int | None = None) SVMMap[源代码]#

喜欢 map() ,但与 flags 为只读地图设置。

as_buffer(ctx: Context, *, flags: int | None = None, size: int | None = None) Buffer[源代码]#
参数:
  • ctx -- 一个 Context

  • flags -- 一种组合 pyopencl.map_flags ,默认为读写。

  • size -- 映射的大小(以字节为单位)。如果未提供,则默认为 size

返回:

一个 Buffer 对应于 self

此对象引用的内存在返回 Buffer 被释放了。

property buf#

一个不透明对象,实现 Python buffer protocol 。它将指向的内存公开为一维字节缓冲区,其大小与 size

不能保证对此属性的两个引用会产生相同的对象。

class pyopencl.SVMAllocation#

是一种 SVMPointer

在 2016.2 版本加入.

__init__(self: pyopencl._cl.SVMAllocation, context: pyopencl._cl.Context, size: int, alignment: int, flags: int, queue: pyopencl._cl.CommandQueue = None) None#
参数:
  • flags -- 看见 svm_mem_flags

  • queue -- 如果未指定,则无论挂起/入队的操作是否仍在使用此内存,都将立即释放分配。如果指定,则内存释放将与给定队列一起入队,并且只有在队列中先前入队的操作完成后才会执行。指定无序队列是错误的。。。警告::不指定队列通常会导致意外行为,包括崩溃和内存损坏。请参阅中的警告 共享虚拟内存(SVM)

enqueue_release(self: pyopencl._cl.SVMAllocation, queue: pyopencl._cl.CommandQueue = None, wait_for: object = None) pyopencl._cl.Event#
返回:

一个 pyopencl.Event

Returns a new pyopencl.Event. wait_for may either be None or a list of pyopencl.Event instances for whose completion this command waits before starting exeuction.

将此分配的释放排队到 queue 。如果 queue 未指定,则将释放入队到分配时提供的队列中或通过 bind_to_queue

bind_to_queue(self: pyopencl._cl.SVMAllocation, queue: pyopencl._cl.CommandQueue) None#

将用于解除分配的隐式入队的队列更改为 queue 。通过将标记入队到旧队列中并在新队列中等待该标记来确保充分的同步。

unbind_from_queue(self: pyopencl._cl.SVMAllocation) None#

将分配配置为不再隐式将内存分配入队。如果先前提供了这样的队列, finish() 会自动在其上调用。

class pyopencl.SVM(mem)#

为显示Python缓冲区接口的对象添加标签(如 numpy.ndarray )指的是共享虚拟内存。

是一种 SVMPointer ,因此可以将此类型的对象传递给内核调用,并 enqueue_copy() ,并且在那里声明的所有方法也在那里可用。请注意 map() 略有不同于 SVMPointer.map()

根据OpenCL实现的功能,可以将以下类型的对象传递到此类型/以此类型包装:

  • 由(例如)返回的细粒度共享内存 fsvm_empty() ,如果实现支持细粒度共享虚拟内存。该内存可以直接传递给内核::

    ary = cl.fsvm_empty(ctx, 1000, np.float32)
    assert isinstance(ary, np.ndarray)
    
    prg.twice(queue, ary.shape, None, cl.SVM(ary))
    queue.finish() # synchronize
    print(ary) # access from host
    

    观察如何不再需要映射(如粗粒度支持向量机中所需)。

  • 任何 numpy.ndarray (或具有缓冲区接口的其他Python对象)(如果实现支持细粒度 system 共享虚拟内存。

    这就是如此平淡 numpy 数组可以直接传递给内核::

    ary = np.zeros(1000, np.float32)
    prg.twice(queue, ary.shape, None, cl.SVM(ary))
    queue.finish() # synchronize
    print(ary) # access from host
    
  • 返回的粗粒度共享内存(例如) csvm_empty() 用于OpenCL 2.0的任何实现。

    备注

    使用粗粒度支持向量机的应用可能会被不透明风格的支持向量机更好地服务。看见 不透明且被“包裹” -numpy “引用支持向量机的风格

    以下是可以从主机和设备使用粗粒度支持向量机的方式:

    svm_ary = cl.SVM(
        cl.csvm_empty(ctx, 1000, np.float32, alignment=64))
    assert isinstance(svm_ary.mem, np.ndarray)
    
    with svm_ary.map_rw(queue) as ary:
        ary.fill(17)  # use from host
    
    prg.twice(queue, svm_ary.mem.shape, None, svm_ary)
    

粗粒度共享内存 must 映射到主机地址空间,使用 map() 在通过 numpy 界面。

备注

这个对象只是充当一个‘标签’,改变它被传递到的函数的行为。它与它标记的内存没有特殊的管理关系。例如,允许获取一个 numpy.ndarray 离开 SVM.mem 一个人的 SVM 实例,并使用该数组构造另一个。这两个标签都不需要保持活动状态。

在 2016.2 版本加入.

mem#

包装的对象。

__init__(mem)[源代码]#
map(queue, flags, is_blocking=True, wait_for=None)[源代码]#
参数:
  • is_blocking -- 如果 False ,后续代码必须等待 SVMMap.event 在访问映射内存之前,在返回的对象中。

  • flags -- 一种组合 pyopencl.map_flags

返回:

一个 SVMMap 实例

这不同于继承的 SVMPointer.map 因为不能指定大小,并且 mem 时生成的确切数组。 SVMMap 被用作上下文管理器。

Returns a new pyopencl.Event. wait_for may either be None or a list of pyopencl.Event instances for whose completion this command waits before starting exeuction.

map_ro(queue, is_blocking=True, wait_for=None)[源代码]#

喜欢 map() ,但与 flags 为只读地图设置。

map_rw(queue, is_blocking=True, wait_for=None)[源代码]#

喜欢 map() ,但与 flags 为只读地图设置。

class pyopencl.SVMMap(svm, array, queue, event)[源代码]#

返回者 SVMPointer.map()SVM.map() 。此类还可以用作 with 陈述。 release() 在退出时将被调用 with 区域。返回给 as 上下文管理器的一部分是映射的Python对象(例如 numpy 数组)。

在 2016.2 版本加入.

property event#

这个 Event 映射内存时返回。

release(queue=None, wait_for=None)[源代码]#
参数:

queue -- 一个 pyopencl.CommandQueue 。如果未指定,则默认为创建映射时使用的映射。

返回:

一个 pyopencl.Event

Returns a new pyopencl.Event. wait_for may either be None or a list of pyopencl.Event instances for whose completion this command waits before starting exeuction.

帮助器函数 numpy 基于支持向量机的分配#

pyopencl.svm_empty(ctx, flags, shape, dtype, order='C', alignment=None, queue=None)[源代码]#

分配一个空的 numpy.ndarray 给出的 shapedtypeorder 。(请参阅 numpy.empty() 这些论点的意义。)该数组将在共享虚拟内存中分配, ctx

参数:
返回:

一个 numpy.ndarray 谁的 numpy.ndarray.base 属性是一个 SVMAllocation

将结果数组传递给OpenCL内核或 enqueue_copy() ,您可能希望将返回的数组包装在 SVM 标签。

在 2016.2 版本加入.

在 2022.2 版本发生变更: queue 添加了参数。

pyopencl.svm_empty_like(ctx, flags, ary, alignment=None)[源代码]#

Allocate an empty numpy.ndarray like the existing numpy.ndarray ary. The array will be allocated in shared virtual memory belonging to ctx.

参数:
返回:

一个 numpy.ndarray 谁的 numpy.ndarray.base 属性是一个 SVMAllocation

将结果数组传递给OpenCL内核或 enqueue_copy() ,您可能希望将返回的数组包装在 SVM 标签。

在 2016.2 版本加入.

pyopencl.csvm_empty(ctx, shape, dtype, order='C', alignment=None)[源代码]#

喜欢 svm_empty() ,但与 flags 为粗粒度读写缓冲区设置。

在 2016.2 版本加入.

pyopencl.csvm_empty_like(ctx, ary, alignment=None)[源代码]#

喜欢 svm_empty_like() ,但与 flags 为粗粒度读写缓冲区设置。

在 2016.2 版本加入.

pyopencl.fsvm_empty(ctx, shape, dtype, order='C', alignment=None)[源代码]#

喜欢 svm_empty() ,但与 flags 设置为细粒度读写缓冲区。

在 2016.2 版本加入.

pyopencl.fsvm_empty_like(ctx, ary, alignment=None)[源代码]#

喜欢 svm_empty_like() ,但与 flags 设置为细粒度读写缓冲区。

在 2016.2 版本加入.

支持向量机的运算#

(也见) 转移

pyopencl.enqueue_svm_memfill(queue, dest, pattern, byte_count=None, wait_for=None)[源代码]#

用一种模式填充共享虚拟内存。

参数:
  • dest -- 一个Python缓冲区对象,或任何 SVMPointer

  • pattern -- 一个Python缓冲区对象(例如 numpy.ndarray 使用要使用的填充图案。

  • byte_count -- 要填充的内存大小。缺省为整个 dest

Returns a new pyopencl.Event. wait_for may either be None or a list of pyopencl.Event instances for whose completion this command waits before starting exeuction.

在 2016.2 版本加入.

pyopencl.enqueue_svm_migratemem(queue, svms, flags, wait_for=None)[源代码]#
参数:

Returns a new pyopencl.Event. wait_for may either be None or a list of pyopencl.Event instances for whose completion this command waits before starting exeuction.

在 2016.2 版本加入.

此功能需要OpenCL 2.1。

图像#

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 版本加入.

__repr__()[源代码]#

返回A str 图像格式的表示。

在 0.91 版本加入.

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 被给予并且被给予 shapeNone ,那么 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_infoimage_info 常量可以用作此类实例上的属性,以直接查询信息属性。

shape#

返回的值 形状 构造函数参数作为 tuple .

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 the numpy.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_intTrue ,则在读取时将整数值归一化为浮点小数位数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 of pyopencl.Event instances for whose completion this command waits before starting exeuction.

仅适用于CL 1.2。

在 2011.2 版本加入.

转移#

pyopencl.enqueue_copy(queue, dest, src, **kwargs)[源代码]#

复制自 ImageBuffer 或主机以 ImageBuffer 或者是主人。(注意:不支持主机到主机拷贝。)

以下关键字参数可用:

参数:
  • wait_for -- (可选,默认为空)

  • is_blocking -- 等待完成。默认为 True 。(在涉及主机内存的任何副本上可用)

返回:

A NannyEvent 如果传输涉及主机端缓冲区,则引发 Event

备注

请注意,删除 NannyEvent 如果涉及主机端缓冲区的传输将被阻塞,直到传输完成,则由函数返回,因此请确保保留对此的引用 Event 直到转账完成。

备注

此函数的参数中出现两种类型的“缓冲区”, Buffer 和‘主机端缓冲区’。后者由Python定义,通常称为 buffer objectsnumpy 数组是一个非常常见的例子。确保始终清楚地说明是否存在 Buffer 或者需要一个Python缓冲区对象。

转接 Buffer ↔主机

参数:
  • src_offset -- 偏移量(以字节为单位)(可选)只有在设备端应用时才能为非零值。

  • dst_offset -- 偏移量(以字节为单位)(可选)只有在设备端应用时才能为非零值。

备注

传输的大小由主机端缓冲区的大小控制。如果主机端缓冲区是 numpy.ndarray ,您可以通过转换到目标数组的较小“视图”来控制传输大小,如下所示:

cl.enqueue_copy(queue, large_dest_numpy_array[:15], src_buffer)

转接 BufferBuffer

参数:
  • byte_count -- (可选)如果未指定,则默认为2012.x及更低版本中的源大小,并从2013.1开始默认为源和目标的最小大小。

  • src_offset -- (可选)

  • dst_offset -- (可选)

长方形 Buffer ↔主机传输(CL1.1及更高版本)

参数:
  • buffer_origin -- tupleint 长度为三或更短的。(必填)

  • host_origin -- tupleint 长度为三或更短的。(必填)

  • region -- tupleint 长度为三或更短的。(必填)

  • buffer_pitches -- tupleint 长度为两个或更短的。(可选,如果未指定,则为“严密包装”)

  • host_pitches -- tupleint 长度为两个或更短的。(可选,如果未指定,则为“严密包装”)

长方形 BufferBuffer 传输(CL 1.1及更高版本)

参数:
  • src_origin -- tupleint 长度为三或更短的。(必填)

  • dst_origin -- tupleint 长度为三或更短的。(必填)

  • region -- tupleint 长度为三或更短的。(必填)

  • src_pitches -- tupleint 长度为两个或更短的。(可选,如果未指定,则为“严密包装”)

  • dst_pitches -- tupleint 长度为两个或更短的。(可选,如果未指定,则为“严密包装”)

转接 Image ↔主机

参数:
  • origin -- tupleint 长度为三或更短的。(必填)

  • region -- tupleint 长度为三或更短的。(必填)

  • pitches -- tupleint 长度为两个或更短的。(可选)

转接 BufferImage

参数:
  • offset -- 缓冲区中的偏移量(必需)

  • origin -- tupleint 长度为三或更短的。(必填)

  • region -- tupleint 长度为三或更短的。(必填)

转接 ImageImage

参数:
  • src_origin -- tupleint 长度为三或更短的。(必填)

  • dest_origin -- tupleint 长度为三或更短的。(必填)

  • region -- tupleint 长度为三或更短的。(必填)

转接 SVMPointer /主机↔ SVMPointer /主机

参数:

byte_count -- (可选)如果未指定,则默认为2012.x及更低版本中的源大小,并从2013.1开始默认为源和目标的最小大小。

Returns a new pyopencl.Event. wait_for may either be None or a list of pyopencl.Event instances for whose completion this command waits before starting exeuction.

在 2011.1 版本加入.

pyopencl.enqueue_fill(queue, dest, src, **kwargs)[源代码]#

在 2022.2 版本加入.

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 of pyopencl.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_modefilter_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 现在默认为空元组。

get_pipe_info(param)#

pipe_info 对于价值 param .

类型别名#

class pyopencl._cl.Buffer#

看见 pyopencl.Buffer