From b316aeedd8abbe622e6baf6300bbcab3eced120e Mon Sep 17 00:00:00 2001 From: Jake Stevens Date: Thu, 28 May 2026 09:19:06 -0700 Subject: [PATCH] Add neutronPowerOn/neutronPowerOff hooks to NeutronBackend Summary: To minimize power, the NPU should be turned on and off, per: https://docs.nxp.com/bundle/AN14700/page/topics/imx_rt700_system_details.html This relies on SDK code. Some users may wrap this code for protection. So, we want two things: 1) (potentially) turnOn -> execute NPU -> turnOff 2) ability to override turnOn/Off implementations Further, some may want to leave these stubs so that the ET backend does not control it for them. Differential Revision: D106668625 --- backends/nxp/runtime/NeutronBackend.cpp | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/backends/nxp/runtime/NeutronBackend.cpp b/backends/nxp/runtime/NeutronBackend.cpp index 3ea973b7c5b..f4865a93205 100644 --- a/backends/nxp/runtime/NeutronBackend.cpp +++ b/backends/nxp/runtime/NeutronBackend.cpp @@ -15,6 +15,12 @@ #include "NeutronDriver.h" #include "NeutronErrors.h" +// Hooks to power on/off the NPU for fine-grained control. +extern "C" { +void __attribute__((weak)) neutronPowerOn(void) {} +void __attribute__((weak)) neutronPowerOff(void) {} +} + using namespace std; namespace torch { @@ -515,7 +521,9 @@ class NeutronBackend final : public PyTorchBackendInterface { #endif // Run neutron compute. + neutronPowerOn(); NeutronError neutronRC = neutronRunBlocking(cfg->nmh, &cfg->dcfg); + neutronPowerOff(); if (neutronRC != ENONE) { ET_LOG( Error, @@ -587,4 +595,4 @@ static auto registered = register_backend(backend_id); } // namespace } // namespace neutron } // namespace executor -} // namespace torch \ No newline at end of file +} // namespace torch