binary_partition
产 品 支 持 情 况
- Ascend 950PR/Ascend 950DT:支 持
- Atlas A3 训 练 系 列 产 品/Atlas A3 推 理 系 列 产 品:不 支 持
- Atlas A2 训 练 系 列 产 品/Atlas A2 推 理 系 列 产 品:不 支 持
- Atlas 200I/500 A2 推 理 产 品:不 支 持
- Atlas 推 理 系 列 产 品AI Core:不 支 持
- Atlas 推 理 系 列 产 品Vector Core:不 支 持
- Atlas 训 练 系 列 产 品:不 支 持
功 能 说 明
binary_partition API用 于 根 据 一 个 标 签(0或1)将 父 组 划 分 为 两 个 子 组,标 签 相 同 的 线 程 会 被 分 配 到 同 一 组 中。
函 数 原 型
C++
coalesced_group binary_partition(const coalesced_group& g, bool pred)
C++
template <unsigned int Size, typename ParentT>
coalesced_group binary_partition(const thread_block_tile<Size, ParentT>& g, bool pred)
参 数 说 明
表 1 参 数 说 明
| 参 数 名 | 输 入/输 出 | 描 述 |
|---|---|---|
| g | 输 入 | 被 划 分 的 父 组,类 型 可 以 是coalesced_group或thread_block_tile。 |
| pred | 输 入 | 标 签,用 于 划 分 子 组。 |
返 回 值 说 明
返 回 划 分 出 的 子 组coalesced_group对 象。
约 束 说 明
无
调 用 示 例
SIMT编 程 场 景:
C++using namespace cooperative_groups; __global__ void simt_kernel(int *inputArr) { auto block = this_thread_block(); auto tile32 = tiled_partition<32>(block); // inputArr 中 是 随 机 的 整 数 int elem = inputArr[block.thread_rank()]; // 根 据 elem&1 是 否 为 true 将tile32划 分 为 两 个 子 组 auto subtile = binary_partition(tile32, (elem & 1)); ... }SIMD与SIMT混 合 编 程 场 景:
C++using namespace cooperative_groups; __simt_vf__ inline void simt_kernel(...) { ... auto block = this_thread_block(); auto tile32 = tiled_partition<32>(block); // inputArr 中 是 随 机 的 整 数 int elem = inputArr[block.thread_rank()]; // 根 据 elem&1 是 否 为 true 将tile32划 分 为 两 个 子 组 auto subtile = binary_partition(tile32, (elem & 1)); ... }