aboutsummaryrefslogtreecommitdiff
path: root/src/backends/cl/workloads/ClBaseWorkload.hpp
blob: 03417e33aee68ec90bdd5b018d380193fd221299 (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
//
// Copyright © 2022 Arm Ltd and Contributors. All rights reserved.
// SPDX-License-Identifier: MIT
//

#pragma once

#include <armnn/backends/Workload.hpp>

namespace armnn
{
template <typename QueueDescriptor>
class ClBaseWorkload : public BaseWorkload<QueueDescriptor>
{
public:
    ClBaseWorkload(const QueueDescriptor& descriptor, const WorkloadInfo& info)
            : BaseWorkload<QueueDescriptor>(descriptor, info)
    {}

    // Replace input tensor handle with the given TensorHandle and call Reconfigure()
    void ReplaceInputTensorHandle(ITensorHandle* tensorHandle, unsigned int slot) override
    {
        ITensorHandle* backupHandle = this->m_Data.m_Inputs[slot];
        this->m_Data.m_Inputs[slot] = tensorHandle;
        try
        {
            Reconfigure();
        }
        catch(armnn::UnimplementedException& e)
        {
            // Cannot reconfigure, revert the slot back and throw the exception.
            this->m_Data.m_Inputs[slot] = backupHandle;
            throw e;
        }
    }

    // Replace output tensor handle with the given TensorHandle and call Reconfigure()
    void ReplaceOutputTensorHandle(ITensorHandle* tensorHandle, unsigned int slot) override
    {
        ITensorHandle* backupHandle = this->m_Data.m_Outputs[slot];
        this->m_Data.m_Outputs[slot] = tensorHandle;
        try
        {
            Reconfigure();
        }
        catch(armnn::UnimplementedException& e)
        {
            // Cannot reconfigure, revert the slot back and throw the exception.
            this->m_Data.m_Inputs[slot] = backupHandle;
            throw e;
        }
    }

protected:
    // Reconfigure the workload configuration. Throw armnn::UnimplementedException by default.
    virtual void Reconfigure()
    {
        throw armnn::UnimplementedException("Reconfigure not implemented for this workload");
    }
};
} //namespace armnn