Alloc
产品支持情况
产品 |
是否支持 |
---|---|
√ |
|
√ |
|
x |
|
√ |
|
√ |
|
x |
|
x |
功能说明
根据用户指定的逻辑位置、数据类型、数据长度返回对应的LocalTensor对象。
函数原型
- 原型1:tileSize为模板参数
1 2 3
// 当tileSize为常量时,建议使用此接口,以获得更优的性能 template <TPosition pos, class DataType, uint32_t tileSize> __aicore__ inline LocalTensor<DataType> Alloc();
- 原型2:tileSize为接口入参
1 2 3
// 当tileSize为动态参数时使用此接口 template <TPosition pos, class DataType> LocalTensor<DataType> __aicore__ inline Alloc(uint32_t tileSize);
参数说明
参数名 |
描述 |
---|---|
pos |
TPosition位置,需要符合LocalMemAllocator中指定的Hardware物理位置。 |
DataType |
LocalTensor的数据类型,只支持基础数据类型,不支持TensorTrait类型。 |
tileSize |
LocalTensor的元素个数,其数量不应超过当前物理位置剩余的内存空间。 |
参数名 |
输入/输出 |
描述 |
---|---|---|
tileSize |
输入 |
LocalTensor的元素个数,其数量不应超过当前物理位置剩余的内存空间。 剩余的内存空间可以通过物理内存最大值与当前可用内存地址(GetCurAddr返回值)的差值来计算。 |
返回值
根据用户输入构造的LocalTensor对象。
约束说明
无
调用示例
1 2 3 4 5 6 7 | ... AscendC::LocalMemAllocator allocator; // 原型1:用户指定逻辑位置VECIN,float类型,Tensor中有1024个元素 auto tensor1 = allocator.Alloc<AscendC::TPosition::VECIN, float, 1024>(); // 原型2:用户指定逻辑位置VECIN,float类型,Tensor中有tileLength个元素 auto tensor1 = allocator.Alloc<AscendC::TPosition::VECIN, float>(tileLength); |
父主题: LocalMemAllocator