如果内核对多个非对称 CU 进行例化,可指定含 CU 名称的 clCreateKernel
命令来创建不同的 CU 组。在此情况下,主机程序可使用 clCreateKernel
返回的 cl_kernel
句柄来引用特定 CU 组。
在以下示例中,内核 mykernel
具有 5 个 CU:K1、K2、K3、K4 和 K5。K1、K2 和 K3 CU 均为对称组,在器件上具有对称连接。同样,CU K4 和 K5 构成第二个对称 CU 组。以下代码片段显示了如何使用 cl_kernel
句柄对特定 CU 组进行寻址。
// Kernel handle for Symmetrical compute unit group 1: K1,K2,K3
cl_kernel kernelA = clCreateKernel(program,"mykernel:{K1,K2,K3}",&err);
for(i=0; i<3; i++) {
// Creating buffers for the kernel_handle1
.....
// Setting kernel arguments for kernel_handle1
.....
// Enqueue buffers for the kernel_handle1
.....
// Possible candidates of the executions K1,K2 or K3
clEnqueueTask(commands, kernelA, 0, NULL, NULL);
//
}
// Kernel handle for Symmetrical compute unit group 1: K4, K5
cl_kernel kernelB = clCreateKernel(program,"mykernel:{K4,K5}",&err);
for(int i=0; i<2; i++) {
// Creating buffers for the kernel_handle2
.....
// Setting kernel arguments for kernel_handle2
.....
// Enqueue buffers for the kernel_handle2
.....
// Possible candidates of the executions K4 or K5
clEnqueueTask(commands, kernelB, 0, NULL, NULL);
}