Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 25 additions & 5 deletions backends/nxp/runtime/NeutronBackend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -523,25 +523,45 @@ class NeutronBackend final : public PyTorchBackendInterface {
}
}

// Resume (clock-ungate) the NPU immediately before inference and suspend it
// again immediately after, so its clock only runs during compute
#ifdef NEUTRON_NPU_POWER_GATING
NeutronError resumeRC = neutronResume();
if (resumeRC != ENONE) {
ET_LOG(Error, "neutronResume failed with error code %ld", resumeRC);
return Error::InvalidProgram;
}
#endif

#ifdef ET_EVENT_TRACER_ENABLED
// Save ticks before neutron compute to measure how much time profiling dump
// takes
et_timestamp_t start_ticks = ::executorch::runtime::pal_current_ticks();
#endif
// Run neutron compute.
NeutronError neutronRC = neutronRunBlocking(cfg->nmh, &cfg->dcfg);
#ifdef ET_EVENT_TRACER_ENABLED
// Save ticks after neutron compute to measure how much time profiling dump
// takes
et_timestamp_t stop_ticks = ::executorch::runtime::pal_current_ticks();
#endif

#ifdef NEUTRON_NPU_POWER_GATING
// Suspend (clock-gate) the NPU again regardless of the run result; a failed
// suspend only wastes power, so it must not fail the inference.
NeutronError suspendRC = neutronSuspend();
if (suspendRC != ENONE) {
ET_LOG(Error, "neutronSuspend failed with error code %ld", suspendRC);
}
#endif

if (neutronRC != ENONE) {
ET_LOG(
Error,
"Neutron model evaluation failed with error code %ld",
neutronRC);
return Error::InvalidProgram;
}
#ifdef ET_EVENT_TRACER_ENABLED
// Save ticks after neutron compute to measure how much time profiling dump
// takes
et_timestamp_t stop_ticks = ::executorch::runtime::pal_current_ticks();
#endif

// Transpose outputs.
for (int i = 0; i < cfg->numOutputs; i++) {
Expand Down
4 changes: 3 additions & 1 deletion backends/nxp/runtime/targets.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ def define_common_targets():
],
link_whole = True,
# Constructor needed for backend registration.
compiler_flags = ["-Wno-global-constructors", "-fno-rtti", "-DNO_HEAP_USAGE"],
# NEUTRON_NPU_POWER_GATING clock-gates the NPU around each inference
# (neutronResume/neutronSuspend in NeutronBackend.cpp).
compiler_flags = ["-Wno-global-constructors", "-fno-rtti", "-DNO_HEAP_USAGE", "-DNEUTRON_NPU_POWER_GATING"],
labels = [ci.skip_target()],
visibility = ["PUBLIC"],
deps = [
Expand Down
Loading