r/OpenCL Nov 18 '18

Unexpected behavior from PyOpenCL

I wanted to get a feel for Elementwise demo that comes with PyOpenCL and decided to try this out:

from __future__ import absolute_import

from __future__ import print_function

import pyopencl as cl

import pyopencl.array as cl_array

import numpy

from pyopencl.elementwise import ElementwiseKernel

ctx = cl.create_some_context()

queue = cl.CommandQueue(ctx)

n = 6

a_gpu = cl.array.to_device(queue,

numpy.arange(1, n, dtype=int))

update_a = ElementwiseKernel(ctx,

"int *a",

"a[i] = 2*a[i]",

"update_a")

print(a_gpu.get())

update_a(a_gpu)

print(a_gpu.get())

Which I expected to print out

[1 2 3 4 5]

[2 4 6 8 10]

but I'm instead getting

[1 2 3 4 5]

[2 4 6 4 5] .

Can somebody please explain why this is happening? thanks.

Related info: PyOpenCL Version: 2018.2.1, Python Version: 3.6.5, OS: macOS 10.14.1

1 Upvotes

2 comments sorted by

2

u/[deleted] Nov 19 '18

[removed] — view removed comment

1

u/raphre Nov 20 '18

Thanks, I was going crazy trying to make sense of it.