Unverified Commit 295ed8eb authored by Robert Kimball's avatar Robert Kimball Committed by GitHub

Remove regex from Backend.cpp (#1228)

parent e6c3d5e3
...@@ -15,7 +15,6 @@ ...@@ -15,7 +15,6 @@
*******************************************************************************/ *******************************************************************************/
#include <dlfcn.h> #include <dlfcn.h>
#include <regex>
#include <sstream> #include <sstream>
#include "ngraph/file_util.hpp" #include "ngraph/file_util.hpp"
...@@ -108,12 +107,11 @@ map<string, string> runtime::Backend::get_registered_device_map() ...@@ -108,12 +107,11 @@ map<string, string> runtime::Backend::get_registered_device_map()
map<string, string> rc; map<string, string> rc;
string my_directory = file_util::get_directory(find_my_file()); string my_directory = file_util::get_directory(find_my_file());
vector<string> backend_list; vector<string> backend_list;
regex reg("^lib(.+)_backend" + string(SHARED_LIB_EXT));
smatch result;
auto f = [&](const string& file, bool is_dir) { auto f = [&](const string& file, bool is_dir) {
string name = file_util::get_file_name(file); string name = file_util::get_file_name(file);
if (regex_match(name, result, reg)) string backend_name;
if (is_backend_name(name, backend_name))
{ {
auto handle = dlopen(file.c_str(), RTLD_LAZY | RTLD_LOCAL); auto handle = dlopen(file.c_str(), RTLD_LAZY | RTLD_LOCAL);
if (handle) if (handle)
...@@ -126,7 +124,7 @@ map<string, string> runtime::Backend::get_registered_device_map() ...@@ -126,7 +124,7 @@ map<string, string> runtime::Backend::get_registered_device_map()
if (get_ngraph_version_string && if (get_ngraph_version_string &&
get_ngraph_version_string() == string(NGRAPH_VERSION)) get_ngraph_version_string() == string(NGRAPH_VERSION))
{ {
rc.insert({to_upper(result[1]), file}); rc.insert({to_upper(backend_name), file});
} }
} }
...@@ -219,3 +217,23 @@ void runtime::Backend::validate_call(shared_ptr<const Function> function, ...@@ -219,3 +217,23 @@ void runtime::Backend::validate_call(shared_ptr<const Function> function,
} }
} }
} }
bool runtime::Backend::is_backend_name(const string& file, string& backend_name)
{
string name = file_util::get_file_name(file);
string ext = SHARED_LIB_EXT;
bool rc = false;
if (!name.compare(0, 3, "lib"))
{
if (!name.compare(name.size() - ext.size(), ext.size(), ext))
{
auto pos = name.find("_backend");
if (pos != name.npos)
{
backend_name = name.substr(3, pos - 3);
rc = true;
}
}
}
return rc;
}
...@@ -85,6 +85,7 @@ namespace ngraph ...@@ -85,6 +85,7 @@ namespace ngraph
private: private:
static void* open_shared_library(std::string type); static void* open_shared_library(std::string type);
static std::map<std::string, std::string> get_registered_device_map(); static std::map<std::string, std::string> get_registered_device_map();
static bool is_backend_name(const std::string& file, std::string& backend_name);
}; };
} }
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment