GetReduceRepeatMaxMinSpr(ISASI)
产品支持情况
功能说明
获取ReduceMax、ReduceMin连续场景下的最大/最小值以及相应的索引值。
函数原型
-
获取ReduceMax、ReduceMin连续场景下的最大值与最小值,以及相应的索引值。
template <typename T> __aicore__ inline void GetReduceRepeatMaxMinSpr(T &maxMinValue, T &maxMinIndex) -
获取ReduceMax、ReduceMin连续场景下的最大值与最小值。
template <typename T> __aicore__ inline void GetReduceRepeatMaxMinSpr(T &maxMinValue)
参数说明
表 1 模板参数说明
表 2 参数说明
返回值说明
无
约束说明
- 针对Atlas A2 训练系列产品/Atlas A2 推理系列产品,由于ReduceMax/ReduceMin的内部实现原因,直接调用GetReduceRepeatMaxMinSpr接口无法获取到准确的索引值,验证时需要使用WholeReduceMax/WholeReduceMin接口来获取准确的索引值。
- 针对Atlas A3 训练系列产品/Atlas A3 推理系列产品,由于ReduceMax/ReduceMin的内部实现原因,直接调用GetReduceRepeatMaxMinSpr接口无法获取到准确的索引值,验证时需要使用WholeReduceMax/WholeReduceMin接口来获取准确的索引值。
- 针对Ascend 950PR/Ascend 950DT,由于ReduceMax/ReduceMin的内部实现原因,直接调用GetReduceRepeatMaxMinSpr接口无法获取到准确的索引值,验证时需要使用WholeReduceMax/WholeReduceMin接口来获取准确的索引值。同时,GetReduceRepeatMaxMinSpr必须紧跟着WholeReduceMax/WholeReduceMin接口进行调用。
- 索引maxMinIndex数据`是按照ReduceMax/ReduceMin的数据类型进行存储的,比如ReduceMax/ReduceMin使用half类型时,maxMinIndex是按照half类型进行存储的,如果按照half格式进行读取,maxMinIndex的值是不对的,因此maxMinIndex的读取需要使用reinterpret_cast方法转换到整数类型,若输入数据类型是half,需要使用reinterpret_cast<uint16_t*>,若输入是float,需要使用reinterpret_cast<uint32_t*>。
调用示例
-
以ReduceMax指令为例,首先执行ReduceMax指令。
AscendC::LocalTensor<float> src; AscendC::LocalTensor<float> work; AscendC::LocalTensor<float> dst; int32_t mask = 64; AscendC::ReduceMax(dst, src, work, mask, 1, 8, true); // 连续场景,srcRepStride = 8,且calIndex = true -
获取上述ReduceMax指令的最值与索引值。
针对Atlas A2 训练系列产品/Atlas A2 推理系列产品,需要使用WholeReduceMax指令获取准确的索引值,然后再调用GetReduceRepeatMaxMinSpr指令。
AscendC::LocalTensor<float> src; AscendC::LocalTensor<float> dst; int32_t mask = 64; AscendC::WholeReduceMax(dst, src, mask, 1, 1, 1, 8); float val = 0; // 最大值 float idx = 0; // 最大值的索引值,与ReduceMax的结果相同,保证和WholeReduceMax的调动次序,而且要配对调用 AscendC::GetReduceRepeatMaxMinSpr<float>(val, idx);针对Atlas A3 训练系列产品/Atlas A3 推理系列产品,需要使用WholeReduceMax指令获取准确的索引值,然后再调用GetReduceRepeatMaxMinSpr指令。
AscendC::LocalTensor<float> src; AscendC::LocalTensor<float> dst; int32_t mask = 64; AscendC::WholeReduceMax(dst, src, mask, 1, 1, 1, 8); float val = 0; // 最大值 float idx = 0; // 最大值的索引值,与ReduceMax的结果相同,保证和WholeReduceMax的调动次序,而且要配对调用 AscendC::GetReduceRepeatMaxMinSpr<float>(val, idx);针对Ascend 950PR/Ascend 950DT,需要先执行WholeReduceMax指令,随后立即调用GetReduceRepeatMaxMinSpr指令。
AscendC::LocalTensor<float> src; AscendC::LocalTensor<float> dst; int32_t mask = 64; float val = 0; // 最大值 float idx = 0; // 最大值的索引值,与ReduceMax的结果相同 AscendC::WholeReduceMax(dst, src, mask, 1, 1, 1, 8); AscendC::GetReduceRepeatMaxMinSpr<float>(val, idx); // 保证和WholeReduceMax的调动次序,而且要配对调