aboutsummaryrefslogtreecommitdiff
path: root/delegate/opaque/src/test/DelegateTestInterpreter.cpp
blob: 04e6ad6208d99b5f9a4bfc197d60623266f24b91 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
//
// Copyright © 2023 Arm Ltd and Contributors. All rights reserved.
// SPDX-License-Identifier: MIT
//

#include <DelegateTestInterpreter.hpp>

#include <armnn_delegate.hpp>

#include <armnn/utility/IgnoreUnused.hpp>

namespace delegateTestInterpreter
{

DelegateTestInterpreter::DelegateTestInterpreter(std::vector<char>& modelBuffer,
                                                 const std::vector<armnn::BackendId>& backends,
                                                 const std::string& customOp,
                                                 bool disableFallback)
{
    armnn::IgnoreUnused(backends);
    armnn::IgnoreUnused(disableFallback);

    TfLiteModel* tfLiteModel = delegateTestInterpreter::CreateTfLiteModel(modelBuffer);

    TfLiteInterpreterOptions* options = delegateTestInterpreter::CreateTfLiteInterpreterOptions();
    if (!customOp.empty())
    {
        options->mutable_op_resolver = delegateTestInterpreter::GenerateCustomOpResolver(customOp);
    }

    // Use default settings until options have been enabled.
    auto armnnDelegate = armnnOpaqueDelegate::TfLiteArmnnOpaqueDelegateCreate(nullptr);
    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)
{
    armnn::IgnoreUnused(delegateOptions);

    TfLiteModel* tfLiteModel = delegateTestInterpreter::CreateTfLiteModel(modelBuffer);

    TfLiteInterpreterOptions* options = delegateTestInterpreter::CreateTfLiteInterpreterOptions();
    if (!customOp.empty())
    {
        options->mutable_op_resolver = delegateTestInterpreter::GenerateCustomOpResolver(customOp);
    }

    // Use default settings until options have been enabled.
    auto armnnDelegate = armnnOpaqueDelegate::TfLiteArmnnOpaqueDelegateCreate(nullptr);
    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)
    {
        armnnOpaqueDelegate::TfLiteArmnnOpaqueDelegateDelete(static_cast<TfLiteOpaqueDelegate*>(m_TfLiteDelegate));
    }
}

} // anonymous namespace