Skip to content

Instantly share code, notes, and snippets.

@fjarri
Created July 4, 2014 01:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fjarri/fde93e0c5ecd6eae59a2 to your computer and use it in GitHub Desktop.
Save fjarri/fde93e0c5ecd6eae59a2 to your computer and use it in GitHub Desktop.
import numpy as np
import pyopencl as cl
import pyopencl.array as array
ctx = cl.create_some_context()
queue = cl.CommandQueue(ctx)
a = np.random.rand(128).astype(np.float32)
a_gpu = array.to_device(queue, a)
dest_gpu = array.empty_like(a_gpu)
prg = cl.Program(ctx, """
__kernel void test(__global float *dest, __global float *src)
{
__local float lmem[128];
int gid = get_global_id(0);
lmem[gid] = src[gid];
barrier(CLK_LOCAL_MEM_FENCE);
dest[gid] = lmem[gid];
}
""").build()
prg.test(queue, a_gpu.shape, None, dest_gpu.data, a_gpu.data)
dest = dest_gpu.get()
assert (dest == a).all()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment