ArmNN
 20.02
DynamicBackend Class Referencefinal

#include <DynamicBackend.hpp>

Public Types

using HandleCloser = std::function< void(const void *)>
 
using HandlePtr = std::unique_ptr< void, HandleCloser >
 

Public Member Functions

 DynamicBackend (const void *sharedObjectHandle)
 
BackendId GetBackendId ()
 Public dynamic backend functions. More...
 
BackendVersion GetBackendVersion ()
 
IBackendInternalUniquePtr GetBackend ()
 
BackendRegistry::FactoryFunction GetFactoryFunction ()
 

Detailed Description

Definition at line 18 of file DynamicBackend.hpp.

Member Typedef Documentation

◆ HandleCloser

using HandleCloser = std::function<void(const void*)>

Definition at line 21 of file DynamicBackend.hpp.

◆ HandlePtr

using HandlePtr = std::unique_ptr<void, HandleCloser>

Definition at line 22 of file DynamicBackend.hpp.

Constructor & Destructor Documentation

◆ DynamicBackend()

DynamicBackend ( const void *  sharedObjectHandle)
explicit

Definition at line 12 of file DynamicBackend.cpp.

References IBackendInternal::GetApiVersion(), DynamicBackend::GetBackendId(), DynamicBackend::GetBackendVersion(), and DynamicBackendUtils::IsBackendCompatible().

13  : m_BackendIdFunction(nullptr)
14  , m_BackendVersionFunction(nullptr)
15  , m_BackendFactoryFunction(nullptr)
16  , m_Handle(const_cast<void*>(sharedObjectHandle), &DynamicBackendUtils::CloseHandle)
17 {
18  if (m_Handle == nullptr)
19  {
20  throw InvalidArgumentException("Cannot create a DynamicBackend object from an invalid shared object handle");
21  }
22 
23  // These calls will throw in case of error
24  m_BackendIdFunction = SetFunctionPointer<IdFunctionType>("GetBackendId");
25  m_BackendVersionFunction = SetFunctionPointer<VersionFunctionType>("GetVersion");
26  m_BackendFactoryFunction = SetFunctionPointer<FactoryFunctionType>("BackendFactory");
27 
28  // Check that the backend is compatible with the current Backend API
29  BackendId backendId = GetBackendId();
30  BackendVersion backendVersion = GetBackendVersion();
31  if (!DynamicBackendUtils::IsBackendCompatible(backendVersion))
32  {
33  throw RuntimeException(boost::str(boost::format("The dynamic backend %1% (version %2%) is not compatible"
34  "with the current Backend API (vesion %3%)")
35  % backendId
36  % backendVersion
38  }
39 }
static bool IsBackendCompatible(const BackendVersion &backendVersion)
static constexpr BackendVersion GetApiVersion()
Returns the version of the Backend API.
BackendId GetBackendId()
Public dynamic backend functions.
static void CloseHandle(const void *sharedObjectHandle)
BackendVersion GetBackendVersion()

Member Function Documentation

◆ GetBackend()

IBackendInternalUniquePtr GetBackend ( )

Definition at line 71 of file DynamicBackend.cpp.

72 {
73  // This call throws in case of error
74  return CreateBackend();
75 }

◆ GetBackendId()

BackendId GetBackendId ( )

Public dynamic backend functions.

Definition at line 41 of file DynamicBackend.cpp.

Referenced by DynamicBackend::DynamicBackend().

42 {
43  if (m_BackendIdFunction == nullptr)
44  {
45  throw RuntimeException("GetBackendId error: invalid function pointer");
46  }
47 
48  const char* backendId = m_BackendIdFunction();
49  if (backendId == nullptr)
50  {
51  throw RuntimeException("GetBackendId error: invalid backend id");
52  }
53 
54  return BackendId(backendId);
55 }

◆ GetBackendVersion()

BackendVersion GetBackendVersion ( )

Definition at line 57 of file DynamicBackend.cpp.

Referenced by DynamicBackend::DynamicBackend().

58 {
59  if (m_BackendVersionFunction == nullptr)
60  {
61  throw RuntimeException("GetBackendVersion error: invalid function pointer");
62  }
63 
64  uint32_t major = 0;
65  uint32_t minor = 0;
66  m_BackendVersionFunction(&major, &minor);
67 
68  return BackendVersion{ major, minor };
69 }

◆ GetFactoryFunction()

BackendRegistry::FactoryFunction GetFactoryFunction ( )

Definition at line 77 of file DynamicBackend.cpp.

78 {
79  if (m_BackendFactoryFunction == nullptr)
80  {
81  throw RuntimeException("GetFactoryFunction error: invalid function pointer");
82  }
83 
84  return [this]() -> IBackendInternalUniquePtr
85  {
86  // This call throws in case of error
87  return CreateBackend();
88  };
89 }
std::unique_ptr< IBackendInternal > IBackendInternalUniquePtr

The documentation for this class was generated from the following files: