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);