Skip to content

Commit 07ef820

Browse files
author
Jonathan Rocher
committed
Added comments and an intermediate index for cl code.
1 parent b729e90 commit 07ef820

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

py_open_cl_demo.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,15 @@
1717

1818
# create the pyopencl function a little like weave.inline
1919
# Just in Time compiler.
20-
# Notice the way we index into the array a: get_global_id
20+
# Notice the way we index into the array a: get_global_id collect the worker's
21+
# ID for each worker and use it as index into the array: this is how parallelism
22+
# is achieved.
2123
prg = cl.Program(ctx, """
2224
__kernel void twice(__global float *a)
23-
{ a[ get_global_id (0)] *= 2;}
24-
""").build()
25+
{
26+
unsigned int i = get_global_id(0);
27+
a[i] *= 2;
28+
}""").build()
2529

2630
# Call the twice function
2731
prg.twice(queue, a.shape, (1,), a_dev)

0 commit comments

Comments
 (0)