Skip to content

Commit 140366d

Browse files
gkrulcefacebook-github-bot
authored andcommitted
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
1 parent c1d482e commit 140366d

2 files changed

Lines changed: 29 additions & 3 deletions

File tree

backends/arm/runtime/EthosUBackend_Cortex_M.cpp

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,24 @@
1717

1818
#include <ethosu_driver.h>
1919

20+
// Compatibility hooks for multi-device driver / non-multi-device driver code
21+
// When multi-device driver code is available, these declarations are overridden
22+
extern "C" __attribute__((weak)) int ethosu_get_product_config_from_cop_data(
23+
const void*,
24+
const int,
25+
uint32_t* product_out,
26+
uint32_t* log2_macs_out) {
27+
*product_out = 0;
28+
*log2_macs_out = 0;
29+
return 0;
30+
}
31+
32+
extern "C" __attribute__((weak)) struct ethosu_driver* ethosu_reserve_driver_ex(
33+
uint32_t,
34+
uint32_t) {
35+
return ethosu_reserve_driver();
36+
}
37+
2038
#include <executorch/backends/arm/runtime/EthosUBackend_Internal.h>
2139
#include <executorch/runtime/core/error.h>
2240

@@ -48,12 +66,20 @@ Error platform_execute(
4866
int output_count,
4967
Span<executorch::runtime::EValue*> args,
5068
char* ethosu_scratch) {
69+
// Parse product config from command stream to reserve the correct driver
70+
uint32_t product, log2_macs;
71+
if (ethosu_get_product_config_from_cop_data(
72+
handles.cmd_data, handles.cmd_data_size, &product, &log2_macs) != 0) {
73+
ET_LOG(Error, "Failed to parse product config from command stream");
74+
return Error::InvalidProgram;
75+
}
76+
5177
// Allocate driver handle and synchronously invoke driver
5278
auto driver =
5379
std::unique_ptr<ethosu_driver, decltype(&ethosu_release_driver)>(
54-
ethosu_reserve_driver(), ethosu_release_driver);
80+
ethosu_reserve_driver_ex(product, log2_macs), ethosu_release_driver);
5581
if (driver == nullptr) {
56-
ET_LOG(Error, "ethosu_reserve_driver failed");
82+
ET_LOG(Error, "ethosu_reserve_driver_ex failed");
5783
return Error::InvalidState;
5884
}
5985

backends/arm/runtime/targets.bzl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ def define_common_targets():
2929
"//executorch/runtime/backend:interface",
3030
":vela_bin_stream",
3131
"//executorch/runtime/core:core",
32-
"fbsource//third-party/ethos-u-core-driver:core_driver",
32+
"fbsource//third-party/ethos-u-core-driver:core_driver_headers_only",
3333
],
3434
)
3535
runtime.cxx_library(

0 commit comments

Comments
 (0)