Function: memcpy_async

Applicable Products

  • Ascend 950PR&950DT products: Supported
  • Atlas A3 products: Supported
  • Atlas A2 products: Supported
  • Atlas 200I/500 A2 inference products: Supported
  • Atlas inference products: Supported
  • Atlas training products: Supported

Function

Copies memory. This API is asynchronous.

The host memory in this API supports pinned memory (for example, memory allocated by calling acl.rt.malloc_host) and non-pinned memory (allocated by calling the malloc API). If the host memory is non-page-locked memory, this API returns only after the memory copy task is complete. If the host memory is page-locked memory, this API is asynchronous. A successful API call only indicates that the task is delivered, not executed. After this API is called, call the synchronization API (for example, acl.rt.synchronize_stream) to ensure that the memory copy task is complete.

Prototype

  • C Prototype

    aclError aclrtMemcpyAsync(void *dst, size_t destMax, const void *src, size_t count, aclrtMemcpyKind kind, aclrtStream stream)
    
  • Python Function

    ret = acl.rt.memcpy_async(dst, dest_max, src, count, kind, stream)
    

Parameters

Parameter Description
dst Int, pointer address of the destination memory address.
dest_max Int, memory size in bytes in the destination address
src Int, pointer address of the source memory address.
count Int, size in bytes to copy.
kind Int, memory copy type.
0: ACL_MEMCPY_HOST_TO_HOST, memory copy within the host.
1: ACL_MEMCPY_HOST_TO_DEVICE, memory copy from the host to the device.
2: ACL_MEMCPY_DEVICE_TO_HOST, memory copy from the device to the host.
3: ACL_MEMCPY_DEVICE_TO_DEVICE, memory copy within the device. This API is not supported on the Atlas 500 Pro AI edge server (model 3000).
4: ACL_MEMCPY_DEFAULT. The system determines the copy direction based on the source and destination memory addresses.
stream Int, stream ID.

Return Values

Return Value Description
ret Int, error code. If 0 is returned, the operation is successful. If other values are returned, the operation fails.

Constraints

  • The source address and destination address passed to this call must be 64-byte aligned.
  • In Ascend EP mode, this API does not support asynchronous memory copy within the host. If the input kind is ACL\_MEMCPY\_HOST\_TO\_HOST, the API returns the error code ACL\_ERROR\_RT\_FEATURE\_NOT\_SUPPORT.
  • In Ascend RC mode, when an application is running on the board, if the kind passed to this API call is ACL\_MEMCPY\_HOST\_TO\_DEVICE, ACL\_MEMCPY\_DEVICE\_TO\_HOST, or ACL\_MEMCPY\_HOST\_TO\_HOST, the system uses ACL\_MEMCPY\_DEVICE\_TO\_DEVICE by default to perform memory copy within the device.
  • In open Ctrl CPU mode, when an application is running on the device, if the kind passed to this API call is ACL\_MEMCPY\_HOST\_TO\_DEVICE, ACL\_MEMCPY\_DEVICE\_TO\_HOST, or ACL\_MEMCPY\_HOST\_TO\_HOST, the system uses ACL\_MEMCPY\_DEVICE\_TO\_DEVICE by default to perform memory copy within the device.