[Python] How to bridge arrays between pyopencl and numpy on CPU?

Discussão em 'Python' iniciado por Stack, Julho 22, 2025.

  1. Stack

    Stack Membro Participativo

    In my program the data is processed with numpy and pyopencl. To exchange data between those two libraries I always have to copy the data with .to_device() or .get() functions available in pyopencl. Those copy operations have signicant overhead. It would be nice if pyopencl and numpy could work on the same underlying memory if the pyopencl device is the CPU (e.g. internal GPU of an Intel processor). In pytorch there exist a feature called "bridge to numpy":

    https://pytorch.org/tutorials/beginner/blitz/tensor_tutorial.html#bridge-to-np-label

    t = torch.ones(5)
    n = t.numpy()
    n += 1
    assert np.all(t.numpy()==n) # True


    Does anyone know if this bridge feature can be realized when using numpy and pyopencl?

    Continue reading...

Compartilhe esta Página