昇腾C SIMD API InitBufPool
InitBufPool产品支持情况产品是否支持Ascend 950PR/Ascend 950DT√Atlas A3 训练系列产品 / Atlas A3 推理系列产品√Atlas A2 训练系列产品 / Atlas A2 推理系列产品√Atlas 200I/500 A2 推理产品xAtlas 推理系列产品 AI Core√Atlas 推理系列产品 Vector CorexAtlas 训练系列产品√Kirin X90√Kirin 9030√功能说明初始化TBufPool内存资源池。本接口适用于内存资源有限时希望手动指定UB/L1内存资源复用的场景。本接口初始化后在整体内存资源中划分出一块子资源池。划分出的子资源池TBufPool提供了如下方式进行资源管理TPipe::InitBufPool的重载接口指定与其他TBufPool子资源池复用;TBufPool::InitBufPool接口对子资源池继续划分TBufPool::InitBuffer接口分配Buffer关于TBufPool的具体介绍及资源划分图示请参考TBufPool。函数原型template class T __aicore__ inline bool InitBufPool(T bufPool, uint32_t len) template class T, class U __aicore__ inline bool InitBufPool(T bufPool, uint32_t len, U shareBuf)参数说明表 1模板参数说明参数名描述TbufPool的类型。UshareBuf的类型。表 2参数说明参数名输入/输出描述bufPool输入新划分的资源池类型为TBufPool。len输入新划分资源池长度单位为Byte非32Bytes对齐会自动补齐至32Bytes对齐。shareBuf输入被复用资源池类型为TBufPool新划分资源池与被复用资源池共享起始地址及长度。约束说明新划分的资源池与被复用资源池的硬件属性需要一致两者共享起始地址及长度输入长度需要小于等于被复用资源池长度其他泛用约束参考TBufPool。返回值说明无调用示例由于物理内存的大小有限在计算过程没有数据依赖的场景或数据依赖串行的场景下可以通过指定内存复用解决资源不足的问题。完整算子样例参考tbufpool_management样例。// 声明一个指向TPipe管道对象的指针 AscendC::TPipe* pipe; // 定义两个子资源池对象tbufPool1和tbufPool2 AscendC::TBufPoolAscendC::TPosition::VECCALC tbufPool1, tbufPool2; // 初始化第一个子资源池tbufPool1 pipe-InitBufPool(tbufPool1, bufSize * 3); // 初始化第二个子资源池tbufPool2并指定tbufPool2复用tbufPool1的起始地址及长度 pipe-InitBufPool(tbufPool2, bufSize * 3, tbufPool1); // 计算串行不存在数据踩踏实现了内存复用及自动同步的能力 tbufPool1.InitBuffer(srcQue0, 1, bufSize); tbufPool1.InitBuffer(srcQue1, 1, bufSize); tbufPool1.InitBuffer(dstQue0, 1, bufSize); CopyIn(); Compute(); CopyOut(); tbufPool1.Reset(); tbufPool2.InitBuffer(srcQue2, 1, bufSize); tbufPool2.InitBuffer(srcQue3, 1, bufSize); tbufPool2.InitBuffer(dstQue1, 1, bufSize); CopyIn1(); Compute1(); CopyOut1(); tbufPool2.Reset();创作声明:本文部分内容由AI辅助生成(AIGC),仅供参考