Fix Windows build:
* CMake "install" commands require a RUNTIME argument for platforms with
DLLs (e.g. Windows).
* Replace use of non-standard variable length array with vector
* Remove unnecessary #include of unistd.h
* Add #ifdefs to dynamic backend code to disable for non-Unix platforms
where you can't use dlopen etc. We could implement this properly for Windows
later using LoadLibrary etc., but for now erroring is fine.
* Add missing #include of <algorithm>
Change-Id: Ic8ef5fd599b37bf8772510157b6e479819f6a1eb
diff --git a/src/backends/backendsCommon/DynamicBackendUtils.cpp b/src/backends/backendsCommon/DynamicBackendUtils.cpp
index fc4336f..da7c324 100644
--- a/src/backends/backendsCommon/DynamicBackendUtils.cpp
+++ b/src/backends/backendsCommon/DynamicBackendUtils.cpp
@@ -16,6 +16,7 @@
void* DynamicBackendUtils::OpenHandle(const std::string& sharedObjectPath)
{
+#if defined(__unix__)
if (sharedObjectPath.empty())
{
throw RuntimeException("OpenHandle error: shared object path must not be empty");
@@ -28,16 +29,23 @@
}
return sharedObjectHandle;
+#else
+ throw RuntimeException("Dynamic backends not supported on this platform");
+#endif
}
void DynamicBackendUtils::CloseHandle(const void* sharedObjectHandle)
{
+#if defined(__unix__)
if (!sharedObjectHandle)
{
return;
}
dlclose(const_cast<void*>(sharedObjectHandle));
+#else
+ throw RuntimeException("Dynamic backends not supported on this platform");
+#endif
}
bool DynamicBackendUtils::IsBackendCompatible(const BackendVersion &backendVersion)
@@ -56,6 +64,7 @@
std::string DynamicBackendUtils::GetDlError()
{
+#if defined(__unix__)
const char* errorMessage = dlerror();
if (!errorMessage)
{
@@ -63,6 +72,9 @@
}
return std::string(errorMessage);
+#else
+ throw RuntimeException("Dynamic backends not supported on this platform");
+#endif
}
std::vector<std::string> DynamicBackendUtils::GetBackendPaths(const std::string& overrideBackendPath)
diff --git a/src/backends/backendsCommon/DynamicBackendUtils.hpp b/src/backends/backendsCommon/DynamicBackendUtils.hpp
index 0aa0ac8..6d9f11d 100644
--- a/src/backends/backendsCommon/DynamicBackendUtils.hpp
+++ b/src/backends/backendsCommon/DynamicBackendUtils.hpp
@@ -10,12 +10,14 @@
#include <armnn/Exceptions.hpp>
-#include <string>
-#include <dlfcn.h>
-#include <vector>
-
#include <boost/format.hpp>
+#include <string>
+#include <vector>
+#if defined(__unix__)
+#include <dlfcn.h>
+#endif
+
#if !defined(DYNAMIC_BACKEND_PATHS)
#define DYNAMIC_BACKEND_PATHS ""
#endif
@@ -58,6 +60,7 @@
template<typename EntryPointType>
EntryPointType DynamicBackendUtils::GetEntryPoint(const void* sharedObjectHandle, const char* symbolName)
{
+#if defined(__unix__)
if (sharedObjectHandle == nullptr)
{
throw RuntimeException("GetEntryPoint error: invalid handle");
@@ -75,6 +78,9 @@
}
return entryPoint;
+#else
+ throw RuntimeException("Dynamic backends not supported on this platform");
+#endif
}
} // namespace armnn
diff --git a/src/backends/reference/RefMemoryManager.cpp b/src/backends/reference/RefMemoryManager.cpp
index 0f4a289..fdd008d 100644
--- a/src/backends/reference/RefMemoryManager.cpp
+++ b/src/backends/reference/RefMemoryManager.cpp
@@ -6,6 +6,8 @@
#include <boost/assert.hpp>
+#include <algorithm>
+
namespace armnn
{
@@ -73,7 +75,7 @@
void* RefMemoryManager::Pool::GetPointer()
{
- BOOST_ASSERT_MSG(m_Pointer, "RefMemoryManager::Pool::GetPointer() called when memory not acquired");
+ BOOST_ASSERT_MSG(m_Pointer, "RefMemoryManager::Pool::GetPointer() called when memory not acquired");
return m_Pointer;
}
@@ -85,14 +87,14 @@
void RefMemoryManager::Pool::Acquire()
{
- BOOST_ASSERT_MSG(!m_Pointer, "RefMemoryManager::Pool::Acquire() called when memory already acquired");
+ BOOST_ASSERT_MSG(!m_Pointer, "RefMemoryManager::Pool::Acquire() called when memory already acquired");
BOOST_ASSERT(m_Size >= 0);
m_Pointer = ::operator new(size_t(m_Size));
}
void RefMemoryManager::Pool::Release()
{
- BOOST_ASSERT_MSG(m_Pointer, "RefMemoryManager::Pool::Release() called when memory not acquired");
+ BOOST_ASSERT_MSG(m_Pointer, "RefMemoryManager::Pool::Release() called when memory not acquired");
::operator delete(m_Pointer);
m_Pointer = nullptr;
}