Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/csharp-4.0/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
OpenCL事件系统未等待_Opencl_Pyopencl - Fatal编程技术网

OpenCL事件系统未等待

OpenCL事件系统未等待,opencl,pyopencl,Opencl,Pyopencl,我有一个简单的openCL内核,名为Test\u Kernel.cl,可以读取图像 const sampler_t sampler = CLK_NORMALIZED_COORDS_FALSE | CLK_ADDRESS_CLAMP | CLK_FILTER_NEAREST; void read(image3d_t image) { int z = get_global_id(0); int y = get_global_id(1); int x

我有一个简单的openCL内核,名为
Test\u Kernel.cl
,可以读取图像

const sampler_t sampler = 
    CLK_NORMALIZED_COORDS_FALSE |
    CLK_ADDRESS_CLAMP |
    CLK_FILTER_NEAREST;

void read(image3d_t image)
{
    int z = get_global_id(0);
    int y = get_global_id(1);
    int x = get_global_id(2);
    float value = read_imagef(image,sampler,(float4)(x,y,z,0)).s0;
}

__kernel void test(image3d_t d_testdata)
{   
    read(d_testdata);
}
以及相应的pyopencl文件,用于在设备上复制numpy阵列,以便能够从中读取:

import pyopencl as cl
import numpy as np

#Setting up contexts, devices and queues. 
platform = cl.get_platforms()[0]
devs = platform.get_devices()
device1 = devs[0]
ctx = cl.Context([device1])
queue = cl.CommandQueue(ctx)
queue2 = cl.CommandQueue(ctx)

#Defining testdata.
h_testdata = np.arange(4096*2).reshape((2,64,64)).astype(np.float32,order='C')

mf = cl.mem_flags

#Building the Kernel.
f = open('Test_Kernel.cl', 'r')
fstr = "".join(f.readlines())
prg = cl.Program(ctx, fstr).build()
test_knl = prg.test

def f():
    d_testdata = cl.Image(ctx, mf.READ_ONLY, cl.ImageFormat(cl.channel_order.INTENSITY,cl.channel_type.FLOAT),h_testdata.shape)
    wev1=cl.enqueue_copy(queue, d_testdata, h_testdata, is_blocking = False, origin = (0,0,0), region = h_testdata.shape)
    test_knl.set_args(d_testdata)
    cl.enqueue_nd_range_kernel(queue2,test_knl,(64,64,64),None,wait_for=[wev1])

f()

随着程序流程越来越复杂,我使用事件和多个队列来处理排序和同步。然而,在我的分析器中,我可以看到,有时内核在拷贝事件之前执行。我做错了什么?

看起来不错,你确定在复制之前执行内核吗?大多数GPU设备不支持从不同队列并行执行多个内核。如果这是您的意图,您可能希望通过使用单个队列来简化事情。内核(有时)在复制过程开始之前启动。至少档案员是这么说的。我不认为你的第二句话是真的。我看到的大多数程序都有IO任务(如复制语句)和工作任务的专用队列,以隐藏内存传输延迟。使用两个队列应该等于使用一个无序队列(这是pyopencl开发人员告诉我的)。是的,这是真的。与内核执行重叠的内存传输可以工作。我指的是多个内核执行。对不起,那么你完全正确。奇怪的是,这并不是一直都在发生,有时顺序是我想要的,有时内核在复制之前执行。我看没问题,你确定内核在复制之前执行吗?大多数GPU设备不支持从不同队列并行执行多个内核。如果这是您的意图,您可能希望通过使用单个队列来简化事情。内核(有时)在复制过程开始之前启动。至少档案员是这么说的。我不认为你的第二句话是真的。我看到的大多数程序都有IO任务(如复制语句)和工作任务的专用队列,以隐藏内存传输延迟。使用两个队列应该等于使用一个无序队列(这是pyopencl开发人员告诉我的)。是的,这是真的。与内核执行重叠的内存传输可以工作。我指的是多个内核执行。对不起,那么你完全正确。奇怪的是,它并不是一直都在发生,有时顺序是我想要的,有时内核在复制之前执行。