Skip to content

Commit a32b8d0

Browse files
committed
Address Copilot and lint review feedback
- Use Error log level for all failure paths instead of Info - Replace ET_CHECK with graceful error log + return for get_outputs - Use Python3_EXECUTABLE instead of hardcoded python in CMake - Add RESULT_VARIABLE/ERROR_VARIABLE checks for gen_oplist.py - Fix grammar in CMake status message - Apply lint formatting suggestions
1 parent 768a02e commit a32b8d0

2 files changed

Lines changed: 28 additions & 21 deletions

File tree

zephyr/samples/mv2-ethosu/CMakeLists.txt

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -47,14 +47,30 @@ set(ET_PTE_FILE_PATH
4747
FORCE
4848
)
4949

50+
find_package(
51+
Python3
52+
COMPONENTS Interpreter
53+
REQUIRED
54+
)
55+
5056
execute_process(
5157
COMMAND
52-
python "${CMAKE_CURRENT_LIST_DIR}/../../../codegen/tools/gen_oplist.py"
58+
${Python3_EXECUTABLE}
59+
"${CMAKE_CURRENT_LIST_DIR}/../../../codegen/tools/gen_oplist.py"
5360
--model_file_path=${ET_PTE_FILE_PATH}
5461
--output_path=${CMAKE_CURRENT_BINARY_DIR}/temp.yaml
62+
RESULT_VARIABLE GEN_OPLIST_RESULT
5563
OUTPUT_VARIABLE CMD_RESULT
64+
ERROR_VARIABLE GEN_OPLIST_ERROR
5665
)
5766

67+
if(NOT GEN_OPLIST_RESULT EQUAL 0)
68+
message(
69+
FATAL_ERROR
70+
"gen_oplist.py failed with exit code ${GEN_OPLIST_RESULT}: ${GEN_OPLIST_ERROR}"
71+
)
72+
endif()
73+
5874
if(CMD_RESULT MATCHES "aten::" OR CMD_RESULT MATCHES "dim_order_ops::")
5975
set(FOUND_OPS_IN_FILE "true")
6076
else()
@@ -76,19 +92,13 @@ else()
7692
set(EXECUTORCH_SELECT_OPS_MODEL "")
7793
set(_EXECUTORCH_GEN_ZEPHYR_PORTABLE_OPS OFF)
7894
message(
79-
"gen_oplist: No non delegated ops was found in ${ET_PTE_FILE_PATH} no ops added to build"
95+
"gen_oplist: No non-delegated ops were found in ${ET_PTE_FILE_PATH}; no ops added to build"
8096
)
8197
endif()
8298

8399
find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
84100
project(executorch_mv2_ethosu)
85101

86-
find_package(
87-
Python3
88-
COMPONENTS Interpreter
89-
REQUIRED
90-
)
91-
92102
set(CMAKE_CXX_FLAGS
93103
"${CMAKE_CXX_FLAGS} -Wall -Wno-switch -Wno-float-conversion -Wno-double-promotion -ffunction-sections -fdata-sections"
94104
)

zephyr/samples/mv2-ethosu/src/main.cpp

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,7 @@ int main(void) {
284284
Result<Program> program = Program::load(&loader);
285285
if (!program.ok()) {
286286
ET_LOG(
287-
Info,
287+
Error,
288288
"Program loading failed @ 0x%p: 0x%" PRIx32,
289289
program_data,
290290
static_cast<uint32_t>(program.error()));
@@ -307,7 +307,7 @@ int main(void) {
307307
Result<MethodMeta> method_meta = program->method_meta(method_name);
308308
if (!method_meta.ok()) {
309309
ET_LOG(
310-
Info,
310+
Error,
311311
"Failed to get method_meta for %s: 0x%x",
312312
method_name,
313313
(unsigned int)method_meta.error());
@@ -362,7 +362,7 @@ int main(void) {
362362

363363
if (!method.ok()) {
364364
ET_LOG(
365-
Info,
365+
Error,
366366
"Loading of method %s failed with status 0x%" PRIx32,
367367
method_name,
368368
static_cast<uint32_t>(method.error()));
@@ -381,7 +381,7 @@ int main(void) {
381381

382382
if (!prepared_inputs.ok()) {
383383
ET_LOG(
384-
Info,
384+
Error,
385385
"Preparing input failed: 0x%" PRIx32,
386386
static_cast<uint32_t>(prepared_inputs.error()));
387387
return 1;
@@ -397,27 +397,24 @@ int main(void) {
397397
uint32_t inference_time = end_time - start_time;
398398

399399
if (status != Error::Ok) {
400-
ET_LOG(
401-
Info,
402-
"Execution failed: 0x%" PRIx32,
403-
static_cast<uint32_t>(status));
400+
ET_LOG(Error, "Execution failed: 0x%" PRIx32, static_cast<uint32_t>(status));
404401
return 1;
405402
}
406403
ET_LOG(Info, "Inference completed in %u ms", inference_time);
407404

408405
std::vector<EValue> outputs(method->outputs_size());
409406
status = method->get_outputs(outputs.data(), outputs.size());
410-
ET_CHECK(status == Error::Ok);
407+
if (status != Error::Ok) {
408+
ET_LOG(Error, "get_outputs failed: 0x%" PRIx32, static_cast<uint32_t>(status));
409+
return 1;
410+
}
411411

412412
ET_LOG(Info, "\n--- Classification Results ---");
413413
print_top_k(outputs);
414414

415415
ET_LOG(Info, "\n========================================");
416416
ET_LOG(Info, "MobileNetV2 Demo Complete");
417-
ET_LOG(
418-
Info,
419-
"Model size: %lu bytes",
420-
static_cast<unsigned long>(pte_size));
417+
ET_LOG(Info, "Model size: %lu bytes", static_cast<unsigned long>(pte_size));
421418
ET_LOG(
422419
Info,
423420
"Input: 224x224x3 RGB image (%lu bytes)",

0 commit comments

Comments
 (0)