Ands
Applicability
|
Product |
Supported |
|---|---|
|
Atlas 350 Accelerator Card |
√ |
|
|
x |
|
|
x |
|
|
x |
|
|
x |
|
|
x |
|
|
x |
Function Usage
Performs bitwise AND between a scalar and each element of a vector. The scalar can be before or after the vector. The scalar input can be a single element from a LocalTensor. idx indicates the position index of a LocalTensor single element.

Prototype
- Computation of the first n pieces of data of a tensor
1 2
template <typename T = BinaryDefaultType, bool isSetMask = true, const BinaryConfig& config = DEFAULT_BINARY_CONFIG, typename U, typename S, typename V> __aicore__ inline void Ands(const U& dst, const S& src0, const V& src1, const int32_t& count)
- High-dimensional tensor sharding computation
- Bitwise mask mode
1 2
template <typename T = BinaryDefaultType, bool isSetMask = true, const BinaryConfig& config = DEFAULT_BINARY_CONFIG, typename U, typename S, typename V> __aicore__ inline void Ands(const U& dst, const S& src0, const V& src1, uint64_t mask[], const uint8_t repeatTime, const UnaryRepeatParams& repeatParams)
- Contiguous mask mode
1 2
template <typename T = BinaryDefaultType, bool isSetMask = true, const BinaryConfig& config = DEFAULT_BINARY_CONFIG, typename U, typename S, typename V> __aicore__ inline void Ands(const U& dst, const S& src0, const V& src1, uint64_t mask, const uint8_t repeatTime, const UnaryRepeatParams& repeatParams)
- Bitwise mask mode
Parameters
|
Parameter |
Description |
||
|---|---|---|---|
|
T |
This parameter is reserved for future use. If this parameter needs to be specified, pass the default value BinaryDefaultType. |
||
|
isSetMask |
Whether to set the mask mode and mask value inside the API.
For the models below, isSetMask is invalid for the APIs that compute the first n pieces of data in a tensor. Retain the default value.
|
||
|
config |
Position of a single element. This parameter is of BinaryConfig type and takes effect when the scalar input is a LocalTensor single element. The default value is DEFAULT_BINARY_CONFIG, indicating that the scalar is after the tensor.
|
||
|
U |
LocalTensor data type. The data type is automatically inferred based on dst. Developers do not need to configure this parameter. Ensure that dst meets the data type requirements. |
||
|
S |
LocalTensor or scalar data type. The data type is automatically inferred based on src0. Developers do not need to configure this parameter. Ensure that src0 meets the data type requirements. |
||
|
V |
LocalTensor or scalar data type. The data type is automatically inferred based on src1. Developers do not need to configure this parameter. Ensure that src1 meets the data type requirements. |
|
Parameter |
Input/Output |
Meaning |
|---|---|---|
|
dst |
Output |
Destination operand. The type is LocalTensor, and TPosition can be VECIN, VECCALC, or VECOUT. The start address of LocalTensor must be 32-byte aligned. For the Atlas 350 Accelerator Card, the supported data types are int16_t, uint16_t, int64_t, and uint64_t. |
|
src0/src1 |
Input |
Source operands.
The data type must be the same as that of the destination operand. |
|
count |
Input |
Number of elements involved in the computation. |
|
mask[]/mask |
Input |
mask controls the elements that participate in computation in each iteration.
|
|
repeatTime |
Input |
Number of iteration repeats. The Vector Unit reads 256 bytes of contiguous data for computation each time. To read the complete data for processing, the unit needs to read the input data in multiple repeats. repeatTime indicates the number of iterations. For details about this parameter, see High-dimensional Sharding APIs. |
|
repeatParams |
Input |
Structure for controlling element-wise operations. For details, see UnaryRepeatParams. |
Returns
None
Restrictions
- To save memory space when using high-dimensional tensor sharding computation APIs, developers can define a tensor shared by the source and destination operands (through address overlapping). The restrictions are as follows:
- For a single repeat (repeatTime = 1), the source operand must completely overlap with the destination operand. Partial overlapping is not supported.
- For multiple repeats (repeatTime > 1), address overlapping is not supported when there is a dependency between the source and destination operands (for example, when the destination operand of the Nth iteration is the source operand of the (N+1)th iteration).
- If the scalar input is a LocalTensor single element, the source operand address cannot overlap with the destination operand address.
- For details about the operand address alignment requirements, see General Address Alignment Restrictions.
- For the Atlas 350 Accelerator Card, uint64_t and int64_t support only the APIs that compute the first n pieces of data in a tensor.
- Either the left or right source operand must be a vector. Currently, the left and right operands cannot be scalars at the same time.
- If the scalar input is a LocalTensor single element, idx must be a compile-time constant. If it is a variable, it must be declared as constexpr.
Examples
- Example of high-dimensional tensor sharding computation (contiguous mask mode)
1 2 3 4 5 6 7 8 9 10 11 12 13 14
// dstLocal: output tensor // src0Local: input tensor // src1Local: input tensor uint64_t mask = 128; // repeatTime = 4. 128 elements are processed in a single iteration. To compute 512 elements, four iterations are required. // dstBlkStride, srcBlkStride = 1. The interval between src0 data addresses involved in computation in each iteration is one data block, indicating that data is continuously read and written in a single iteration. // dstRepStride, srcRepStride = 8. The interval between addresses of adjacent iterations is eight data blocks, indicating that data is continuously read and written between adjacent iterations. // The scalar is after the tensor. AscendC::Ands(dstLocal, src0Local, src1Local[0], mask, 4, { 1, 1, 8, 8 }); // The scalar is before the tensor. static constexpr AscendC::BinaryConfig config = { 0 }; AscendC::Ands<BinaryDefaultType, true, config>(dstLocal, src0Local[0], src1Local, mask, 4, {1, 1, 8, 8});
- Example of high-dimensional tensor sharding computation (bitwise mask mode)
1 2 3 4 5 6 7 8 9 10 11 12 13 14
// dstLocal: output tensor // src0Local: input tensor // src1Local: input tensor uint64_t mask[2] = { UINT64_MAX, UINT64_MAX }; // repeatTime = 4. 128 elements are processed in a single iteration. To compute 512 elements, four iterations are required. // dstBlkStride, srcBlkStride = 1. The interval between src0 data addresses involved in computation in each iteration is one data block, indicating that data is continuously read and written in a single iteration. // dstRepStride, srcRepStride = 8. The interval between addresses of adjacent iterations is eight data blocks, indicating that data is continuously read and written between adjacent iterations. // The scalar is after the tensor. AscendC::Ands(dstLocal, src0Local, src1Local[0], mask, 4, {1, 1, 8, 8}); // The scalar is before the tensor. static constexpr AscendC::BinaryConfig config = { 0 }; AscendC::Ands<BinaryDefaultType, true, config>(dstLocal, src0Local[0], src1Local, mask, 4, {1, 1, 8, 8});
- Example of computing the first n pieces of data of a tensor
1 2 3 4 5 6
// The scalar is after the tensor. AscendC::Ands(dstLocal, src0Local, src1Local[0], 512); // The scalar is before the tensor. static constexpr AscendC::BinaryConfig config = { 0 }; AscendC::Ands<BinaryDefaultType, true, config>(dstLocal, src0Local[0], src1Local, 512);
// The scalar src1Local[0] is after the tensor. Input (src0Local): [1 2 3 ... 512] Input (src1Local): [0] Output (dstLocal): [0 0 0 ... 0] // The scalar src0Local[0] is before the tensor. Input (src0Local): [0] Input (src1Local): [1 2 3 ... 512] Output (dstLocal): [0 0 0 ... 0]