LogicalAnds
Applicability
Product |
Supported |
|---|---|
Atlas 350 Accelerator Card |
√ |
x |
|
x |
|
x |
|
x |
|
x |
|
x |
Function Usage
Performs a logical AND operation between each element in an input vector and a scalar. When the input data type of a vector or scalar is not bool, zero is treated as False and non-zero values are treated as True. The sequence of vectors and scalars in the API can be either scalar first or scalar last. The scalar may be configured as a single-point element within a LocalTensor. The calculation formulas are shown below, where idx specifies the positional index of the single-point element in the LocalTensor.

Prototype
1 2 | template <const LogicalAndsConfig& config = DEFAULT_LOGICAL_ANDS_CONFIG, typename T, typename U, typename S> __aicore__ inline void LogicalAnds(const LocalTensor<T>& dst, const U& src0, const S& src1, const uint32_t count) |
Parameters
Parameter |
Description |
|---|---|
config |
LogicalAnds algorithm configuration. This is an optional parameter of the LogicalAndsConfig type. The code below describes the definition. isReuseSource: This parameter is reserved. Pass the default value false. scalarTensorIndex: When the scalar is a single-point element of a LocalTensor, this parameter specifies whether the scalar is used as the left or right operand in the AND operation. The value 0 indicates the left operand, and the default value 1 indicates the right operand. |
T |
Data type of the destination operand. For the Atlas 350 Accelerator Card, the supported data type is bool. |
U |
LocalTensor or Scalar type. The type is automatically inferred based on the input parameter src0. You do not need to set this parameter. Ensure that src0 meets the data type constraints. For the Atlas 350 Accelerator Card, the supported data types are bool, int8_t, uint8_t, int16_t, uint16_t, half, bfloat16_t, int32_t, uint32_t, float, int64_t, and uint64_t. |
S |
LocalTensor or Scalar type. The type is automatically inferred based on the input parameter src1. You do not need to set this parameter. Ensure that src1 meets the data type constraints. For the Atlas 350 Accelerator Card, the supported data types are bool, int8_t, uint8_t, int16_t, uint16_t, half, bfloat16_t, int32_t, uint32_t, float, int64_t, and uint64_t. |
1 2 3 4 | struct LogicalAndsConfig { bool isReuseSource; int8_t scalarTensorIndex; }; |
Parameter |
Input/Output |
Description |
|---|---|---|
dst |
Output |
Destination operand. The type is LocalTensor, and TPosition can be VECIN, VECCALC, or VECOUT. |
src0, src1 |
Input |
Source operand. The type is scalar or LocalTensor. When the type is LocalTensor, the value can be a vector operand or a single scalar element. The supported TPositions are VECIN, VECCALC, and VECOUT. |
count |
Input |
Number of elements involved in the computation. |
Returns
None
Constraints
- Either the left or right operand of an AND operation in this API must be a vector. Currently, the left and right operands cannot be scalars at the same time.
- When the single-point data of LocalTensor is transferred as a scalar, the scalarTensorIndex parameter must be a constant known during compilation. If a variable is transferred, it must be declared as constexpr.
- The source operand address must not overlap the destination operand address.
- For details about the operand address alignment requirements, see General Address Alignment Restrictions.
Examples
For details about a complete example, see logicalands operator sample.
1 2 3 4 5 6 7 8 | AscendC::LocalTensor<bool> dst; AscendC::LocalTensor<half> src0, src1; uint32_t count = 512; // Number of elements involved in computation // Scalar at the end AscendC::LogicalAnds(dst, src0, src1, count); // Scalar at the beginning static constexpr AscendC::LogicalAndsConfig config = { false, 0 }; AscendC::LogicalAnds<config>(dst, src0, src1, count); |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | // Scalar at the end Input (src0): [1, 2, 0, -1, -2, 0, 3, 4, 0, -3, -4, 0, 5, 6, 0, -5, -6, 0, ... 0] Input (src1): [3.0] Output (dst): [ True, True, False, True, True, False, True, True, False, True, True, False, True, True, False, True, True, False, ... False] // Scalar at the beginning Input (src1): [1, 2, 0, -1, -2, 0, 3, 4, 0, -3, -4, 0, 5, 6, 0, -5, -6, 0, ... 0] Input (src0): [3.0] Output (dst): [ True, True, False, True, True, False, True, True, False, True, True, False, True, True, False, True, True, False, ... False] |