Skip to content

lanemask_le

产品支持情况

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

功能说明

获取当前线程的一个32位掩码,在当前线程所属的Warp中,将“Lane ID小于等于当前线程”的线程的对应位设为1,其余位为0。

如Lane ID为0的线程,调用本接口获取到32位掩码:0000 0000 0000 0000 0000 0000 0000 0001。

如Lane ID为31的线程,调用本接口获取到32位掩码:1111 1111 1111 1111 1111 1111 1111 1111。

图1 lanemask_le示意图

函数原型

C++
int32_t lanemask_le()

参数说明

返回值说明

返回一个32位整数的位掩码。

约束说明

需要包含的头文件

使用该接口需要包含"simt_api/device_functions.h"头文件。

C++
#include "simt_api/device_functions.h"

调用示例

下面示例使用lanemask_le统计当前Lane及其之前的线程数,并据此判断当前线程位于Warp的上半区还是下半区,再通过asc_shfl分别广播上下半Warp中指定Lane的数据。示例中使用asc_shfl,需另外包含"simt_api/device_warp_functions.h"头文件,其中srcLane的取值范围为[0, 15]。

  • SIMT编程场景:

    C++
    __global__ __launch_bounds__(1024) void kernel_lanemask_le(int32_t* src, int32_t* dst, int32_t srcLane)
    {
        int idx = threadIdx.x + blockIdx.x * blockDim.x;
        int32_t lane_rank = __popc(static_cast<uint32_t>(lanemask_le())) - 1;
        int32_t group_leader_lane = (lane_rank < 16) ? srcLane : (srcLane + 16);
        int32_t value = src[idx];
        value = asc_shfl(value, group_leader_lane, 32);
        dst[idx] = value;
    }
    
  • SIMD与SIMT混合编程场景:

    C++
    __simt_vf__ __launch_bounds__(1024) void kernel_lanemask_le(__gm__ int32_t* src, __gm__ int32_t* dst, int32_t srcLane)
    {
        int idx = threadIdx.x + blockIdx.x * blockDim.x;
        int32_t lane_rank = __popc(static_cast<uint32_t>(lanemask_le())) - 1;
        int32_t group_leader_lane = (lane_rank < 16) ? srcLane : (srcLane + 16);
        int32_t value = src[idx];
        value = asc_shfl(value, group_leader_lane, 32);
        dst[idx] = value;
    }
    

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