IsInf

Applicability

Product

Supported

Atlas 350 Accelerator Card

Atlas A3 training product/Atlas A3 inference product

x

Atlas A2 training product/Atlas A2 inference product

x

Atlas 200I/500 A2 inference product

x

Atlas inference product AI Core

x

Atlas inference product Vector Core

x

Atlas training product

x

Function Usage

Checks whether a floating-point number is ±INF element-wise. The output is a floating-point number or bool value. When the output is of floating-point type, inputs that are ±INF produce a result of floating-point 1, while non-±INF inputs produce floating-point 0. When the output is of bool type, inputs that are ±INF produce true, while non-±INF inputs produce false. The formula is as follows:

  • If the output is of the floating-point type:

  • If the output is of the bool type:

Prototype

  • Pass the temporary space through the sharedTmpBuffer input parameter.
    1
    2
    template <const IsInfConfig& config = DEFAULT_IS_INF_CONFIG, typename T, typename U>
    __aicore__ inline void IsInf(const LocalTensor<T>& dst, const LocalTensor<U>& src, const LocalTensor<uint8_t>& sharedTmpBuffer, const uint32_t count)
    
  • The API framework allocates temporary space.
    1
    2
    template <const IsInfConfig& config = DEFAULT_IS_INF_CONFIG, typename T, typename U>
    __aicore__ inline void IsInf(const LocalTensor<T>& dst, const LocalTensor<U>& src, const uint32_t count)
    

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 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 GetIsInfMaxMinTmpSize.

Parameters

Table 1 Template parameters

Parameter

Description

IsInfConfig

IsInf algorithm configuration. This is an optional parameter of the IsInfConfig 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

Data type of the destination operand.

For the Atlas 350 Accelerator Card, the supported data types are bool, half, and float.

U

Data type of the source operand.

For the Atlas 350 Accelerator Card, the supported data types are half and float.

1
2
3
struct IsInfConfig {
    bool isReuseSource;
};
Table 2 API parameters

Parameter

Input/Output

Description

dst

Output

Destination operand.

The type is LocalTensor, and TPosition can be VECIN, VECCALC, or VECOUT.

The destination operand must be of the same data type as the source operand or of bool type. For details about the supported data type groups, see Table 3.

src

Input

Source operand.

The type is LocalTensor, and TPosition can be VECIN, VECCALC, or VECOUT.

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 IsInf and is provided by developers.

For details about how to obtain the temporary space size (BufferSize), see GetIsInfMaxMinTmpSize.

count

Input

Number of elements involved in the computation.

Table 3 Data type groups supported by the input and output.

srcDtype

dstDtype

half

half

half

bool

float

float

float

bool

Returns

None

Constraints

  • The source operand address must not overlap the destination operand address.
  • For details about the alignment requirements of the operand address offset, see General Description and Restrictions.

Examples

For details about a complete example, see IsInf 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::IsInfConfig isInfConfig = { false }; // The source operand is not modified.
    // dst is a LocalTensor of the bool type, and src is a LocalTensor of the half type.
    AscendC::IsInf<isInfConfig, bool, 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::IsInfConfig isInfConfig = { false }; // The source operand is not modified.
    // dst is a LocalTensor of the bool type, and src is a LocalTensor of the half type.
    AscendC::IsInf<isInfConfig, bool, half>(dst, src, 512);
    
Result example:
1
2
3
The input data type is half, and the output data type is bool.
Input (src): [1.0 inf 3.0 4.0 inf 6.0 -inf 8.0]
Output (dst): [false true false false true false true false]