Привет
Запускаю пример вот отсюда: https://github.com/inducer/pyopencl/blob/main/examples/demo.py
#!/usr/bin/env python
import numpy as np
import pyopencl as cl
rng = np.random.default_rng()
a_np = rng.random(50000, dtype=np.float32)
b_np = rng.random(50000, dtype=np.float32)
ctx = cl.create_some_context()
queue = cl.CommandQueue(ctx)
mf = cl.mem_flags
a_g = cl.Buffer(ctx, mf.READ_ONLY | mf.COPY_HOST_PTR, hostbuf=a_np)
b_g = cl.Buffer(ctx, mf.READ_ONLY | mf.COPY_HOST_PTR, hostbuf=b_np)
prg = cl.Program(ctx, """
__kernel void sum(
__global const float *a_g, __global const float *b_g, __global float *res_g)
{
int gid = get_global_id(0);
res_g[gid] = a_g[gid] + b_g[gid];
}
""").build()
res_g = cl.Buffer(ctx, mf.WRITE_ONLY, a_np.nbytes)
knl = prg.sum # Use this Kernel object for repeated calls
knl(queue, a_np.shape, None, a_g, b_g, res_g)
res_np = np.empty_like(a_np)
cl.enqueue_copy(queue, res_np, res_g)
# Check on CPU with Numpy:
error_np = res_np - (a_np + b_np)
print(f"Error:\n{error_np}")
print(f"Norm: {np.linalg.norm(error_np):.16e}")
assert np.allclose(res_np, a_np + b_np)
Получаю ошибку:
/usr/lib/python3.12/site-packages/pyopencl/cache.py:495: CompilerWarning: Non-empty compiler output encountered. Set the environment variable PYOPENCL_COMPILER_OUTPUT=1 to see more.
_create_built_program_from_source_cached(
Traceback (most recent call last):
File "/home/kroz/mine/prj/prg/python/hsa/test_2.py", line 29, in <module>
knl = prg.sum # Use this Kernel object for repeated calls
^^^^^^^
File "/usr/lib/python3.12/site-packages/pyopencl/__init__.py", line 443, in __getattr__
knl = Kernel(self, attr)
^^^^^^^^^^^^^^^^^^
TypeError: __init__(): incompatible function arguments. The following argument types are supported:
1. __init__(self, arg0: pyopencl._cl._Program, arg1: str, /) -> None
Invoked with types: pyopencl._cl.Kernel, pyopencl.Program, str
Что я делаю не так?