开发者
资源

asc_reduce_min

产品支持情况

产品

是否支持

Ascend 950PR/Ascend 950DT

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

x

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

x

Atlas 200I/500 A2 推理产品

x

Atlas 推理系列产品AI Core

x

Atlas 推理系列产品Vector Core

x

Atlas 训练系列产品

x

功能说明

对Warp内所有活跃线程输入val求最小值。Warp内所有活跃线程返回相同的结果。

函数原型

1
inline int32_t asc_reduce_min(int32_t val)
1
inline uint32_t asc_reduce_min(uint32_t val)
1
inline float asc_reduce_min(float val)
1
inline half asc_reduce_min(half val)

参数说明

表1 参数说明

参数名

输入/输出

描述

val

输入

源操作数。

返回值说明

Warp内所有活跃线程输入val的最小值。

约束说明

需要包含的头文件

使用除half类型之外的接口需要包含"simt_api/device_warp_functions.h"头文件,使用half类型接口需要包含"simt_api/asc_fp16.h"头文件。

1
#include "simt_api/device_warp_functions.h" 
1
#include "simt_api/asc_fp16.h"

调用示例

  • SIMT编程场景:
    1
    2
    3
    4
    5
    6
    7
    __global__ __launch_bounds__(1024) void KernelReduceMin(int32_t* dst)
    {
        int idx = threadIdx.x + blockIdx.x * blockDim.x;
        int32_t laneId = idx % 32;
        int32_t result = asc_reduce_min(laneId); // 返回值为0
        dst[idx] = result;
    }
    
  • SIMD与SIMT混合编程场景:
    1
    2
    3
    4
    5
    6
    7
    8
    __simt_vf__ __launch_bounds__(1024) inline void KernelReduceMin(__gm__ int32_t* dst)
    {
        // asc_vf_call参数:dim3{1024, 1, 1}
        int idx = threadIdx.x + blockIdx.x * blockDim.x;
        int32_t laneId = idx % 32;
        int32_t result = asc_reduce_min(laneId); // 返回值为0
        dst[idx] = result;
    }