【发布时间】:2018-11-19 00:08:22
【问题描述】:
我想感受一下 PyOpenCL 附带的 Elementwise 演示,并决定尝试一下:
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())
我希望打印出来的
[1 2 3 4 5]
[2 4 6 8 10]
但我却得到了
[1 2 3 4 5]
[2 4 6 4 5] .
此外,当我尝试将“i”值存储到数组中以查看发生了什么时,我得到了一些非常奇怪的值。它们到处都是,有些甚至是负面的。
一段时间以来,我一直试图理解这一点,但无法理解。有人可以解释为什么会这样吗?谢谢。
相关信息:PyOpenCL 版本:2018.2.1,Python 版本:3.6.5,操作系统:macOS 10.14.1
【问题讨论】:
标签: python-3.x opencl pyopencl