Skip to content

hard_swish

Classes

HardSwishOperator

HardSwishOperator(op: AirOperator, model: AirModel, platform: SocPlatform, prefix: str = 'aot', attributes: dict[str, str] = {})

HARD_SWISH operator.

This operator computes the hard swish activation function on the input tensor.

Parameters:

  • op

    (AirOperator) –

    The AIR operator to wrap.

  • model

    (AirModel) –

    The AIR model.

  • platform

    (SocPlatform) –

    The target platform for code generation.

  • prefix

    (str, default: 'aot' ) –

    Prefix for generated code files. Defaults to "aot".

  • attributes

    (dict[str, str], default: {} ) –

    Attributes for template values. Defaults to {}.

Functions

compute_values
compute_values() -> dict[str, str]

Compute the values for the operator.

Returns:

  • dict[str, str]

    dict[str, str]: Computed values for the operator.

emit
emit(save_path: Path)

Generate the source code for the operator.

Parameters:

  • save_path
    (Path) –

    Path to save the generated code.

Functions

compute_prescale

compute_prescale(q6: int, dtype: dtype) -> int

Compute the prescale shift needed to keep intermediate products in range.

Parameters:

  • q6

    (int) –

    The quantized value representing 6.0 in the input scale

  • dtype

    (dtype) –

    The data type of the input tensor (np.int8 or np.int16)

Returns:

  • int ( int ) –

    The prescale shift amount

make_hardswish_lut_s8

make_hardswish_lut_s8(input_scale: float, input_zero_point: int, output_scale: float, output_zero_point: int) -> np.ndarray

Build a 256-entry int8 → int8 LUT for HardSwish, iterating over q in [-128,127].

Parameters:

  • input_scale

    (float) –

    Scale of the input tensor.

  • input_zero_point

    (int) –

    Zero point of the input tensor.

  • output_scale

    (float) –

    Scale of the output tensor.

  • output_zero_point

    (int) –

    Zero point of the output tensor.

Returns:

  • ndarray

    np.ndarray: The generated LUT.