8 #include <armnnTestUtils/MockBackend.hpp>
9 #include <armnnTestUtils/MockTensorHandle.hpp>
11 #include <backendsCommon/test/MockBackendId.hpp>
19 const BackendId& MockBackend::GetIdStatic()
21 static const BackendId s_Id{MockBackendId()};
27 static const BackendId s_Id{ MockBackendId() };
30 MockWorkloadFactory::MockWorkloadFactory(
const std::shared_ptr<MockMemoryManager>& memoryManager)
31 : m_MemoryManager(memoryManager)
34 MockWorkloadFactory::MockWorkloadFactory()
35 : m_MemoryManager(new MockMemoryManager())
43 std::unique_ptr<IWorkload> MockWorkloadFactory::CreateWorkload(
LayerType type,
44 const QueueDescriptor& descriptor,
45 const WorkloadInfo& info)
const
49 case LayerType::MemCopy: {
50 auto memCopyQueueDescriptor = PolymorphicDowncast<const MemCopyQueueDescriptor*>(&descriptor);
51 if (descriptor.m_Inputs.empty())
53 throw InvalidArgumentException(
"MockWorkloadFactory: CreateMemCopy() expected an input tensor.");
55 return std::make_unique<CopyMemGenericWorkload>(*memCopyQueueDescriptor, info);
93 const std::string layerName(layer->
GetName());
94 bool optimizable = layerName.find(
"unoptimizable") == std::string::npos;
109 MockBackendInitialiser::MockBackendInitialiser()
118 MockBackendInitialiser::~MockBackendInitialiser()
126 std::cerr <<
"could not deregister mock backend" << std::endl;
133 return IWorkloadFactoryPtr{};
138 return IBackendContextPtr{};
142 const IRuntime::CreationOptions& options, IBackendProfilingPtr& backendProfiling)
145 std::shared_ptr<armnn::MockBackendProfilingContext> context =
146 std::make_shared<MockBackendProfilingContext>(backendProfiling);
147 MockBackendProfilingService::Instance().SetProfilingContextPtr(context);
162 OptimizationViews MockBackend::OptimizeSubgraphView(
const SubgraphView& subgraph)
const
165 OptimizationViews optimizationViews;
174 std::for_each(subgraphLayers.begin(),
175 subgraphLayers.end(),
176 [&](IConnectableLayer* layer)
178 bool supported = IsLayerSupported(PolymorphicDowncast<Layer*>(layer));
182 bool optimizable = IsLayerOptimizable(PolymorphicDowncast<Layer*>(layer));
186 supportedLayers.push_back(layer);
191 untouchedLayers.push_back(layer);
197 unsupportedLayers.push_back(layer);
202 if (!supportedLayers.empty())
205 auto supportedSubgraphSelector = [](
const Layer& layer)
214 SubgraphView mutableSubgraph(subgraph);
219 std::for_each(supportedSubgraphs.begin(),
220 supportedSubgraphs.end(),
223 ARMNN_ASSERT(supportedSubgraph != nullptr);
225 CompiledBlobPtr blobPtr;
226 BackendId backend = MockBackendId();
228 IConnectableLayer* preCompiledLayer =
229 optimizationViews.GetINetwork()->AddPrecompiledLayer(
230 PreCompiledDescriptor(supportedSubgraph->GetNumInputSlots(),
231 supportedSubgraph->GetNumOutputSlots()),
236 SubgraphView substitutionSubgraph(*supportedSubgraph);
237 SubgraphView replacementSubgraph(preCompiledLayer);
239 optimizationViews.AddSubstitution({ substitutionSubgraph, replacementSubgraph });
244 if (!unsupportedLayers.empty())
247 auto unsupportedSubgraphSelector = [](
const Layer& layer)
249 return layer.GetType() != LayerType::Input &&
250 layer.GetType() != LayerType::Output &&
255 SubgraphView mutableSubgraph(subgraph);
256 SubgraphViewSelector::Subgraphs unsupportedSubgraphs =
257 SubgraphViewSelector::SelectSubgraphs(mutableSubgraph, unsupportedSubgraphSelector);
260 std::for_each(unsupportedSubgraphs.begin(),
261 unsupportedSubgraphs.end(),
262 [&optimizationViews](
const SubgraphView::SubgraphViewPtr& unsupportedSubgraph)
264 ARMNN_ASSERT(unsupportedSubgraph != nullptr);
266 optimizationViews.AddFailedSubgraph(SubgraphView(*unsupportedSubgraph));
271 if (!untouchedLayers.empty())
274 auto untouchedSubgraphSelector = [](
const Layer& layer)
276 return layer.GetType() != LayerType::Input &&
277 layer.GetType() != LayerType::Output &&
283 SubgraphView mutableSubgraph(subgraph);
284 SubgraphViewSelector::Subgraphs untouchedSubgraphs =
285 SubgraphViewSelector::SelectSubgraphs(mutableSubgraph, untouchedSubgraphSelector);
288 std::for_each(untouchedSubgraphs.begin(),
289 untouchedSubgraphs.end(),
290 [&optimizationViews](
const SubgraphView::SubgraphViewPtr& untouchedSubgraph)
292 ARMNN_ASSERT(untouchedSubgraph != nullptr);
294 optimizationViews.AddUntouchedSubgraph(SubgraphView(*untouchedSubgraph));
298 return optimizationViews;
301 std::unique_ptr<ICustomAllocator> MockBackend::GetDefaultAllocator()
const
303 return std::make_unique<DefaultAllocator>();