Skip to content

Commit

Permalink
Merge pull request #55 from yuyichao/pull.test_enqueue_task
Browse files Browse the repository at this point in the history
test_enqueue_task
  • Loading branch information
inducer committed Jun 29, 2014
2 parents 76acf94 + 3ee443f commit 4cfa5d2
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions test/test_wrapper.py
Expand Up @@ -642,6 +642,36 @@ def test_unload_compiler(ctx_factory):
skip("Intel proprietary driver does not support unloading compiler")
cl.unload_platform_compiler(platform)


def test_enqueue_task(ctx_factory):
ctx = ctx_factory()
queue = cl.CommandQueue(ctx)
mf = cl.mem_flags

prg = cl.Program(ctx, """
__kernel void
reverse(__global const float *in, __global float *out, int n)
{
for (int i = 0;i < n;i++) {
out[i] = in[n - 1 - i];
}
}
""").build()
knl = prg.reverse

n = 1000000
a = np.random.rand(n).astype(np.float32)
b = np.empty_like(a)

buf1 = cl.Buffer(ctx, mf.READ_ONLY | mf.COPY_HOST_PTR, hostbuf=a)
buf2 = cl.Buffer(ctx, mf.WRITE_ONLY, b.nbytes)

knl.set_args(buf1, buf2, np.int32(n))
cl.enqueue_task(queue, knl)

cl.enqueue_read_buffer(queue, buf2, b).wait()
assert la.norm(a[::-1] - b) == 0

if __name__ == "__main__":
# make sure that import failures get reported, instead of skipping the tests.
import pyopencl # noqa
Expand Down

0 comments on commit 4cfa5d2

Please sign in to comment.