Skip to content

Commit 39f2210

Browse files
gkrulcefacebook-github-bot
authored andcommitted
Ethos Driver Backwards Compatibility
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 de8ce55 commit 39f2210

2 files changed

Lines changed: 25 additions & 3 deletions

File tree

backends/arm/runtime/EthosUBackend_Cortex_M.cpp

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,20 @@
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 weak declarations are overridden
22+
extern "C" __attribute__((weak)) int ethosu_get_product_config_from_cop_data(
23+
const void*, const int, uint32_t* product_out, uint32_t* log2_macs_out) {
24+
*product_out = 0;
25+
*log2_macs_out = 0;
26+
return 0;
27+
}
28+
29+
extern "C" __attribute__((weak)) struct ethosu_driver* ethosu_reserve_driver_ex(
30+
uint32_t, uint32_t) {
31+
return ethosu_reserve_driver();
32+
}
33+
2034
#include <executorch/backends/arm/runtime/EthosUBackend_Internal.h>
2135
#include <executorch/runtime/core/error.h>
2236

@@ -48,12 +62,20 @@ Error platform_execute(
4862
int output_count,
4963
Span<executorch::runtime::EValue*> args,
5064
char* ethosu_scratch) {
65+
// Parse product config from command stream to reserve the correct driver
66+
uint32_t product, log2_macs;
67+
if (ethosu_get_product_config_from_cop_data(
68+
handles.cmd_data, handles.cmd_data_size, &product, &log2_macs) != 0) {
69+
ET_LOG(Error, "Failed to parse product config from command stream");
70+
return Error::InvalidProgram;
71+
}
72+
5173
// Allocate driver handle and synchronously invoke driver
5274
auto driver =
5375
std::unique_ptr<ethosu_driver, decltype(&ethosu_release_driver)>(
54-
ethosu_reserve_driver(), ethosu_release_driver);
76+
ethosu_reserve_driver_ex(product, log2_macs), ethosu_release_driver);
5577
if (driver == nullptr) {
56-
ET_LOG(Error, "ethosu_reserve_driver failed");
78+
ET_LOG(Error, "ethosu_reserve_driver_ex failed");
5779
return Error::InvalidState;
5880
}
5981

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)