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