Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 9 additions & 7 deletions backends/cortex_m/passes/convert_to_cortex_m_pass.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,15 +119,17 @@ def _get_linear_replacement(self, node):
(input_scale * weight_scale) / output_scale
)

# TODO: Add support for configuring the backend to support other extensions.
# Kernel sum is only used in the CMSIS-NN implementation for the MVE extension,
# so this should be optional.
# The CMSIS-NN fully-connected kernel sources the bias differently per
# ISA: the MVE path seeds its accumulator from the precomputed
# kernel_sum and never reads the bias argument, while the DSP and scalar
# paths ignore kernel_sum and read the bias argument directly. Fold the
# bias into kernel_sum for MVE and also pass the bias node through for
# DSP/scalar; only one path runs in a given build, so it is applied once.
weights = node.args[1]
weights_tensor = get_param_tensor(self.exported_program, weights)
bias = node.args[2] if len(node.args) > 2 else None
bias_tensor = (
get_param_tensor(self.exported_program, node.args[2])
if len(node.args) > 2
else None
get_param_tensor(self.exported_program, bias) if bias is not None else None
)
kernel_sum_tensor = self._compute_kernel_sum(
weights_tensor, bias_tensor, -input_zp, -weight_zp
Expand All @@ -144,7 +146,7 @@ def _get_linear_replacement(self, node):
args = (
node.args[0],
weights,
None,
bias,
kernel_sum,
-input_zp,
-weight_zp,
Expand Down
Loading