Skip to content

Commit a1bd696

Browse files
authored
Arm backend: Keep Ethos-U55 powered across semihosting jobs (pytorch#22895)
Repeated power cycles can make the U55 FVP stop responding after several inferences. Hold one power reference while semihosting processes multiple jobs, then release it when the run finishes. This only affects U55 FVP builds. Signed-off-by: Zingo Andersen <Zingo.Andersen@arm.com>
1 parent 614a6bc commit a1bd696

1 file changed

Lines changed: 35 additions & 0 deletions

File tree

‎examples/arm/executor_runner/arm_executor_runner.cpp‎

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,9 @@
102102
*/
103103

104104
#include <errno.h>
105+
#if defined(ETHOSU55) && defined(SEMIHOSTING)
106+
#include <ethosu_driver.h>
107+
#endif
105108
#include <executorch/extension/data_loader/buffer_data_loader.h>
106109
#include <executorch/extension/runner_util/inputs.h>
107110
#include <executorch/runtime/core/exec_aten/util/scalar_type_util.h>
@@ -1363,6 +1366,24 @@ bool run_model(RunnerContext& ctx, const void* model_data) {
13631366
return model_ok;
13641367
}
13651368

1369+
#if defined(ETHOSU55) && defined(SEMIHOSTING)
1370+
void set_runner_power(bool enabled) {
1371+
struct ethosu_driver* driver = ethosu_reserve_driver();
1372+
ET_CHECK_MSG(driver != nullptr, "Failed to reserve the Ethos-U driver");
1373+
1374+
int result = 0;
1375+
if (enabled) {
1376+
result = ethosu_request_power(driver);
1377+
} else {
1378+
ethosu_release_power(driver);
1379+
}
1380+
ethosu_release_driver(driver);
1381+
1382+
// ET_CHECK_MSG aborts and does not return if the power request failed.
1383+
ET_CHECK_MSG(result == 0, "Failed to power the Ethos-U NPU");
1384+
}
1385+
#endif
1386+
13661387
#if defined(SEMIHOSTING)
13671388
bool run_model_server(
13681389
RunnerContext& ctx,
@@ -1537,11 +1558,25 @@ int main(int argc, const char* argv[]) {
15371558
runner_init(ctx, model_data, model_size, input_buffers);
15381559
bool model_ok = true;
15391560
#if defined(SEMIHOSTING)
1561+
#if defined(ETHOSU55)
1562+
// For semihosting FVP builds repeated U55 power cycles can make FVP fast mode
1563+
// stop responding, so keep one power reference across jobs.
1564+
// cppcheck-suppress knownConditionTrueFalse
1565+
const bool keep_powered = ctx.server_mode || num_inferences > 1;
1566+
if (keep_powered) {
1567+
set_runner_power(true);
1568+
}
1569+
#endif
15401570
if (ctx.server_mode) {
15411571
model_ok = run_model_server(ctx, model_data, input_buffers);
15421572
} else {
15431573
model_ok = run_model(ctx, model_data);
15441574
}
1575+
#if defined(ETHOSU55)
1576+
if (keep_powered) {
1577+
set_runner_power(false);
1578+
}
1579+
#endif
15451580
#else
15461581
model_ok = run_model(ctx, model_data);
15471582
#endif

0 commit comments

Comments
 (0)