Skip to content

AllocTensor

产品支持情况

  • 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_tpipe.h"

从TSCM中分配tensor,tensor所占大小为InitBuffer时设置的每块内存长度。注意,分配的tensor内容并非全0,可能会是随机值。

函数原型

C++
template <typename T>
__aicore__ inline LocalTensor<T> AllocTensor()

参数说明

参数名称说明
T待获取Tensor的数据类型,支持的类型请见LocalTensor相关描述。

约束说明

返回值说明

LocalTensor对象。

调用示例

C++
AscendC::TPipe pipe;
AscendC::TSCM<AscendC::TPosition::VECIN, 1> tscm;
int num = 4;
int len = 1024;
pipe.InitBuffer(tscm, num, len); // InitBuffer分配内存块数为4,每块大小为1024Bytes
AscendC::LocalTensor<half> tensor1 = tscm.AllocTensor<half>(); // AllocTensor分配Tensor长度为1024Bytes
tscm.EnQue(tensor1);
tensor1 = tscm.DeQue<half>();
tscm.FreeTensor(tensor1);

免责声明:本站内容由 asc-devkit 仓 master 分支自动编译生成,属于持续开发版本,可能存在缺陷,仅供预览与参考。如需稳定及商用资料,请查阅官方 昇腾社区