add_definitions(-DARMNNREF_ENABLED)
endif()
+# ArmNN dynamic backend
+if(DYNAMIC_BACKEND_PATHS)
+ add_definitions(-DARMNN_DYNAMIC_BACKEND_ENABLED)
+endif()
+
# Streamline annotate
if(PROFILING_BACKEND_STREAMLINE)
include_directories("${GATOR_ROOT}/annotate")
}
};
+ void Deregister(const BackendId& id);
+
protected:
using FactoryStorage = std::unordered_map<BackendId, FactoryFunction>;
m_Factories[id] = factory;
}
+void BackendRegistry::Deregister(const BackendId& id)
+{
+ m_Factories.erase(id);
+}
+
bool BackendRegistry::IsBackendRegistered(const BackendId& id) const
{
return (m_Factories.find(id) != m_Factories.end());
return m_SupportedBackends;
}
- void AddSupportedBackends(const BackendIdSet& backendIds)
+ void AddSupportedBackends(const BackendIdSet& backendIds, bool isDynamic = false)
{
m_SupportedBackends.insert(backendIds.begin(), backendIds.end());
+ if (isDynamic)
+ {
+ m_DynamicBackends.insert(backendIds.begin(), backendIds.end());
+ }
+ }
+
+ void ClearDynamicBackends()
+ {
+ for (const auto& id : m_DynamicBackends)
+ {
+ m_SupportedBackends.erase(id);
+ }
+ m_DynamicBackends.clear();
+ }
+
+ const BackendIdSet& GetDynamicBackends() const
+ {
+ return m_DynamicBackends;
}
private:
DeviceSpec() = delete;
BackendIdSet m_SupportedBackends;
+ BackendIdSet m_DynamicBackends;
};
} // namespace armnn
<< std::endl;
}
}
+
+ // Clear all dynamic backends.
+ DynamicBackendUtils::DeregisterDynamicBackends(m_DeviceSpec.GetDynamicBackends());
+ m_DeviceSpec.ClearDynamicBackends();
}
LoadedNetwork* Runtime::GetLoadedNetworkPtr(NetworkId networkId) const
BackendIdSet registeredBackendIds = DynamicBackendUtils::RegisterDynamicBackends(m_DynamicBackends);
// Add the registered dynamic backend ids to the list of supported backends
- m_DeviceSpec.AddSupportedBackends(registeredBackendIds);
+ m_DeviceSpec.AddSupportedBackends(registeredBackendIds, true);
}
} // namespace armnn
return dynamicBackends;
}
+void DynamicBackendUtils::DeregisterDynamicBackends(const BackendIdSet& dynamicBackends)
+{
+ // Get a reference of the backend registry
+ BackendRegistry& backendRegistry = BackendRegistryInstance();
+
+ for (const auto& id : dynamicBackends)
+ {
+ backendRegistry.Deregister(id);
+ }
+
+}
+
BackendIdSet DynamicBackendUtils::RegisterDynamicBackends(const std::vector<DynamicBackendPtr>& dynamicBackends)
{
// Get a reference of the backend registry
static std::vector<DynamicBackendPtr> CreateDynamicBackends(const std::vector<std::string>& sharedObjects);
static BackendIdSet RegisterDynamicBackends(const std::vector<DynamicBackendPtr>& dynamicBackends);
+ static void DeregisterDynamicBackends(const BackendIdSet& dynamicBackends);
protected:
/// Protected methods for testing purposes
ARMNN_SIMPLE_TEST_CASE(RegisterMultipleInvalidDynamicBackends, RegisterMultipleInvalidDynamicBackendsTestImpl);
ARMNN_SIMPLE_TEST_CASE(RegisterMixedDynamicBackends, RegisterMixedDynamicBackendsTestImpl);
+#if !defined(ARMNN_DYNAMIC_BACKEND_ENABLED)
ARMNN_SIMPLE_TEST_CASE(RuntimeEmpty, RuntimeEmptyTestImpl);
+#endif
ARMNN_SIMPLE_TEST_CASE(RuntimeDynamicBackends, RuntimeDynamicBackendsTestImpl);
ARMNN_SIMPLE_TEST_CASE(RuntimeDuplicateDynamicBackends, RuntimeDuplicateDynamicBackendsTestImpl);
ARMNN_SIMPLE_TEST_CASE(RuntimeInvalidDynamicBackends, RuntimeInvalidDynamicBackendsTestImpl);
}
}
+#if !defined(ARMNN_DYNAMIC_BACKEND_ENABLED)
+
void RuntimeEmptyTestImpl()
{
using namespace armnn;
BOOST_TEST(backendRegistry.Size() == 0);
}
+#endif
+
void RuntimeDynamicBackendsTestImpl()
{
using namespace armnn;
{
case LayerType::Input:
++m_inputLayerCount;
- if (layer->GetGuid() == profiling::ProfilingGuid(0))
- {
- BOOST_TEST(layer->GetName() == "inLayer0");
- }
- else if (layer->GetGuid() == profiling::ProfilingGuid(1))
- {
- BOOST_TEST(layer->GetName() == "inLayer1");
- }
+ BOOST_TEST((layer->GetName() == std::string("inLayer0") ||
+ layer->GetName() == std::string("inLayer1")));
break;
// The Addition layer should become a PreCompiled Layer after Optimisation
case LayerType::PreCompiled:
--- /dev/null
+#
+# Copyright © 2019 Arm Ltd. All rights reserved.
+# SPDX-License-Identifier: MIT
+#
+
+cmake_minimum_required (VERSION 3.0.2)
+
+set(CMAKE_POSITION_INDEPENDENT_CODE ON)
+
+# File needed to wrap the existing backend into a dynamic one
+list(APPEND armnnRefDynamicBackend_sources
+ RefDynamicBackend.cpp
+ RefDynamicBackend.hpp
+)
+
+# Set the backend source path
+set(RefBackendPath ${PROJECT_SOURCE_DIR}/../../../src/backends/reference)
+
+# Source files of the backend, taken directly from the source tree
+file(GLOB RefBackendBaseFiles ${RefBackendPath}/*.cpp)
+file(GLOB RefBackendWorloadFiles ${RefBackendPath}/workloads/*.cpp)
+set(RefBackendFiles ${RefBackendBaseFiles} ${RefBackendWorloadFiles})
+
+# Remove the file that contains the static backend registration
+list(REMOVE_ITEM RefBackendFiles ${RefBackendPath}/RefRegistryInitializer.cpp)
+
+# Create the shared object
+add_library(Arm_CpuRef_backend MODULE ${armnnRefDynamicBackend_sources} ${RefBackendFiles})
+
+target_include_directories(Arm_CpuRef_backend PRIVATE ${PROJECT_SOURCE_DIR}/../../../include)
+target_include_directories(Arm_CpuRef_backend PRIVATE ${PROJECT_SOURCE_DIR}/../../../third-party) # for half
+target_include_directories(Arm_CpuRef_backend PRIVATE ${PROJECT_SOURCE_DIR}/../../../src/armnn)
+target_include_directories(Arm_CpuRef_backend PRIVATE ${PROJECT_SOURCE_DIR}/../../../src/armnnUtils)
+target_include_directories(Arm_CpuRef_backend PRIVATE ${PROJECT_SOURCE_DIR}/../../../src/backends)
+target_include_directories(Arm_CpuRef_backend PRIVATE ${PROJECT_SOURCE_DIR}/../../../src/profiling)
\ No newline at end of file
--- /dev/null
+//
+// Copyright © 2019 Arm Ltd. All rights reserved.
+// SPDX-License-Identifier: MIT
+//
+
+#include "RefDynamicBackend.hpp"
+
+#include <reference/RefBackend.hpp>
+
+using namespace armnn;
+
+const char* GetBackendId()
+{
+ return RefBackend::GetIdStatic().Get().c_str();
+}
+
+void GetVersion(uint32_t* outMajor, uint32_t* outMinor)
+{
+ if (!outMajor || !outMinor)
+ {
+ return;
+ }
+
+ BackendVersion apiVersion = IBackendInternal::GetApiVersion();
+
+ *outMajor = apiVersion.m_Major;
+ *outMinor = apiVersion.m_Minor;
+}
+
+void* BackendFactory()
+{
+ return new RefBackend();
+}
--- /dev/null
+//
+// Copyright © 2019 Arm Ltd. All rights reserved.
+// SPDX-License-Identifier: MIT
+//
+
+#pragma once
+
+#include <cstdint>
+
+extern "C"
+{
+const char* GetBackendId();
+void GetVersion(uint32_t* outMajor, uint32_t* outMinor);
+void* BackendFactory();
+}