From eb74d97642473cd8bd836f8fe02246510edce052 Mon Sep 17 00:00:00 2001 From: Alexander Bengtsson Date: Sat, 29 Mar 2025 09:37:12 +0100 Subject: [PATCH] MLBEDSW-10567: Add supported-op checks for Pad - Constrain parameters to 32 or 64-bits. Change-Id: I5f8c4d7e56586701bec3765c1be1ab379c522c7b Signed-off-by: Alexander Bengtsson --- .../tflite/tflite_supported_operators.cpp | 22 +++++++++++++++++++ .../tflite/tflite_supported_operators.hpp | 1 + 2 files changed, 23 insertions(+) diff --git a/ethosu/regor/tflite/tflite_supported_operators.cpp b/ethosu/regor/tflite/tflite_supported_operators.cpp index 6f472221..5cd6f57b 100644 --- a/ethosu/regor/tflite/tflite_supported_operators.cpp +++ b/ethosu/regor/tflite/tflite_supported_operators.cpp @@ -574,6 +574,9 @@ bool TfLiteSupportedOperators::ConstraintConstParams(const Operation *op) { case OpType::Slice: case OpType::Mean: + case OpType::Pad: + case OpType::PadV2: + case OpType::MirrorPad: break; default: return true; @@ -722,6 +725,24 @@ bool TfLiteSupportedOperators::ConstraintSoftmax(const Operation *op) return true; } +bool TfLiteSupportedOperators::ConstraintPad(const Operation *op) +{ + OpType opType = op->Type(); + if ( opType != OpType::Pad && opType != OpType::PadV2 && opType != OpType::MirrorPad ) + { + return true; + } + auto params = op->Input(TensorUsage::Params); + assert(params); + const auto &pType = params->tensor->Type(); + if ( pType != DataType::Int32 && pType != DataType::Int64 ) + { + Failure(op, fmt::format("Params tensor with datatype: {}", DataTypeToString(pType)), "Params tensor must be Int32 or Int64."); + return false; + } + return true; +} + void TfLiteSupportedOperators::Failure(const Operation *op, const std::string &message, const std::string &constraint) { assert(op); @@ -778,6 +799,7 @@ TfLiteSupportedOperators::TfLiteSupportedOperators(IArchitectureConstraints *con &TfLiteSupportedOperators::ConstraintConstParams, &TfLiteSupportedOperators::ConstraintMean, &TfLiteSupportedOperators::ConstraintSoftmax, + &TfLiteSupportedOperators::ConstraintPad, }; } diff --git a/ethosu/regor/tflite/tflite_supported_operators.hpp b/ethosu/regor/tflite/tflite_supported_operators.hpp index 92552e41..b2e3ebba 100644 --- a/ethosu/regor/tflite/tflite_supported_operators.hpp +++ b/ethosu/regor/tflite/tflite_supported_operators.hpp @@ -71,5 +71,6 @@ private: bool ConstraintConstParams(const Operation *op); bool ConstraintMean(const Operation *op); bool ConstraintSoftmax(const Operation *op); + bool ConstraintPad(const Operation *op); }; } // namespace regor -- GitLab