Matteo Martincigh | d73cecb | 2019-07-24 09:15:00 +0100 | [diff] [blame] | 1 | // |
| 2 | // Copyright © 2017 Arm Ltd. All rights reserved. |
| 3 | // SPDX-License-Identifier: MIT |
| 4 | // |
| 5 | |
Matteo Martincigh | e5b8eb9 | 2019-11-28 15:45:42 +0000 | [diff] [blame] | 6 | #include <backendsCommon/DynamicBackendUtils.hpp> |
Matteo Martincigh | d73cecb | 2019-07-24 09:15:00 +0100 | [diff] [blame] | 7 | |
Jan Eilers | 4a539fc | 2019-07-25 17:08:37 +0100 | [diff] [blame] | 8 | #include <boost/filesystem.hpp> |
Matteo Martincigh | e7d4498 | 2019-08-05 12:16:47 +0100 | [diff] [blame] | 9 | #include <boost/algorithm/string.hpp> |
Matteo Martincigh | e7d4498 | 2019-08-05 12:16:47 +0100 | [diff] [blame] | 10 | |
Jan Eilers | 4a539fc | 2019-07-25 17:08:37 +0100 | [diff] [blame] | 11 | #include <regex> |
| 12 | |
Matteo Martincigh | d73cecb | 2019-07-24 09:15:00 +0100 | [diff] [blame] | 13 | namespace armnn |
| 14 | { |
| 15 | |
| 16 | void* DynamicBackendUtils::OpenHandle(const std::string& sharedObjectPath) |
| 17 | { |
Rob Hughes | 91e1d89 | 2019-08-23 10:11:58 +0100 | [diff] [blame] | 18 | #if defined(__unix__) |
Matteo Martincigh | d73cecb | 2019-07-24 09:15:00 +0100 | [diff] [blame] | 19 | if (sharedObjectPath.empty()) |
| 20 | { |
| 21 | throw RuntimeException("OpenHandle error: shared object path must not be empty"); |
| 22 | } |
| 23 | |
Matteo Martincigh | e54aa06 | 2019-08-05 14:12:11 +0100 | [diff] [blame] | 24 | void* sharedObjectHandle = dlopen(sharedObjectPath.c_str(), RTLD_LAZY); |
Matteo Martincigh | d73cecb | 2019-07-24 09:15:00 +0100 | [diff] [blame] | 25 | if (!sharedObjectHandle) |
| 26 | { |
Matteo Martincigh | b19d2e9 | 2019-07-25 14:04:40 +0100 | [diff] [blame] | 27 | throw RuntimeException(boost::str(boost::format("OpenHandle error: %1%") % GetDlError())); |
Matteo Martincigh | d73cecb | 2019-07-24 09:15:00 +0100 | [diff] [blame] | 28 | } |
| 29 | |
| 30 | return sharedObjectHandle; |
Rob Hughes | 91e1d89 | 2019-08-23 10:11:58 +0100 | [diff] [blame] | 31 | #else |
| 32 | throw RuntimeException("Dynamic backends not supported on this platform"); |
| 33 | #endif |
Matteo Martincigh | d73cecb | 2019-07-24 09:15:00 +0100 | [diff] [blame] | 34 | } |
| 35 | |
| 36 | void DynamicBackendUtils::CloseHandle(const void* sharedObjectHandle) |
| 37 | { |
Rob Hughes | 91e1d89 | 2019-08-23 10:11:58 +0100 | [diff] [blame] | 38 | #if defined(__unix__) |
Matteo Martincigh | d73cecb | 2019-07-24 09:15:00 +0100 | [diff] [blame] | 39 | if (!sharedObjectHandle) |
| 40 | { |
| 41 | return; |
| 42 | } |
| 43 | |
| 44 | dlclose(const_cast<void*>(sharedObjectHandle)); |
Rob Hughes | 91e1d89 | 2019-08-23 10:11:58 +0100 | [diff] [blame] | 45 | #else |
| 46 | throw RuntimeException("Dynamic backends not supported on this platform"); |
| 47 | #endif |
Matteo Martincigh | d73cecb | 2019-07-24 09:15:00 +0100 | [diff] [blame] | 48 | } |
| 49 | |
Matteo Martincigh | ac60d28 | 2019-07-25 15:25:44 +0100 | [diff] [blame] | 50 | bool DynamicBackendUtils::IsBackendCompatible(const BackendVersion &backendVersion) |
| 51 | { |
| 52 | BackendVersion backendApiVersion = IBackendInternal::GetApiVersion(); |
| 53 | |
| 54 | return IsBackendCompatibleImpl(backendApiVersion, backendVersion); |
| 55 | } |
| 56 | |
| 57 | bool DynamicBackendUtils::IsBackendCompatibleImpl(const BackendVersion &backendApiVersion, |
| 58 | const BackendVersion &backendVersion) |
| 59 | { |
| 60 | return backendVersion.m_Major == backendApiVersion.m_Major && |
| 61 | backendVersion.m_Minor <= backendApiVersion.m_Minor; |
| 62 | } |
| 63 | |
Matteo Martincigh | d73cecb | 2019-07-24 09:15:00 +0100 | [diff] [blame] | 64 | std::string DynamicBackendUtils::GetDlError() |
| 65 | { |
Rob Hughes | 91e1d89 | 2019-08-23 10:11:58 +0100 | [diff] [blame] | 66 | #if defined(__unix__) |
Matteo Martincigh | d73cecb | 2019-07-24 09:15:00 +0100 | [diff] [blame] | 67 | const char* errorMessage = dlerror(); |
| 68 | if (!errorMessage) |
| 69 | { |
| 70 | return ""; |
| 71 | } |
| 72 | |
| 73 | return std::string(errorMessage); |
Rob Hughes | 91e1d89 | 2019-08-23 10:11:58 +0100 | [diff] [blame] | 74 | #else |
| 75 | throw RuntimeException("Dynamic backends not supported on this platform"); |
| 76 | #endif |
Matteo Martincigh | d73cecb | 2019-07-24 09:15:00 +0100 | [diff] [blame] | 77 | } |
| 78 | |
Matteo Martincigh | e7d4498 | 2019-08-05 12:16:47 +0100 | [diff] [blame] | 79 | std::vector<std::string> DynamicBackendUtils::GetBackendPaths(const std::string& overrideBackendPath) |
| 80 | { |
| 81 | // Check if a path where to dynamically load the backends from is given |
| 82 | if (!overrideBackendPath.empty()) |
| 83 | { |
| 84 | if (!IsPathValid(overrideBackendPath)) |
| 85 | { |
Derek Lamberti | 0844697 | 2019-11-26 16:38:31 +0000 | [diff] [blame] | 86 | ARMNN_LOG(warning) << "WARNING: The given override path for dynamic backends \"" |
| 87 | << overrideBackendPath << "\" is not valid"; |
Matteo Martincigh | e7d4498 | 2019-08-05 12:16:47 +0100 | [diff] [blame] | 88 | |
| 89 | return {}; |
| 90 | } |
| 91 | |
| 92 | return std::vector<std::string>{ overrideBackendPath }; |
| 93 | } |
| 94 | |
| 95 | // Expects a colon-separated list: DYNAMIC_BACKEND_PATHS="PATH_1:PATH_2:...:PATH_N" |
| 96 | const std::string backendPaths = DYNAMIC_BACKEND_PATHS; |
| 97 | |
| 98 | return GetBackendPathsImpl(backendPaths); |
| 99 | } |
| 100 | |
| 101 | std::vector<std::string> DynamicBackendUtils::GetBackendPathsImpl(const std::string& backendPaths) |
| 102 | { |
Matteo Martincigh | f97a5de | 2019-08-12 14:07:59 +0100 | [diff] [blame] | 103 | // Check if there's any path to process at all |
| 104 | if (backendPaths.empty()) |
| 105 | { |
| 106 | // Silently return without issuing a warning as no paths have been passed, so |
| 107 | // the whole dynamic backend loading feature can be considered as disabled |
| 108 | return {}; |
| 109 | } |
| 110 | |
Matteo Martincigh | e7d4498 | 2019-08-05 12:16:47 +0100 | [diff] [blame] | 111 | std::unordered_set<std::string> uniqueBackendPaths; |
| 112 | std::vector<std::string> tempBackendPaths; |
| 113 | std::vector<std::string> validBackendPaths; |
| 114 | |
| 115 | // Split the given list of paths |
| 116 | boost::split(tempBackendPaths, backendPaths, boost::is_any_of(":")); |
| 117 | |
| 118 | for (const std::string& path : tempBackendPaths) |
| 119 | { |
| 120 | // Check whether the path is valid |
| 121 | if (!IsPathValid(path)) |
| 122 | { |
| 123 | continue; |
| 124 | } |
| 125 | |
| 126 | // Check whether the path is a duplicate |
| 127 | auto it = uniqueBackendPaths.find(path); |
| 128 | if (it != uniqueBackendPaths.end()) |
| 129 | { |
| 130 | // The path is a duplicate |
| 131 | continue; |
| 132 | } |
| 133 | |
| 134 | // Add the path to the set of unique paths |
| 135 | uniqueBackendPaths.insert(path); |
| 136 | |
| 137 | // Add the path to the list of valid paths |
| 138 | validBackendPaths.push_back(path); |
| 139 | } |
| 140 | |
| 141 | return validBackendPaths; |
| 142 | } |
| 143 | |
| 144 | bool DynamicBackendUtils::IsPathValid(const std::string& path) |
| 145 | { |
| 146 | if (path.empty()) |
| 147 | { |
Derek Lamberti | 0844697 | 2019-11-26 16:38:31 +0000 | [diff] [blame] | 148 | ARMNN_LOG(warning) << "WARNING: The given backend path is empty"; |
Matteo Martincigh | e7d4498 | 2019-08-05 12:16:47 +0100 | [diff] [blame] | 149 | return false; |
| 150 | } |
| 151 | |
| 152 | boost::filesystem::path boostPath(path); |
| 153 | |
| 154 | if (!boost::filesystem::exists(boostPath)) |
| 155 | { |
Derek Lamberti | 0844697 | 2019-11-26 16:38:31 +0000 | [diff] [blame] | 156 | ARMNN_LOG(warning) << "WARNING: The given backend path \"" << path << "\" does not exist"; |
Matteo Martincigh | e7d4498 | 2019-08-05 12:16:47 +0100 | [diff] [blame] | 157 | return false; |
| 158 | } |
| 159 | |
| 160 | if (!boost::filesystem::is_directory(boostPath)) |
| 161 | { |
Derek Lamberti | 0844697 | 2019-11-26 16:38:31 +0000 | [diff] [blame] | 162 | ARMNN_LOG(warning) << "WARNING: The given backend path \"" << path << "\" is not a directory"; |
Matteo Martincigh | e7d4498 | 2019-08-05 12:16:47 +0100 | [diff] [blame] | 163 | return false; |
| 164 | } |
| 165 | |
| 166 | if (!boostPath.is_absolute()) |
| 167 | { |
Derek Lamberti | 0844697 | 2019-11-26 16:38:31 +0000 | [diff] [blame] | 168 | ARMNN_LOG(warning) << "WARNING: The given backend path \"" << path << "\" is not absolute"; |
Matteo Martincigh | e7d4498 | 2019-08-05 12:16:47 +0100 | [diff] [blame] | 169 | return false; |
| 170 | } |
| 171 | |
| 172 | return true; |
| 173 | } |
| 174 | |
Jan Eilers | 4a539fc | 2019-07-25 17:08:37 +0100 | [diff] [blame] | 175 | std::vector<std::string> DynamicBackendUtils::GetSharedObjects(const std::vector<std::string>& backendPaths) |
| 176 | { |
| 177 | std::unordered_set<std::string> uniqueSharedObjects; |
| 178 | std::vector<std::string> sharedObjects; |
| 179 | |
| 180 | for (const std::string& backendPath : backendPaths) |
| 181 | { |
| 182 | using namespace boost::filesystem; |
| 183 | |
| 184 | // Check if the path is valid. In case of error, IsValidPath will log an error message |
| 185 | if (!IsPathValid(backendPath)) |
| 186 | { |
| 187 | continue; |
| 188 | } |
| 189 | |
Matteo Martincigh | e54aa06 | 2019-08-05 14:12:11 +0100 | [diff] [blame] | 190 | // Get all the files in the current path in alphabetical order |
| 191 | std::vector<path> backendPathFiles; |
| 192 | std::copy(directory_iterator(backendPath), directory_iterator(), std::back_inserter(backendPathFiles)); |
| 193 | std::sort(backendPathFiles.begin(), backendPathFiles.end()); |
| 194 | |
Jan Eilers | 4a539fc | 2019-07-25 17:08:37 +0100 | [diff] [blame] | 195 | // Go through all the files in the current backend path |
Matteo Martincigh | e54aa06 | 2019-08-05 14:12:11 +0100 | [diff] [blame] | 196 | for (const path& backendPathFile : backendPathFiles) |
Jan Eilers | 4a539fc | 2019-07-25 17:08:37 +0100 | [diff] [blame] | 197 | { |
Matteo Martincigh | e54aa06 | 2019-08-05 14:12:11 +0100 | [diff] [blame] | 198 | // Get only the name of the file (without the full path) |
| 199 | std::string filename = backendPathFile.filename().string(); |
Jan Eilers | 4a539fc | 2019-07-25 17:08:37 +0100 | [diff] [blame] | 200 | |
| 201 | if (filename.empty()) |
| 202 | { |
| 203 | // Empty filename |
| 204 | continue; |
| 205 | } |
| 206 | |
| 207 | path canonicalPath; |
| 208 | try |
| 209 | { |
| 210 | // Get the canonical path for the current file, it will throw if for example the file is a |
| 211 | // symlink that cannot be resolved |
Matteo Martincigh | e54aa06 | 2019-08-05 14:12:11 +0100 | [diff] [blame] | 212 | canonicalPath = canonical(backendPathFile); |
Jan Eilers | 4a539fc | 2019-07-25 17:08:37 +0100 | [diff] [blame] | 213 | } |
| 214 | catch (const filesystem_error& e) |
| 215 | { |
Derek Lamberti | 0844697 | 2019-11-26 16:38:31 +0000 | [diff] [blame] | 216 | ARMNN_LOG(warning) << "GetSharedObjects warning: " << e.what(); |
Jan Eilers | 4a539fc | 2019-07-25 17:08:37 +0100 | [diff] [blame] | 217 | } |
| 218 | if (canonicalPath.empty()) |
| 219 | { |
| 220 | // No such file or perhaps a symlink that couldn't be resolved |
| 221 | continue; |
| 222 | } |
| 223 | |
| 224 | // Check if the current filename matches the expected naming convention |
| 225 | // The expected format is: <vendor>_<name>_backend.so[<version>] |
| 226 | // e.g. "Arm_GpuAcc_backend.so" or "Arm_GpuAcc_backend.so.1.2" |
| 227 | const std::regex dynamicBackendRegex("^[a-zA-Z0-9]+_[a-zA-Z0-9]+_backend.so(\\.[0-9]+)*$"); |
| 228 | |
| 229 | bool filenameMatch = false; |
| 230 | try |
| 231 | { |
| 232 | // Match the filename to the expected naming scheme |
| 233 | filenameMatch = std::regex_match(filename, dynamicBackendRegex); |
| 234 | } |
| 235 | catch (const std::exception& e) |
| 236 | { |
Derek Lamberti | 0844697 | 2019-11-26 16:38:31 +0000 | [diff] [blame] | 237 | ARMNN_LOG(warning) << "GetSharedObjects warning: " << e.what(); |
Jan Eilers | 4a539fc | 2019-07-25 17:08:37 +0100 | [diff] [blame] | 238 | } |
| 239 | if (!filenameMatch) |
| 240 | { |
| 241 | // Filename does not match the expected naming scheme (or an error has occurred) |
| 242 | continue; |
| 243 | } |
| 244 | |
| 245 | // Append the valid canonical path to the output list only if it's not a duplicate |
| 246 | std::string validCanonicalPath = canonicalPath.string(); |
| 247 | auto it = uniqueSharedObjects.find(validCanonicalPath); |
| 248 | if (it == uniqueSharedObjects.end()) |
| 249 | { |
| 250 | // Not a duplicate, append the canonical path to the output list |
| 251 | sharedObjects.push_back(validCanonicalPath); |
| 252 | |
| 253 | // Add the canonical path to the collection of unique shared objects |
| 254 | uniqueSharedObjects.insert(validCanonicalPath); |
| 255 | } |
| 256 | } |
| 257 | } |
| 258 | |
| 259 | return sharedObjects; |
| 260 | } |
| 261 | |
Matteo Martincigh | e54aa06 | 2019-08-05 14:12:11 +0100 | [diff] [blame] | 262 | std::vector<DynamicBackendPtr> DynamicBackendUtils::CreateDynamicBackends(const std::vector<std::string>& sharedObjects) |
| 263 | { |
| 264 | // Create a list of dynamic backends |
| 265 | std::vector<DynamicBackendPtr> dynamicBackends; |
| 266 | for (const std::string& sharedObject : sharedObjects) |
| 267 | { |
| 268 | // Create a handle to the shared object |
| 269 | void* sharedObjectHandle = nullptr; |
| 270 | try |
| 271 | { |
| 272 | sharedObjectHandle = DynamicBackendUtils::OpenHandle(sharedObject); |
| 273 | } |
| 274 | catch (const RuntimeException& e) |
| 275 | { |
Derek Lamberti | 0844697 | 2019-11-26 16:38:31 +0000 | [diff] [blame] | 276 | ARMNN_LOG(warning) << "Cannot create a handle to the shared object file \"" |
| 277 | << sharedObject << "\": " << e.what(); |
Matteo Martincigh | e54aa06 | 2019-08-05 14:12:11 +0100 | [diff] [blame] | 278 | continue; |
| 279 | } |
| 280 | if (!sharedObjectHandle) |
| 281 | { |
Derek Lamberti | 0844697 | 2019-11-26 16:38:31 +0000 | [diff] [blame] | 282 | ARMNN_LOG(warning) << "Invalid handle to the shared object file \"" << sharedObject << "\""; |
Matteo Martincigh | e54aa06 | 2019-08-05 14:12:11 +0100 | [diff] [blame] | 283 | |
| 284 | continue; |
| 285 | } |
| 286 | |
| 287 | // Create a dynamic backend object |
| 288 | DynamicBackendPtr dynamicBackend; |
| 289 | try |
| 290 | { |
| 291 | dynamicBackend.reset(new DynamicBackend(sharedObjectHandle)); |
| 292 | } |
| 293 | catch (const Exception& e) |
| 294 | { |
Derek Lamberti | 0844697 | 2019-11-26 16:38:31 +0000 | [diff] [blame] | 295 | ARMNN_LOG(warning) << "Cannot create a valid dynamic backend from the shared object file \"" |
| 296 | << sharedObject << "\": " << e.what(); |
Matteo Martincigh | e54aa06 | 2019-08-05 14:12:11 +0100 | [diff] [blame] | 297 | continue; |
| 298 | } |
| 299 | if (!dynamicBackend) |
| 300 | { |
Derek Lamberti | 0844697 | 2019-11-26 16:38:31 +0000 | [diff] [blame] | 301 | ARMNN_LOG(warning) << "Invalid dynamic backend object for the shared object file \"" |
| 302 | << sharedObject << "\""; |
Matteo Martincigh | e54aa06 | 2019-08-05 14:12:11 +0100 | [diff] [blame] | 303 | continue; |
| 304 | } |
| 305 | |
| 306 | // Append the newly created dynamic backend to the list |
| 307 | dynamicBackends.push_back(std::move(dynamicBackend)); |
| 308 | } |
| 309 | |
| 310 | return dynamicBackends; |
| 311 | } |
| 312 | |
Narumol Prangnawarat | 60a20fb | 2019-12-09 17:24:41 +0000 | [diff] [blame] | 313 | void DynamicBackendUtils::DeregisterDynamicBackends(const BackendIdSet& dynamicBackends) |
| 314 | { |
| 315 | // Get a reference of the backend registry |
| 316 | BackendRegistry& backendRegistry = BackendRegistryInstance(); |
| 317 | |
| 318 | for (const auto& id : dynamicBackends) |
| 319 | { |
| 320 | backendRegistry.Deregister(id); |
| 321 | } |
| 322 | |
| 323 | } |
| 324 | |
Matteo Martincigh | 8953390 | 2019-08-15 12:08:06 +0100 | [diff] [blame] | 325 | BackendIdSet DynamicBackendUtils::RegisterDynamicBackends(const std::vector<DynamicBackendPtr>& dynamicBackends) |
Matteo Martincigh | 0c2b289 | 2019-08-05 14:12:11 +0100 | [diff] [blame] | 326 | { |
| 327 | // Get a reference of the backend registry |
| 328 | BackendRegistry& backendRegistry = BackendRegistryInstance(); |
| 329 | |
Matteo Martincigh | 8953390 | 2019-08-15 12:08:06 +0100 | [diff] [blame] | 330 | // Register the dynamic backends in the backend registry, and return a list of registered backend ids |
| 331 | return RegisterDynamicBackendsImpl(backendRegistry, dynamicBackends); |
Matteo Martincigh | 0c2b289 | 2019-08-05 14:12:11 +0100 | [diff] [blame] | 332 | } |
| 333 | |
Matteo Martincigh | 8953390 | 2019-08-15 12:08:06 +0100 | [diff] [blame] | 334 | BackendIdSet DynamicBackendUtils::RegisterDynamicBackendsImpl(BackendRegistry& backendRegistry, |
| 335 | const std::vector<DynamicBackendPtr>& dynamicBackends) |
Matteo Martincigh | 0c2b289 | 2019-08-05 14:12:11 +0100 | [diff] [blame] | 336 | { |
Matteo Martincigh | 8953390 | 2019-08-15 12:08:06 +0100 | [diff] [blame] | 337 | // Initialize the list of registered backend ids |
| 338 | BackendIdSet registeredBackendIds; |
| 339 | |
Matteo Martincigh | 0c2b289 | 2019-08-05 14:12:11 +0100 | [diff] [blame] | 340 | // Register the dynamic backends in the backend registry |
| 341 | for (const DynamicBackendPtr& dynamicBackend : dynamicBackends) |
| 342 | { |
Matteo Martincigh | 8953390 | 2019-08-15 12:08:06 +0100 | [diff] [blame] | 343 | // Get the id of the dynamic backend |
Matteo Martincigh | 0c2b289 | 2019-08-05 14:12:11 +0100 | [diff] [blame] | 344 | BackendId dynamicBackendId; |
| 345 | try |
| 346 | { |
| 347 | dynamicBackendId = dynamicBackend->GetBackendId(); |
| 348 | } |
| 349 | catch (const RuntimeException& e) |
| 350 | { |
Derek Lamberti | 0844697 | 2019-11-26 16:38:31 +0000 | [diff] [blame] | 351 | ARMNN_LOG(warning) << "Cannot register dynamic backend, " |
| 352 | << "an error has occurred when getting the backend id: " << e.what(); |
Matteo Martincigh | 0c2b289 | 2019-08-05 14:12:11 +0100 | [diff] [blame] | 353 | continue; |
| 354 | } |
| 355 | if (dynamicBackendId.IsEmpty() || |
| 356 | dynamicBackendId.IsUndefined()) |
| 357 | { |
Derek Lamberti | 0844697 | 2019-11-26 16:38:31 +0000 | [diff] [blame] | 358 | ARMNN_LOG(warning) << "Cannot register dynamic backend, invalid backend id: " << dynamicBackendId; |
Matteo Martincigh | 0c2b289 | 2019-08-05 14:12:11 +0100 | [diff] [blame] | 359 | continue; |
| 360 | } |
| 361 | |
| 362 | // Check whether the dynamic backend is already registered |
| 363 | bool backendAlreadyRegistered = backendRegistry.IsBackendRegistered(dynamicBackendId); |
| 364 | if (backendAlreadyRegistered) |
| 365 | { |
Derek Lamberti | 0844697 | 2019-11-26 16:38:31 +0000 | [diff] [blame] | 366 | ARMNN_LOG(warning) << "Cannot register dynamic backend \"" << dynamicBackendId |
| 367 | << "\": backend already registered"; |
Matteo Martincigh | 0c2b289 | 2019-08-05 14:12:11 +0100 | [diff] [blame] | 368 | continue; |
| 369 | } |
| 370 | |
| 371 | // Get the dynamic backend factory function |
| 372 | BackendRegistry::FactoryFunction dynamicBackendFactoryFunction = nullptr; |
| 373 | try |
| 374 | { |
| 375 | dynamicBackendFactoryFunction = dynamicBackend->GetFactoryFunction(); |
| 376 | } |
| 377 | catch (const RuntimeException& e) |
| 378 | { |
Derek Lamberti | 0844697 | 2019-11-26 16:38:31 +0000 | [diff] [blame] | 379 | ARMNN_LOG(warning) << "Cannot register dynamic backend \"" << dynamicBackendId |
| 380 | << "\": an error has occurred when getting the backend factory function: " |
| 381 | << e.what(); |
Matteo Martincigh | 0c2b289 | 2019-08-05 14:12:11 +0100 | [diff] [blame] | 382 | continue; |
| 383 | } |
| 384 | if (dynamicBackendFactoryFunction == nullptr) |
| 385 | { |
Derek Lamberti | 0844697 | 2019-11-26 16:38:31 +0000 | [diff] [blame] | 386 | ARMNN_LOG(warning) << "Cannot register dynamic backend \"" << dynamicBackendId |
| 387 | << "\": invalid backend factory function"; |
Matteo Martincigh | 0c2b289 | 2019-08-05 14:12:11 +0100 | [diff] [blame] | 388 | continue; |
| 389 | } |
| 390 | |
| 391 | // Register the dynamic backend |
Matteo Martincigh | 8953390 | 2019-08-15 12:08:06 +0100 | [diff] [blame] | 392 | try |
| 393 | { |
| 394 | backendRegistry.Register(dynamicBackendId, dynamicBackendFactoryFunction); |
| 395 | } |
| 396 | catch (const InvalidArgumentException& e) |
| 397 | { |
Derek Lamberti | 0844697 | 2019-11-26 16:38:31 +0000 | [diff] [blame] | 398 | ARMNN_LOG(warning) << "An error has occurred when registering the dynamic backend \"" |
| 399 | << dynamicBackendId << "\": " << e.what(); |
Matteo Martincigh | 8953390 | 2019-08-15 12:08:06 +0100 | [diff] [blame] | 400 | continue; |
| 401 | } |
| 402 | |
| 403 | // Add the id of the dynamic backend just registered to the list of registered backend ids |
| 404 | registeredBackendIds.insert(dynamicBackendId); |
Matteo Martincigh | 0c2b289 | 2019-08-05 14:12:11 +0100 | [diff] [blame] | 405 | } |
Matteo Martincigh | 8953390 | 2019-08-15 12:08:06 +0100 | [diff] [blame] | 406 | |
| 407 | return registeredBackendIds; |
Matteo Martincigh | 0c2b289 | 2019-08-05 14:12:11 +0100 | [diff] [blame] | 408 | } |
| 409 | |
Matteo Martincigh | d73cecb | 2019-07-24 09:15:00 +0100 | [diff] [blame] | 410 | } // namespace armnn |