Terminology

Table 1 Terminology

Term

Description

Synchronous/Asynchronous

Indicates whether an API call returns immediately when the request is delivered.

  • Asynchronous: If an API call returns immediately without waiting for the device to complete the execution, the host scheduling is in asynchronous mode.
  • Synchronous: If the API call does not return until the device completes the execution, the host scheduling is in synchronous mode.

Process/Thread

Unless otherwise specified, the processes and threads mentioned in this document refer to those on the host.

Host

A host refers to the x86 or Arm server connected to the device. The host utilizes the NN compute capability provided by the device to implement services.

Device

A device refers to an Ascend AI Processor-powered hardware device that connects to the host over the PCIe interface, providing the host with the NN computing capability. Memory sharing between devices is not supported.

Context

A context is a container that manages the lifetime of its objects (including streams, events, and device memory). Each unique context has isolated streams and events, and they cannot be synchronized with one another.

Contexts come in two types:

  • Default context: a default context created implicitly upon the aclrtSetDevice call that sets the compute device. Each device corresponds to a default context. The default context cannot be destroyed by the aclrtDestroyContext call.
  • Explicitly created context (recommended): a context created explicitly upon the aclrtCreateContext call in a process or thread.

Stream

Streams preserve the order of a stack of asynchronous operations being executed on the device.

Stream-based kernel execution and data transfer can implement parallel computing on both the host and the device, as well as data transfer between the host and the device.

Streams come in two types:

  • Default stream: a default stream created implicitly upon the aclrtSetDevice call that specifies the device for computation. Each device corresponds to a default stream. A default stream cannot be released by calling aclrtDestroyStream.
  • Explicitly created stream (recommended): a stream created explicitly upon the aclrtCreateStream call in a process or thread.

Event

Events are used to synchronize tasks between streams by using AscendCL API calls, including tasks between the host and the device, and tasks on the same device.

For example, to execute a task from stream 2 after executing a task from stream 1, create an event and append it to stream 1.

AIPP

The Artificial Intelligence Pre-Processing (AIPP) module is introduced for AI Core–based image preprocessing including Color Space Conversion (CSC), image normalization (by subtracting the mean value or multiplying a factor), image cropping (by specifying the crop start and cropping the image to the size required by the NN), and much more.

AIPP supports static and dynamic modes. However, these two modes are mutually exclusive.
  • Static AIPP: During model conversion, set the AIPP mode to static and specify the AIPP attributes. After the model is generated, the AIPP attribute values are saved in the .om offline model. Fixed AIPP configurations are used in every model inference.

    In static AIPP mode, the same set of AIPP configurations is used across batches.

  • Dynamic AIPP: If you use this mode when converting a model, you can set dynamic AIPP parameters before running the model for inference. Then, different AIPP parameters are used in model execution.

    In dynamic AIPP mode, different sets of AIPP configurations can be used across batches.

Dynamic batch/image size

The batch size or image size is not fixed in certain scenarios. For example, as the number of detected objects is subject to change in the object detection+target recognition cascade scenario, the batch size of the target recognition input is dynamic.

  • Dynamic batch size: The batch size is not determinable until inference time.
  • Dynamic image size: The image size (H x W) of each image is not determinable until inference time.

Dynamic dimensions (ND format only)

Dynamic dimensions for the ND format are useful in scenarios where input dimensions are unknown (such as the Transformer network).

ND indicates any format with up to four dimensions.

Channel

An RGB image has three channels: red, green, and blue. HSV stands for hue, saturation, and value (brightness) and is an alternative representation of the RGB color model.

Standard form

The device functions as an endpoint (EP) and cooperates with the host (namely, an x86 or Arm server) over the PCIe interface. In this case, CPU resources on the device are available only to the host, and inference apps run on the host. The device only provides the NN compute capability for the server.

EP mode/RC mode

The following uses the Ascend AI Processor as an example. If the PCIe works as the master and supports peripherals, this mode is referred to as the RC mode (or Ascend RC in the following). If the PCIe serves as a slave, this mode is referred to as the EP mode (or Ascend EP in the following).

Device, Context, and Stream

Figure 1 Device, context, and stream

Thread, Context, and Stream

Context Migration Between Threads in a Process

Figure 2 API call sequence

Use Cases of Default Context and Default Stream

The following code snippet shows key steps only, and is not ready to be built or run.

...
aclInit(...);
aclrtSetDevice(0); 

/* In the default context, a default stream is created, and the stream is available in the current thread. */
...
aclopExecuteV2(op1,...,NULL);  //NULL indicates that op1 is executed in the default stream.
aclopExecuteV2(op2,...,NULL); //NULL indicates that op2 is executed in the default stream.
aclrtSynchronizeStream(NULL); 

/* Output the result as required when all computing tasks (op1 and op2 execution tasks) are complete. */
...
aclrtResetDevice(0); //Reset device 0. The lifetime of the corresponding default context and default stream end.

Multithreading and Multistreaming Performance