// // Copyright © 2017 Arm Ltd. All rights reserved. // SPDX-License-Identifier: MIT // #pragma once #include "IBackendInternal.hpp" #include "DynamicBackend.hpp" #include #include #include #include #include #if !defined(DYNAMIC_BACKEND_PATHS) #define DYNAMIC_BACKEND_PATHS "" #endif namespace armnn { class DynamicBackendUtils { public: static void* OpenHandle(const std::string& sharedObjectPath); static void CloseHandle(const void* sharedObjectHandle); template static EntryPointType GetEntryPoint(const void* sharedObjectHandle, const char* symbolName); static bool IsBackendCompatible(const BackendVersion& backendVersion); static std::vector GetBackendPaths(const std::string& overrideBackendPath = ""); static bool IsPathValid(const std::string& path); static std::vector GetSharedObjects(const std::vector& backendPaths); static std::vector CreateDynamicBackends(const std::vector& sharedObjects); static void RegisterDynamicBackends(const std::vector& dynamicBackends); protected: /// Protected methods for testing purposes static bool IsBackendCompatibleImpl(const BackendVersion& backendApiVersion, const BackendVersion& backendVersion); static std::vector GetBackendPathsImpl(const std::string& backendPaths); static void RegisterDynamicBackendsImpl(BackendRegistry& backendRegistry, const std::vector& dynamicBackends); private: static std::string GetDlError(); /// This class is to hold utility functions only DynamicBackendUtils() = delete; }; template EntryPointType DynamicBackendUtils::GetEntryPoint(const void* sharedObjectHandle, const char* symbolName) { if (sharedObjectHandle == nullptr) { throw RuntimeException("GetEntryPoint error: invalid handle"); } if (symbolName == nullptr) { throw RuntimeException("GetEntryPoint error: invalid symbol"); } auto entryPoint = reinterpret_cast(dlsym(const_cast(sharedObjectHandle), symbolName)); if (!entryPoint) { throw RuntimeException(boost::str(boost::format("GetEntryPoint error: %1%") % GetDlError())); } return entryPoint; } } // namespace armnn