|
102 | 102 | */ |
103 | 103 |
|
104 | 104 | #include <errno.h> |
| 105 | +#if defined(ETHOSU55) && defined(SEMIHOSTING) |
| 106 | +#include <ethosu_driver.h> |
| 107 | +#endif |
105 | 108 | #include <executorch/extension/data_loader/buffer_data_loader.h> |
106 | 109 | #include <executorch/extension/runner_util/inputs.h> |
107 | 110 | #include <executorch/runtime/core/exec_aten/util/scalar_type_util.h> |
@@ -1363,6 +1366,24 @@ bool run_model(RunnerContext& ctx, const void* model_data) { |
1363 | 1366 | return model_ok; |
1364 | 1367 | } |
1365 | 1368 |
|
| 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 | + |
1366 | 1387 | #if defined(SEMIHOSTING) |
1367 | 1388 | bool run_model_server( |
1368 | 1389 | RunnerContext& ctx, |
@@ -1537,11 +1558,25 @@ int main(int argc, const char* argv[]) { |
1537 | 1558 | runner_init(ctx, model_data, model_size, input_buffers); |
1538 | 1559 | bool model_ok = true; |
1539 | 1560 | #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 |
1540 | 1570 | if (ctx.server_mode) { |
1541 | 1571 | model_ok = run_model_server(ctx, model_data, input_buffers); |
1542 | 1572 | } else { |
1543 | 1573 | model_ok = run_model(ctx, model_data); |
1544 | 1574 | } |
| 1575 | +#if defined(ETHOSU55) |
| 1576 | + if (keep_powered) { |
| 1577 | + set_runner_power(false); |
| 1578 | + } |
| 1579 | +#endif |
1545 | 1580 | #else |
1546 | 1581 | model_ok = run_model(ctx, model_data); |
1547 | 1582 | #endif |
|
0 commit comments