2 // Copyright © 2017 Arm Ltd. All rights reserved.
3 // SPDX-License-Identifier: MIT
8 #include "IBackendInternal.hpp"
10 #include <armnn/Exceptions.hpp>
15 #include <boost/format.hpp>
20 class DynamicBackendUtils
23 static void* OpenHandle(const std::string& sharedObjectPath);
24 static void CloseHandle(const void* sharedObjectHandle);
26 template<typename EntryPointType>
27 static EntryPointType GetEntryPoint(const void* sharedObjectHandle, const char* symbolName);
29 static bool IsBackendCompatible(const BackendVersion& backendVersion);
32 /// Protected for testing purposes
33 static bool IsBackendCompatibleImpl(const BackendVersion& backendApiVersion, const BackendVersion& backendVersion);
36 static std::string GetDlError();
38 /// This class is to hold utility functions only
39 DynamicBackendUtils() = delete;
42 template<typename EntryPointType>
43 EntryPointType DynamicBackendUtils::GetEntryPoint(const void* sharedObjectHandle, const char* symbolName)
45 if (sharedObjectHandle == nullptr)
47 throw RuntimeException("GetEntryPoint error: invalid handle");
50 if (symbolName == nullptr)
52 throw RuntimeException("GetEntryPoint error: invalid symbol");
55 auto entryPoint = reinterpret_cast<EntryPointType>(dlsym(const_cast<void*>(sharedObjectHandle), symbolName));
58 throw RuntimeException(boost::str(boost::format("GetEntryPoint error: %1%") % GetDlError()));