Skip to content

Commit e039af1

Browse files
committed
Address new Copilot feedback
- Add <cinttypes> for PRIx32 portability - Check memory_planned_buffer_size Result before .get() - Validate single tensor input (reject multi-input models) - Remove Twister test entries from sample.yaml since CMake hard-fails without ET_PTE_FILE_PATH which Twister cannot provide
1 parent 89345ce commit e039af1

2 files changed

Lines changed: 21 additions & 8 deletions

File tree

zephyr/samples/mv2-ethosu/sample.yaml

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,3 @@ common:
1212
depends_on:
1313
- executorch
1414
- arm_ethos_u
15-
build_only: true
16-
tests:
17-
sample.executorch.mv2_ethosu.corstone300:
18-
platform_allow: mps3/corstone300/fvp
19-
sample.executorch.mv2_ethosu.corstone320:
20-
platform_allow: mps4/corstone320/fvp

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

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include <stdio.h>
1818
#include <zephyr/kernel.h>
1919
#include <zephyr/sys/printk.h>
20+
#include <cinttypes>
2021
#include <cstring>
2122
#include <vector>
2223

@@ -90,6 +91,7 @@ Error prepare_input_tensors(
9091
size_t input_size) {
9192
MethodMeta method_meta = method.method_meta();
9293
size_t num_inputs = method_meta.num_inputs();
94+
size_t tensor_inputs_seen = 0;
9395

9496
for (size_t i = 0; i < num_inputs; i++) {
9597
auto tag = method_meta.input_tag(i);
@@ -101,6 +103,14 @@ Error prepare_input_tensors(
101103
ET_LOG(Debug, "Skipping non-tensor input %zu", i);
102104
continue;
103105
}
106+
if (tensor_inputs_seen > 0) {
107+
ET_LOG(
108+
Error,
109+
"Model has multiple tensor inputs; this sample supports only one");
110+
return Error::InvalidArgument;
111+
}
112+
tensor_inputs_seen++;
113+
104114
Result<TensorInfo> tensor_meta = method_meta.input_tensor_meta(i);
105115
if (!tensor_meta.ok()) {
106116
return tensor_meta.error();
@@ -315,8 +325,17 @@ int main(void) {
315325
size_t num_memory_planned_buffers = method_meta->num_memory_planned_buffers();
316326

317327
for (size_t id = 0; id < num_memory_planned_buffers; ++id) {
318-
size_t buffer_size =
319-
static_cast<size_t>(method_meta->memory_planned_buffer_size(id).get());
328+
Result<int64_t> buffer_size_result =
329+
method_meta->memory_planned_buffer_size(id);
330+
if (!buffer_size_result.ok()) {
331+
ET_LOG(
332+
Error,
333+
"Failed to get planned buffer size for buffer %lu: 0x%x",
334+
static_cast<unsigned long>(id),
335+
(unsigned int)buffer_size_result.error());
336+
return 1;
337+
}
338+
size_t buffer_size = static_cast<size_t>(buffer_size_result.get());
320339
ET_LOG(
321340
Info,
322341
"Setting up planned buffer %lu, size %lu.",

0 commit comments

Comments
 (0)