2 // Copyright © 2017 Arm Ltd. All rights reserved.
3 // SPDX-License-Identifier: MIT
8 #include "IBackendInternal.hpp"
10 #include <armnn/Exceptions.hpp>
16 #include <boost/format.hpp>
18 #if !defined(DYNAMIC_BACKEND_PATHS)
19 #define DYNAMIC_BACKEND_PATHS ""
25 class DynamicBackendUtils
28 static void* OpenHandle(const std::string& sharedObjectPath);
29 static void CloseHandle(const void* sharedObjectHandle);
31 template<typename EntryPointType>
32 static EntryPointType GetEntryPoint(const void* sharedObjectHandle, const char* symbolName);
34 static bool IsBackendCompatible(const BackendVersion& backendVersion);
36 static std::vector<std::string> GetBackendPaths(const std::string& overrideBackendPath = "");
37 static bool IsPathValid(const std::string& path);
40 /// Protected methods for testing purposes
41 static bool IsBackendCompatibleImpl(const BackendVersion& backendApiVersion, const BackendVersion& backendVersion);
42 static std::vector<std::string> GetBackendPathsImpl(const std::string& backendPaths);
45 static std::string GetDlError();
47 /// This class is to hold utility functions only
48 DynamicBackendUtils() = delete;
51 template<typename EntryPointType>
52 EntryPointType DynamicBackendUtils::GetEntryPoint(const void* sharedObjectHandle, const char* symbolName)
54 if (sharedObjectHandle == nullptr)
56 throw RuntimeException("GetEntryPoint error: invalid handle");
59 if (symbolName == nullptr)
61 throw RuntimeException("GetEntryPoint error: invalid symbol");
64 auto entryPoint = reinterpret_cast<EntryPointType>(dlsym(const_cast<void*>(sharedObjectHandle), symbolName));
67 throw RuntimeException(boost::str(boost::format("GetEntryPoint error: %1%") % GetDlError()));