Skip to content

Commit e4ede92

Browse files
authored
Ethos Driver Backwards Compatibility (#19116)
Differential Revision: D102359186 Pull Request resolved: #19116
1 parent 1c2d50b commit e4ede92

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
@@ -24,6 +24,24 @@ using executorch::runtime::BackendExecutionContext;
2424
using executorch::runtime::Error;
2525
using executorch::runtime::Span;
2626

27+
// Compatibility hooks for multi-device driver / non-multi-device driver code
28+
// When multi-device driver code is available, these declarations are overridden
29+
extern "C" __attribute__((weak)) int ethosu_get_product_config_from_cop_data(
30+
const void*,
31+
const int,
32+
uint32_t* product_out,
33+
uint32_t* log2_macs_out) {
34+
*product_out = 0;
35+
*log2_macs_out = 0;
36+
return 0;
37+
}
38+
39+
extern "C" __attribute__((weak)) struct ethosu_driver* ethosu_reserve_driver_ex(
40+
uint32_t,
41+
uint32_t) {
42+
return ethosu_reserve_driver();
43+
}
44+
2745
namespace executorch {
2846
namespace backends {
2947
namespace arm {
@@ -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)