Skip to content

fully_connected

Classes

FullyConnectedOperator

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

FULLY_CONNECTED operator.

This operator performs a fully connected layer operation on the input tensor with the given weight and bias tensors.

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 {}.

Attributes

has_init property
has_init: bool

Elide the init for the shared per-channel int8 path (no-op there).

Functions

ctx_buf_required
ctx_buf_required() -> bool

Whether the dispatched fully-connected kernel dereferences ctx->buf.

Read off ns-cmsis-nn v7.29.0 rather than off :meth:compute_weight_sum_size, so the resolve-time guard compares two independent derivations: arm_fully_connected_s8 and arm_fully_connected_per_channel_s8 read const int32_t *kernel_sum = (const int32_t *)ctx->buf; only inside #if defined(ARM_MATH_MVEI), behind a NULL check that returns ARM_CMSIS_NN_ARG_ERROR. arm_fully_connected_s16 / _s4 and the float kernels are (void)ctx;.

KNOWN GAP -- deliberately not reported by this guard: arm_fully_connected_per_channel_s16 requires ctx->buf unconditionally for its reduced-multiplier table (arm_fully_connected_per_channel_s16.c: if ((ctx == NULL) || (ctx->buf == NULL) || ...) return ARM_CMSIS_NN_ARG_ERROR; then int32_t *reduced_multiplier = (int32_t *)ctx->buf;, needing output_ch * sizeof(int32_t) bytes). fully_connected.c.j2 reaches that kernel on the per-channel int16 path whenever :meth:_can_use_direct_int16_per_channel declines (e.g. non-zero filter zero-points), and :meth:compute_weight_sum_size returns 0 for int16 -- so ctx.buf is NULL and the kernel bails out with ARG_ERROR at runtime. That is a separate, pre-existing defect: it needs a new scratch allocation and changes the memory plan, not just a declaration. Returning True here would make it a hard resolve failure for a configuration that already ships, so it is reported rather than enforced. Widen this method once that buffer is actually allocated.

Returns:

  • bool

    True if the selected lowering needs a non-NULL ctx.buf.

shared_kernel_helpers
shared_kernel_helpers() -> list[KernelHelper]

Declare the shared FC kernel when the per-channel int8 path is used.

compute_weight_sum_size
compute_weight_sum_size() -> int

Compute the size of the weight sum tensor.

Returns:

  • int ( int ) –

    Size of the weight sum tensor in int32_t.

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