
Alloc【免费下载链接】asc-devkit本项目是CANN 推出的昇腾AI处理器专用的算子程序开发语言原生支持C和C标准规范主要由类库和语言扩展层构成提供多层级API满足多维场景算子开发诉求。项目地址: https://gitcode.com/cann/asc-devkit产品支持情况Ascend 950PR/Ascend 950DT支持Atlas A3 训练系列产品/Atlas A3 推理系列产品支持Atlas A2 训练系列产品/Atlas A2 推理系列产品支持Atlas 200I/500 A2 推理产品不支持Atlas 推理系列产品AI Core支持Atlas 推理系列产品Vector Core支持Atlas 训练系列产品不支持功能说明头文件路径为basic_api/kernel_tensor.h。根据用户指定的逻辑位置、数据类型、数据长度返回对应的LocalTensor对象。函数原型原型1tileSize为模板参数// 当tileSize为常量时建议使用此接口以获得更优的性能 template class DataType, uint32_t tileSize LocalTensorDataType __aicore__ inline Alloc() template TPosition pos, class DataType, uint32_t tileSize __aicore__ inline LocalTensorDataType Alloc()原型2tileSize为接口入参// 当tileSize为动态参数时使用此接口 template class DataType LocalTensorDataType __aicore__ inline Alloc(uint32_t tileSize) template TPosition pos, class DataType LocalTensorDataType __aicore__ inline Alloc(uint32_t tileSize)原型3使用TensorTrait时使用此接口template class DataType LocalTensorDataType __aicore__ inline Alloc()参数说明表1原型1和原型2模板参数说明参数名描述posTPosition位置需要符合LocalMemAllocator中指定的Hardware物理位置C Tensor编程场景下此参数可以省略。DataTypeLocalTensor的数据类型只支持基础数据类型不支持TensorTrait类型。tileSizeLocalTensor的元素个数其数量不应超过当前物理位置剩余的内存空间。表2原型2参数说明参数名输入/输出描述tileSize输入LocalTensor的元素个数其数量不应超过当前物理位置剩余的内存空间。剩余的内存空间可以通过物理内存最大值与当前可用内存地址GetCurAddr返回值的差值来计算。表3原型3模板参数说明参数名描述TensorTraitType只支持传入TensorTrait类型TensorTrait的数据类型/逻辑位置/Shape大小需要匹配LocalMemAllocator中指定的物理位置及其剩余空间。返回值说明根据用户输入构造的LocalTensor对象。约束说明针对Ascend 950PR/Ascend 950DT对UB的内存分配会基于静态内存的基础上进行分配即动态内存初始位置参考内存层级。当前暂不支持与L1 Buffer, L0A Buffer, L0B Buffer, L0C Buffer, BiasTable静态数组混用。调用示例template uint32_t v using UIntImm Std::integral_constantuint32_t, v; ... AscendC::LocalMemAllocator allocator; // 原型1float类型Tensor中有1024个元素用户可以指定逻辑位置(或者不指定由Alloc函数根据物理位置给出默认值不影响功能) auto tensor1 allocator.AllocAscendC::TPosition::VECIN, float, 1024(); auto tensor1 allocator.Allocfloat, 1024(); // 原型2float类型Tensor中有tileLength个元素用户可以指定逻辑位置(或者不指定由Alloc函数根据物理位置给出默认值不影响功能) auto tensor1 allocator.AllocAscendC::TPosition::VECIN, float(tileLength); // 原型3用户指定逻辑位置VECIN数据类型为floatTensor中元素个数为16*16*16 auto shape AscendC::MakeShape(UIntImm16{}, UIntImm16{}, UIntImm16{}); auto stride AscendC::MakeStride(UIntImm0{}, UIntImm0{}, UIntImm0{}); auto layoutMake AscendC::MakeLayout(shape, stride); auto tensorTraitMake AscendC::MakeTensorTraitfloat, AscendC::TPosition::VECIN(layoutMake); auto tensor3 allocator.Allocdecltype(tensorTraitMake)();【免费下载链接】asc-devkit本项目是CANN 推出的昇腾AI处理器专用的算子程序开发语言原生支持C和C标准规范主要由类库和语言扩展层构成提供多层级API满足多维场景算子开发诉求。项目地址: https://gitcode.com/cann/asc-devkit创作声明:本文部分内容由AI辅助生成(AIGC),仅供参考