Hypot
Applicability
Product |
Supported |
|---|---|
Atlas 350 Accelerator Card |
√ |
x |
|
x |
|
x |
|
x |
|
x |
|
x |
Function Usage
Computes the square root of the sum of squares of two floating-point numbers element-wise. The formula is as follows:


Example:
Hypot(3.0, 4.0) = 5.0
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 Hypot(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 Hypot(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 Hypot(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 Hypot(const LocalTensor<T>& dstTensor, const LocalTensor<T>& src0Tensor, const LocalTensor<T>& src1Tensor)
- All or part of the source operand tensors are involved in computation.
Precision conversion is involved in the internal implementation of this API. Therefore, extra temporary space is required to store intermediate variables during computation. The temporary space can be allocated through the API framework or passed by developers through the sharedTmpBuffer input parameter.
- 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 the API framework is used, developers must reserve the temporary space. If sharedTmpBuffer is used, developers must allocate space for the tensor. To obtain the size of the temporary space (BufferSize) to be reserved, use the API provided in GetHypotMaxMinTmpSize.
Parameters
Parameter |
Description |
|---|---|
T |
Operand data type. For the Atlas 350 Accelerator Card, the supported data types are half, bfloat16_t, and float. |
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, src1Tensor |
Input |
Source operand. 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 Hypot and is provided by developers. For details about how to obtain the temporary space size (BufferSize), see GetHypotMaxMinTmpSize. |
calCount |
Input |
Number of elements involved in the computation. |
Returns
None
Constraints
- The source operands src0Tensor and src1Tensor must have the same data length.
- The source operand address must not overlap the destination operand address.
- 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.
- If any of the input values in src0Tensor or src1Tensor is inf, the corresponding position in the destination operand output will be inf.
- If any of the input values in src0Tensor or src1Tensor is nan, and none of the inputs at that position is inf, the corresponding position in the destination operand output will be nan.
Examples
1 2 3 4 5 6 | AscendC::TPipe pipe; AscendC::TQue<AscendC::TPosition::VECCALC, 1> tmpQue; pipe.InitBuffer(tmpQue, 1, bufferSize); // bufferSize is obtained through the tiling parameter on the host. AscendC::LocalTensor<uint8_t> sharedTmpBuffer = tmpQue.AllocTensor<uint8_t>(); // The input tensor length is 1,024, the input data type of the operator is half, and the number of actually computed data elements is 512. AscendC::Hypot(dstLocal, src0Local, src1Local, sharedTmpBuffer, 512); // The input parameter sharedTmpBuffer is passed, and this tensor is used as the temporary space for processing. |
1 2 3 | Input (src0Local): [ 0.5317103 -6.37912032 5.53408647 ... 11.11059642 -11.67860335 ] Input (src1Local): [ 2.12526834 3.09347812 -0.327234 ... 5.64334232 5.97345923] Output (dstLocal): [ 2.1907718 7.08962502 5.5437528 ... 12.461647 13.1176214] |