Repository navigation
Commit ad434a3
authored
Optimized HiFi4 kernel for 4- and 6-bit packed weights (#23501)
Summary:
Adds a HiFi implementation of `quantized_fully_connected_packed` for the 4- and
6-bit packed formats added in the parent diff. Without it, HiFi uses the
generic scalar kernel, which is about 55x slower.
nnlib has no sub-byte matmul. So the kernel unpacks a tile of rows into int8
scratch and passes the tile to `xa_nn_matmul_per_chan_sym8sxasym8s_asym8s`,
reusing nnlib's tuned MAC and per-channel requantize. Unpacking is just bit
masking, because the offset-binary bias is folded into the bias term instead
of being subtracted from each value.
The vector unpack needs in_dim to be a multiple of 32 and the weights to be
8-byte aligned. Other shapes use a scalar unpack. There is no unaligned vector
version, because the unaligned-store idiom writes whole 8-byte words and
overwrites neighbouring rows. A non-int8 dtype, a non-symmetric weight or a
failed scratch allocation drops to a scalar path. The kernel never aborts.
On HiFi1S, nnlib's per-channel matmul requantizes rows in pairs and applies
the second row's shift to both. When paired rows have different shifts, the
kernel therefore calls nnlib one row at a time on that core. Other cores are
unaffected.
The output is not bit-identical to the generic kernel's. This kernel
requantizes the way nnlib does, like the existing 8-bit HiFi kernels. Both are
well within tolerance.
Adds `test_op_quantized_fully_connected_packed_out`, a HiFi unit test that
covers both widths on the vector unpack, the scalar unpack, scalar qparams,
leading_dims > 1, a tile boundary, and every scalar fallback (no scratch, no
bias scratch, asymmetric weight). Each output isolates a single weight, so the
test checks every decoded value exactly against an independent reference.
Reviewed By: ethansfng
Differential Revision: D118197911
Pull Request resolved: #235011 parent 93776ca commit ad434a3
4 files changed
Lines changed: 976 additions & 0 deletions
File tree
- backends/cadence/hifi/operators
- tests
0 commit comments