Programming Model Design Principles

In the Ascend C programming model, the core elements of the parallel programming paradigm are a group of parallel compute tasks, synchronization between tasks through queues, and custom scheduling of parallel compute tasks and resources. This section describes the design principles of the programming model, helping you better understand the design and advantages of the programming model and facilitating subsequent in-depth development.

The programming paradigm of each parallel task stage is as follows:

  1. Obtain the local memory: Call AllocTensor to allocate memory, or call DeQue to deque a memory data block from the upstream queue.
  2. Complete computation or data movement.
  3. Call EnQue to enqueue the data processed in the previous step.
  4. Call FreeTensor to free the memory that is no longer needed.

Take the simplest vector programming paradigm as an example. When the preceding APIs are called, some instructions are actually delivered to each execution unit, as shown in the following figure.

Figure 1 Vector programming paradigm instruction queue

In conclusion, complex synchronization control needs to be considered for asynchronous parallel programs. The Ascend C programming model encapsulates these processes and uses EnQue/DeQue/AllocTensor/FreeTensor to simplify programming and facilitate understanding.