Xor
Applicability
Product |
Supported |
|---|---|
Atlas 350 Accelerator Card |
√ |
√ |
|
√ |
|
√ |
|
√ |
|
x |
|
x |
Function Usage
Performs XOR operation element-wise. The concept and rule of XOR are as follows:
- Concept: The XOR operation is a binary computation that applies to two data elements.
- Rule: 0^0 = 0; 0^1 = 1; 1^0 = 1; 1^1 = 0. Specifically, if the bits of two objects involved in computation are different, one bit is 1 and the other bit is 0. If input bits are the same, then the output will be 0 else 1.
The formula is as follows:


1 | For example, 3^5 = 6 equals 0000 0011^0000 0101 = 0000 0110. |
Prototype
- Pass the temporary space through the sharedTmpBuffer input parameter.
- All or part of the source operand tensors are involved in computation.
1 2
template <typename T, bool isReuseSource = false> __aicore__ inline void Xor(const LocalTensor<T>& dstTensor, const LocalTensor<T>& src0Tensor, const LocalTensor<T>& src1Tensor, const LocalTensor<uint8_t>& sharedTmpBuffer, const uint32_t calCount)
- All source operand tensors are involved in computation.
1 2
template <typename T, bool isReuseSource = false> __aicore__ inline void Xor(const LocalTensor<T>& dstTensor, const LocalTensor<T>& src0Tensor, const LocalTensor<T>& src1Tensor, const LocalTensor<uint8_t>& sharedTmpBuffer)
- All or part of the source operand tensors are involved in computation.
- The API framework allocates temporary space.
- All or part of the source operand tensors are involved in computation.
1 2
template <typename T, bool isReuseSource = false> __aicore__ inline void Xor(const LocalTensor<T>& dstTensor, const LocalTensor<T>& src0Tensor, const LocalTensor<T>& src1Tensor, const uint32_t calCount)
- All source operand tensors are involved in computation.
1 2
template <typename T, bool isReuseSource = false> __aicore__ inline void Xor(const LocalTensor<T>& dstTensor, const LocalTensor<T>& src0Tensor, const LocalTensor<T>& src1Tensor)
- All or part of the source operand tensors are involved in computation.
Due to the complex mathematical computation involved in the internal implementation of this API, extra temporary space is required to store intermediate variables generated during computation. The temporary space can be passed by developers through the sharedTmpBuffer input parameter or allocated by the API framework.
- When the sharedTmpBuffer input parameter is used for passing the temporary space, the tensor serves as the temporary space. In this case, the API framework is not required for temporary space allocation. This enables developers to manage the sharedTmpBuffer space and reuse the buffer after calling the API, so that the buffer is not repeatedly allocated or deallocated, improving the flexibility and buffer utilization.
- When the API framework allocates temporary space, developers do not need to allocate the space but must reserve the required size for the temporary space.
If sharedTmpBuffer is used, developers must allocate space for the tensor. If the API framework is used, developers must reserve the temporary space. To obtain the size of the temporary space (BufferSize) to be reserved, use the API provided in GetXorMaxMinTmpSize.
Parameters
Parameter |
Description |
|---|---|
T |
Operand data type. For the Atlas 350 Accelerator Card, the supported data types are int16_t and uint16_t. For the For the For the For the |
isReuseSource |
Whether the source operand can be modified. This parameter is reserved. Pass the default value false. |
Parameter |
Input/Output |
Description |
|---|---|---|
dstTensor |
Output |
Destination operand. The type is LocalTensor, and TPosition can be VECIN, VECCALC, or VECOUT. |
src0Tensor |
Input |
Source operand 0. The type is LocalTensor, and TPosition can be VECIN, VECCALC, or VECOUT. The source operand must have the same data type as the destination operand. |
src1Tensor |
Input |
Source operand 1. The type is LocalTensor, and TPosition can be VECIN, VECCALC, or VECOUT. The source operand must have the same data type as the destination operand. |
sharedTmpBuffer |
Input |
Temporary buffer. The type is LocalTensor, and TPosition can be VECIN, VECCALC, or VECOUT. This parameter is used to store intermediate variables during complex computation in Xor and is provided by developers. For details about how to obtain the temporary space size (BufferSize), see GetXorMaxMinTmpSize. |
calCount |
Input |
Number of elements involved in the computation. |
Returns
None
Constraints
- The source operand address must not overlap the destination operand address.
- Currently, only the ND format is supported.
- Ensure that calCount is less than or equal to the element range stored in src0Tensor, src1Tensor, and dstTensor.
- For APIs without calCount, ensure that the shape sizes of src0Tensor and src1Tensor are the same.
- The address of sharedTmpBuffer cannot overlap that of the source or destination operand.
- For details about the operand address alignment requirements, see General Address Alignment Restrictions.
Examples
For a complete call example, see Xor operator sample.
1 2 3 4 5 | // dstLocal: tensor for storing the computation result // src0Local: input tensor involved in computation // src1Local: input tensor involved in computation AscendC::Xor(dstLocal, src0Local, src1Local); |
Result example:
Input (srcLocal): [ 2 3 5 7 11 13 17 19 ] Input (srcLocal): [ 1 2 3 4 5 6 7 8 ] Output (dstLocal): [ 3 1 6 3 14 10 22 27 ]