0

出于对调用 OpenCL 内核时可以传递的最大参数大小的好奇,我发现我可以传递一个大小大于最大大小的数组。这是正在发生的事情:(顺便说一句,我正在使用 pyopencl )

>>> plat = cl.get_platforms()
>>> dev = plat[0].get_devices( cl.device_type.ALL )
>>> dev[0]
<pyopencl.Device 'Juniper' on 'AMD Accelerated Parallel Processing' at 0x58fde60>
>>> dev[0].max_parameter_size
1024

在谷歌搜索中,我了解到 1024 以字节为单位。(我忘了它是在哪里声明的,我认为是一个 Nvidia 论坛。)

现在,我运行了这个脚本:

import pyopencl as cl
import numpy as np

plat = cl.get_platforms()
dev = plat[0].get_devices( cl.device_type.ALL )
ctx = ctx = cl.Context( [ dev[0] ] )
cq = cl.CommandQueue( ctx )

kernel = """
__kernel void test( __global int* A, __global int* B ){
const int id = get_global_id( 0 );
B[ id ] = A[ id ];
barrier( CLK_GLOBAL_MEM_FENCE );
}
"""

prg = cl.Program( ctx, kernel ).build()

A = np.ones( ( 2**18, ), dtype = np.int32 )
B = np.zeros_like( A )

A_buf = cl.Buffer( ctx, cl.mem_flags.READ_ONLY|cl.mem_flags.COPY_HOST_PTR, hostbuf = A )   
B_buf = cl.Buffer( ctx, cl.mem_flags.WRITE_ONLY, B.nbytes )

在调用内核之前,我做了以下事情:

>>> A.nonzero()[0].shape
(262144,)
>>> B.nonzero()[0].shape
(0,)

然后我调用内核并检查 B 中的非零元素:

>>> prg.test( cq, A.shape, A_buf, B_buf ).wait()
>>> cl.enqueue_copy( cq, B, B_buf )
>>> B.nonzero()[0].shape
(262144,)

所以,很明显,我可以发送和读回大小大于cl.max_parameter_size. 这怎么可能?或者我哪里错了?

4

1 回答 1

3

CL_DEVICE_MAX_PARAMETER_SIZE 是指传递给clSetKernelArg的内核参数的最大大小。请参阅clGetDeviceInfo中的 CL_DEVICE_MAX_MEM_ALLOC_SIZE 和 CL_DEVICE_GLOBAL_MEM_SIZE 。

于 2013-03-20T19:06:23.700 回答