Rank
产品支持情况
- Ascend 950PR/Ascend 950DT:支持
- Atlas A3 训练系列产品/Atlas A3 推理系列产品:不支持
- Atlas A2 训练系列产品/Atlas A2 推理系列产品:不支持
- Atlas 200I/500 A2 推理产品:不支持
- Atlas 推理系列产品AI Core:不支持
- Atlas 推理系列产品Vector Core:不支持
- Atlas 训练系列产品:不支持
功能说明
用于返回Layout的秩。
函数原型
C++
template <size_t... Is, typename Shape, typename Stride>
__aicore__ inline constexpr auto Rank(const Layout<Shape, Stride>& layout);
参数说明
表1 模板参数说明
| 参数名 | 类型 | 描述 |
|---|---|---|
| Shape | 输入 | 组成Layout的shape的类型,即元组(tuple)类型。 |
| Stride | 输入 | 组成Layout的stride的类型,即元组(tuple)类型。 |
| Is... | size_t | 索引序列,用于编译时递归选择shape和stride的子结构。 |
表2 参数说明
| 参数名 | 类型 | 描述 |
|---|---|---|
| layout | 输入 | Layout用于描述张量的布局。 |
返回值
返回Layout的秩,即返回Layout布局的Shape或其子结构的元组(tuple)维度的个数。
示例代码
C++
using namespace AscendC::Te;
auto layout = MakeLayout(MakeShape(10, 20), MakeStride(1, 100));
auto rank1 = Rank(layout); //rank1 = 2
auto rank2 = Rank<0>(layout); //rank2 = 1