Commit 66967ef
Cortex-M backend: supply a zero bias for grouped convolutions (pytorch#21825)
### Summary
CMSIS-NN's grouped convolutions index the bias per group rather than
from a fixed base, so they need a real bias pointer: arm_convolve_s8
advances it once per group in every build, and the MVE
arm_depthwise_conv_s8_opt offsets it per channel block. Leaving it null
means those kernels read from an offset null pointer, and on
Corstone-300 the affected output channels come back pinned at the int8
ceiling. Lower a zero bias for convolutions that do not have one.
Both paths get it on every target. Strictly only the MVE depthwise
kernel needs it, since the DSP and scalar depthwise kernels re-base per
row, but which depthwise kernel a convolution reaches depends on channel
multiplier, batch, dilation, kernel size and padding, and that is not
worth predicting from the graph. It costs nothing on the models in tree,
where every convolution already carries a folded bias.
The existing conv2d_groups test missed this because its all-positive
ramp summed straight to qmax, where a wrong result is indistinguishable
from the correct one; it now convolves 3x3 over 8x8 with a signed input.
A grouped case that does carry a bias is added next to it, and a
structural test asserts the bias slot is populated for both the grouped
and depthwise ops, since the numeric cases only cover this on the FVP
leg and cannot reach the depthwise channel counts at all.
### Test plan
Verified on Corstone-300 for scalar (cortex-m0plus), DSP (cortex-m7) and
MVE (cortex-m55).
---------
Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>1 parent 88f0c74 commit 66967ef
2 files changed
Lines changed: 61 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
538 | 538 | | |
539 | 539 | | |
540 | 540 | | |
| 541 | + | |
| 542 | + | |
| 543 | + | |
| 544 | + | |
| 545 | + | |
| 546 | + | |
| 547 | + | |
| 548 | + | |
| 549 | + | |
| 550 | + | |
| 551 | + | |
| 552 | + | |
| 553 | + | |
541 | 554 | | |
542 | 555 | | |
543 | 556 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
11 | 11 | | |
12 | 12 | | |
13 | 13 | | |
| 14 | + | |
| 15 | + | |
14 | 16 | | |
15 | 17 | | |
16 | 18 | | |
| |||
181 | 183 | | |
182 | 184 | | |
183 | 185 | | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
184 | 191 | | |
185 | | - | |
| 192 | + | |
186 | 193 | | |
187 | | - | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
188 | 201 | | |
189 | 202 | | |
190 | 203 | | |
| |||
343 | 356 | | |
344 | 357 | | |
345 | 358 | | |
| 359 | + | |
| 360 | + | |
| 361 | + | |
| 362 | + | |
| 363 | + | |
| 364 | + | |
| 365 | + | |
| 366 | + | |
| 367 | + | |
| 368 | + | |
| 369 | + | |
| 370 | + | |
| 371 | + | |
| 372 | + | |
| 373 | + | |
| 374 | + | |
| 375 | + | |
| 376 | + | |
| 377 | + | |
| 378 | + | |
| 379 | + | |
| 380 | + | |
| 381 | + | |
| 382 | + | |
| 383 | + | |
| 384 | + | |
| 385 | + | |
| 386 | + | |
| 387 | + | |
| 388 | + | |
| 389 | + | |
| 390 | + | |
| 391 | + | |
0 commit comments