From 5768cb4dd99756d23dac2dafc993095d71708112 Mon Sep 17 00:00:00 2001 From: Zingo Andersen Date: Mon, 16 Jun 2025 12:55:48 +0200 Subject: [PATCH] Arm backend: Test temp memory allocation return code in backend Signed-off-by: Zingo Andersen Change-Id: I150ab46e76a6b57d83ec74d47d8194a64a058ada --- backends/arm/runtime/EthosUBackend.cpp | 22 +++++++++++-------- .../executor_runner/arm_executor_runner.cpp | 8 ++++++- 2 files changed, 20 insertions(+), 10 deletions(-) diff --git a/backends/arm/runtime/EthosUBackend.cpp b/backends/arm/runtime/EthosUBackend.cpp index f5e4af860d6..b5575e21b61 100644 --- a/backends/arm/runtime/EthosUBackend.cpp +++ b/backends/arm/runtime/EthosUBackend.cpp @@ -113,7 +113,7 @@ class EthosUBackend final : public ::executorch::runtime::BackendInterface { BackendInitContext& context, FreeableBuffer* processed, ArrayRef compile_specs) const override { - ET_LOG(Info, "EthosUBackend::init %p", processed->data()); + ET_LOG(Info, "data:%p", processed->data()); const char* data = static_cast(processed->data()); size_t size = processed->size(); @@ -173,7 +173,7 @@ class EthosUBackend final : public ::executorch::runtime::BackendInterface { static_cast(execution_handle->processed->data()); EXECUTORCH_PROF_END(event_tracer, event_tracer_local_scope); - ET_LOG(Debug, "EthosUBackend::execute %p", data); + ET_LOG(Debug, "data:%p", data); EXECUTORCH_PROF_START( event_tracer, @@ -182,7 +182,7 @@ class EthosUBackend final : public ::executorch::runtime::BackendInterface { // Read key sections from the vela_bin_stream if (vela_bin_read(data, &handles, execution_handle->processed->size()) == false) { - ET_LOG(Error, "EthosUBackend::vela_read: error, invalid binary layout"); + ET_LOG(Error, "vela_read: error, invalid binary layout"); return Error::InvalidProgram; } EXECUTORCH_PROF_END(event_tracer, event_tracer_local_scope); @@ -193,9 +193,16 @@ class EthosUBackend final : public ::executorch::runtime::BackendInterface { // the end of the execution of the Ethos-U custom delegate char* ethosu_scratch = static_cast(temp_allocator->allocate(handles.scratch_data_size)); + if (ethosu_scratch == nullptr) { + ET_LOG( + Error, + "Failed to allocate scratch buffer of %zu bytes from temp_allocator", + handles.scratch_data_size); + return Error::MemoryAllocationFailed; + } ET_LOG( Debug, - "EthosUBackend::execute: Running program data:\n cmd %p %zu\n weight %p %zu\n scratch %p %zu\n fast scratch %p %zu\n", + "Running program data:\n cmd %p %zu\n weight %p %zu\n scratch %p %zu\n fast scratch %p %zu\n", handles.cmd_data, handles.cmd_data_size, handles.weight_data, @@ -301,7 +308,7 @@ class EthosUBackend final : public ::executorch::runtime::BackendInterface { std::unique_ptr( ethosu_reserve_driver(), ethosu_release_driver); if (driver == NULL) { - ET_LOG(Error, "EthosUBackend::execute: ethosu_reserve_driver failed"); + ET_LOG(Error, "ethosu_reserve_driver failed"); return Error::InvalidState; } @@ -333,10 +340,7 @@ class EthosUBackend final : public ::executorch::runtime::BackendInterface { EXECUTORCH_PROF_END(event_tracer, event_tracer_local_scope); if (result != 0) { - ET_LOG( - Error, - "EthosUBackend::execute: Ethos-U invocation failed error (%d)", - result); + ET_LOG(Error, "Ethos-U invocation failed error (%d)", result); return Error::InvalidProgram; } int tensor_dim = 0, io_dim = 0; diff --git a/examples/arm/executor_runner/arm_executor_runner.cpp b/examples/arm/executor_runner/arm_executor_runner.cpp index debc955dcc0..9046df25a47 100644 --- a/examples/arm/executor_runner/arm_executor_runner.cpp +++ b/examples/arm/executor_runner/arm_executor_runner.cpp @@ -201,7 +201,13 @@ void et_pal_emit_log_message( const char* message, ET_UNUSED size_t length) { fprintf( - stderr, "%c [executorch:%s:%zu] %s\n", level, filename, line, message); + stderr, + "%c [executorch:%s:%zu %s()] %s\n", + level, + filename, + line, + function, + message); } /**