ReduceXorSum
Applicability
Product |
Supported |
|---|---|
Atlas 350 Accelerator Card |
√ |
√ |
|
√ |
|
x |
|
√ |
|
x |
|
x |
Function Usage
Performs the XOR (bitwise XOR) operation by element and computes the sum of the results using ReduceSum.
If the final calculation result exceeds the int16 range [-32768, 32767], the output will be -32768 or 32767.
Prototype
- Pass the temporary space through the sharedTmpBuffer input parameter.
1 2
template <typename T, bool isReuseSource = false> __aicore__ inline void ReduceXorSum(LocalTensor<T>& dstTensor, const LocalTensor<T>& src0Tensor, const LocalTensor<T>& src1Tensor, LocalTensor<uint8_t>& sharedTmpBuffer, const uint32_t calCount)
- Allocate the temporary space through the API framework.
1 2
template <typename T, bool isReuseSource = false> __aicore__ inline void ReduceXorSum(LocalTensor<T>& dstTensor, const LocalTensor<T>& src0Tensor, const LocalTensor<T>& src1Tensor, const uint32_t calCount);
Due to the internal implementation of this API, which requires the storage of XOR outcomes and the execution of other operations, additional 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 through 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 is used for temporary space allocation, 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 GetReduceXorSumMaxMinTmpSize.
Parameters
Parameter |
Description |
|---|---|
T |
Data type of the operand. For the Atlas 350 Accelerator Card, the supported data type is int16_t. For the For the For the |
isReuseSource |
Whether the source operand can be modified. The default value is false. If developers allow the source operand to be modified, enable this parameter, to reduce memory space usage. If this parameter is set to true, the src0Tensor and src1Tensor memory space is reused during internal computation of this API to reduce memory space usage. If this parameter is set to false, the src0Tensor and src1Tensor memory space is not reused during internal computation of this API. For details about how to use isReuseSource, see Example 4. |
Parameter |
Input/Output |
Description |
|---|---|---|
dstTensor |
Output |
Destination operand. The type is LocalTensor, and TPosition can be VECIN, VECCALC, or VECOUT. The output value needs to be saved in a space with a size of sizeof(T). Developers need to allocate the actual buffer space to dstTensor based on this size and the framework's alignment requirements. NOTE:
The size of allocated buffer must be 32-byte aligned according to the framework's requirements. If the value of sizeof(T) is not 32-byte aligned, it should be rounded up to the nearest multiple of 32 bytes. The extra buffer space allocated for alignment purposes should not be filled with values, but rather left with random values. |
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 ReduceXorSum computation and is provided by developers. For details about how to obtain the temporary space size (BufferSize), see GetReduceXorSumMaxMinTmpSize. |
calCount |
Input |
Number of elements involved in the computation. |
Returns
None
Constraints
- For details about the operand address alignment requirements, see General Address Alignment Restrictions.
- The source operand address must not overlap the destination operand address.
- The address of sharedTmpBuffer cannot overlap that of the source or destination operand.
- Ensure that calCount is less than or equal to the element range of src0Tensor and src1Tensor.
- If the final calculation result exceeds the int16 range [-32768, 32767], the output will be -32768 or 32767.
- For the
Atlas inference product AI Core, the intermediate computation data is stored in half type. The final result error is larger compared with other processors.
Examples
1 2 3 4 | // Template parameter: The operand data type is int16. The value false indicates that the source operand cannot be modified. // dstLocal: tensor of the output data; src0Local: source operand 0; src1Local: source operand 1 // sharedTmpBuffer: temporary buffer, with 32 elements involved in computation. AscendC::ReduceXorSum<int16_t, false>(dstLocal, src0Local, src1Local, sharedTmpBuffer, 32); |
1 2 3 4 5 | The input and output data type is int16_t. Input (src0Local): [0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0] Input (src1Local): [1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1] Output (dstLocal): [32 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0] // Only 32 is a valid value. |