LocalMemAllocator是在使用Ascend C更底层编程方式时用于内存管理的类,用户无需构建TPipe/TQue,而是直接创建LocalTensor对象(也可以直接通过LocalTensor构造函数进行构造)并开发算子,从而减少运行时的开销,实现更优的性能。
LocalMemAllocator仅支持在Ascend C更底层编程方式中使用,不可以与TPipe等接口混用。
1
|
#include "kernel_operator.h" |
1 2 3 4 5 6 7 8 9 10 11 12 |
template<Hardware hard = Hardware::UB> class LocalMemAllocator { public: __aicore__ inline LocalMemAllocator(); __aicore__ inline uint32_t GetCurAddr() const; template <TPosition pos, class DataType, uint32_t tileSize> __aicore__ inline LocalTensor<DataType> Alloc(); template <TPosition pos, class DataType> LocalTensor<DataType> __aicore__ inline Alloc(uint32_t tileSize); }; |
|
参数名 |
描述 |
||
|---|---|---|---|
|
hard |
用于表示数据的物理位置,Hardware枚举类型,定义如下,合法位置为:UB、L1、L0A、L0B、L0C、BIAS、FIXBUF。物理位置的具体说明可参考存储单元。
|
1 2 3 4 5 6 |
__aicore__ inline LocalMemAllocator() __aicore__ inline uint32_t GetCurAddr() const template <TPosition pos, class DataType, uint32_t tileSize> __aicore__ inline LocalTensor<DataType> Alloc() template <TPosition pos, class DataType> LocalTensor<DataType> __aicore__ inline Alloc(uint32_t tileSize) |