You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The current implementation in ContextCpu of nparray_from_context_array and nparray_to_context_array currently reads:
defnparray_to_context_array(self, arr):
""" Moves a numpy array to the device memory. No action is performed by this function in the CPU context. The method is provided so that the CPU context has an identical API to the GPU ones. Args: arr (numpy.ndarray): Array to be transferred Returns: numpy.ndarray: The same array (no copy!). """returnarrdefnparray_from_context_array(self, dev_arr):
""" Moves an array to the device to a numpy array. No action is performed by this function in the CPU context. The method is provided so that the CPU context has an identical API to the GPU ones. Args: dev_arr (numpy.ndarray): Array to be transferred Returns: numpy.ndarray: The same array (no copy!) """returndev_arr
However, this behavior is extremely different from the one provided in the implementation of ContextCupy and ContextPyopencl, where an explicit copy of an array is made from guest memory to host memory.
This big difference in behavour forces the user to require an extra explicit copy whenever an array manipulation is taken from an XObject, in order to be able to cover both CPU and GPU cases. E.g., if I need to access and save some arrays along the tracking, and I want to use nparray_from_context_array, I am forced to do it like so:
in order to have my code operating in the same way both on CPU context and on CUPY/PYOPENCL context....
To avoid this extra (wasteful) copy, and to restore coherence in behavior between different contexts, could you just add a .copy() to the CPU context? Or would it break inner dependencies?
Thanks!
The text was updated successfully, but these errors were encountered:
It is possible there could be performances issues depending on where this method is used. I suggest to add another method with the behaviour you suggested for your use case, while evaluating the impact.
The current implementation in
ContextCpu
ofnparray_from_context_array
andnparray_to_context_array
currently reads:However, this behavior is extremely different from the one provided in the implementation of ContextCupy and ContextPyopencl, where an explicit copy of an array is made from guest memory to host memory.
This big difference in behavour forces the user to require an extra explicit copy whenever an array manipulation is taken from an XObject, in order to be able to cover both CPU and GPU cases. E.g., if I need to access and save some arrays along the tracking, and I want to use nparray_from_context_array, I am forced to do it like so:
in order to have my code operating in the same way both on CPU context and on CUPY/PYOPENCL context....
To avoid this extra (wasteful) copy, and to restore coherence in behavior between different contexts, could you just add a .copy() to the CPU context? Or would it break inner dependencies?
Thanks!
The text was updated successfully, but these errors were encountered: