ArmNN
 20.02
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  bool EnableProfiling(bool)
92  {
93  return true;
94  }
95 
96 private:
97  IBackendInternal::IBackendProfilingPtr m_BackendProfiling;
98  uint32_t m_CapturePeriod;
99  std::vector<uint16_t> m_ActiveCounters;
100 };
101 
103 {
104 public:
105  // Getter for the singleton instance
107  {
108  static MockBackendProfilingService instance;
109  return instance;
110  }
111 
113  {
114  return m_sharedContext.get();
115  }
116 
117  void SetProfilingContextPtr(std::shared_ptr<MockBackendProfilingContext> shared)
118  {
119  m_sharedContext = shared;
120  }
121 
122 private:
123  std::shared_ptr<MockBackendProfilingContext> m_sharedContext;
124 };
125 
127 {
128 public:
129  MockBackend() = default;
130  ~MockBackend() = default;
131 
132  static const BackendId& GetIdStatic();
133  const BackendId& GetId() const override
134  {
135  return GetIdStatic();
136  }
137 
138  IBackendInternal::IMemoryManagerUniquePtr CreateMemoryManager() const override;
139 
141  CreateWorkloadFactory(const IBackendInternal::IMemoryManagerSharedPtr& memoryManager = nullptr) const override;
142 
143  IBackendInternal::IBackendContextPtr CreateBackendContext(const IRuntime::CreationOptions&) const override;
145  CreateBackendProfilingContext(const IRuntime::CreationOptions& creationOptions,
146  IBackendProfilingPtr& backendProfiling) override;
147 
148  IBackendInternal::Optimizations GetOptimizations() const override;
149  IBackendInternal::ILayerSupportSharedPtr GetLayerSupport() const override;
150 
151  OptimizationViews OptimizeSubgraphView(const SubgraphView& subgraph) const override;
152 };
153 
155 {
156 public:
157  bool IsInputSupported(const TensorInfo& /*input*/,
158  Optional<std::string&> /*reasonIfUnsupported = EmptyOptional()*/) const override
159  {
160  return true;
161  }
162 
163  bool IsOutputSupported(const TensorInfo& /*input*/,
164  Optional<std::string&> /*reasonIfUnsupported = EmptyOptional()*/) const override
165  {
166  return true;
167  }
168 
169  bool IsAdditionSupported(const TensorInfo& /*input0*/,
170  const TensorInfo& /*input1*/,
171  const TensorInfo& /*output*/,
172  Optional<std::string&> /*reasonIfUnsupported = EmptyOptional()*/) const override
173  {
174  return true;
175  }
176 
177  bool IsConvolution2dSupported(const TensorInfo& /*input*/,
178  const TensorInfo& /*output*/,
179  const Convolution2dDescriptor& /*descriptor*/,
180  const TensorInfo& /*weights*/,
181  const Optional<TensorInfo>& /*biases*/,
182  Optional<std::string&> /*reasonIfUnsupported = EmptyOptional()*/) const override
183  {
184  return true;
185  }
186 };
187 
188 } // namespace armnn
MockBackendProfilingContext(IBackendInternal::IBackendProfilingPtr &backendProfiling)
Definition: MockBackend.hpp:32
std::unique_ptr< IWorkloadFactory > IWorkloadFactoryPtr
void SetProfilingContextPtr(std::shared_ptr< MockBackendProfilingContext > shared)
std::vector< OptimizationPtr > Optimizations
bool IsOutputSupported(const TensorInfo &, Optional< std::string &>) const override
A Convolution2dDescriptor for the Convolution2dLayer.
bool IsInputSupported(const TensorInfo &, Optional< std::string &>) const override
Copyright (c) 2020 ARM Limited.
std::unique_ptr< IMemoryManager > IMemoryManagerUniquePtr
const BackendId & GetId() const override
The SubgraphView class represents a subgraph of a Graph.
Optional< std::string > ActivateCounters(uint32_t capturePeriod, const std::vector< uint16_t > &counterIds)
Definition: MockBackend.hpp:63
std::unique_ptr< armnn::profiling::IBackendProfiling > IBackendProfilingPtr
std::shared_ptr< IMemoryManager > IMemoryManagerSharedPtr
bool IsConvolution2dSupported(const TensorInfo &, const TensorInfo &, const Convolution2dDescriptor &, const TensorInfo &, const Optional< TensorInfo > &, Optional< std::string &>) const override
static MockBackendProfilingService & Instance()
bool IsAdditionSupported(const TensorInfo &, const TensorInfo &, const TensorInfo &, Optional< std::string &>) const override
std::shared_ptr< ILayerSupport > ILayerSupportSharedPtr
MockBackendProfilingContext * GetContext()
std::vector< profiling::Timestamp > ReportCounterValues()
Definition: MockBackend.hpp:78
IBackendInternal::IBackendProfilingPtr & GetBackendProfiling()
Definition: MockBackend.hpp:39
std::shared_ptr< armnn::profiling::IBackendProfilingContext > IBackendProfilingContextPtr
This is the bridge between backend and backend profiling we&#39;ll keep it in the backend namespace...
uint16_t RegisterCounters(uint16_t currentMaxGlobalCounterId)
Definition: MockBackend.hpp:44
std::unique_ptr< IBackendContext > IBackendContextPtr