#include <backendsCommon/CpuTensorHandle.hpp>
#include <backendsCommon/WorkloadFactory.hpp>
+#include <backendsCommon/BackendRegistry.hpp>
+#include <backendsCommon/IBackendInternal.hpp>
#include <armnn/Exceptions.hpp>
#include <armnn/Utils.hpp>
return IOptimizedNetworkPtr(nullptr, &IOptimizedNetwork::Destroy);
};
+ // The backends that we choose to run layers on
+ std::unordered_set<BackendId> chosenBackends;
+
// Assign a compute device for all nodes
bool bErrorFound = false;
for (auto&& layer : optNetObjPtr->GetGraph())
else
{
found = true;
+ chosenBackends.insert(backend);
break;
}
}
layerType == armnn::LayerType::Permute))
{
layer->SetBackendId(armnn::Compute::CpuRef);
+ chosenBackends.insert(armnn::Compute::CpuRef);
}
else
{
Optimizer::Pass(optNetObjPtr->GetGraph(), MakeOptimizations(ConvertConstantsFloatToHalf()));
Optimizer::Pass(optNetObjPtr->GetGraph(), MakeOptimizations(ConvertConstantsHalfToFloat()));
+ // Run backend specific optimizations
+ for (auto&& chosenBackend : chosenBackends)
+ {
+ auto factoryFun = BackendRegistryInstance().GetFactory(chosenBackend);
+ auto backendPtr = factoryFun();
+ BOOST_ASSERT(backendPtr.get() != nullptr);
+
+ auto backendSpecificOptimizations = backendPtr->GetOptimizations();
+ if (!backendSpecificOptimizations.empty())
+ {
+ Optimizer::Pass(optNetObjPtr->GetGraph(), backendSpecificOptimizations);
+ }
+ }
+
return optNet;
}
#include <armnn/Types.hpp>
#include <armnn/IRuntime.hpp>
+#include <vector>
namespace armnn
{
class IWorkloadFactory;
class IBackendContext;
+class Optimization;
class IBackendInternal : public IBackend
{
using IWorkloadFactoryPtr = std::unique_ptr<IWorkloadFactory>;
using IBackendContextPtr = std::unique_ptr<IBackendContext>;
+ using OptimizationPtr = std::unique_ptr<Optimization>;
+ using Optimizations = std::vector<OptimizationPtr>;
virtual IWorkloadFactoryPtr CreateWorkloadFactory() const = 0;
virtual IBackendContextPtr CreateBackendContext(const IRuntime::CreationOptions&) const = 0;
+ virtual Optimizations GetOptimizations() const = 0;
};
using IBackendInternalUniquePtr = std::unique_ptr<IBackendInternal>;
#include "ClWorkloadFactory.hpp"
#include "ClBackendContext.hpp"
+#include <backendsCommon/IBackendContext.hpp>
#include <backendsCommon/BackendRegistry.hpp>
+#include <Optimizer.hpp>
namespace armnn
{
return IBackendContextPtr{new ClBackendContext{options}};
}
+IBackendInternal::Optimizations ClBackend::GetOptimizations() const
+{
+ return Optimizations{};
+}
} // namespace armnn
//
#pragma once
-#include <backendsCommon/IBackendContext.hpp>
#include <backendsCommon/IBackendInternal.hpp>
namespace armnn
IBackendInternal::IWorkloadFactoryPtr CreateWorkloadFactory() const override;
IBackendInternal::IBackendContextPtr CreateBackendContext(const IRuntime::CreationOptions&) const override;
+ IBackendInternal::Optimizations GetOptimizations() const override;
};
} // namespace armnn
\ No newline at end of file
#include "NeonBackendId.hpp"
#include "NeonWorkloadFactory.hpp"
+#include <backendsCommon/IBackendContext.hpp>
#include <backendsCommon/BackendRegistry.hpp>
+#include <Optimizer.hpp>
#include <boost/cast.hpp>
return std::make_unique<NeonWorkloadFactory>();
}
+IBackendInternal::IBackendContextPtr NeonBackend::CreateBackendContext(const IRuntime::CreationOptions&) const
+{
+ return IBackendContextPtr{};
+}
+
+IBackendInternal::Optimizations NeonBackend::GetOptimizations() const
+{
+ return Optimizations{};
+}
+
} // namespace armnn
\ No newline at end of file
//
#pragma once
-#include <backendsCommon/IBackendContext.hpp>
#include <backendsCommon/IBackendInternal.hpp>
namespace armnn
const BackendId& GetId() const override { return GetIdStatic(); }
IWorkloadFactoryPtr CreateWorkloadFactory() const override;
-
- IBackendInternal::IBackendContextPtr CreateBackendContext(const IRuntime::CreationOptions&) const override
- {
- return IBackendContextPtr{};
- }
+ IBackendInternal::IBackendContextPtr CreateBackendContext(const IRuntime::CreationOptions&) const override;
+ IBackendInternal::Optimizations GetOptimizations() const override;
};
} // namespace armnn
\ No newline at end of file
#include "RefBackendId.hpp"
#include "RefWorkloadFactory.hpp"
+#include <backendsCommon/IBackendContext.hpp>
#include <backendsCommon/BackendRegistry.hpp>
+#include <Optimizer.hpp>
#include <boost/cast.hpp>
return std::make_unique<RefWorkloadFactory>();
}
+IBackendInternal::IBackendContextPtr RefBackend::CreateBackendContext(const IRuntime::CreationOptions&) const
+{
+ return IBackendContextPtr{};
+}
+
+IBackendInternal::Optimizations RefBackend::GetOptimizations() const
+{
+ return Optimizations{};
+}
+
} // namespace armnn
\ No newline at end of file
//
#pragma once
-#include <backendsCommon/IBackendContext.hpp>
#include <backendsCommon/IBackendInternal.hpp>
namespace armnn
const BackendId& GetId() const override { return GetIdStatic(); }
IBackendInternal::IWorkloadFactoryPtr CreateWorkloadFactory() const override;
-
- IBackendInternal::IBackendContextPtr CreateBackendContext(const IRuntime::CreationOptions&) const override
- {
- return IBackendContextPtr{};
- }
+ IBackendInternal::IBackendContextPtr CreateBackendContext(const IRuntime::CreationOptions&) const override;
+ IBackendInternal::Optimizations GetOptimizations() const override;
};
} // namespace armnn
\ No newline at end of file