1 // 2 // Copyright © 2017 Arm Ltd. All rights reserved. 3 // SPDX-License-Identifier: MIT 4 // 5 6 #pragma once 7 8 #include "IBackendInternal.hpp" 9 10 #include <armnn/BackendRegistry.hpp> 11 12 #include <functional> 13 #include <memory> 14 15 namespace armnn 16 { 17 18 class DynamicBackend final 19 { 20 public: 21 using HandleCloser = std::function<void(const void*)>; 22 using HandlePtr = std::unique_ptr<void, HandleCloser>; 23 24 explicit DynamicBackend(const void* sharedObjectHandle); 25 26 /// Public dynamic backend functions 27 BackendId GetBackendId(); 28 BackendVersion GetBackendVersion(); 29 IBackendInternalUniquePtr GetBackend(); 30 BackendRegistry::FactoryFunction GetFactoryFunction(); 31 32 private: 33 /// Private utility functions 34 template<typename BackendFunctionType> 35 BackendFunctionType SetFunctionPointer(const std::string& backendFunctionName); 36 IBackendInternalUniquePtr CreateBackend(); 37 38 /// Backend function pointer types 39 using IdFunctionType = const char*(*)(); 40 using VersionFunctionType = void(*)(uint32_t*, uint32_t*); 41 using FactoryFunctionType = void*(*)(); 42 43 /// Backend function pointers 44 IdFunctionType m_BackendIdFunction; 45 VersionFunctionType m_BackendVersionFunction; 46 FactoryFunctionType m_BackendFactoryFunction; 47 48 /// Shared object handle 49 HandlePtr m_Handle; 50 }; 51 52 using DynamicBackendPtr = std::unique_ptr<DynamicBackend>; 53 54 } // namespace armnn 55