aboutsummaryrefslogtreecommitdiff
path: root/src/backends/backendsCommon/DynamicBackendUtils.cpp
diff options
context:
space:
mode:
authorMatteo Martincigh <matteo.martincigh@arm.com>2019-08-05 12:16:47 +0100
committerMatteo Martincigh <matteo.martincigh@arm.com>2019-08-05 16:32:05 +0000
commite7d449893b85a00a063836bd01dce4f925a24dd2 (patch)
treebff2b2770caa91c3bbf7270db8a21a3f4eb9964f /src/backends/backendsCommon/DynamicBackendUtils.cpp
parent4fc3c48c2d230d8c55aa01aa98e32b6df7cafc0c (diff)
downloadarmnn-e7d449893b85a00a063836bd01dce4f925a24dd2.tar.gz
IVGCVSW-3541 Get the paths where to load the dynamic backends from
* Adds GetBackendPaths and IsPathValid to DynamicBackendUtils * Adds related unit tests Change-Id: I94e377d92a88a4b5d48026f6ad5b4d5387d20c21 Signed-off-by: Jan Eilers <jan.eilers@arm.com> Signed-off-by: Matteo Martincigh <matteo.martincigh@arm.com>
Diffstat (limited to 'src/backends/backendsCommon/DynamicBackendUtils.cpp')
-rw-r--r--src/backends/backendsCommon/DynamicBackendUtils.cpp92
1 files changed, 92 insertions, 0 deletions
diff --git a/src/backends/backendsCommon/DynamicBackendUtils.cpp b/src/backends/backendsCommon/DynamicBackendUtils.cpp
index 0ab02d7c98..ae36a24b30 100644
--- a/src/backends/backendsCommon/DynamicBackendUtils.cpp
+++ b/src/backends/backendsCommon/DynamicBackendUtils.cpp
@@ -5,6 +5,10 @@
#include "DynamicBackendUtils.hpp"
+#include <boost/filesystem/operations.hpp>
+#include <boost/algorithm/string.hpp>
+#include <boost/log/trivial.hpp>
+
namespace armnn
{
@@ -59,4 +63,92 @@ std::string DynamicBackendUtils::GetDlError()
return std::string(errorMessage);
}
+std::vector<std::string> DynamicBackendUtils::GetBackendPaths(const std::string& overrideBackendPath)
+{
+ // Check if a path where to dynamically load the backends from is given
+ if (!overrideBackendPath.empty())
+ {
+ if (!IsPathValid(overrideBackendPath))
+ {
+ BOOST_LOG_TRIVIAL(warning) << "WARNING: The given override path for dynamic backends \""
+ << overrideBackendPath << "\" is not valid";
+
+ return {};
+ }
+
+ return std::vector<std::string>{ overrideBackendPath };
+ }
+
+ // Expects a colon-separated list: DYNAMIC_BACKEND_PATHS="PATH_1:PATH_2:...:PATH_N"
+ const std::string backendPaths = DYNAMIC_BACKEND_PATHS;
+
+ return GetBackendPathsImpl(backendPaths);
+}
+
+std::vector<std::string> DynamicBackendUtils::GetBackendPathsImpl(const std::string& backendPaths)
+{
+ std::unordered_set<std::string> uniqueBackendPaths;
+ std::vector<std::string> tempBackendPaths;
+ std::vector<std::string> validBackendPaths;
+
+ // Split the given list of paths
+ boost::split(tempBackendPaths, backendPaths, boost::is_any_of(":"));
+
+ for (const std::string& path : tempBackendPaths)
+ {
+ // Check whether the path is valid
+ if (!IsPathValid(path))
+ {
+ continue;
+ }
+
+ // Check whether the path is a duplicate
+ auto it = uniqueBackendPaths.find(path);
+ if (it != uniqueBackendPaths.end())
+ {
+ // The path is a duplicate
+ continue;
+ }
+
+ // Add the path to the set of unique paths
+ uniqueBackendPaths.insert(path);
+
+ // Add the path to the list of valid paths
+ validBackendPaths.push_back(path);
+ }
+
+ return validBackendPaths;
+}
+
+bool DynamicBackendUtils::IsPathValid(const std::string& path)
+{
+ if (path.empty())
+ {
+ BOOST_LOG_TRIVIAL(warning) << "WARNING: The given backend path is empty";
+ return false;
+ }
+
+ boost::filesystem::path boostPath(path);
+
+ if (!boost::filesystem::exists(boostPath))
+ {
+ BOOST_LOG_TRIVIAL(warning) << "WARNING: The given backend path \"" << path << "\" does not exist";
+ return false;
+ }
+
+ if (!boost::filesystem::is_directory(boostPath))
+ {
+ BOOST_LOG_TRIVIAL(warning) << "WARNING: The given backend path \"" << path << "\" is not a directory";
+ return false;
+ }
+
+ if (!boostPath.is_absolute())
+ {
+ BOOST_LOG_TRIVIAL(warning) << "WARNING: The given backend path \"" << path << "\" is not absolute";
+ return false;
+ }
+
+ return true;
+}
+
} // namespace armnn