GetReduceRepeatMaxMinSpr(ISASI)
产 品 支 持 情 况
功 能 说 明
获 取ReduceMax、ReduceMin连 续 场 景 下 的 最 大/最 小 值 以 及 相 应 的 索 引 值。
函 数 原 型
获 取ReduceMax、ReduceMin连 续 场 景 下 的 最 大 值 与 最 小 值,以 及 相 应 的 索 引 值。
Texttemplate <typename T> __aicore__ inline void GetReduceRepeatMaxMinSpr(T &maxMinValue, T &maxMinIndex)获 取ReduceMax、ReduceMin连 续 场 景 下 的 最 大 值 与 最 小 值。
Texttemplate <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*>。
调 用 示 例
具 体 可 参 考WholeReduce系 列 归 约 指 令 样 例。
以ReduceMax指 令 为 例,首 先 执 行ReduceMax指 令。
TextAscendC::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指 令。
TextAscendC::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指 令。
TextAscendC::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 推 理 系 列 产 品AI Core版 本,则 可 在 调 用ReduceMax后 直 接 调 用GetReduceRepeatMaxMinSpr指 令 获 取 其 最 大/最 小 值。
TextAscendC::LocalTensor<float> src; AscendC::LocalTensor<float> work; AscendC::LocalTensor<float> dst; int32_t mask = 64; AscendC::ReduceMax(dst, src, work, mask, 1, 8, true); float val = 0; // 最 大 值 AscendC::GetReduceRepeatMaxMinSpr<float>(val); // 保 证 和WholeReduceMax的 调 动 次 序,而 且 要 配 对 调 用针 对Ascend 950PR/Ascend 950DT,需 要 先 执 行WholeReduceMax指 令,随 后 立 即 调 用GetReduceRepeatMaxMinSpr指 令。
TextAscendC::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的 调 动 次 序,而 且 要 配 对 调 用