blob: 04e6ad6208d99b5f9a4bfc197d60623266f24b91 [file] [log] [blame]
Matthew Sloyan65c21a12023-04-04 12:06:14 +01001//
2// Copyright © 2023 Arm Ltd and Contributors. All rights reserved.
3// SPDX-License-Identifier: MIT
4//
5
6#include <DelegateTestInterpreter.hpp>
7
8#include <armnn_delegate.hpp>
9
10#include <armnn/utility/IgnoreUnused.hpp>
11
12namespace delegateTestInterpreter
13{
14
15DelegateTestInterpreter::DelegateTestInterpreter(std::vector<char>& modelBuffer,
16 const std::vector<armnn::BackendId>& backends,
17 const std::string& customOp,
18 bool disableFallback)
19{
20 armnn::IgnoreUnused(backends);
21 armnn::IgnoreUnused(disableFallback);
22
23 TfLiteModel* tfLiteModel = delegateTestInterpreter::CreateTfLiteModel(modelBuffer);
24
25 TfLiteInterpreterOptions* options = delegateTestInterpreter::CreateTfLiteInterpreterOptions();
26 if (!customOp.empty())
27 {
28 options->mutable_op_resolver = delegateTestInterpreter::GenerateCustomOpResolver(customOp);
29 }
30
31 // Use default settings until options have been enabled.
32 auto armnnDelegate = armnnOpaqueDelegate::TfLiteArmnnOpaqueDelegateCreate(nullptr);
33 TfLiteInterpreterOptionsAddDelegate(options, armnnDelegate);
34
35 m_TfLiteDelegate = armnnDelegate;
36 m_TfLiteInterpreter = TfLiteInterpreterCreate(tfLiteModel, options);
37
38 // The options and model can be deleted after the interpreter is created.
39 TfLiteInterpreterOptionsDelete(options);
40 TfLiteModelDelete(tfLiteModel);
41}
42
43DelegateTestInterpreter::DelegateTestInterpreter(std::vector<char>& modelBuffer,
44 const armnnDelegate::DelegateOptions& delegateOptions,
45 const std::string& customOp)
46{
47 armnn::IgnoreUnused(delegateOptions);
48
49 TfLiteModel* tfLiteModel = delegateTestInterpreter::CreateTfLiteModel(modelBuffer);
50
51 TfLiteInterpreterOptions* options = delegateTestInterpreter::CreateTfLiteInterpreterOptions();
52 if (!customOp.empty())
53 {
54 options->mutable_op_resolver = delegateTestInterpreter::GenerateCustomOpResolver(customOp);
55 }
56
57 // Use default settings until options have been enabled.
58 auto armnnDelegate = armnnOpaqueDelegate::TfLiteArmnnOpaqueDelegateCreate(nullptr);
59 TfLiteInterpreterOptionsAddDelegate(options, armnnDelegate);
60
61 m_TfLiteDelegate = armnnDelegate;
62 m_TfLiteInterpreter = TfLiteInterpreterCreate(tfLiteModel, options);
63
64 // The options and model can be deleted after the interpreter is created.
65 TfLiteInterpreterOptionsDelete(options);
66 TfLiteModelDelete(tfLiteModel);
67}
68
69void DelegateTestInterpreter::Cleanup()
70{
71 TfLiteInterpreterDelete(m_TfLiteInterpreter);
72
73 if (m_TfLiteDelegate)
74 {
75 armnnOpaqueDelegate::TfLiteArmnnOpaqueDelegateDelete(static_cast<TfLiteOpaqueDelegate*>(m_TfLiteDelegate));
76 }
77}
78
79} // anonymous namespace