Rint
Applicability
Product |
Supported |
|---|---|
Atlas 350 Accelerator Card |
√ |
x |
|
x |
|
x |
|
x |
|
x |
|
x |
Function Usage
Returns the nearest integer to the input value. If there are two equally close integers, the even one will be returned. The formula is as follows:

Example:
Rint(3.9) = 4
Rint(3.3) = 3
Rint(3.5) = 4
Prototype
- Pass the temporary space through the sharedTmpBuffer input parameter.
1 2
template <const RintConfing& config = DEFAULT_RINT_CONFIG, typename T> __aicore__ inline void Rint(const LocalTensor<T>& dst, const LocalTensor<T>& src, const LocalTensor<uint8_t>& sharedTmpBuffer, const uint32_t count)
- The API framework allocates temporary space.
1 2
template <const RintConfing& config = DEFAULT_RINT_CONFIG, typename T> __aicore__ inline void Rint(const LocalTensor<T>& dst, const LocalTensor<T>& src, const uint32_t count)
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 GetRintMaxMinTmpSize.
Parameters
Parameter |
Description |
|---|---|
RintConfig |
Rint algorithm configuration. This is an optional parameter of the RintConfig type. The code below describes the definition. isReuseSource: whether the source operand can be modified. This parameter is reserved. Pass the default value false. |
T |
Operand data type. For the Atlas 350 Accelerator Card, the supported data types are half and float. |
1 2 3 | struct RintConfig { bool isReuseSource; }; |
Parameter |
Input/Output |
Description |
|---|---|---|
dst |
Output |
Destination operand. The type is LocalTensor, and TPosition can be VECIN, VECCALC, or VECOUT. |
src |
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 Rint and is provided by developers. For details about how to obtain the temporary space size (BufferSize), see GetRintMaxMinTmpSize. |
count |
Input |
Number of elements involved in the computation. |
Returns
None
Constraints
- 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.
Examples
For details about a complete example, see Rint operator sample.
- Pass the temporary space through the sharedTmpBuffer input parameter.
1 2 3 4 5 6 7 8
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. static constexpr AscendC::RintConfig rintConfig = { false }; // The source operand is not modified. // dst and src are LocalTensors of the half type. AscendC::Rint<rintConfig, half>(dst, src, sharedTmpBuffer, 512);
- The API framework allocates temporary space.
1 2 3 4 5 6 7
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. // 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. static constexpr AscendC::RintConfig rintConfig = { false }; // The source operand is not modified. // dst and src are LocalTensors of the half type. AscendC::Rint<rintConfig, half>(dst, src, 512);
1 2 | Input (src): [-1.5, -1.3, -0.9, -0.5, 0.5, 0.9, 1.1, 1.5, 2.2, 2.5, 2.8, 3.2] Output (dst): [-2, -1, -1, 0, 0, 1, 1, 2, 2, 2, 3, 3] |