shfl_down
产品支持情况
产品 |
是否支持 |
|---|---|
Atlas 350 加速卡 |
√ |
x |
|
x |
|
x |
|
x |
|
x |
|
x |
功能说明
获取coalesced_group组内当前线程向后偏移delta的线程的数据。
函数原型
1 2 | template <typename T> T shfl_down(T var, unsigned int delta) const |
参数说明
参数名 |
输入/输出 |
描述 |
|---|---|---|
T |
输入 |
var的数据类型,支持half、int32_t、uint32_t、float、half2、int64_t、uint64_t。 |
参数名 |
输入/输出 |
描述 |
|---|---|---|
var |
输入 |
线程用于交换的输入操作数。 |
delta |
输入 |
期望获取的var值所在线程相对当前线程的向后偏移值。 |
返回值说明
coalesced_group组内当前线程向后偏移delta的线程输入的var值。若偏移后超出组范围,返回当前线程输入的var值。
约束说明
无
调用示例
示例代码中的条件分支将一个warp中所有线程id是偶数的线程组成coalesced_group协作组,组内各线程shfl_down接口返回结果如下图所示。
图1 shfl_down结果示意图


- SIMT编程场景:
1 2 3 4 5 6 7 8 9 10
using namespace cooperative_groups; __global__ void simt_kernel(...) { ... if (threadIdx.x % 2 == 0) { coalesced_group active = coalesced_threads(); uint32_t result = active.shfl_down(threadIdx.x + 100, 2); } ... }
- SIMD与SIMT混合编程场景:
1 2 3 4 5 6 7 8 9 10
using namespace cooperative_groups; __simt_vf__ inline void simt_kernel(...) { ... if (threadIdx.x % 2 == 0) { coalesced_group active = coalesced_threads(); uint32_t result = active.shfl_down(threadIdx.x + 100, 2); } ... }
父主题: coalesced_group