From f70b47094762b41eb66643c2f6228791fd85e2e3 Mon Sep 17 00:00:00 2001 From: Jacob Bohlin Date: Fri, 4 Jul 2025 11:15:49 +0100 Subject: [PATCH] MLBEDSW-10904 Added check to only decode TosaShape if present Change-Id: I0228e2cb7d7a0efb44aa4c1b763ffcb77a5a7f60 Signed-off-by: Jacob Bohlin --- ethosu/regor/tosa/tosa_reader.cpp | 39 +++++++++++++++++-------------- 1 file changed, 21 insertions(+), 18 deletions(-) diff --git a/ethosu/regor/tosa/tosa_reader.cpp b/ethosu/regor/tosa/tosa_reader.cpp index 328e698f..458955f7 100644 --- a/ethosu/regor/tosa/tosa_reader.cpp +++ b/ethosu/regor/tosa/tosa_reader.cpp @@ -416,29 +416,32 @@ void TosaReader::LoadGraphs(const tosaFb::TosaGraph *model, std::listshapes()) ) + if ( tosa_basicblock->shapes() ) { - GraphApi::GraphBuffer *buffer = nullptr; + for ( const auto &tosa_shape : SafeDeref(tosa_basicblock->shapes()) ) + { + GraphApi::GraphBuffer *buffer = nullptr; - const char *name = SafeDeref(tosa_shape->name(), "No shape name").c_str(); - tosa_assert(name, "Shape needs a valid name"); - const auto type = GraphApi::GraphDataType::Int64; + const char *name = SafeDeref(tosa_shape->name(), "No shape name").c_str(); + tosa_assert(name, "Shape needs a valid name"); + const auto type = GraphApi::GraphDataType::Int64; - const auto &shapeData = tosa_shape->data(); - if ( shapeData && shapeData->size() ) - { - buffer = builder->CreateBuffer(shapeData->size(), GraphApi::BufferMapping::Alias, shapeData->Data()); - builder_assert(buffer, "Failed to create buffer"); - } + const auto &shapeData = tosa_shape->data(); + if ( shapeData && shapeData->size() ) + { + buffer = builder->CreateBuffer(shapeData->size(), GraphApi::BufferMapping::Alias, shapeData->Data()); + builder_assert(buffer, "Failed to create buffer"); + } - GraphApi::GraphShape tosaShape; - tosaShape.count = 1; - tosaShape.axisNHWC[0] = tosa_shape->rank(); - auto tensor = builder->CreateTensor(name, tosaShape, GraphApi::GraphTensorLayout::Linear, type, buffer); - builder_assert(tensor, "Failed to create tensor"); + GraphApi::GraphShape tosaShape; + tosaShape.count = 1; + tosaShape.axisNHWC[0] = tosa_shape->rank(); + auto tensor = builder->CreateTensor(name, tosaShape, GraphApi::GraphTensorLayout::Linear, type, buffer); + builder_assert(tensor, "Failed to create tensor"); - tosa_assert(tensors.count(name) == 0, "Shape and Tensor name collision"); - tensors[name] = tensor; + tosa_assert(tensors.count(name) == 0, "Shape and Tensor name collision"); + tensors[name] = tensor; + } } const auto &tosa_operators = SafeDeref(tosa_basicblock->operators(), "No operators"); -- GitLab