OpenCL event system not waiting
<p>I have a simple openCL Kernel, called <code>Test_Kernel.cl</code> that reads from an image.</p>

<pre><code>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);
}
</code></pre>

<p>And the corresponding pyopencl file to copy a numpy array on the device, to be able to read from it:</p>

<pre><code>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()
</code></pre>

<p>As the program flow will get more complex further down the road, I am using events and multiple queues to care for ordering and synchronisation. However, in my profiler, I can see, that sometimes the kernel executes <strong>BEFORE</strong> the copy event. What am I doing wrong?</p>