Matteo Martincigh | 88054f8 | 2019-05-17 12:15:30 +0100 | [diff] [blame] | 1 | // |
| 2 | // Copyright © 2017 Arm Ltd. All rights reserved. |
| 3 | // SPDX-License-Identifier: MIT |
| 4 | // |
| 5 | |
| 6 | #pragma once |
| 7 | |
David Monahan | c1536d6 | 2020-02-12 15:52:35 +0000 | [diff] [blame] | 8 | #include "armnn/backends/profiling/IBackendProfiling.hpp" |
| 9 | #include "armnn/backends/profiling/IBackendProfilingContext.hpp" |
| 10 | #include "MockBackendId.hpp" |
| 11 | |
Colm Donelan | 1aff393 | 2020-02-05 17:48:59 +0000 | [diff] [blame] | 12 | #include <LayerSupportCommon.hpp> |
Matteo Martincigh | e5b8eb9 | 2019-11-28 15:45:42 +0000 | [diff] [blame] | 13 | #include <armnn/backends/IBackendInternal.hpp> |
| 14 | #include <armnn/backends/OptimizationViews.hpp> |
David Monahan | 7f2c35a | 2019-05-24 10:46:28 +0100 | [diff] [blame] | 15 | #include <backendsCommon/LayerSupportBase.hpp> |
Finn Williams | 032bc74 | 2020-02-12 11:02:34 +0000 | [diff] [blame^] | 16 | #include <armnn/backends/profiling/IBackendProfiling.hpp> |
| 17 | #include <backends/BackendProfiling.hpp> |
Matteo Martincigh | 88054f8 | 2019-05-17 12:15:30 +0100 | [diff] [blame] | 18 | |
| 19 | namespace armnn |
| 20 | { |
| 21 | |
David Monahan | c1536d6 | 2020-02-12 15:52:35 +0000 | [diff] [blame] | 22 | class MockBackendInitialiser |
| 23 | { |
| 24 | public: |
| 25 | MockBackendInitialiser(); |
| 26 | ~MockBackendInitialiser(); |
| 27 | }; |
| 28 | |
| 29 | class MockBackendProfilingService |
| 30 | { |
| 31 | public: |
| 32 | // Getter for the singleton instance |
| 33 | static MockBackendProfilingService& Instance() |
| 34 | { |
| 35 | static MockBackendProfilingService instance; |
| 36 | return instance; |
| 37 | } |
| 38 | |
| 39 | armnn::profiling::IBackendProfilingContext* GetContext() |
| 40 | { |
| 41 | return m_sharedContext.get(); |
| 42 | } |
| 43 | |
| 44 | void SetProfilingContextPtr(IBackendInternal::IBackendProfilingContextPtr& shared) |
| 45 | { |
| 46 | m_sharedContext = shared; |
| 47 | } |
| 48 | |
| 49 | private: |
| 50 | IBackendInternal::IBackendProfilingContextPtr m_sharedContext; |
| 51 | }; |
| 52 | |
| 53 | class MockBackendProfilingContext : public profiling::IBackendProfilingContext |
| 54 | { |
| 55 | public: |
| 56 | MockBackendProfilingContext(IBackendInternal::IBackendProfilingPtr& backendProfiling) |
| 57 | : m_BackendProfiling(backendProfiling) |
Finn Williams | 032bc74 | 2020-02-12 11:02:34 +0000 | [diff] [blame^] | 58 | , m_CapturePeriod(0) |
David Monahan | c1536d6 | 2020-02-12 15:52:35 +0000 | [diff] [blame] | 59 | {} |
| 60 | |
| 61 | ~MockBackendProfilingContext() = default; |
| 62 | |
| 63 | IBackendInternal::IBackendProfilingPtr& GetBackendProfiling() |
| 64 | { |
| 65 | return m_BackendProfiling; |
| 66 | } |
| 67 | |
| 68 | uint16_t RegisterCounters(uint16_t currentMaxGlobalCounterId) |
| 69 | { |
| 70 | std::unique_ptr<profiling::IRegisterBackendCounters> counterRegistrar = |
| 71 | m_BackendProfiling->GetCounterRegistrationInterface(currentMaxGlobalCounterId); |
| 72 | |
| 73 | std::string categoryName("MockCounters"); |
| 74 | counterRegistrar->RegisterCategory(categoryName); |
| 75 | uint16_t nextMaxGlobalCounterId = counterRegistrar->RegisterCounter( |
| 76 | 0, categoryName, 0, 0, 1.f, "Mock Counter One", "Some notional counter"); |
| 77 | |
| 78 | nextMaxGlobalCounterId = counterRegistrar->RegisterCounter( |
| 79 | 1, categoryName, 0, 0, 1.f, "Mock Counter Two", "Another notional counter"); |
| 80 | |
| 81 | std::string units("microseconds"); |
| 82 | nextMaxGlobalCounterId = counterRegistrar->RegisterCounter( |
| 83 | 2, categoryName, 0, 0, 1.f, "Mock MultiCore Counter", "A dummy four core counter", units, 4); |
| 84 | return nextMaxGlobalCounterId; |
| 85 | } |
| 86 | |
Finn Williams | 032bc74 | 2020-02-12 11:02:34 +0000 | [diff] [blame^] | 87 | Optional<std::string> ActivateCounters(uint32_t capturePeriod, const std::vector<uint16_t>& counterIds) |
| 88 | { |
| 89 | if ( capturePeriod == 0 || counterIds.size() == 0) |
| 90 | { |
| 91 | m_ActiveCounters.clear(); |
| 92 | } |
| 93 | else if (capturePeriod == 15939u) |
| 94 | { |
| 95 | return armnn::Optional<std::string>("ActivateCounters example test error"); |
| 96 | } |
| 97 | m_CapturePeriod = capturePeriod; |
| 98 | m_ActiveCounters = counterIds; |
| 99 | return armnn::Optional<std::string>(); |
| 100 | } |
David Monahan | c1536d6 | 2020-02-12 15:52:35 +0000 | [diff] [blame] | 101 | |
| 102 | std::vector<profiling::Timestamp> ReportCounterValues() |
| 103 | { |
Finn Williams | 032bc74 | 2020-02-12 11:02:34 +0000 | [diff] [blame^] | 104 | std::vector<profiling::CounterValue> counterValues; |
| 105 | |
| 106 | for(auto counterId : m_ActiveCounters) |
| 107 | { |
| 108 | counterValues.emplace_back(profiling::CounterValue{counterId, counterId+1u}); |
| 109 | } |
| 110 | |
| 111 | uint64_t timestamp = m_CapturePeriod; |
| 112 | return {profiling::Timestamp{timestamp, counterValues}}; |
David Monahan | c1536d6 | 2020-02-12 15:52:35 +0000 | [diff] [blame] | 113 | } |
| 114 | |
| 115 | void EnableProfiling(bool) |
| 116 | {} |
| 117 | |
| 118 | private: |
Finn Williams | 032bc74 | 2020-02-12 11:02:34 +0000 | [diff] [blame^] | 119 | |
David Monahan | c1536d6 | 2020-02-12 15:52:35 +0000 | [diff] [blame] | 120 | IBackendInternal::IBackendProfilingPtr& m_BackendProfiling; |
Finn Williams | 032bc74 | 2020-02-12 11:02:34 +0000 | [diff] [blame^] | 121 | uint32_t m_CapturePeriod; |
| 122 | std::vector<uint16_t> m_ActiveCounters; |
David Monahan | c1536d6 | 2020-02-12 15:52:35 +0000 | [diff] [blame] | 123 | }; |
Colm Donelan | 1aff393 | 2020-02-05 17:48:59 +0000 | [diff] [blame] | 124 | |
Matteo Martincigh | 88054f8 | 2019-05-17 12:15:30 +0100 | [diff] [blame] | 125 | class MockBackend : public IBackendInternal |
| 126 | { |
| 127 | public: |
| 128 | MockBackend() = default; |
| 129 | ~MockBackend() = default; |
| 130 | |
| 131 | static const BackendId& GetIdStatic(); |
Colm Donelan | 1aff393 | 2020-02-05 17:48:59 +0000 | [diff] [blame] | 132 | const BackendId& GetId() const override |
| 133 | { |
| 134 | return GetIdStatic(); |
| 135 | } |
Matteo Martincigh | 88054f8 | 2019-05-17 12:15:30 +0100 | [diff] [blame] | 136 | |
| 137 | IBackendInternal::IMemoryManagerUniquePtr CreateMemoryManager() const override; |
| 138 | |
Colm Donelan | 1aff393 | 2020-02-05 17:48:59 +0000 | [diff] [blame] | 139 | IBackendInternal::IWorkloadFactoryPtr |
| 140 | CreateWorkloadFactory(const IBackendInternal::IMemoryManagerSharedPtr& memoryManager = nullptr) const override; |
Matteo Martincigh | 88054f8 | 2019-05-17 12:15:30 +0100 | [diff] [blame] | 141 | |
| 142 | IBackendInternal::IBackendContextPtr CreateBackendContext(const IRuntime::CreationOptions&) const override; |
Colm Donelan | 1aff393 | 2020-02-05 17:48:59 +0000 | [diff] [blame] | 143 | IBackendInternal::IBackendProfilingContextPtr |
| 144 | CreateBackendProfilingContext(const IRuntime::CreationOptions& creationOptions, |
| 145 | IBackendProfilingPtr& backendProfiling) override; |
Matteo Martincigh | 88054f8 | 2019-05-17 12:15:30 +0100 | [diff] [blame] | 146 | |
| 147 | IBackendInternal::Optimizations GetOptimizations() const override; |
| 148 | IBackendInternal::ILayerSupportSharedPtr GetLayerSupport() const override; |
| 149 | |
| 150 | OptimizationViews OptimizeSubgraphView(const SubgraphView& subgraph) const override; |
| 151 | }; |
| 152 | |
Colm Donelan | 1aff393 | 2020-02-05 17:48:59 +0000 | [diff] [blame] | 153 | class MockLayerSupport : public LayerSupportBase |
| 154 | { |
David Monahan | 7f2c35a | 2019-05-24 10:46:28 +0100 | [diff] [blame] | 155 | public: |
Derek Lamberti | 901ea11 | 2019-12-10 22:07:09 +0000 | [diff] [blame] | 156 | bool IsInputSupported(const TensorInfo& /*input*/, |
| 157 | Optional<std::string&> /*reasonIfUnsupported = EmptyOptional()*/) const override |
David Monahan | 7f2c35a | 2019-05-24 10:46:28 +0100 | [diff] [blame] | 158 | { |
| 159 | return true; |
| 160 | } |
| 161 | |
Derek Lamberti | 901ea11 | 2019-12-10 22:07:09 +0000 | [diff] [blame] | 162 | bool IsOutputSupported(const TensorInfo& /*input*/, |
Colm Donelan | 1aff393 | 2020-02-05 17:48:59 +0000 | [diff] [blame] | 163 | Optional<std::string&> /*reasonIfUnsupported = EmptyOptional()*/) const override |
David Monahan | 7f2c35a | 2019-05-24 10:46:28 +0100 | [diff] [blame] | 164 | { |
| 165 | return true; |
| 166 | } |
| 167 | |
Derek Lamberti | 901ea11 | 2019-12-10 22:07:09 +0000 | [diff] [blame] | 168 | bool IsAdditionSupported(const TensorInfo& /*input0*/, |
| 169 | const TensorInfo& /*input1*/, |
| 170 | const TensorInfo& /*output*/, |
| 171 | Optional<std::string&> /*reasonIfUnsupported = EmptyOptional()*/) const override |
David Monahan | 7f2c35a | 2019-05-24 10:46:28 +0100 | [diff] [blame] | 172 | { |
| 173 | return true; |
| 174 | } |
| 175 | |
Derek Lamberti | 901ea11 | 2019-12-10 22:07:09 +0000 | [diff] [blame] | 176 | bool IsConvolution2dSupported(const TensorInfo& /*input*/, |
| 177 | const TensorInfo& /*output*/, |
| 178 | const Convolution2dDescriptor& /*descriptor*/, |
| 179 | const TensorInfo& /*weights*/, |
| 180 | const Optional<TensorInfo>& /*biases*/, |
| 181 | Optional<std::string&> /*reasonIfUnsupported = EmptyOptional()*/) const override |
David Monahan | 7f2c35a | 2019-05-24 10:46:28 +0100 | [diff] [blame] | 182 | { |
| 183 | return true; |
| 184 | } |
| 185 | }; |
| 186 | |
Colm Donelan | 1aff393 | 2020-02-05 17:48:59 +0000 | [diff] [blame] | 187 | } // namespace armnn |