Skip to content

integer_sequence

产品支持情况

  • Ascend 950PR/Ascend 950DT:支持
  • Atlas A3 训练系列产品/Atlas A3 推理系列产品:支持
  • Atlas A2 训练系列产品/Atlas A2 推理系列产品:支持
  • Atlas 200I/500 A2 推理产品:不支持
  • Atlas 推理系列产品AI Core:支持
  • Atlas 推理系列产品Vector Core:不支持
  • Atlas 训练系列产品:不支持

功能说明

index_sequence是Ascend C提供的一个类模板,用于生成一个编译时的整数序列,适用于模板元编程。

make_index_sequence是Ascend C提供的一个模板,通常使用make_index_sequence创建一个index_sequence类型的对象,用于生成一个从0到N-1的整数序列。

函数原型

Text
template<size_t... Idx>
using index_sequence = IntegerSequence<size_t, Idx...>;
Text
template<size_t N>
using make_index_sequence = MakeIntegerSequence<size_t, N>;

参数说明

表1 模板参数说明

参数名含义
...Idx表示序列的形参包。

size_t,在64位系统中为long unsigned int,非64位系统中为unsigned int。
N生成的整数序列的大小。

size_t,在64位系统中为long unsigned int,非64位系统中为unsigned int。

约束说明

  • N的范围为[0, 64]。
  • index_sequence作为序列,长度最大为64。

返回值说明

调用示例

生成并打印一个长度为5的整数序列。

Text
template<size_t... Is>
__aicore__  inline void PrintIndexSequence(AscendC::Std::index_sequence<Is...>) {
   ((AscendC::printf(" Is:%lu", Is)), ...);
}
__aicore__ inline void Process()
{
    PrintIndexSequence(AscendC::Std::make_index_sequence<5>{}); // 打印结果: 0,1,2,3,4
    PrintIndexSequence(AscendC::Std::index_sequence<0,1,2,10,8000>{}); // 打印结果: 0,1,2,10, 8000
}

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