Skip to content
版 本

GetReduceRepeatMaxMinSpr(ISASI)

产 品 支 持 情 况

产 品

是 否 支 持(仅 获 取 最 值 的 原 型)

是 否 支 持(获 取 最 值 和 索 引 的 原 型)

Ascend 950PR/Ascend 950DT

x

Atlas A3 训 练 系 列 产 品/Atlas A3 推 理 系 列 产 品

x

Atlas A2 训 练 系 列 产 品/Atlas A2 推 理 系 列 产 品

x

Atlas 200I/500 A2 推 理 产 品

x

x

Atlas 推 理 系 列 产 品AI Core

x

Atlas 推 理 系 列 产 品Vector Core

x

x

Atlas 训 练 系 列 产 品

x

x

功 能 说 明

获 取ReduceMaxReduceMin连 续 场 景 下 的 最 大/最 小 值 以 及 相 应 的 索 引 值。

函 数 原 型

  • 获 取ReduceMaxReduceMin连 续 场 景 下 的 最 大 值 与 最 小 值,以 及 相 应 的 索 引 值。

    Text
    template <typename T>
    __aicore__ inline void GetReduceRepeatMaxMinSpr(T &maxMinValue, T &maxMinIndex)
    
  • 获 取ReduceMaxReduceMin连 续 场 景 下 的 最 大 值 与 最 小 值。

    Text
    template <typename T>
    __aicore__ inline void GetReduceRepeatMaxMinSpr(T &maxMinValue)
    

参 数 说 明

表 1 模 板 参 数 说 明

参 数 名

描 述

T

ReduceMax/ReduceMin指 令 的 数 据 类 型,支 持half/float。

表 2 参 数 说 明

参 数 名

输 入/输 出

描 述

maxMinValue

输 出

ReduceMax/ReduceMin指 令 的 最 大 值/最 小 值。

maxMinIndex

输 出

ReduceMax/ReduceMin指 令 的 最 值 对 应 的 索 引 值。

返 回 值 说 明

约 束 说 明

  • 针 对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系 列 归 约 指 令 样 例

  1. 以ReduceMax指 令 为 例,首 先 执 行ReduceMax指 令。

    Text
    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
    
  2. 获 取 上 述ReduceMax指 令 的 最 值 与 索 引 值。

    针 对Atlas A2 训 练 系 列 产 品/Atlas A2 推 理 系 列 产 品,需 要 使 用WholeReduceMax指 令 获 取 准 确 的 索 引 值,然 后 再 调 用GetReduceRepeatMaxMinSpr指 令。

    Text
    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指 令。

    Text
    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 推 理 系 列 产 品AI Core版 本,则 可 在 调 用ReduceMax后 直 接 调 用GetReduceRepeatMaxMinSpr指 令 获 取 其 最 大/最 小 值。

    Text
    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);
    float val = 0;   // 最 大 值
    AscendC::GetReduceRepeatMaxMinSpr<float>(val); // 保 证 和WholeReduceMax的 调 动 次 序,而 且 要 配 对 调 用
    

    针 对Ascend 950PR/Ascend 950DT,需 要 先 执 行WholeReduceMax指 令,随 后 立 即 调 用GetReduceRepeatMaxMinSpr指 令。

    Text
    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的 调 动 次 序,而 且 要 配 对 调 用
    

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