Skip to content
版 本

shfl

产 品 支 持 情 况

  • Ascend 950PR/Ascend 950DT:支 持
  • Atlas A3 训 练 系 列 产 品/Atlas A3 推 理 系 列 产 品:不 支 持
  • Atlas A2 训 练 系 列 产 品/Atlas A2 推 理 系 列 产 品:不 支 持
  • Atlas 200I/500 A2 推 理 产 品:不 支 持
  • Atlas 推 理 系 列 产 品AI Core:不 支 持
  • Atlas 推 理 系 列 产 品Vector Core:不 支 持
  • Atlas 训 练 系 列 产 品:不 支 持

功 能 说 明

thread_block_tile组 内 线 程 的 数 据 交 换 接 口,不 通 过 共 享 内 存 实 现 直 接 读 取 组 内 指 定 线 程 的 寄 存 器 中 的 值。

函 数 原 型

C++
template <typename T>
T shfl(T var, int src_rank) const

参 数 说 明

表 1 参 数 说 明

参 数 名输 入/输 出描 述
var输 入线 程 用 于 交 换 的 输 入 操 作 数。支 持 的 数 据 类 型 为:half、int32_t、uint32_t、float、half2、int64_t、uint64_t。
src_rank输 入期 望 获 取 的var值 所 在 的 线 程 在 组 内 的 排 名。当src_rank大 于 等 于 组 内 线 程 数 时,获 取src_rank % Size对 应rank线 程 的var值。

返 回 值 说 明

thread_block_tile组 内 指 定 线 程 输 入 的var值。

约 束 说 明

调 用 示 例

示 例 代 码 中 以4个 线 程 为 一 组 划 分 线 程 块,获 取 组 内 排 名 为2的 线 程 输 入 的var值。

图 1 shfl接 口 返 回 结 果 示 意 图

  • SIMT编 程 场 景:

    C++
    using namespace cooperative_groups;
    __global__ void simt_kernel(...)
    {
        ...
        thread_block block = this_thread_block();
        auto tile4 = tiled_partition<4>(block);
        uint32_t result = tile4.shfl(threadIdx.x + 100, 2);
        ...
    }
    
  • SIMD与SIMT混 合 编 程 场 景:

    C++
    using namespace cooperative_groups;
    __simt_vf__ inline void simt_kernel(...)
    {
        ...
        thread_block block = this_thread_block();
        auto tile4 = tiled_partition<4>(block);
        uint32_t result = tile4.shfl(threadIdx.x + 100, 2);
        ...
    }
    

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