Skip to content
Snippets Groups Projects
Commit 4a603cfb authored by Andreas Klöckner's avatar Andreas Klöckner
Browse files

Add (fixed) narray example by Roger Pau Monn'e.

parent bdb37787
No related branches found
No related tags found
No related merge requests found
# example by Roger Pau Monn'e
import pyopencl as cl
import numpy as np
demo_r = np.empty( (500,5), dtype=np.uint32)
ctx = cl.create_context_from_type(cl.device_type.GPU)
queue = cl.CommandQueue(ctx)
mf = cl.mem_flags
demo_buf = cl.create_buffer(ctx, mf.WRITE_ONLY, demo_r.nbytes)
prg = cl.create_program_with_source(ctx,
"""
__kernel void demo(__global uint *demo)
{
int i;
int gid = get_global_id(0);
for(i=0; i<5;i++)
{
demo[gid*5+i] = (uint) 1;
}
}""")
try:
prg.build()
except:
print "Error:"
print prg.get_build_info(ctx.devices[0], cl.program_build_info.LOG)
raise
prg.demo(queue, (500,), demo_buf)
cl.enqueue_read_buffer(queue, demo_buf, demo_r).wait()
for res in demo_r:
print res
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment