return dynamicBackends;
}
-void DynamicBackendUtils::RegisterDynamicBackends(const std::vector<DynamicBackendPtr>& dynamicBackends)
+BackendIdSet DynamicBackendUtils::RegisterDynamicBackends(const std::vector<DynamicBackendPtr>& dynamicBackends)
{
// Get a reference of the backend registry
BackendRegistry& backendRegistry = BackendRegistryInstance();
- // Register the dynamic backends in the backend registry
- RegisterDynamicBackendsImpl(backendRegistry, dynamicBackends);
+ // Register the dynamic backends in the backend registry, and return a list of registered backend ids
+ return RegisterDynamicBackendsImpl(backendRegistry, dynamicBackends);
}
-void DynamicBackendUtils::RegisterDynamicBackendsImpl(BackendRegistry& backendRegistry,
- const std::vector<DynamicBackendPtr>& dynamicBackends)
+BackendIdSet DynamicBackendUtils::RegisterDynamicBackendsImpl(BackendRegistry& backendRegistry,
+ const std::vector<DynamicBackendPtr>& dynamicBackends)
{
+ // Initialize the list of registered backend ids
+ BackendIdSet registeredBackendIds;
+
// Register the dynamic backends in the backend registry
for (const DynamicBackendPtr& dynamicBackend : dynamicBackends)
{
+ // Get the id of the dynamic backend
BackendId dynamicBackendId;
try
{
}
// Register the dynamic backend
- backendRegistry.Register(dynamicBackendId, dynamicBackendFactoryFunction);
+ try
+ {
+ backendRegistry.Register(dynamicBackendId, dynamicBackendFactoryFunction);
+ }
+ catch (const InvalidArgumentException& e)
+ {
+ BOOST_LOG_TRIVIAL(warning) << "An error has occurred when registering the dynamic backend \""
+ << dynamicBackendId << "\": " << e.what();
+ continue;
+ }
+
+ // Add the id of the dynamic backend just registered to the list of registered backend ids
+ registeredBackendIds.insert(dynamicBackendId);
}
+
+ return registeredBackendIds;
}
} // namespace armnn
return GetBackendPathsImpl(path);
}
- static void RegisterDynamicBackendsImplTest(armnn::BackendRegistry& backendRegistry,
- const std::vector<armnn::DynamicBackendPtr>& dynamicBackends)
+ static armnn::BackendIdSet RegisterDynamicBackendsImplTest(
+ armnn::BackendRegistry& backendRegistry,
+ const std::vector<armnn::DynamicBackendPtr>& dynamicBackends)
{
- RegisterDynamicBackendsImpl(backendRegistry, dynamicBackends);
+ return RegisterDynamicBackendsImpl(backendRegistry, dynamicBackends);
}
};
BackendVersion dynamicBackendVersion = dynamicBackends[0]->GetBackendVersion();
BOOST_TEST(TestDynamicBackendUtils::IsBackendCompatible(dynamicBackendVersion));
- TestDynamicBackendUtils::RegisterDynamicBackendsImplTest(backendRegistry, dynamicBackends);
+ BackendIdSet registeredBackendIds = TestDynamicBackendUtils::RegisterDynamicBackendsImplTest(backendRegistry,
+ dynamicBackends);
BOOST_TEST(backendRegistry.Size() == 1);
+ BOOST_TEST(registeredBackendIds.size() == 1);
BackendIdSet backendIds = backendRegistry.GetBackendIds();
BOOST_TEST(backendIds.size() == 1);
BOOST_TEST((backendIds.find(dynamicBackendId) != backendIds.end()));
+ BOOST_TEST((registeredBackendIds.find(dynamicBackendId) != registeredBackendIds.end()));
auto dynamicBackendFactoryFunction = backendRegistry.GetFactory(dynamicBackendId);
BOOST_TEST((dynamicBackendFactoryFunction != nullptr));
BackendRegistry backendRegistry;
BOOST_TEST(backendRegistry.Size() == 0);
- TestDynamicBackendUtils::RegisterDynamicBackendsImplTest(backendRegistry, dynamicBackends);
+ BackendIdSet registeredBackendIds = TestDynamicBackendUtils::RegisterDynamicBackendsImplTest(backendRegistry,
+ dynamicBackends);
BOOST_TEST(backendRegistry.Size() == 3);
+ BOOST_TEST(registeredBackendIds.size() == 3);
BackendIdSet backendIds = backendRegistry.GetBackendIds();
BOOST_TEST(backendIds.size() == 3);
BOOST_TEST((backendIds.find(dynamicBackendId1) != backendIds.end()));
BOOST_TEST((backendIds.find(dynamicBackendId2) != backendIds.end()));
BOOST_TEST((backendIds.find(dynamicBackendId3) != backendIds.end()));
+ BOOST_TEST((registeredBackendIds.find(dynamicBackendId1) != registeredBackendIds.end()));
+ BOOST_TEST((registeredBackendIds.find(dynamicBackendId2) != registeredBackendIds.end()));
+ BOOST_TEST((registeredBackendIds.find(dynamicBackendId3) != registeredBackendIds.end()));
for (size_t i = 0; i < dynamicBackends.size(); i++)
{
BOOST_TEST(backendRegistry.Size() == 0);
// Check that no dynamic backend got registered
- TestDynamicBackendUtils::RegisterDynamicBackendsImplTest(backendRegistry, dynamicBackends);
+ BackendIdSet registeredBackendIds = TestDynamicBackendUtils::RegisterDynamicBackendsImplTest(backendRegistry,
+ dynamicBackends);
BOOST_TEST(backendRegistry.Size() == 0);
+ BOOST_TEST(registeredBackendIds.empty());
}
void RegisterMixedDynamicBackendsTestImpl()
"TestValid5"
};
- TestDynamicBackendUtils::RegisterDynamicBackendsImplTest(backendRegistry, dynamicBackends);
+ BackendIdSet registeredBackendIds = TestDynamicBackendUtils::RegisterDynamicBackendsImplTest(backendRegistry,
+ dynamicBackends);
BOOST_TEST(backendRegistry.Size() == expectedRegisteredbackendIds.size());
+ BOOST_TEST(registeredBackendIds.size() == expectedRegisteredbackendIds.size());
BackendIdSet backendIds = backendRegistry.GetBackendIds();
BOOST_TEST(backendIds.size() == expectedRegisteredbackendIds.size());
for (const BackendId& expectedRegisteredbackendId : expectedRegisteredbackendIds)
{
BOOST_TEST((backendIds.find(expectedRegisteredbackendId) != backendIds.end()));
+ BOOST_TEST((registeredBackendIds.find(expectedRegisteredbackendId) != registeredBackendIds.end()));
auto dynamicBackendFactoryFunction = backendRegistry.GetFactory(expectedRegisteredbackendId);
BOOST_TEST((dynamicBackendFactoryFunction != nullptr));
// Swapping the backend registry storage for testing
TestBackendRegistry testBackendRegistry;
+ const BackendRegistry& backendRegistry = BackendRegistryInstance();
+ BOOST_TEST(backendRegistry.Size() == 0);
+
IRuntime::CreationOptions creationOptions;
IRuntimePtr runtime = IRuntime::Create(creationOptions);
- const BackendRegistry& backendRegistry = BackendRegistryInstance();
+ const DeviceSpec& deviceSpec = *boost::polymorphic_downcast<const DeviceSpec*>(&runtime->GetDeviceSpec());
+ BackendIdSet supportedBackendIds = deviceSpec.GetSupportedBackends();
+ BOOST_TEST(supportedBackendIds.empty());
+
BOOST_TEST(backendRegistry.Size() == 0);
}
{
BOOST_TEST((backendIds.find(expectedRegisteredbackendId) != backendIds.end()));
}
+
+ const DeviceSpec& deviceSpec = *boost::polymorphic_downcast<const DeviceSpec*>(&runtime->GetDeviceSpec());
+ BackendIdSet supportedBackendIds = deviceSpec.GetSupportedBackends();
+ BOOST_TEST(supportedBackendIds.size() == expectedRegisteredbackendIds.size());
+ for (const BackendId& expectedRegisteredbackendId : expectedRegisteredbackendIds)
+ {
+ BOOST_TEST((supportedBackendIds.find(expectedRegisteredbackendId) != supportedBackendIds.end()));
+ }
}
void RuntimeDuplicateDynamicBackendsTestImpl()
{
BOOST_TEST((backendIds.find(expectedRegisteredbackendId) != backendIds.end()));
}
+
+ const DeviceSpec& deviceSpec = *boost::polymorphic_downcast<const DeviceSpec*>(&runtime->GetDeviceSpec());
+ BackendIdSet supportedBackendIds = deviceSpec.GetSupportedBackends();
+ BOOST_TEST(supportedBackendIds.size() == expectedRegisteredbackendIds.size());
+ for (const BackendId& expectedRegisteredbackendId : expectedRegisteredbackendIds)
+ {
+ BOOST_TEST((supportedBackendIds.find(expectedRegisteredbackendId) != supportedBackendIds.end()));
+ }
}
void RuntimeInvalidDynamicBackendsTestImpl()
const BackendRegistry& backendRegistry = BackendRegistryInstance();
BOOST_TEST(backendRegistry.Size() == 0);
+
+ const DeviceSpec& deviceSpec = *boost::polymorphic_downcast<const DeviceSpec*>(&runtime->GetDeviceSpec());
+ BackendIdSet supportedBackendIds = deviceSpec.GetSupportedBackends();
+ BOOST_TEST(supportedBackendIds.empty());
}
void RuntimeInvalidOverridePathTestImpl()
const BackendRegistry& backendRegistry = BackendRegistryInstance();
BOOST_TEST(backendRegistry.Size() == 0);
+
+ const DeviceSpec& deviceSpec = *boost::polymorphic_downcast<const DeviceSpec*>(&runtime->GetDeviceSpec());
+ BackendIdSet supportedBackendIds = deviceSpec.GetSupportedBackends();
+ BOOST_TEST(supportedBackendIds.empty());
}
void CreateReferenceDynamicBackendTestImpl()
BackendIdSet backendIds = backendRegistry.GetBackendIds();
BOOST_TEST((backendIds.find("CpuRef") != backendIds.end()));
+ const DeviceSpec& deviceSpec = *boost::polymorphic_downcast<const DeviceSpec*>(&runtime->GetDeviceSpec());
+ BackendIdSet supportedBackendIds = deviceSpec.GetSupportedBackends();
+ BOOST_TEST(supportedBackendIds.size() == 1);
+ BOOST_TEST((supportedBackendIds.find("CpuRef") != supportedBackendIds.end()));
+
// Get the factory function
auto referenceDynamicBackendFactoryFunction = backendRegistry.GetFactory("CpuRef");
BOOST_TEST((referenceDynamicBackendFactoryFunction != nullptr));