我在 pyopencl 中尝试了一些基本示例,并注意到,无论我做什么,numpy 都比 pyopengl 运行得更快。我在 Intel i5 嵌入式 HD4400 上运行我的脚本。显然没有什么特别的,但是 numpy 的运行速度至少是 pyopengl 的两倍。我尝试的最后一个脚本:
import pyopencl as cl
from pyopencl import algorithm
import numpy as np
from time import time
from pyopencl.clrandom import rand
from pyopencl.array import to_device
if __name__ == '__main__':
ctx = cl.create_some_context()
queue = cl.CommandQueue(ctx)
q = np.random.random_integers(-10**6,high=10**6, size=2**24)
r = to_device(queue, q)
begin = time()
out, count, even = algorithm.copy_if(r, "ary[i] < 42", queue=queue)
out.get()
print("OpenCL takes {:9.6F} seconds".format(time() - begin))
begin = time()
b …Run Code Online (Sandbox Code Playgroud)