|
1 | | -# Copyright 2024 NXP |
| 1 | +# Copyright 2024,2026 NXP |
2 | 2 | # |
3 | 3 | # This source code is licensed under the BSD-style license found in the |
4 | 4 | # LICENSE file in the root directory of this source tree. |
|
28 | 28 | ToNCHWPreprocess, |
29 | 29 | ToNHWCPreprocess, |
30 | 30 | ) |
| 31 | +from executorch.backends.nxp.tests.graph_verifier import BaseGraphVerifier |
31 | 32 | from executorch.backends.nxp.tests.models import AvgPool2dConvModule, AvgPool2dModule |
| 33 | + |
| 34 | +from executorch.backends.nxp.tests.nsys_testing import lower_run_compare |
32 | 35 | from torch.export import ExportedProgram |
33 | 36 | from executorch.backends.nxp.tests.use_qat import * # noqa F403 |
34 | 37 | from executorch.exir.dialects._ops import ops as exir_ops |
@@ -296,3 +299,73 @@ def test_from_avg_pool_1d(mocker): |
296 | 299 | tflite_input_preprocess=ToChannelLastPreprocess(), |
297 | 300 | tflite_output_preprocess=ToChannelFirstPreprocess(), |
298 | 301 | ) |
| 302 | + |
| 303 | + |
| 304 | +class TestAvgPool2DNewNeutronFlow: |
| 305 | + def test__basic_nsys_inference(self): |
| 306 | + input_shape = (2, 4, 6, 7) |
| 307 | + model = AvgPool2dModule(False, 0) |
| 308 | + graph_verifier = BaseGraphVerifier( |
| 309 | + exp_num_delegate_call_nodes=1, # Delegated AvgPool. |
| 310 | + exp_non_delegated_nodes=[], |
| 311 | + ) |
| 312 | + |
| 313 | + lower_run_compare( |
| 314 | + model, input_shape, graph_verifier, use_new_flow_neutron_c=True |
| 315 | + ) |
| 316 | + |
| 317 | + def test__kernel_size_limit(self): |
| 318 | + kernel_size = (1, 4096) |
| 319 | + input_shape = (1, 4) + kernel_size |
| 320 | + model = AvgPool2dModule(False, 0, kernel_size) |
| 321 | + graph_verifier = BaseGraphVerifier( |
| 322 | + exp_num_delegate_call_nodes=1, # Delegated AvgPool. |
| 323 | + exp_non_delegated_nodes=[], |
| 324 | + ) |
| 325 | + |
| 326 | + lower_run_compare( |
| 327 | + model, input_shape, graph_verifier, use_new_flow_neutron_c=True |
| 328 | + ) |
| 329 | + |
| 330 | + def test__kernel_size_limit_exceeded(self): |
| 331 | + kernel_size = (1, 4097) # Exceeds the kernel size limit. |
| 332 | + input_shape = (1, 4) + kernel_size |
| 333 | + model = AvgPool2dModule(False, 0, kernel_size) |
| 334 | + |
| 335 | + delegated_ep = to_quantized_edge_program( |
| 336 | + model, input_shape, use_new_flow_neutron_c=True |
| 337 | + ).exported_program() |
| 338 | + |
| 339 | + # Make sure the `avg_pool2d` was NOT delegated. |
| 340 | + assert not graph_contains_any_of_ops( |
| 341 | + delegated_ep.graph, [ExecutorchDelegateCall] |
| 342 | + ) |
| 343 | + assert graph_contains_any_of_ops(delegated_ep.graph, [AvgPool2D]) |
| 344 | + |
| 345 | + def test__stride_limit(self): |
| 346 | + stride = 4096 |
| 347 | + input_shape = (1, 4, 1, 4096) |
| 348 | + model = AvgPool2dModule(False, 0, 1, stride) |
| 349 | + graph_verifier = BaseGraphVerifier( |
| 350 | + exp_num_delegate_call_nodes=1, # Delegated AvgPool. |
| 351 | + exp_non_delegated_nodes=[], |
| 352 | + ) |
| 353 | + |
| 354 | + lower_run_compare( |
| 355 | + model, input_shape, graph_verifier, use_new_flow_neutron_c=True |
| 356 | + ) |
| 357 | + |
| 358 | + def test__stride_limit_exceeded(self): |
| 359 | + stride = 4097 # Exceeds the stride limit. |
| 360 | + input_shape = (1, 4, 1, 4096) |
| 361 | + model = AvgPool2dModule(False, 0, 1, stride) |
| 362 | + |
| 363 | + delegated_ep = to_quantized_edge_program( |
| 364 | + model, input_shape, use_new_flow_neutron_c=True |
| 365 | + ).exported_program() |
| 366 | + |
| 367 | + # Make sure the `avg_pool2d` was NOT delegated. |
| 368 | + assert not graph_contains_any_of_ops( |
| 369 | + delegated_ep.graph, [ExecutorchDelegateCall] |
| 370 | + ) |
| 371 | + assert graph_contains_any_of_ops(delegated_ep.graph, [AvgPool2D]) |
0 commit comments