CANN/asc-devkit AllocTensor API文档
AllocTensor【免费下载链接】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 推理系列产品√功能说明从Que中分配TensorTensor所占大小为InitBuffer时设置的每块内存长度。函数原型non-inplace接口构造新的Tensor作为内存管理的对象template typename T __aicore__ inline LocalTensorT AllocTensor()inplace接口直接使用传入的Tensor作为内存管理的对象可以减少Tensor反复创建的开销。template typename T __aicore__ inline void AllocTensor(LocalTensorT tensor)参数说明表 1模板参数说明参数名说明TTensor的数据类型。表 2参数说明参数名称输入/输出含义tensor输入inplace接口需要传入LocalTensor作为内存管理的对象。约束说明non-inplace接口分配的Tensor内容可能包含随机值。non-inplace接口需要将TQueBind的depth模板参数设置为非零值inplace接口需要将TQueBind的depth模板参数设置为0。返回值说明non-inplace接口返回值为LocalTensor对象inplace接口没有返回值。调用示例non-inplace接口AscendC::TPipe pipe; AscendC::TQueBindAscendC::TPosition::VECOUT, AscendC::TPosition::GM, 2 que; int num 4; int len 1024; pipe.InitBuffer(que, num, len); // InitBuffer分配内存块数为4每块大小为1024Bytes AscendC::LocalTensorhalf tensor1 que.AllocTensorhalf(); // AllocTensor分配Tensor长度为1024Bytesinplace接口AscendC::TPipe pipe; AscendC::TQueBindAscendC::TPosition::VECOUT, AscendC::TPosition::GM, 0 que; int num 2; int len 1024; pipe.InitBuffer(que, num, len); // InitBuffer分配内存块数为2每块大小为1024Bytes AscendC::LocalTensorhalf tensor1; que.AllocTensorhalf(tensor1); // AllocTensor分配Tensor长度为1024Bytes【免费下载链接】asc-devkit本项目是CANN 推出的昇腾AI处理器专用的算子程序开发语言原生支持C和C标准规范主要由类库和语言扩展层构成提供多层级API满足多维场景算子开发诉求。项目地址: https://gitcode.com/cann/asc-devkit创作声明:本文部分内容由AI辅助生成(AIGC),仅供参考