Fill

Applicability

Product

Supported

Atlas 350 Accelerator Card

Atlas A3 training product/Atlas A3 inference product

Atlas A2 training product/Atlas A2 inference product

Atlas 200I/500 A2 inference product

Atlas inference product AI Core

Atlas inference product Vector Core

x

Atlas training product

Function Usage

Initializes LocalTensor of a specific TPosition to a specific value.

Prototype

1
2
template <typename T, typename U = PrimT<T>, typename Std::enable_if<Std::is_same<PrimT<T>, U>::value, bool>::type = true>
__aicore__ inline void Fill(const LocalTensor<T>& dst, const InitConstValueParams<U>& initConstValueParams)

Parameters

Table 1 Template parameters

Parameter

Description

T

Data type of dst.

For the Atlas training product, the supported data type is half.

For the Atlas inference product AI Core, the supported data types are half, int16_t, and uint16_t.

For the Atlas A2 training product/Atlas A2 inference product, the supported data types are half, int16_t, uint16_t, bfloat16_t, float, int32_t, and uint32_t.

For the Atlas A3 training product/Atlas A3 inference product, the supported data types are half, int16_t, uint16_t, bfloat16_t, float, int32_t, and uint32_t.

For the Atlas 200I/500 A2 inference product, the supported data types are half, int16_t, uint16_t, bfloat16_t, float, int32_t, and uint32_t.

For the Atlas 350 Accelerator Card, the supported data types are half, int16_t, uint16_t, bfloat16_t, float, int32_t, and uint32_t.

U

Data type of the initial value.

  • When dst uses a basic data type, the data type T of U must be the same as that of dst. Otherwise, the compilation fails.
  • When dst uses the TensorTrait type, the LiteType of the data type T of U must be the same as that of dst. Otherwise, the compilation fails.

The last template parameter is used only for checking the preceding data types.

Table 2 Parameters

Parameter

Input/Output

Description

dst

Output

Destination operand for the result matrix, which is of the LocalTensor type.

For the Atlas training product, TPosition can only be A1, A2, B1, or B2.

For the Atlas inference product AI Core, TPosition can only be A1, A2, B1, or B2.

For the Atlas A2 training product/Atlas A2 inference product, TPosition can only be A1, A2, B1, or B2.

For the Atlas A3 training product/Atlas A3 inference product, TPosition can only be A1, A2, B1, or B2.

For the Atlas 200I/500 A2 inference product, TPosition can only be A1, A2, B1, or B2.

For the Atlas 350 Accelerator Card, TPosition can only be A1 or B1.

If TPosition is A1/B1, the start address must be 32-byte aligned. If TPosition is A2/B2, the start address must be 512-byte aligned.

InitConstValueParams

Input

Initialization parameters, of the InitConstValueParams type.

For details, see ${INSTALL_DIR}/include/ascendc/basic_api/interface/kernel_struct_mm.h. Replace ${INSTALL_DIR} with the actual path for storing files after the CANN software is installed.

For details about the parameter description, see Table 3.

For the Atlas training product, only repeatTimes and initValue can be configured.

For the Atlas inference product AI Core, only repeatTimes and initValue can be configured.

For the Atlas A2 training product/Atlas A2 inference product, all parameters can be configured.

For the Atlas A3 training product/Atlas A3 inference product, all parameters can be configured.

For the Atlas 200I/500 A2 inference product, all parameters can be configured.

For the Atlas 350 Accelerator Card, all parameters can be configured.

  • In the scenario where only repeatTimes and initValue can be configured, configuration of other parameters is invalid. The amount of data (512 bytes) processed in each iteration is fixed, and there is no interval between iterations.
  • In the scenario where all parameters can be configured, the following parameters can be configured: repeatTimes, initValue, blockNum, and dstGap.
Table 3 Parameters in the InitConstValueParams structure

Parameter

Description

repeatTimes

Number of iterations. Default value: 0.

  • In the scenario where only repeatTimes and initValue can be configured, the value range of repeatTimes is [0, 255].
  • In the scenario where all parameters can be configured, the value range of repeatTimes is [0, 32767].

blockNum

Number of data blocks initialized in each iteration. Value range: blockNum ∈ [0, 32767]. Default value: 0.

  • When the location of dst is A1 or B1, the size of each data block is 32 bytes.
  • When the location of dst is A2 or B2, the size of each data block is 512 bytes.

dstGap

Gap between the end address of the previous iteration and the start address of the next iteration of the destination operand.

  • When the location of dst is A1 or B1, the unit is 32 bytes.
  • When the location of dst is A2 or B2, the unit is 512 bytes.

Value range: dstGap ∈ [0, 32767]. Default value: 0.

initValue

Initialized value. The supported data types are the same as those of dst.

Restrictions

Examples

1
2
3
uint32 mLength = 16;
uint32 kLength = 16;
Fill(leftMatrix, {1, static_cast<uint16_t>(mLength * kLength * sizeof(float) / 32), 0, 1}); // It fills leftMatrix with mLength × kLength elements, each set to the value 1, using 32-byte granularity.