Skip to content
版 本

Duplicate

产 品 支 持 情 况

产 品

是 否 支 持

Ascend 950PR/Ascend 950DT

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

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

Atlas 200I/500 A2 推 理 产 品

Atlas 推 理 系 列 产 品AI Core

Atlas 推 理 系 列 产 品Vector Core

x

Atlas 训 练 系 列 产 品

Kirin X90

Kirin 9030

功 能 说 明

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

Duplicate接 口 将 一 个 变 量 或 立 即 数 复 制 多 次 并 填 充 到 向 量 中。

接 口 支 持 使 用 前n个 数 据 计 算 和 高 维 切 分 计 算 的 方 式,前n个 数 据 计 算 原 理 和 参 考 伪 代 码 如 下:

Python
import numpy as np

def Duplicate(scalarValue, dst, count):
    for i in range(count):     
        dst[i] = scalarValue

函 数 原 型

  • tensor前n个 数 据 计 算,源 操 作 数 为 标 量

    C++
    template <typename T>
    __aicore__ inline void Duplicate(const LocalTensor<T>& dst, const T& scalarValue, const int32_t& count)
    
  • tensor前n个 数 据 计 算,源 操 作 数 为Tensor

    C++
    // 该 函 数 原 型,仅 支 持Ascend 950PR/Ascend 950DT。
    template <typename T>
    __aicore__ inline void Duplicate(const LocalTensor<T>& dst, const LocalTensor<T>& src, const int32_t& count)
    
  • tensor高 维 切 分 计 算,mask逐 比 特 模 式

    C++
    template <typename T, bool isSetMask = true>
    __aicore__ inline void Duplicate(const LocalTensor<T>& dst, const T& scalarValue, uint64_t mask[], const uint8_t repeatTime, const uint16_t dstBlockStride, const uint8_t dstRepeatStride)
    
  • tensor高 维 切 分 计 算,mask连 续 模 式

    C++
    template <typename T, bool isSetMask = true>
    __aicore__ inline void Duplicate(const LocalTensor<T>& dst, const T& scalarValue, uint64_t mask, const uint8_t repeatTime, const uint16_t dstBlockStride, const uint8_t dstRepeatStride)
    

参 数 说 明

表 1 模 板 参 数 说 明

参 数 说 明描 述
T操 作 数 数 据 类 型。
isSetMask是 否 在 接 口 内 部 设 置mask,默 认 为true。
• true,表 示 在 接 口 内 部 设 置mask。
• false,表 示 在 接 口 外 部 设 置mask,开 发 者 需 要 使 用SetVectorMask接 口 设 置mask值。这 种 模 式 下,本 接 口 入 参 中 的mask值 必 须 设 置 为 占 位 符MASK_PLACEHOLDER。

表 2 接 口 参 数 说 明

参 数 说 明输 入/输 出含 义
dst输 出目 的 操 作 数,类 型 为LocalTensor,支 持 的TPosition为VECIN/VECCALC/VECOUT(存 储 位 置 为Unified Buffer)。LocalTensor的 起 始 地 址 需 要 按 照32字 节 对 齐。
scalarValue输 入被 复 制 的 源 操 作 数,数 据 类 型 需 与dst中 元 素 的 数 据 类 型 保 持 一 致。
src
输 入源 操 作 数,类 型 为LocalTensor,支 持 的TPosition为VECIN/VECCALC/VECOUT。
数 据 类 型 需 与dst中 元 素 的 数 据 类 型 保 持 一 致。
当 传 入 该 参 数 时,会 将src[0]复 制 多 次 并 填 充 到 向 量 中。
count输 入参 与 计 算 的 元 素 个 数。关 于 该 参 数 的 具 体 说 明 请 参 考连 续 计 算
mask/mask[]输 入mask用 于 控 制 每 次 迭 代 内 参 与 计 算 的 元 素。
设 置 详 见掩 码 操 作
repeatTime输 入指 令 迭 代 次 数,每 次 迭 代 完 成8个DataBlock的 数 据 收 集,取 值 范 围:repeatTime∈[0,255]。
dstBlockStride输 入单 次 迭 代 内,矢 量 目 的 操 作 数 不 同datablock间 地 址 步 长,单 位 为DataBlock。
dstRepStride输 入相 邻 迭 代 间,矢 量 目 的 操 作 数 相 同datablock地 址 步 长,单 位 为DataBlock。

数 据 类 型

Ascend 950PR/Ascend 950DT,支 持 的 数 据 类 型 为:bool、int8_t、uint8_t、fp4x2_e2m1_t、fp4x2_e1m2_t、hifloat8_t、fp8_e8m0_t、fp8_e5m2_t、fp8_e4m3fn_t、int16_t、uint16_t、half、bfloat16_t、int32_t、uint32_t、float、complex32、int64_t、uint64_t、complex64。

Atlas A3 训 练 系 列 产 品/Atlas A3 推 理 系 列 产 品,支 持 的 数 据 类 型 为:int16_t、uint16_t、half、bfloat16_t、int32_t、uint32_t、float。

Atlas A2 训 练 系 列 产 品/Atlas A2 推 理 系 列 产 品,支 持 的 数 据 类 型 为:int16_t、uint16_t、half、bfloat16_t、int32_t、uint32_t、float。

Atlas 200I/500 A2 推 理 产 品,支 持 的 数 据 类 型 为:int16_t、uint16_t、half、bfloat16_t、int32_t、uint32_t、float。

Atlas 推 理 系 列 产 品 AI Core,支 持 的 数 据 类 型 为:int16_t、uint16_t、half、bfloat16_t、int32_t、uint32_t、float。

Atlas 训 练 系 列 产 品,支 持 的 数 据 类 型 为:int16_t、uint16_t、half、bfloat16_t、int32_t、uint32_t、float。

Kirin X90,支 持 的 数 据 类 型 为:half。

Kirin 9030,支 持 的 数 据 类 型 为:half。

返 回 值 说 明

约 束 说 明

- repeatTime = 0表 示 不 会 执 行 计 算 操 作,不 会 对 目 的 操 作 数 进 行 写 入,该 接 口 将 被 视 为 NOP(空 操 作)。该 约 束 适 用 于 以 下 型 号。
  • Atlas A3 训 练 系 列 产 品/Atlas A3 推 理 系 列 产 品
  • Atlas A2 训 练 系 列 产 品/Atlas A2 推 理 系 列 产 品
  • 针 对Ascend 950PR/Ascend 950DT,bool、int8_t、uint8_t、fp4x2_e2m1_t、fp4x2_e1m2_t、hifloat8_t、fp8_e8m0_t、fp8_e5m2_t、fp8_e4m3fn_t、 complex32、int64_t、uint64_t、complex64数 据 类 型 仅 支 持tensor前n个 数 据 计 算 接 口。

调 用 示 例

本 示 例 仅 展 示Compute流 程 的 部 分 代 码。如 需 运 行,请 将 代 码 段 复 制 并 粘 贴 到Duplicate样 例中 的Compute函 数 对 应 位 置。

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

    C++
    uint64_t mask = 128;
    half scalar = 18.0;
    // repeatTime = 2, 128 elements one repeat, 256 elements total
    // dstBlkStride = 1, no gap between blocks in one repeat
    // dstRepStride = 8, no gap between repeats
    AscendC::Duplicate(dstLocal, scalar, mask, 2, 1, 8 );
    
  • tensor高 维 切 分 计 算 样 例,mask逐bit模 式

    C++
    uint64_t mask[2] = { UINT64_MAX, UINT64_MAX };
    half scalar = 18.0;
    // repeatTime = 2, 128 elements one repeat, 256 elements total
    // dstBlkStride = 1, no gap between blocks in one repeat
    // dstRepStride = 8, no gap between repeats
    AscendC::Duplicate(dstLocal, scalar, mask, 2, 1, 8 );
    
  • tensor前n个 数 据 计 算 样 例,源 操 作 数 为 标 量

    C++
    half inputVal(18.0);
    int32_t srcDataSize = 256; // 参 与 计 算 的 元 素 个 数
    AscendC::Duplicate<half>(dstLocal, inputVal, srcDataSize);
    
  • tensor前n个 数 据 计 算 样 例,源 操 作 数 为Tensor
    C++
    AscendC::Duplicate<half>(dstLocal, srcLocal, srcDataSize);
    
结 果 示 例 如 下:
scalar: 18.0
srcLocal: [18.0 1.0 2.0 ... 254.0 255.0]
dstLocal: [18.0 18.0 18.0 ... 18.0 18.0]

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