__usad
产品支持情况
- Ascend 950PR/Ascend 950DT:支持
- Atlas A3 训练系列产品/Atlas A3 推理系列产品:不支持
- Atlas A2 训练系列产品/Atlas A2 推理系列产品:不支持
- Atlas 200I/500 A2 推理产品:不支持
- Atlas 推理系列产品AI Core:不支持
- Atlas 推理系列产品Vector Core:不支持
- Atlas 训练系列产品:不支持
功能说明
对输入数据x、y、z,计算|x - y| + z的结果,即前两个输入作差的绝对值与第三个输入的和。
函数原型
C++
unsigned int __usad(unsigned int x, unsigned int y, unsigned int z)
参数说明
表1 参数说明
| 参数名 | 输入/输出 | 描述 |
|---|---|---|
| x | 输入 | 源操作数,uint32_t类型。 |
| y | 输入 | 源操作数,uint32_t类型。 |
| z | 输入 | 源操作数,uint32_t类型。 |
返回值说明
|x - y| + z的结果。
约束说明
无
需要包含的头文件
使用该接口需要包含"simt_api/device_functions.h"头文件。
C++
#include "simt_api/device_functions.h"
调用示例
SIMT编程场景:
C++__global__ __launch_bounds__(1024) void KernelUsad(unsigned int* dst, unsigned int* x, unsigned int* y, unsigned int* z) { int idx = threadIdx.x + blockIdx.x * blockDim.x; dst[idx] = __usad(x[idx], y[idx], z[idx]); }SIMD与SIMT混合编程场景:
C++__simt_vf__ __launch_bounds__(1024) inline void KernelUsad(__gm__ unsigned int* dst, __gm__ unsigned int* x, __gm__ unsigned int* y, __gm__ unsigned int* z) { int idx = threadIdx.x + blockIdx.x * blockDim.x; dst[idx] = __usad(x[idx], y[idx], z[idx]); }