Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions backends/arm/runtime/EthosUBackend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,7 @@ class EthosUBackend final : public ::executorch::runtime::BackendInterface {
~EthosUBackend() = default;

virtual bool is_available() const override {
// TODO: revise to use a register check/init function
return 1;
return platform_is_available();
}

Result<DelegateHandle*> init(
Expand Down
17 changes: 17 additions & 0 deletions backends/arm/runtime/EthosUBackend_Cortex_A.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,23 @@ Error invoke_linux_driver(
}
} // namespace

bool platform_is_available() {
// Open the NPU device driver; thrown if it is absent or unopenable.
const LinuxDriverOptions defaults;
try {
EthosU::Device device(defaults.device_path.c_str());
(void)device;
return true;
} catch (const std::exception& e) {
ET_LOG(
Info,
"Ethos-U device %s not available: %s",
defaults.device_path.c_str(),
e.what());
return false;
}
}

PlatformState* platform_init(
ArrayRef<CompileSpec> specs,
MemoryAllocator* allocator) {
Expand Down
15 changes: 15 additions & 0 deletions backends/arm/runtime/EthosUBackend_Cortex_M.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,21 @@ namespace arm {

struct PlatformState {};

// TODO: Upstream ethosu_driver_is_registered() into the core driver.
// Keep the weak fallback until all builds are confirmed to be using a driver
// with ethosu_driver_is_registered() implemented, at which point the weak
// fallback can be removed.
extern "C" __attribute__((weak)) bool ethosu_driver_is_registered(void) {
return true;
}

bool platform_is_available() {
// Check whether ethosu_init() was called before ExecuTorch runs.
// If ethosu_init() was not called and this unconditionally returned true,
// then the firmware freezes without any error.
return ethosu_driver_is_registered();
}

PlatformState* platform_init(
executorch::runtime::ArrayRef<executorch::runtime::CompileSpec> /*specs*/,
executorch::runtime::MemoryAllocator* /*allocator*/) {
Expand Down
3 changes: 3 additions & 0 deletions backends/arm/runtime/EthosUBackend_Internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,9 @@ extern unsigned char* ethosu_fast_scratch;
extern size_t ethosu_fast_scratch_size;
}

// Returns whether the Ethos-U device driver is available
bool platform_is_available();

PlatformState* platform_init(
executorch::runtime::ArrayRef<executorch::runtime::CompileSpec> specs,
executorch::runtime::MemoryAllocator* allocator);
Expand Down
Loading