From 140366d3941a0282faf840256bb8b2f212e08cc0 Mon Sep 17 00:00:00 2001 From: Galen Krulce Date: Sat, 25 Apr 2026 10:01:15 -0700 Subject: [PATCH] Ethos Driver Backwards Compatibility (#19116) Summary: The version of ethos driver that supports multiple devices / multiple NPUs has a few breaking API changes. Installing backwards compatibility hooks so that Executorch continues to work with both old and new driver code. It adds the new APIs as weak definitions and redirects to old driver code. If new driver code is available, those definitions override the weak definitions. Driver code ref: https://gitlab.arm.com/artificial-intelligence/ethos-u/ethos-u-core-driver/-/blob/experimental/multidevice/README.md?ref_type=heads#experimental---multi-device Differential Revision: D102359186 --- .../arm/runtime/EthosUBackend_Cortex_M.cpp | 30 +++++++++++++++++-- backends/arm/runtime/targets.bzl | 2 +- 2 files changed, 29 insertions(+), 3 deletions(-) diff --git a/backends/arm/runtime/EthosUBackend_Cortex_M.cpp b/backends/arm/runtime/EthosUBackend_Cortex_M.cpp index 11d5360b123..9a810ce706e 100644 --- a/backends/arm/runtime/EthosUBackend_Cortex_M.cpp +++ b/backends/arm/runtime/EthosUBackend_Cortex_M.cpp @@ -17,6 +17,24 @@ #include +// Compatibility hooks for multi-device driver / non-multi-device driver code +// When multi-device driver code is available, these declarations are overridden +extern "C" __attribute__((weak)) int ethosu_get_product_config_from_cop_data( + const void*, + const int, + uint32_t* product_out, + uint32_t* log2_macs_out) { + *product_out = 0; + *log2_macs_out = 0; + return 0; +} + +extern "C" __attribute__((weak)) struct ethosu_driver* ethosu_reserve_driver_ex( + uint32_t, + uint32_t) { + return ethosu_reserve_driver(); +} + #include #include @@ -48,12 +66,20 @@ Error platform_execute( int output_count, Span args, char* ethosu_scratch) { + // Parse product config from command stream to reserve the correct driver + uint32_t product, log2_macs; + if (ethosu_get_product_config_from_cop_data( + handles.cmd_data, handles.cmd_data_size, &product, &log2_macs) != 0) { + ET_LOG(Error, "Failed to parse product config from command stream"); + return Error::InvalidProgram; + } + // Allocate driver handle and synchronously invoke driver auto driver = std::unique_ptr( - ethosu_reserve_driver(), ethosu_release_driver); + ethosu_reserve_driver_ex(product, log2_macs), ethosu_release_driver); if (driver == nullptr) { - ET_LOG(Error, "ethosu_reserve_driver failed"); + ET_LOG(Error, "ethosu_reserve_driver_ex failed"); return Error::InvalidState; } diff --git a/backends/arm/runtime/targets.bzl b/backends/arm/runtime/targets.bzl index 29455f0e657..42df03fb58b 100644 --- a/backends/arm/runtime/targets.bzl +++ b/backends/arm/runtime/targets.bzl @@ -29,7 +29,7 @@ def define_common_targets(): "//executorch/runtime/backend:interface", ":vela_bin_stream", "//executorch/runtime/core:core", - "fbsource//third-party/ethos-u-core-driver:core_driver", + "fbsource//third-party/ethos-u-core-driver:core_driver_headers_only", ], ) runtime.cxx_library(