pythongpuopenclpyopencl

Does pyopencl transfer arrays to host memory implicitly?


I have AMD GPU. I'm using pyopencl. I have a context and a queue. Then I created an array:

import pyopencl
import pyopencl.array
ctx = pyopencl.create_some_context(interactive=False)
queue = pyopencl.CommandQueue(ctx)
array = pyopencl.array.empty(queue, [10], dtype=float)
print(array)

The print statement is showing some contents. Has pyopencl transferred data from GPU memory to print those values? If not, where do they come from?


Solution

  • Has pyopencl transferred data from GPU memory to print those values?

    Yes.

    print calls __str__(). The documentation for __str__ links to the source code which shows return str(self.get()). What does get() do?

    Transfer the contents of self into […] a newly allocated numpy.ndarray