Arange

Applicability

Product

Supported

Atlas A3 training products / Atlas A3 inference products

Atlas A2 training products / Atlas A2 inference products

Atlas 200I/500 A2 inference products

x

Atlas inference product 's AI Core

Atlas inference product 's Vector Core

x

Atlas training products

x

Function

Returns an arithmetic progression given the start value, arithmetical value, and length.

Principles

The figure below illustrates the internal algorithm block diagram of ArithProgression high-level APIs, taking the float type, ND format, and firstValue and diffValue input scalars as examples.

Figure 1 Arange algorithm block diagram

The computation process is divided into the following steps, all of which are performed on vectors:

  1. Step for arithmetic progression with a length less than 8: Use SetValue to expand the arithmetic progression based on the values of firstValue and diffValue. The maximum expanded length is 8. If the length of the arithmetic progression is less than 8, the algorithm ends.
  2. Step for arithmetic progression with a length of 8 to 64: Use Adds to expand the arithmetic progression result in step 1, with a maximum of seven cycles of expansion to reach a length of 64. If the length of the arithmetic progression is less than 64, the algorithm ends.
  3. Step for arithmetic progression with a length greater than 64: Use Adds to expand the arithmetic progression result in step 2, and repeat until the target length of the arithmetic progression is reached.

Prototype

1
2
template <typename T>
__aicore__ inline void Arange(const LocalTensor<T>& dst, const T firstValue, const T diffValue, const int32_t count)

Parameters

Table 1 Template parameters

Parameter

Description

T

Data type of the operand.

Atlas A3 training products / Atlas A3 inference products : The supported data types are int16_t, half, int32_t, and float.

Atlas A2 training products / Atlas A2 inference products : The supported data types are int16_t, half, int32_t, and float.

Atlas inference product 's AI Core: The supported data types are int16_t, half, int32_t, and float.

Table 2 API parameters

Parameter

Input/Output

Description

dst

Output

Destination operand. The size of dst must be greater than or equal to count x sizeof(T).

The type is LocalTensor, and the supported TPosition is VECIN, VECCALC, or VECOUT.

firstValue

Input

Value of the first element in an arithmetic progression.

diffValue

Input

Difference between elements in an arithmetic progression. The value must be greater than or equal to 0.

count

Input

Length of an arithmetic progression. The value of count is greater than 0.

Returns

None

Restrictions

Currently, only the ND format is supported.

Example

1
2
3
AscendC::LocalTensor<T> dst = outDst.AllocTensor<T>();
AscendC::Arange<T>(dst, static_cast<T>(firstValue_), static_cast<T>(diffValue_), count_);
outDst.EnQue<T>(dst);