diff options
author | Matthew Sloyan <matthew.sloyan@arm.com> | 2023-03-30 10:12:08 +0100 |
---|---|---|
committer | ryan.oshea3 <ryan.oshea3@arm.com> | 2023-04-05 20:36:32 +0000 |
commit | ebe392df1635790bf21714549adb97f2f75559e1 (patch) | |
tree | 6fb8e56cc755d7c47a62bbe72c54b6ca5445377d /delegate/classic | |
parent | ac9607f401dc30003aa97bd179a06d6b8a32139f (diff) | |
download | armnn-ebe392df1635790bf21714549adb97f2f75559e1.tar.gz |
IVGCVSW-7562 Implement DelegateTestInterpreter for classic delegate
* Updated all tests to use new DelegateTestInterpreter.
* Fixed some unit tests where the shape was incorrect.
* Add file identifier to FlatBuffersBuilder, as it is required for
validation when creating the model using new API.
Signed-off-by: Matthew Sloyan <matthew.sloyan@arm.com>
Change-Id: I1c4f5464367b35d4528571fa94d14bfaef18fb4d
Diffstat (limited to 'delegate/classic')
-rw-r--r-- | delegate/classic/src/test/DelegateTestInterpreter.cpp | 74 |
1 files changed, 74 insertions, 0 deletions
diff --git a/delegate/classic/src/test/DelegateTestInterpreter.cpp b/delegate/classic/src/test/DelegateTestInterpreter.cpp new file mode 100644 index 0000000000..45b6cd0932 --- /dev/null +++ b/delegate/classic/src/test/DelegateTestInterpreter.cpp @@ -0,0 +1,74 @@ +// +// Copyright © 2023 Arm Ltd and Contributors. All rights reserved. +// SPDX-License-Identifier: MIT +// + +#include <DelegateTestInterpreter.hpp> + +#include <armnn_delegate.hpp> + +namespace delegateTestInterpreter +{ + +DelegateTestInterpreter::DelegateTestInterpreter(std::vector<char>& modelBuffer, + const std::vector<armnn::BackendId>& backends, + const std::string& customOp, + bool disableFallback) +{ + TfLiteModel* tfLiteModel = delegateTestInterpreter::CreateTfLiteModel(modelBuffer); + + TfLiteInterpreterOptions* options = delegateTestInterpreter::CreateTfLiteInterpreterOptions(); + if (!customOp.empty()) + { + options->mutable_op_resolver = delegateTestInterpreter::GenerateCustomOpResolver(customOp); + } + + // Disable fallback by default for unit tests unless specified. + armnnDelegate::DelegateOptions delegateOptions(backends); + delegateOptions.DisableTfLiteRuntimeFallback(disableFallback); + + auto armnnDelegate = armnnDelegate::TfLiteArmnnDelegateCreate(delegateOptions); + TfLiteInterpreterOptionsAddDelegate(options, armnnDelegate); + + m_TfLiteDelegate = armnnDelegate; + m_TfLiteInterpreter = TfLiteInterpreterCreate(tfLiteModel, options); + + // The options and model can be deleted after the interpreter is created. + TfLiteInterpreterOptionsDelete(options); + TfLiteModelDelete(tfLiteModel); +} + +DelegateTestInterpreter::DelegateTestInterpreter(std::vector<char>& modelBuffer, + const armnnDelegate::DelegateOptions& delegateOptions, + const std::string& customOp) +{ + TfLiteModel* tfLiteModel = delegateTestInterpreter::CreateTfLiteModel(modelBuffer); + + TfLiteInterpreterOptions* options = delegateTestInterpreter::CreateTfLiteInterpreterOptions(); + if (!customOp.empty()) + { + options->mutable_op_resolver = delegateTestInterpreter::GenerateCustomOpResolver(customOp); + } + + auto armnnDelegate = armnnDelegate::TfLiteArmnnDelegateCreate(delegateOptions); + TfLiteInterpreterOptionsAddDelegate(options, armnnDelegate); + + m_TfLiteDelegate = armnnDelegate; + m_TfLiteInterpreter = TfLiteInterpreterCreate(tfLiteModel, options); + + // The options and model can be deleted after the interpreter is created. + TfLiteInterpreterOptionsDelete(options); + TfLiteModelDelete(tfLiteModel); +} + +void DelegateTestInterpreter::Cleanup() +{ + TfLiteInterpreterDelete(m_TfLiteInterpreter); + + if (m_TfLiteDelegate) + { + armnnDelegate::TfLiteArmnnDelegateDelete(static_cast<TfLiteDelegate*>(m_TfLiteDelegate)); + } +} + +} // anonymous namespace
\ No newline at end of file |