Fix Windows build:
authorRob Hughes <robert.hughes@arm.com>
Fri, 23 Aug 2019 09:11:58 +0000 (10:11 +0100)
committerRob Hughes <robert.hughes@arm.com>
Fri, 23 Aug 2019 09:16:16 +0000 (09:16 +0000)
* 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

CMakeLists.txt
src/armnn/layers/StackLayer.cpp
src/armnnTfLiteParser/CMakeLists.txt
src/armnnTfLiteParser/test/LoadModel.cpp
src/backends/backendsCommon/DynamicBackendUtils.cpp
src/backends/backendsCommon/DynamicBackendUtils.hpp
src/backends/reference/RefMemoryManager.cpp

index 2236e24..420aabd 100644 (file)
@@ -449,18 +449,22 @@ target_link_libraries(armnn armnnUtils)
 target_link_libraries(armnn ${CMAKE_DL_LIBS})
 
 install(TARGETS armnn
-        LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR})
+        LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
+        RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
 if(BUILD_CAFFE_PARSER)
     install(TARGETS armnnCaffeParser
-            LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR})
+            LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
+            RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
 endif()
 if(BUILD_ONNX_PARSER)
     install(TARGETS armnnOnnxParser
-            LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR})
+            LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
+            RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
 endif()
 if(BUILD_TF_PARSER)
     install(TARGETS armnnTfParser
-            LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR})
+            LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
+            RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
 endif()
 
 install(DIRECTORY include/ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
index 7f1dbec..43e0ac3 100644 (file)
@@ -38,7 +38,7 @@ std::vector<TensorShape> StackLayer::InferOutputShapes(const std::vector<TensorS
 
     BOOST_ASSERT(axis <= inputNumDimensions);
 
-    unsigned int dimensionSizes[inputNumDimensions + 1];
+    std::vector<unsigned int> dimensionSizes(inputNumDimensions + 1, 0);
     for (unsigned int i = 0; i < axis; ++i)
     {
         dimensionSizes[i] = inputShape[i];
@@ -51,7 +51,7 @@ std::vector<TensorShape> StackLayer::InferOutputShapes(const std::vector<TensorS
         dimensionSizes[i] = inputShape[i-1];
     }
 
-    TensorShape targetShape = TensorShape(inputNumDimensions + 1, dimensionSizes);
+    TensorShape targetShape = TensorShape(inputNumDimensions + 1, dimensionSizes.data());
 
     return std::vector<TensorShape>({ targetShape });
 }
index 8ff0837..17d4cf6 100755 (executable)
@@ -22,5 +22,6 @@ if(BUILD_TF_LITE_PARSER)
     target_link_libraries(armnnTfLiteParser armnn ${FLATBUFFERS_LIBRARY})
 
     install(TARGETS armnnTfLiteParser
-            LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR})
+            LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
+            RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
 endif()
index dac30ef..9ae3412 100644 (file)
@@ -6,8 +6,6 @@
 #include "ParserFlatbuffersFixture.hpp"
 #include "../TfLiteParser.hpp"
 
-#include <unistd.h>
-
 using armnnTfLiteParser::TfLiteParser;
 using ModelPtr = TfLiteParser::ModelPtr;
 using SubgraphPtr = TfLiteParser::SubgraphPtr;
index fc4336f..da7c324 100644 (file)
@@ -16,6 +16,7 @@ namespace armnn
 
 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 @@ void* DynamicBackendUtils::OpenHandle(const std::string& sharedObjectPath)
     }
 
     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 @@ bool DynamicBackendUtils::IsBackendCompatibleImpl(const BackendVersion &backendA
 
 std::string DynamicBackendUtils::GetDlError()
 {
+#if defined(__unix__)
     const char* errorMessage = dlerror();
     if (!errorMessage)
     {
@@ -63,6 +72,9 @@ std::string DynamicBackendUtils::GetDlError()
     }
 
     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)
index 0aa0ac8..6d9f11d 100644 (file)
 
 #include <armnn/Exceptions.hpp>
 
+#include <boost/format.hpp>
+
 #include <string>
-#include <dlfcn.h>
 #include <vector>
-
-#include <boost/format.hpp>
+#if defined(__unix__)
+#include <dlfcn.h>
+#endif
 
 #if !defined(DYNAMIC_BACKEND_PATHS)
 #define DYNAMIC_BACKEND_PATHS ""
@@ -58,6 +60,7 @@ private:
 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 @@ EntryPointType DynamicBackendUtils::GetEntryPoint(const void* sharedObjectHandle
     }
 
     return entryPoint;
+#else
+    throw RuntimeException("Dynamic backends not supported on this platform");
+#endif
 }
 
 } // namespace armnn
index 0f4a289..fdd008d 100644 (file)
@@ -6,6 +6,8 @@
 
 #include <boost/assert.hpp>
 
+#include <algorithm>
+
 namespace armnn
 {
 
@@ -73,7 +75,7 @@ RefMemoryManager::Pool::~Pool()
 
 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::Reserve(unsigned int numBytes)
 
 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;
 }