LogicalOr

产品支持情况

产品

是否支持

Ascend 950PR/Ascend 950DT

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

x

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

x

功能说明

按元素进行或操作。当输入的数据类型不是bool时,零被视为False,非零数据被视为True。

函数原型

template <const LogicalOrConfig& config = DEFAULT_LOGICAL_OR_CONFIG, typename T, typename U>
__aicore__ inline void LogicalOr(const LocalTensor<T>& dst, const LocalTensor<U>& src0, const LocalTensor<U>& src1, const uint32_t count)

参数说明

表 1 模板参数说明

参数名

描述

config

LogicalOr算法的相关配置。此参数可选配,LogicalOrConfig类型,具体定义如下方代码所示,其中参数的含义为:

isReuseSource:该参数预留,传入默认值false即可。

T

目的操作数的数据类型。

Ascend 950PR/Ascend 950DT,支持的数据类型为:bool。

U

源操作数的数据类型。

Ascend 950PR/Ascend 950DT,支持的数据类型为:bool、int8_t、uint8_t、int16_t、uint16_t、half、bfloat16_t、int32_t、uint32_t、float、int64_t、uint64_t。

struct LogicalOrConfig {
    bool isReuseSource;
};

表 2 接口参数说明

参数名

输入/输出

描述

dst

输出

目的操作数。

类型为LocalTensor,支持的TPosition为VECIN/VECCALC/VECOUT。

src0、src1

输入

源操作数。

类型为LocalTensor,支持的TPosition为VECIN/VECCALC/VECOUT。

源操作数的数据类型与目的操作数保持一致。

count

输入

参与计算的元素个数。

返回值说明

约束说明

  • 不支持源操作数与目的操作数地址重叠。
  • 操作数地址对齐要求请参见通用地址对齐约束

调用示例

AscendC::LocalTensor<bool> dst;
AscendC::LocalTensor<half> src0, src1;
uint32_t count = 512;
AscendC::LogicalOr(dst, src0, src1, count); 

结果示例如下:

输入数据(src0): 
[0.2550, 0.1061, 0.3844, 0.0000, 0.8429, 0.0000, 0.7801, 0.1333, 0.7148,
 0.0000, 0.3084, 0.4829, 0.2707, 0.7245, 0.5522, 0.5332, 0.3101, 0.4532,
 ... 0.0881]
输入数据(src1): 
[0.9937, 0.6244, 0.9564, 0.0000, 0.6597, 0.0000, 0.2963, 0.0000, 0.1437,
 0.5362, 0.8746, 0.3545, 0.4965, 0.0453, 0.7116, 0.2941, 0.2769, 0.6361,
 ... 0.8044]
输出数据(dst): 
[ True,  True,  True,  False,  True,  False,  True,  True,  True,  True,
  True,  True,  True,  True,  True,  True,  True,  True,  ...  True]