Skip to content

Commit 85163e8

Browse files
committed
[Espressif] Upgrade ESP-NN to 1.5.0
Pin the delegate, operator-library, and packaged ESP-IDF components to ESP-NN 1.5.0 for the S3 AvgPool row-stride fix, faster multiply, and convolution/pooling alignment fixes. Remove the temporary rectangular AvgPool checks from lowering and the kernel wrapper. Exercise wide and tall outputs through the shared operator cases and four delegate cases. All 76 operator-library cases and 20 delegate programs in each of optimized and ANSI modes pass on the S3 emulator. Generated component manifest validation and scoped lintrunner pass. Compared with 1.4.2, matching test firmware grows by 2896 bytes for the operator library and 4512 bytes for the optimized delegate; ANSI shrinks by 224 bytes. The new S3 multiply frames require 216 additional stack bytes. Authored with OpenAI Codex.
1 parent 2fbfc01 commit 85163e8

9 files changed

Lines changed: 33 additions & 27 deletions

File tree

‎backends/espressif/README.md‎

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,17 +24,14 @@ Fused Quant frontend convention. The two flows have distinct quantizers:
2424
| `EspNNQuantizer` | Existing delegate: PT2E Q/DQ graphs partitioned by `EspNNPartitioner` into `EspNNBackend` delegates |
2525
| `get_esp_fused_quant_quantizer` | Operator library: shared Fused Quant annotation and fusion, followed by `EspPassManager` lowering to direct ESP-NN operators or portable fallback |
2626

27-
Both flows use ESP-NN kernels. The operator library currently accelerates
27+
Both flows use ESP-NN 1.5.0 kernels. The operator library currently accelerates
2828
int8 tensor add with equal input shapes and multiply with equal shapes or a
2929
contiguous trailing block broadcast across the full tensor, including
3030
one-element tensors. It also accelerates values-only 4-D int8 MaxPool2d with matching input
3131
and output qparams, unit dilation, floor mode, and channel counts divisible by
3232
four. AvgPool2d uses the same shape and channel restrictions, with shared
3333
input/output qparams, floor mode, and no divisor override. Padding is supported
34-
when `count_include_pad=False`. AvgPool2d acceleration currently requires square
35-
outputs or a single output row because ESP-NN 1.4.1's optimized S3 kernel has
36-
an output-row-stride bug; other output shapes retain portable execution.
37-
The upstream fix is available in ESP-NN 1.4.2; this backend still pins 1.4.1.
34+
when `count_include_pad=False`.
3835
Its integer kernel rounds ties away from zero; the FQ reference rounds ties to
3936
even, so results can differ by one int8 step.
4037
The shared Fused Quant layout pass introduces contiguous NHWC tensors for

‎backends/espressif/espnn_runtime/idf_component.yml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,4 @@ description: ExecuTorch ESP-NN backend runtime (XTS3 int8 interpreter and EspNNB
1010
dependencies:
1111
idf:
1212
version: ">=6.0"
13-
espressif/esp-nn: "^1.4.0"
13+
espressif/esp-nn: "1.5.0"

‎backends/espressif/idf_component.yml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,4 @@ description: ExecuTorch Espressif operator library
88
dependencies:
99
idf:
1010
version: ">=6.0"
11-
espressif/esp-nn: "1.4.1"
11+
espressif/esp-nn: "1.5.0"

‎backends/espressif/ops/op_quantized_avg_pool2d.cpp‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,6 @@ Tensor& quantized_avg_pool2d_int8_out(
7575
ET_KERNEL_CHECK(
7676
ctx,
7777
channels % 4 == 0 && batches >= 0 &&
78-
(output_height == 1 || output_height == output_width) &&
7978
input_bytes <= std::numeric_limits<int32_t>::max() &&
8079
output_bytes <= std::numeric_limits<int32_t>::max() &&
8180
static_cast<size_t>(batches) <= input.nbytes() / input_bytes &&

‎backends/espressif/passes/lower_to_esp.py‎

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -251,10 +251,6 @@ def _lower_avg_pool2d(program, node) -> bool:
251251
args = _pool_kernel_args(program, node, node.meta["val"])
252252
if args is None:
253253
return False
254-
output_height, output_width = node.meta["val"].shape[1:3]
255-
# ESP-NN 1.4.1's S3 assembly uses output height for the output row stride.
256-
if output_height != 1 and output_height != output_width:
257-
return False
258254
inp, kernel, _, padding = args
259255
if get_arg(node, "count_include_pad") and any(padding):
260256
return False

‎backends/espressif/test/ops/test_avgpool2d.py‎

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -98,18 +98,18 @@ def _input(shape, *, negative=False):
9898
"channels_4": EspTestCase(EspAvgPool2d(kernel_size=2), (_input((1, 4, 5, 5)),)),
9999
"channels_8": EspTestCase(EspAvgPool2d(), (_input((1, 8, 9, 11)),)),
100100
"channels_12": EspTestCase(EspAvgPool2d(), (_input((1, 12, 9, 11)),)),
101-
"batches": EspTestCase(EspAvgPool2d(), (_input((3, 4, 7, 8)),)),
101+
"batches": EspTestCase(EspAvgPool2d(), (_input((3, 4, 7, 9)),)),
102102
"rectangular": EspTestCase(
103103
EspAvgPool2d(
104104
kernel_size=(3, 2), stride=(2, 1), padding=(1, 0), count_include_pad=False
105105
),
106-
(_input((1, 8, 7, 5)),),
106+
(_input((1, 8, 7, 9)),),
107107
),
108108
"negative_padding": EspTestCase(
109109
EspAvgPool2d(kernel_size=3, stride=2, padding=1, count_include_pad=False),
110-
(_input((1, 4, 7, 7), negative=True),),
110+
(_input((1, 4, 7, 9), negative=True),),
111111
),
112-
"identity": EspTestCase(EspAvgPool2d(kernel_size=1), (_input((1, 4, 3, 3)),)),
112+
"identity": EspTestCase(EspAvgPool2d(kernel_size=1), (_input((1, 4, 3, 5)),)),
113113
"global": EspTestCase(EspAvgPool2d(kernel_size=(5, 7)), (_input((1, 4, 5, 7)),)),
114114
"single_row": EspTestCase(EspAvgPool2d(), (_input((1, 8, 3, 9)),)),
115115
"large_window": EspTestCase(
@@ -123,24 +123,24 @@ def _input(shape, *, negative=False):
123123
.reshape(1, 4, 1, 8),
124124
),
125125
),
126-
"chain": EspTestCase(EspAvgPoolChain(), (_input((1, 4, 9, 9)),)),
126+
"chain": EspTestCase(EspAvgPoolChain(), (_input((1, 4, 9, 11)),)),
127127
"add_between_pools": EspTestCase(EspAvgPoolAddChain(), (_input((1, 4, 9, 9)),)),
128128
"add_producer": EspTestCase(EspAvgPoolAndAdd(), (_input((1, 4, 7, 7)),)),
129129
"constant_between_pools": EspTestCase(
130130
EspAvgPoolWithBuffer(), (torch.linspace(-2, 4, 64).reshape(1, 4, 4, 4),)
131131
),
132-
"float_users": EspTestCase(EspAvgPoolWithFloatUsers(), (_input((1, 4, 7, 8)),)),
133-
"wide_output_channels_4_fallback": EspTestCase(
134-
EspAvgPool2d(kernel_size=2, supported=False), (_input((1, 4, 5, 7)),)
132+
"float_users": EspTestCase(EspAvgPoolWithFloatUsers(), (_input((1, 4, 7, 9)),)),
133+
"wide_output_channels_4": EspTestCase(
134+
EspAvgPool2d(kernel_size=2), (_input((1, 4, 5, 7)),)
135135
),
136-
"tall_output_channels_4_fallback": EspTestCase(
137-
EspAvgPool2d(kernel_size=2, supported=False), (_input((1, 4, 7, 5)),)
136+
"tall_output_channels_4": EspTestCase(
137+
EspAvgPool2d(kernel_size=2), (_input((1, 4, 7, 5)),)
138138
),
139-
"wide_output_channels_8_fallback": EspTestCase(
140-
EspAvgPool2d(kernel_size=2, supported=False), (_input((1, 8, 5, 7)),)
139+
"wide_output_channels_8": EspTestCase(
140+
EspAvgPool2d(kernel_size=2), (_input((1, 8, 5, 7)),)
141141
),
142-
"tall_output_channels_8_fallback": EspTestCase(
143-
EspAvgPool2d(kernel_size=2, supported=False), (_input((1, 8, 7, 5)),)
142+
"tall_output_channels_8": EspTestCase(
143+
EspAvgPool2d(kernel_size=2), (_input((1, 8, 7, 5)),)
144144
),
145145
"channel_tail_fallback": EspTestCase(
146146
EspAvgPool2d(supported=False), (_input((1, 5, 7, 8)),)

‎backends/espressif/test/test_int8_ops.py‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,15 @@ def forward(self, x):
228228
torch.manual_seed(20261014)
229229

230230

231+
class ConvAvgPool(nn.Module):
232+
def __init__(self, channels):
233+
super().__init__()
234+
self.conv = nn.Conv2d(channels, channels, 1)
235+
236+
def forward(self, x):
237+
return F.avg_pool2d(self.conv(x), 2)
238+
239+
231240
class GroupedConvs(nn.Module):
232241
"""Grouped (not depthwise) convolutions: plain, strided and dilated."""
233242

@@ -263,6 +272,10 @@ def forward(self, x):
263272
("broadcast-pad-split-cat", BroadcastPadSplit(), [(1, 4, 6, 6)], 2),
264273
("two-inputs-two-outputs", TwoInputTwoOutput(), [(1, 3, 12, 12), (1, 6)], 2),
265274
("transpose-select-stack", TransposeSelect(), [(1, 3, 4, 5)], 2),
275+
("avgpool-wide-c4", ConvAvgPool(4), [(1, 4, 5, 7)], 2),
276+
("avgpool-tall-c4", ConvAvgPool(4), [(1, 4, 7, 5)], 2),
277+
("avgpool-wide-c8", ConvAvgPool(8), [(1, 8, 5, 7)], 2),
278+
("avgpool-tall-c8", ConvAvgPool(8), [(1, 8, 7, 5)], 2),
266279
]
267280

268281

‎examples/espressif/idf_component_template/README.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ The component depends on `espressif/esp-nn`, which the component manager
9393
fetches from the production registry, components.espressif.com, even
9494
for a project that names another registry. A project that builds
9595
without the component manager provides it as `components/esp-nn`.
96+
The local copy must be ESP-NN 1.5.0 or newer.
9697

9798
### Set up Python
9899

‎examples/espressif/idf_component_template/idf_component.yml.in‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,5 +25,5 @@ dependencies:
2525
## Pinned to the production registry, because the staging registry records
2626
## a dependency without a registry_url as one of its own.
2727
espressif/esp-nn:
28-
version: "^1.4"
28+
version: "1.5.0"
2929
registry_url: https://components.espressif.com

0 commit comments

Comments
 (0)