aboutsummaryrefslogtreecommitdiff
path: root/src/backends/backendsCommon/DynamicBackendUtils.hpp
diff options
context:
space:
mode:
authorMatteo Martincigh <matteo.martincigh@arm.com>2019-07-24 09:15:00 +0100
committerNikhil Raj Arm <nikhil.raj@arm.com>2019-07-24 14:19:58 +0000
commitd73cecba2fb3525453d102603f6f27a9636754b5 (patch)
tree8c7019115be71acc3e79f101a6f47947023c5149 /src/backends/backendsCommon/DynamicBackendUtils.hpp
parentee18dc8d1725f472850ab0c398fd7cbc4b850891 (diff)
downloadarmnn-d73cecba2fb3525453d102603f6f27a9636754b5.tar.gz
IVGCVSW-3563 + IVGCVSW-3555 Create new utility functions for dynamic backends
* Created new DynamicBackendUtils class * Added OpenHandle, CloseHandle, GetEntryPoint and GetDlError methods to it Signed-off-by: Matteo Martincigh <matteo.martincigh@arm.com> Change-Id: I88c683b2c5d37968a9ebdf335be932ae2d9061e5
Diffstat (limited to 'src/backends/backendsCommon/DynamicBackendUtils.hpp')
-rw-r--r--src/backends/backendsCommon/DynamicBackendUtils.hpp56
1 files changed, 56 insertions, 0 deletions
diff --git a/src/backends/backendsCommon/DynamicBackendUtils.hpp b/src/backends/backendsCommon/DynamicBackendUtils.hpp
new file mode 100644
index 0000000000..6bedec4580
--- /dev/null
+++ b/src/backends/backendsCommon/DynamicBackendUtils.hpp
@@ -0,0 +1,56 @@
+//
+// Copyright © 2017 Arm Ltd. All rights reserved.
+// SPDX-License-Identifier: MIT
+//
+
+#pragma once
+
+#include <armnn/Exceptions.hpp>
+
+#include <string>
+#include <dlfcn.h>
+
+#include <boost/format.hpp>
+
+namespace armnn
+{
+
+class DynamicBackendUtils
+{
+public:
+ static void* OpenHandle(const std::string& sharedObjectPath);
+ static void CloseHandle(const void* sharedObjectHandle);
+
+ template<typename EntryPointType>
+ static EntryPointType GetEntryPoint(const void* sharedObjectHandle, const char* symbolName);
+
+private:
+ static std::string GetDlError();
+
+ /// This class is to hold utility functions only
+ DynamicBackendUtils() = delete;
+};
+
+template<typename EntryPointType>
+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<EntryPointType>(dlsym(const_cast<void*>(sharedObjectHandle), symbolName));
+ if (!entryPoint)
+ {
+ throw RuntimeException(boost::str(boost::format("GetEntryPoint error: %1") % GetDlError()));
+ }
+
+ return entryPoint;
+}
+
+} // namespace armnn