Commit ff87e2e4 authored by Yixing Lao's avatar Yixing Lao Committed by Yixing Lao

addresses review issues

parent 6fe8f8e5
......@@ -135,7 +135,7 @@ add_library(ngraph SHARED ${SRC})
# plugin is specified at compile time but the corresponding library could not be resolved at run-
# time, an error will be generated.
# E.g. assume compiling with Argon and Xpu, then -DRUNTIME_PLUGIN_LIBS="libargon.so:libxpu.so".
if (RUNTIME_PLUGIN_LIBS)
if (DEFINED RUNTIME_PLUGIN_LIBS)
target_compile_definitions(ngraph PRIVATE RUNTIME_PLUGIN_LIBS=${RUNTIME_PLUGIN_LIBS})
else()
target_compile_definitions(ngraph PRIVATE RUNTIME_PLUGIN_LIBS="")
......@@ -143,13 +143,15 @@ endif()
# This is used to ensure that libngraph.so and libargon.so are in the same directory for dlopen.
# Effective at build time. Does not affect `make install` logics.
if (COMMON_LIBRARY_OUTPUT_DIRECTORY)
if (DEFINED COMMON_LIBRARY_OUTPUT_DIRECTORY)
set_target_properties(ngraph PROPERTIES
LIBRARY_OUTPUT_DIRECTORY ${COMMON_LIBRARY_OUTPUT_DIRECTORY})
message(STATUS "LIBRARY_OUTPUT_DIRECTORY set to: ${COMMON_LIBRARY_OUTPUT_DIRECTORY}")
else()
message(STATUS "LIBRARY_OUTPUT_DIRECTORY not set, will use the defualt value")
set_target_properties(ngraph PROPERTIES
LIBRARY_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
endif()
message(STATUS "LIBRARY_OUTPUT_DIRECTORY set to: ${COMMON_LIBRARY_OUTPUT_DIRECTORY}")
target_include_directories(ngraph PUBLIC "${NGRAPH_INCLUDE_PATH}")
......
......@@ -12,20 +12,23 @@
// See the License for the specific language governing permissions and
// ----------------------------------------------------------------------------
#include "ngraph/runtime/manager.hpp"
#include <dlfcn.h>
#include <iostream>
#include <sstream>
#include <string>
#include "ngraph/runtime/manager.hpp"
#include "ngraph/util.hpp"
using namespace ngraph::runtime;
bool Manager::load_plugins(const std::string& runtime_plugin_libs)
bool Manager::m_is_factory_map_initialized = false;
void Manager::load_plugins(const std::string& runtime_plugin_libs)
{
std::istringstream ss(runtime_plugin_libs);
std::string plugin_lib_path;
std::vector<std::string> plugin_lib_paths = ngraph::split(runtime_plugin_libs, ':', false);
while (std::getline(ss, plugin_lib_path, ':'))
for (auto plugin_lib_path : plugin_lib_paths)
{
if (plugin_lib_path.size() > 0)
{
......@@ -34,7 +37,6 @@ bool Manager::load_plugins(const std::string& runtime_plugin_libs)
{
std::cerr << "Cannot open library: " << plugin_lib_path << ", " << dlerror()
<< std::endl;
return false;
}
else
{
......@@ -42,7 +44,6 @@ bool Manager::load_plugins(const std::string& runtime_plugin_libs)
}
}
}
return true;
}
Manager::FactoryMap& Manager::get_factory_map()
......@@ -53,11 +54,7 @@ Manager::FactoryMap& Manager::get_factory_map()
// Try to load runtime plugins
if (!Manager::m_is_factory_map_initialized)
{
if (!Manager::load_plugins(RUNTIME_PLUGIN_LIBS))
{
std::cerr << "Failed to load at least one of the following libraries: "
<< RUNTIME_PLUGIN_LIBS << std::endl;
}
Manager::load_plugins(RUNTIME_PLUGIN_LIBS);
Manager::m_is_factory_map_initialized = true;
}
return factory_map;
......@@ -68,10 +65,8 @@ std::shared_ptr<Manager> Manager::get(const std::string& name)
return get_factory_map().at(name)(name);
}
Manager::Factory Manager::register_factory(std::string name, Factory factory)
Manager::Factory Manager::register_factory(const std::string& name, Factory factory)
{
get_factory_map()[name] = factory;
return factory;
}
bool Manager::m_is_factory_map_initialized = false;
......@@ -49,10 +49,10 @@ namespace ngraph
static std::shared_ptr<Manager> get(const std::string& name);
static Factory register_factory(std::string name, Factory factory);
static Factory register_factory(const std::string& name, Factory factory);
private:
static bool load_plugins(const std::string& runtime_plugin_libs);
static void load_plugins(const std::string& runtime_plugin_libs);
static bool m_is_factory_map_initialized;
......
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