Skip to content

Commit 4fd39a2

Browse files
authored
NXP backend: improve mapping algorithm (pytorch#22614)
### Summary Improve NXP Neutron operator-to-Edge profiling map 1. Improve TFLite-to-Neutron mapping algorithm - Filter tensor I/O to dynamic (Variable) tensors only, excluding constants - Group Neutron subgraphs into linearly-connected execution chains based on matching dynamic I/O tensor names - Match each Neutron chain to a corresponding TFLite operator chain by comparing boundary inputs and outputs 2. Fix mapping for batch > 1 - Enable `dumpMicrocode` in the converter log to include the Microinstructions section - Remap NeutronOperator locations and kernel counts using the actual CALLARGS sequence from the microcode, which accounts for batch repetitions and converter-injected helper kernels (e.g. MemCpy) 3. Fix profiling time scaling - Neutron profiling timestamps are measured in clock cycles; divide by the Neutron NPU frequency to convert to seconds ### Test plan Tests included cc @robert-kalmar @JakeStevens @digantdesai @rascani
1 parent d28c77e commit 4fd39a2

6 files changed

Lines changed: 899 additions & 360 deletions

File tree

‎backends/nxp/backend/neutron_compiler_manager.py‎

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,14 +41,18 @@ def _build_compilation_context(compilation_opts):
4141
cctx.compilationOpts.dumpKernelSelectionCode = compilation_opts[
4242
"dumpKernelSelectionCode"
4343
]
44-
if (
45-
hasattr(cctx.compilationOpts, "useProfiling")
46-
and compilation_opts["useProfiling"]
47-
):
48-
cctx.compilationOpts.useProfiling = compilation_opts["useProfiling"]
44+
if compilation_opts["useProfiling"]:
45+
if not _USING_NEUTRON_COMPILER:
46+
raise RuntimeError(
47+
"Profiling requires eIQ Neutron SDK >= 3.2.1. "
48+
"The installed SDK (neutron_converter-based, <= 3.2.0) does not provide neutronGetSdkVersion(); "
49+
"the ExecuTorch runtime will fail to link. Upgrade the SDK."
50+
)
51+
cctx.compilationOpts.useProfiling = True
4952
cctx.compilationOpts.dumpAfterImport = "console"
5053
cctx.compilationOpts.dumpAfterGenerate = "console"
51-
cctx.compilationOpts.verbose = compilation_opts["useProfiling"]
54+
cctx.compilationOpts.verbose = True
55+
cctx.compilationOpts.dumpMicrocode = True
5256

5357
return cctx
5458

0 commit comments

Comments
 (0)