API Call Sequence

API Call Sequence

The API call sequence for data transfer is as follows:

  1. Allocate memory.
  2. Load data to the memory.

    The implementation logic of loading data to the memory is managed by the user.

  3. Implement data transfer using memory copy.
    Data transfer can be implemented in the following two memory copy modes:

    Data transfer within the host, within the device, or between the host and device can be implemented by using the memory copy API calls or by using pointers.

For the Ascend 310 AI Processor in Ascend RC mode, host memory allocation and data transfer within the host or between the host and device are not involved.

Considerations

If the current version supports multiple run modes and you want to run your app in multiple forms, the selection of the data transfer API varies with the memory allocation method.
  • If the C++ standard library API or AscendCL API is called to allocate memory (aclrtMallocHost for host memory or aclrtMalloc for device memory):

    Call aclrtGetRunMode to obtain the run mode of the software stack. If ACL_HOST is returned, you only need to allocate host memory. If ACL_DEVICE is returned, you only need to allocate device memory. Although more code logic judgment is introduced, you do not need to care about address alignment of device memory. In the scenario where your app runs on the device, this mode does not require memory copy and promises better performance.

  • If aclrtMallocHost is called to allocate memory, the system determines whether to allocate host memory or device memory based on the running status.

    aclrtGetRunMode does not need to be called to obtain the run mode of the software stack. The code logic is simpler. However, address alignment of device memory needs to be guaranteed by the user.