// // Copyright © 2017 Arm Ltd. All rights reserved. // SPDX-License-Identifier: MIT // #pragma once #include #include #include #include #include #include "OptimizationViews.hpp" #include namespace armnn { class IWorkloadFactory; class IBackendContext; class IMemoryManager; class Optimization; class ILayerSupport; class IBackendInternal : public IBackend { protected: // Creation must be done through a specific // backend interface. IBackendInternal() = default; public: // Allow backends created by the factory function // to be destroyed through IBackendInternal. ~IBackendInternal() override = default; using IWorkloadFactoryPtr = std::unique_ptr; using IBackendContextPtr = std::unique_ptr; using OptimizationPtr = std::unique_ptr; using Optimizations = std::vector; using ILayerSupportSharedPtr = std::shared_ptr; using IMemoryManagerUniquePtr = std::unique_ptr; using IMemoryManagerSharedPtr = std::shared_ptr; using GraphUniquePtr = std::unique_ptr; using SubgraphViewUniquePtr = std::unique_ptr; virtual IMemoryManagerUniquePtr CreateMemoryManager() const = 0; virtual IWorkloadFactoryPtr CreateWorkloadFactory( const IMemoryManagerSharedPtr& memoryManager = nullptr) const = 0; virtual IBackendContextPtr CreateBackendContext(const IRuntime::CreationOptions&) const = 0; virtual Optimizations GetOptimizations() const = 0; virtual ILayerSupportSharedPtr GetLayerSupport() const = 0; ARMNN_DEPRECATED_MSG("Use \"OptimizationViews OptimizeSubgraphView(const SubgraphView&)\" instead") virtual SubgraphViewUniquePtr OptimizeSubgraphView(const SubgraphView& subgraph, bool& optimizationAttempted) const { optimizationAttempted = false; return nullptr; } // Default implementation of OptimizeSubgraphView for backward compatibility with old API. // Override this method with a custom optimization implementation. virtual OptimizationViews OptimizeSubgraphView(const SubgraphView& subgraph) const { bool optimizationAttempted = false; ARMNN_NO_DEPRECATE_WARN_BEGIN SubgraphViewUniquePtr optSubgraph = OptimizeSubgraphView(subgraph, optimizationAttempted); ARMNN_NO_DEPRECATE_WARN_END OptimizationViews result; if (!optimizationAttempted) { result.AddUntouchedSubgraph(SubgraphView(subgraph)); } else { if (optSubgraph) { result.AddSubstitution({subgraph, SubgraphView(*optSubgraph.get())}); } else { result.AddFailedSubgraph(SubgraphView(subgraph)); } } return result; } }; using IBackendInternalUniquePtr = std::unique_ptr; } // namespace armnn