From 01f217d9e27be9da45348e7056c363c0d928d75d Mon Sep 17 00:00:00 2001 From: Johan Gunnarsson Date: Fri, 13 Dec 2024 11:51:00 +0100 Subject: [PATCH] MLBEDSW-10228: Remove ConstraintSliceRanges This check is not correct. The begin/end/strides vectors are not guaranteed have the same length as number of dimensions in IFM. Also, it's not possible to implement a proper check of begin/end/strides since these tensors are not guaranteed to be constant or known at compile time. Signed-off-by: Johan Gunnarsson Change-Id: Id4326e05584c81929bc5fd9aafcc584319e10d0b --- .../regor/tflite/tflite_model_semantics.cpp | 57 +------------------ 1 file changed, 1 insertion(+), 56 deletions(-) diff --git a/ethosu/regor/tflite/tflite_model_semantics.cpp b/ethosu/regor/tflite/tflite_model_semantics.cpp index 6b3d9515..fdc351f3 100644 --- a/ethosu/regor/tflite/tflite_model_semantics.cpp +++ b/ethosu/regor/tflite/tflite_model_semantics.cpp @@ -1,5 +1,5 @@ // -// SPDX-FileCopyrightText: Copyright 2023-2024 Arm Limited and/or its affiliates +// SPDX-FileCopyrightText: Copyright 2023-2025 Arm Limited and/or its affiliates // // SPDX-License-Identifier: Apache-2.0 // @@ -216,31 +216,6 @@ Shape ShapeFromTens(const Tensor *tens) return Shape(); } -Shape _getSliceOffsets(Shape input_shape, const Tensor *offset_tens, int offset_mask, BufferOffsetRef buffers, bool is_begin) -{ - Shape offsets(nullptr, input_shape.Size()); - for ( int i = 0; i < input_shape.Size(); i++ ) - { - // For strided slice operator: get start or end offsets - if ( !is_begin ) - { - offsets[i] = CheckedAdd(offsets[i], input_shape[i]); - } - // If the i:th bit in the mask is not set then the value in offset_tens[i] should be used, otherwise it - // should be ignored - if ( (offset_mask & (1 << i)) == 0 ) - { - offsets[i] = DataFromBuffer(buffers, offset_tens->buffer(), i); - if ( offsets[i] < 0 ) - { - // Convert negative indexing to positive ones - offsets[i] = CheckedAdd(offsets[i], input_shape[i]); - } - } - } - return offsets; -} - void ConstraintEmptyConstTensors(const Model &m_model) { std::unordered_set writtenTensors; @@ -659,35 +634,6 @@ void ConstraintPadOutputShape(const Operator &op, const SubGraph &subgraph, cons } } -void ConstraintSliceRanges(const Operator &op, const SubGraph &subgraph, const BuiltinOperator &builtinOperator, BufferOffsetRef buffers) -{ - auto ifm = TensorFromUsage(regor::TensorUsage::IFM, op, builtinOperator, *subgraph.tensors()); - auto ifmShape = ShapeFromTens(ifm); - - auto begin = TensorFromUsage(MakeTensorUsage(regor::TensorUsage::Params, 0), op, builtinOperator, *subgraph.tensors()); - auto end = TensorFromUsage(MakeTensorUsage(regor::TensorUsage::Params, 1), op, builtinOperator, *subgraph.tensors()); - auto StridedSliceOptions = CheckedPtr(op.builtin_options_as_StridedSliceOptions()); - - auto begin_mask = StridedSliceOptions->begin_mask(); - auto end_mask = StridedSliceOptions->end_mask(); - auto shrink_axis_mask = StridedSliceOptions->shrink_axis_mask(); - - auto offsetBegin = _getSliceOffsets(ifmShape, begin, begin_mask, buffers, true); - auto offsetEnd = _getSliceOffsets(ifmShape, end, end_mask, buffers, false); - assert(offsetBegin.Size() == ifmShape.Size() && offsetEnd.Size() == ifmShape.Size()); - - for ( int i = 0; i < ifmShape.Size(); i++ ) - { - // Note: Vela does some options handling here, which I'm guessing should be done in the TFLite reader in Regor. - if ( offsetEnd[i] <= offsetBegin[i] && (shrink_axis_mask & (1 << i)) == 0 ) - { - std::string constraint = "Slice end values must be greater than begin values"; - std::string extra = fmt::format("Offset begin={}, Offset end={}", offsetBegin.ToString(), offsetEnd.ToString()); - throw InvalidTfLiteException(constraint, extra, op, subgraph, builtinOperator); - } - } -} - void ConstraintMatchingInputsTypes(const Operator &op, const SubGraph &subgraph, const BuiltinOperator &builtinOperator, BufferOffsetRef) { auto ifm = TensorFromUsage(regor::TensorUsage::IFM, op, builtinOperator, *subgraph.tensors()); @@ -994,7 +940,6 @@ regor::ordered_map GetSpecificConstraints() // StridedSliceSpecificChecks specificOpConstraints[BuiltinOperator::STRIDED_SLICE].emplace_back(&ConstraintStridedsliceInputCount); - specificOpConstraints[BuiltinOperator::STRIDED_SLICE].emplace_back(&ConstraintSliceRanges); // FullyConnectedSpecificChecks specificOpConstraints[BuiltinOperator::FULLY_CONNECTED].emplace_back(&ConstraintKeepDimIfmOfm); -- GitLab