ArmNN
 24.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 20 of file DynamicBackend.hpp.

Member Typedef Documentation

◆ HandleCloser

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

Definition at line 23 of file DynamicBackend.hpp.

◆ HandlePtr

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

Definition at line 24 of file DynamicBackend.hpp.

Constructor & Destructor Documentation

◆ DynamicBackend()

DynamicBackend ( const void *  sharedObjectHandle)
explicit

Definition at line 12 of file DynamicBackend.cpp.

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  // This exception message could not be formatted simply using fmt::format
34  std::stringstream message;
35  message << "The dynamic backend " << backendId << " (version " << backendVersion <<
36  ") is not compatible with the current Backend API (version " << IBackendInternal::GetApiVersion() << ")";
37 
38  throw RuntimeException(message.str());
39  }
40 }

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

Member Function Documentation

◆ GetBackend()

IBackendInternalUniquePtr GetBackend ( )

Definition at line 72 of file DynamicBackend.cpp.

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

◆ GetBackendId()

BackendId GetBackendId ( )

Public dynamic backend functions.

Definition at line 42 of file DynamicBackend.cpp.

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

Referenced by DynamicBackend::DynamicBackend().

◆ GetBackendVersion()

BackendVersion GetBackendVersion ( )

Definition at line 58 of file DynamicBackend.cpp.

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

Referenced by DynamicBackend::DynamicBackend().

◆ GetFactoryFunction()

BackendRegistry::FactoryFunction GetFactoryFunction ( )

Definition at line 78 of file DynamicBackend.cpp.

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

The documentation for this class was generated from the following files:
armnn::DynamicBackend::GetBackendVersion
BackendVersion GetBackendVersion()
Definition: DynamicBackend.cpp:58
armnn::DynamicBackend::GetBackendId
BackendId GetBackendId()
Public dynamic backend functions.
Definition: DynamicBackend.cpp:42
armnn::DynamicBackendUtils::CloseHandle
static void CloseHandle(const void *sharedObjectHandle)
Definition: DynamicBackendUtils.cpp:37
armnn::IBackendInternal::GetApiVersion
static constexpr BackendVersion GetApiVersion()
Returns the version of the Backend API.
Definition: IBackendInternal.hpp:167
armnn::DynamicBackendUtils::IsBackendCompatible
static bool IsBackendCompatible(const BackendVersion &backendVersion)
Definition: DynamicBackendUtils.cpp:52
armnn::IBackendInternalUniquePtr
std::unique_ptr< IBackendInternal > IBackendInternalUniquePtr
Definition: BackendRegistry.hpp:32