Created
July 4, 2014 01:35
-
-
Save fjarri/fde93e0c5ecd6eae59a2 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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