@@ -356,24 +356,33 @@ def memset(self, allocation, value, size):
356
356
C .memset (allocation .ctypes , value , size )
357
357
358
358
def memcpy_dtoh (self , dest , src ):
359
- """There is no memcpy_dtoh for the compiler backend."""
360
- pass
359
+ """This method implements the semantic of a device to host copy for the Compiler backend.
360
+ There is no actual copy from device to host happening, but host to host.
361
+
362
+ :param dest: A numpy or cupy array to store the data
363
+ :type dest: np.ndarray or cupy.ndarray
364
+
365
+ :param src: An Argument for some memory allocation
366
+ :type src: Argument
367
+ """
368
+ # there is no real copy from device to host, but host to host
369
+ if isinstance (dest , np .ndarray ) and is_cupy_array (src .numpy ):
370
+ # Implicit conversion to a NumPy array is not allowed.
371
+ value = src .numpy .get ()
372
+ else :
373
+ value = src .numpy
374
+ xp = get_array_module (dest )
375
+ dest [:] = xp .asarray (value )
361
376
362
377
def memcpy_htod (self , dest , src ):
363
- """There is no memcpy_htod for the compiler backend."""
378
+ """There is no memcpy_htod implemented for the compiler backend."""
364
379
pass
365
380
366
381
def refresh_memory (self , arguments , should_sync ):
367
382
"""Copy the preserved content of the output memory to used arrays."""
368
383
for i , arg in enumerate (arguments ):
369
384
if should_sync [i ]:
370
- if isinstance (arg , np .ndarray ) and is_cupy_array (self .allocations [i ].numpy ):
371
- # Implicit conversion to a NumPy array is not allowed.
372
- value = self .allocations [i ].numpy .get ()
373
- else :
374
- value = self .allocations [i ].numpy
375
- xp = get_array_module (arg )
376
- arg [:] = xp .asarray (value )
385
+ self .memcpy_dtoh (arg , self .allocations [i ])
377
386
378
387
def cleanup_lib (self ):
379
388
"""Unload the previously loaded shared library"""
0 commit comments