blob: d1cb2deea343c82771954dab90e892217d56a150 [file] [log] [blame]
Laurent Carlier749294b2020-06-01 09:03:17 +01001//
telsoa014fcda012018-03-09 14:13:49 +00002// Copyright © 2017 Arm Ltd. All rights reserved.
David Beckecb56cd2018-09-05 12:52:57 +01003// SPDX-License-Identifier: MIT
telsoa014fcda012018-03-09 14:13:49 +00004//
5#pragma once
6
Matteo Martincighe5b8eb92019-11-28 15:45:42 +00007#include <armnn/backends/ITensorHandle.hpp>
8#include <armnn/backends/ITensorHandleFactory.hpp>
telsoa014fcda012018-03-09 14:13:49 +00009
Aron Virginas-Tarc9cc8042018-11-01 16:15:57 +000010#include <armnn/Descriptors.hpp>
11#include <armnn/INetwork.hpp>
12#include <armnn/Tensor.hpp>
13#include <armnn/Types.hpp>
14
telsoa014fcda012018-03-09 14:13:49 +000015#include <memory>
16#include <set>
Aron Virginas-Tarc9cc8042018-11-01 16:15:57 +000017#include <string>
18#include <vector>
telsoa014fcda012018-03-09 14:13:49 +000019
telsoa014fcda012018-03-09 14:13:49 +000020namespace armnn
21{
22
23class ITensorHandle;
24class IWorkloadFactory;
25class OutputSlot;
26class WorkloadDataCollector;
27
28class OutputHandler
29{
30public:
telsoa01c577f2c2018-08-31 09:22:23 +010031 /// @brief - Sets the TensorInfo used by this output handler.
32 /// @param tensorInfo - TensorInfo for the output.
telsoa014fcda012018-03-09 14:13:49 +000033 void SetTensorInfo(const TensorInfo& tensorInfo);
34
Derek Lamberti84da38b2019-06-13 11:40:08 +010035 /// @brief - Creates tensor handles used by the intermediate tensors. Does not allocate memory.
telsoa01c577f2c2018-08-31 09:22:23 +010036 /// @param factory - Factory to be used for handler creation.
David Monahan3fb7e102019-08-20 11:25:29 +010037 void CreateTensorHandles(const IWorkloadFactory& factory, const bool IsMemoryManaged = true);
38 void CreateTensorHandles(const ITensorHandleFactory& factory, const bool IsMemoryManaged = true);
Francis Murtagh351d13d2018-09-24 15:01:18 +010039
telsoa01c577f2c2018-08-31 09:22:23 +010040 /// @brief - Gets the matching TensorInfo for the output.
41 /// @return - References to the output TensorInfo.
telsoa014fcda012018-03-09 14:13:49 +000042 const TensorInfo& GetTensorInfo() const { return m_TensorInfo; }
43
telsoa01c577f2c2018-08-31 09:22:23 +010044 /// @brief - Gets the allocated tensor memory.
45 /// @return - Pointer to the tensor memory.
telsoa014fcda012018-03-09 14:13:49 +000046 ITensorHandle* GetData() const { return m_TensorHandle.get(); }
47
telsoa01c577f2c2018-08-31 09:22:23 +010048 /// Fill the outputs for a given queue descriptor.
telsoa014fcda012018-03-09 14:13:49 +000049 void CollectWorkloadOutputs(WorkloadDataCollector& dataCollector) const;
50
51 void SetData(std::unique_ptr<ITensorHandle> data) { m_TensorHandle = std::move(data); }
52
Narumol Prangnawaratec5463d2022-02-04 17:50:20 +000053 void SetAllocatedData();
Narumol Prangnawarate2af6f42022-01-28 17:59:18 +000054
Narumol Prangnawaratec5463d2022-02-04 17:50:20 +000055 void UseAllocatedData() { m_TensorHandle = m_AllocatedTensorHandle; }
Narumol Prangnawarate2af6f42022-01-28 17:59:18 +000056
telsoa014fcda012018-03-09 14:13:49 +000057 /// @brief Returns true if SetTensorInfo() has been called at least once on this.
58 bool IsTensorInfoSet() const { return m_bTensorInfoSet; }
59private:
Narumol Prangnawaratec5463d2022-02-04 17:50:20 +000060 std::shared_ptr<ITensorHandle> m_TensorHandle;
61 std::shared_ptr<ITensorHandle> m_AllocatedTensorHandle;
telsoa014fcda012018-03-09 14:13:49 +000062 TensorInfo m_TensorInfo;
63 bool m_bTensorInfoSet = false;
64};
65
66} //namespace armnn