LocalMemAllocator Overview

LocalMemAllocator is a class used for memory management when the static tensor programming mode is used. You can directly create a LocalTensor object (or use the LocalTensor constructor to construct it) and develop operators, without the need to build TPipe or TQue. This reduces the overhead during runtime and achieves better performance.

LocalMemAllocator can be used only in the Ascend C static tensor programming mode and cannot be used together with APIs such as TPipe.

Header Files to Be Included

1
#include "kernel_operator.h"

Prototype

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
template<Hardware hard = Hardware::UB>
class LocalMemAllocator {
public:
    __aicore__ inline LocalMemAllocator();
    __aicore__ inline uint32_t GetCurAddr() const;
    template <class DataType, uint32_t tileSize> LocalTensor<DataType> __aicore__ inline Alloc();
    template <TPosition pos, class DataType, uint32_t tileSize> __aicore__ inline LocalTensor<DataType> Alloc();
    template <class DataType> LocalTensor<DataType> __aicore__ inline Alloc(uint32_t tileSize);    
    template <TPosition pos, class DataType> LocalTensor<DataType> __aicore__ inline Alloc(uint32_t tileSize);
    
    template <class TensorTraitType> LocalTensor<TensorTraitType> __aicore__ inline Alloc();
    
    
};

Template parameter

Table 1 Parameters in the template

Parameter

Description

hard

Indicates the physical location of data. The enumerated type of Hardware is defined as follows: UB, L1, L0A, L0B, L0C, BIAS, and FIXBUF. Valid locations are as follows:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
enum class Hardware : uint8_t { 
GM,     // Global Memory
UB,     // Unified Buffer
L1,     // L1 Buffer
L0A,    // L0A Buffer
L0B,    // L0B Buffer
L0C,    // L0C Buffer
BIAS,   // BiasTable Buffer
FIXBUF, // Fixpipe Buffer
MAX };