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