Skip to content
版 本

Mins

产 品 支 持 情 况

产 品是 否 支 持
Ascend 950PR/Ascend 950DT
Atlas A3 训 练 系 列 产 品/Atlas A3 推 理 系 列 产 品
Atlas A2 训 练 系 列 产 品/Atlas A2 推 理 系 列 产 品
Atlas 200I/500 A2 推 理 产 品
Atlas 推 理 系 列 产 品AI Core
Atlas 推 理 系 列 产 品Vector Core
x
Atlas 训 练 系 列 产 品
x
Kirin X90
Kirin 9030

功 能 说 明

头 文 件 路 径 为:"basic_api/kernel_operator_vec_binary_scalar_intf.h"

Mins属 于 双 目 标 量 类 计 算 接 口,输 入 为 一 个 矢 量tensor和 一 个 标 量scalar,Mins负 责 将 矢 量tensor内 的 每 个 元 素 与 标 量 进 行 求 最 小 值。计 算 公 式 如 下:

$dst_i = \min(src_i, scalarValue)$

函 数 原 型

  • tensor前n个 数 据 连 续 计 算

    C++
    template <typename T, bool isSetMask = true>
    __aicore__ inline void Mins(const LocalTensor<T>& dst, const LocalTensor<T>& src, const T& scalarValue, const int32_t& count)
    
  • tensor高 维 切 分 计 算

    • mask逐bit模 式

      C++
      template <typename T, bool isSetMask = true>
      __aicore__ inline void Mins(const LocalTensor<T>& dst, const LocalTensor<T>& src, const T& scalarValue, uint64_t mask[], const uint8_t repeatTime, const UnaryRepeatParams& repeatParams)
      
    • mask连 续 模 式

      C++
      template <typename T, bool isSetMask = true>
      __aicore__ inline void Mins(const LocalTensor<T>& dst, const LocalTensor<T>& src, const T& scalarValue, uint64_t mask, const uint8_t repeatTime, const UnaryRepeatParams& repeatParams)
      

dst和src使 用TensorTrait类 型 时,其 数 据 类 型TensorTrait和scalarValue的 数 据 类 型(对 应TensorTrait中 的LiteType类 型)不 一 致。因 此 新 增 模 板 类 型U表 示scalarValue的 数 据 类 型,并 通 过std::enable_if检 查T中 萃 取 出 的LiteType和U是 否 完 全 一 致,一 致 则 接 口 通 过 编 译,否 则 编 译 失 败。接 口 原 型 定 义 如 下:

  • tensor前n个 数 据 计 算

    C++
    template <typename T, typename U, bool isSetMask = true, typename Std::enable_if<Std::is_same<PrimT<T>, U>::value, bool>::type = true>
    __aicore__ inline void Mins(const LocalTensor<T>& dst, const LocalTensor<T>& src, const U& scalarValue, const int32_t& count)
    
  • tensor高 维 切 分 计 算

    • mask逐bit模 式

      C++
      template <typename T, typename U, bool isSetMask = true, typename Std::enable_if<Std::is_same<PrimT<T>, U>::value, bool>::type = true>
      __aicore__ inline void Mins(const LocalTensor<T>& dst, const LocalTensor<T>& src, const U& scalarValue, uint64_t mask[], const uint8_t repeatTime, const UnaryRepeatParams& repeatParams)
      
    • mask连 续 模 式

      C++
      template <typename T, typename U, bool isSetMask = true, typename Std::enable_if<Std::is_same<PrimT<T>, U>::value, bool>::type = true>
      __aicore__ inline void Mins(const LocalTensor<T>& dst, const LocalTensor<T>& src, const U& scalarValue, uint64_t mask, const uint8_t repeatTime, const UnaryRepeatParams& repeatParams)
      

参 数 说 明

表 1 模 板 参 数 说 明

参 数 名描 述
T操 作 数 数 据 类 型。
UscalarValue的 数 据 类 型。
isSetMask是 否 在 接 口 内 部 设 置mask。
• true,表 示 在 接 口 内 部 设 置mask。
• false,表 示 在 接 口 外 部 设 置mask,开 发 者 需 要 使 用SetVectorMask接 口 设 置mask值。这 种 模 式 下,本 接 口 入 参 中 的mask值 必 须 设 置 为 占 位 符MASK_PLACEHOLDER
具 体 使 用 方 式 可 参 考掩 码
针 对 以 下 型 号,tensor前n个 数 据 计 算API中 的isSetMask参 数 不 生 效,保 持 默 认 值 即 可。
Ascend 950PR/Ascend 950DT

Atlas 200I/500 A2 推 理 产 品

表 2 参 数 说 明

参 数 名输 入/输 出描 述
dst输 出目 的 操 作 数。
类 型 为LocalTensor,支 持 的TPosition为VECIN/VECCALC/VECOUT。
地 址 对 齐 约 束 参 考通 用 地 址 对 齐 约 束
src输 入源 操 作 数。
类 型 为LocalTensor,支 持 的TPosition为VECIN/VECCALC/VECOUT。
地 址 对 齐 约 束 参 考通 用 地 址 对 齐 约 束
scalarValue输 入源 操 作 数,数 据 类 型 需 要 与 目 的 操 作 数 中 的 元 素 类 型 保 持 一 致。
count输 入参 与 计 算 的 元 素 个 数。关 于 该 参 数 的 具 体 说 明 请 参 考连 续 计 算
mask[]/mask输 入mask用 于 控 制 每 次 迭 代 内 参 与 计 算 的 元 素。详 细 设 置 参 考掩 码
repeatTime输 入重 复 迭 代 次 数。矢 量 计 算 单 元,每 次 读 取 连 续 的256Bytes数 据 进 行 计 算,为 完 成 对 输 入 数 据 的 处 理,必 须 通 过 多 次 迭 代(repeat)才 能 完 成 所 有 数 据 的 读 取 与 计 算。repeatTime表 示 迭 代 的 次 数。
关 于 该 参 数 的 具 体 说 明 请 参 考高 维 切 分
repeatParams输 入控 制 操 作 数 地 址 步 长 的 参 数。UnaryRepeatParams类 型,包 含 操 作 数 相 邻 迭 代 间 相 同DataBlock的 地 址 步 长,操 作 数 同 一 迭 代 内 不 同DataBlock的 地 址 步 长 等 参 数。
相 邻 迭 代 间 的 地 址 步 长 参 数 说 明 请 参 考repeatStride;同 一 迭 代 内DataBlock的 地 址 步 长 参 数 说 明 请 参 考dataBlockStride

数 据 类 型

  • 针 对Ascend 950PR/Ascend 950DT,T和U支 持 的 数 据 类 型 为:int8_t、uint8_t、int16_t、half、bfloat16_t、int32_t、float、int64_t、uint64_t。数 据 类 型int8_t、uint8_t、int64_t、uint64_t仅 支 持tensor前n个 数 据 计 算 接 口。
  • 针 对Atlas A3 训 练 系 列 产 品/Atlas A3 推 理 系 列 产 品,T和U支 持 的 数 据 类 型 为:int16_t、half、int32_t、float。
  • 针 对Atlas A2 训 练 系 列 产 品/Atlas A2 推 理 系 列 产 品,T和U支 持 的 数 据 类 型 为:int16_t、half、int32_t、float。
  • 针 对Atlas 200I/500 A2 推 理 产 品,T和U支 持 的 数 据 类 型 为:int16_t、half、int32_t、float。
  • 针 对Atlas 推 理 系 列 产 品AI Core,T和U支 持 的 数 据 类 型 为:int16_t、half、int32_t、float。
  • 针 对Kirin X90,T和U支 持 的 数 据 类 型 为:int16_t、half、int32_t、float。
  • 针 对Kirin 9030,T和U支 持 的 数 据 类 型 为:int16_t、half、int32_t、float。

返 回 值 说 明

约 束 说 明

  • 针 对 如 下 型 号,当 参 数count或repeatTime取 值 为0时,不 会 执 行 计 算 操 作,不 会 对 目 的 操 作 数 进 行 写 入,该 接 口 将 被 视 为NOP(空 操 作)。

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

调 用 示 例

  • tensor高 维 切 分 计 算 样 例-mask连 续 模 式

    C++
    uint64_t mask = 128;
    int16_t scalar = 2;
    // repeatTime = 4, 128 elements one repeat, 512 elements total.
    // dstBlkStride, srcBlkStride = 1, no gap between blocks in one repeat.
    // dstRepStride, srcRepStride = 8, no gap between repeats.
    AscendC::Mins(dstLocal, srcLocal, scalar, mask, 4, { 1, 1, 8, 8 });
    
  • tensor高 维 切 分 计 算 样 例-mask逐bit模 式

    C++
    uint64_t mask[2] = { UINT64_MAX, UINT64_MAX };
    int16_t scalar = 2;
    // repeatTime = 4, 128 elements one repeat, 512 elements total.
    // dstBlkStride, srcBlkStride = 1, no gap between blocks in one repeat.
    // dstRepStride, srcRepStride = 8, no gap between repeats.
    AscendC::Mins(dstLocal, srcLocal, scalar, mask, 4, {1, 1, 8, 8});
    
  • tensor前n个 数 据 计 算 接 口 样 例

    C++
    int16_t scalar = 2;
    AscendC::Mins(dstLocal, srcLocal, scalar, 512);
    

结 果 示 例 如 下:

Bash
输 入 数 据src0Local:[1 2 3 ... 512]
输 入 数 据scalar = 2
输 出 数 据dstLocal:[1 2 2 ... 2]

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