Python 3.x OpenCL内核无法按预期工作(pyopencl)

Python 3.x OpenCL内核无法按预期工作(pyopencl),python-3.x,opencl,pyopencl,Python 3.x,Opencl,Pyopencl,我编写了一个OpenCL函数来增加数组中的64位浮点值。 但是CPU和GPU的结果是不同的 import numpy as np import pyopencl as cl CL_INC = ''' __kernel void inc_f64(__global const double *a_g, __global double *res_g) { int gid = get_global_id(0); res_g[gid] = a_g[gid] + 1.0; } ''' def t

我编写了一个OpenCL函数来增加数组中的64位浮点值。 但是CPU和GPU的结果是不同的

import numpy as np
import pyopencl as cl

CL_INC = '''
__kernel void inc_f64(__global const double *a_g, __global double *res_g)
{
  int gid = get_global_id(0);
  res_g[gid] = a_g[gid] + 1.0;
}
'''

def test(dev_type):
    ctx = cl.Context(dev_type=dev_type)
    queue = cl.CommandQueue(ctx)
    mf = cl.mem_flags
    prg = cl.Program(ctx, CL_INC).build()

    in_py = np.array([1.0, 2.0, 3.0, 4.0, 5.0])
    out_py = np.empty_like(in_py)
    in_cl = cl.Buffer(ctx, mf.READ_ONLY | mf.COPY_HOST_PTR, hostbuf=in_py)
    out_cl = cl.Buffer(ctx, mf.WRITE_ONLY, in_py.nbytes)
    prg.inc_f64(queue, in_py.shape, None, in_cl, out_cl)
    cl.enqueue_copy(queue, out_py, out_cl)

    queue.finish()
    return out_py

print('Run inc_f64() on CPU: ', end='')
print(test(cl.device_type.CPU))
print('Run inc_f64() on GPU: ', end='')
print(test(cl.device_type.GPU))
输出:

Run inc_f64() on CPU: [2. 3. 4. 5. 6.]
Run inc_f64() on GPU: [2.40000038e+001 3.20000076e+001 5.26354425e-315 0.00000000e+000
 0.00000000e+000]
硬件信息:

[0] Apple / OpenCL 1.2 (Oct 31 2017 18:30:00)
  |- [0:0] CPU / OpenCL 1.2 / Intel(R) Core(TM) i7-3667U CPU @ 2.00GHz
  |- [0:1] GPU / OpenCL 1.2 / HD Graphics 4000

这是硬件限制还是源代码中的错误?

您的GPU可能不支持双精度浮点数。您是否检查了对
cl\u khr\u fp64
扩展的支持

您的内核还必须声明其要求:

#pragma OPENCL EXTENSION cl_khr_fp64 : enable

有关更多详细信息,.

@RaymondWu这是否意味着您已经检查了设备的
CL\u设备\u扩展
字符串,并且它包含
CL\u khr\u fp64
扩展?(请参阅)另外,您是否检查了缓冲区副本、内核执行等的任何返回值。?他们返回什么?