MulsCast(ISASI)

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

Multiplies the first count elements of the vector source operand by a scalar, converts the result to half type in CAST_ROUND mode, and stores the final result to dst. The scalar can be before or after the tensor. The formula is as follows:

The scalar input can also be a single element from a LocalTensor. idx indicates the position index of a LocalTensor single element.

Prototype

1
2
template <typename T0 = BinaryDefaultType, typename T1 = BinaryDefaultType, const BinaryConfig &config = DEFAULT_BINARY_CONFIG, typename T2, typename T3, typename T4>
__aicore__ inline void MulsCast(const T2 &dst, const T3 &src0, const T4 &src1, const uint32_t count)

Parameters

Table 1 Template parameters

Parameter

Description

T0

Data type of the destination operand.

This parameter is reserved for future use. If this parameter needs to be specified, pass the default value BinaryDefaultType.

T1

Data type of the source operands.

This parameter is reserved for future use. If this parameter needs to be specified, pass the default value BinaryDefaultType.

config

Position of a single element. This parameter is of BinaryConfig type and takes effect when the scalar input is a LocalTensor single element. The default value is DEFAULT_BINARY_CONFIG, indicating that the scalar is after the tensor.

1
2
3
4
struct BinaryConfig {
    int8_t scalarTensorIndex = 1; // Position of the scalar when the scalar input is a LocalTensor single element. 0 indicates the scalar is before the tensor and 1 indicates the scalar is after the tensor.
};
constexpr BinaryConfig DEFAULT_BINARY_CONFIG = {1};

T2

LocalTensor data type. The data type is automatically inferred based on dst. Developers do not need to configure this parameter. Ensure that dst meets the data type requirements.

T3

LocalTensor or scalar data type. The data type is automatically inferred based on src0. Developers do not need to configure this parameter. Ensure that src0 meets the data type requirements.

T4

LocalTensor or scalar data type. The data type is automatically inferred based on src1. Developers do not need to configure this parameter. Ensure that src1 meets the data type requirements.

Table 2 Parameters

Parameter

Input/Output

Description

dst

Output

Destination operand.

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

The start address of LocalTensor must be 32-byte aligned.

For the Atlas 350 Accelerator Card, the supported data type is half.

For details about precision conversion rules for different data types, see Table 3.

src0/src1

Input

Source operands.

  • If the scalar input is a LocalTensor, the source operands are a vector operand and a single element from the LocalTensor. TPosition can be VECIN, VECCALC, or VECOUT.

    The start address of LocalTensor must be 32-byte aligned.

    For the Atlas 350 Accelerator Card, the supported data type is float.

  • If the scalar input is an immediate value:

    For the Atlas 350 Accelerator Card, the supported data type is float.

count

Input

Number of elements involved in the computation.

Table 3 Precision conversion rules

src

dst

Type Conversion Mode

float

half

The source operand is cast to the values representable by the half format in CAST_ROUND mode, and then stored to dst in half format (with overflow handled by saturation by default).

Returns

None

Restrictions

  • Either the left or right source operand must be a vector. Currently, the left and right operands cannot be scalars at the same time.
  • If the scalar input is a LocalTensor single element, idx must be a compile-time constant. If it is a variable, it must be declared as constexpr.

Examples

1
2
3
4
5
6
// The scalar is after the tensor.
AscendC::MulsCast(dstLocal, src0Local, src1Local[0], 512);

// The scalar is before the tensor.
static constexpr AscendC::BinaryConfig config = { 0 };
AscendC::MulsCast<BinaryDefaultType, BinaryDefaultType, config>(dstLocal, src0Local[0], src1Local, 512);
Result example:
Input (src0Local): [6 5 11 ... ]
Input (src1Local): 2
Output (dstLocal): [12 10 22 ... ]