Unverified Commit 4a84f51f authored by Scott Cyphers's avatar Scott Cyphers Committed by GitHub

Separate dynamic loading from static linking (#3456)

* Separate dynamic loading from static linking

* Missed find_my_pathname
parent d7893701
......@@ -185,6 +185,7 @@ option(NGRAPH_JSON_ENABLE "Enable JSON based serialization and tracing features"
option(NGRAPH_STATIC_LIB_ENABLE "Enable build nGraph static library" FALSE)
option(NGRAPH_INTERPRETER_STATIC_LIB_ENABLE "Enable build INTERPRETER backend static library" FALSE)
option(NGRAPH_CPU_STATIC_LIB_ENABLE "Enable build CPU backend static library" FALSE)
option(NGRAPH_DYNAMIC_COMPONENTS_ENABLE "Enable dynamic loading of components" TRUE)
if (NGRAPH_CPU_ENABLE
AND
......@@ -263,6 +264,7 @@ NORMALIZE_BOOL(NGRAPH_JSON_ENABLE)
NORMALIZE_BOOL(NGRAPH_STATIC_LIB_ENABLE)
NORMALIZE_BOOL(NGRAPH_INTERPRETER_STATIC_LIB_ENABLE)
NORMALIZE_BOOL(NGRAPH_CPU_STATIC_LIB_ENABLE)
NORMALIZE_BOOL(NGRAPH_DYNAMIC_COMPONENTS_ENABLE)
message(STATUS "NGRAPH_UNIT_TEST_ENABLE: ${NGRAPH_UNIT_TEST_ENABLE}")
message(STATUS "NGRAPH_TOOLS_ENABLE: ${NGRAPH_TOOLS_ENABLE}")
......@@ -289,6 +291,7 @@ message(STATUS "NGRAPH_JSON_ENABLE: ${NGRAPH_JSON_ENABLE}")
message(STATUS "NGRAPH_STATIC_LIB_ENABLE: ${NGRAPH_STATIC_LIB_ENABLE}")
message(STATUS "NGRAPH_INTERPRETER_STATIC_LIB_ENABLE: ${NGRAPH_INTERPRETER_STATIC_LIB_ENABLE}")
message(STATUS "NGRAPH_CPU_STATIC_LIB_ENABLE: ${NGRAPH_CPU_STATIC_LIB_ENABLE}")
message(STATUS "NGRAPH_DYNAMIC_COMPONENTS_ENABLE: ${NGRAPH_DYNAMIC_COMPONENTS_ENABLE}")
#-----------------------------------------------------------------------------------------------
# Installation logic...
......@@ -402,6 +405,10 @@ if (NGRAPH_STATIC_LIB_ENABLE)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DNGRAPH_STATIC_LIB_ENABLE")
endif()
if (NGRAPH_DYNAMIC_COMPONENTS_ENABLE)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DNGRAPH_DYNAMIC_COMPONENTS_ENABLE")
endif()
if (NGRAPH_PLAIDML_ENABLE)
find_package(PlaidML CONFIG)
if (NOT PLAIDML_FOUND)
......
......@@ -37,9 +37,7 @@ std::string runtime::Backend::s_backend_shared_library_search_directory;
// This finds the full path of the containing shared library
static string find_my_pathname()
{
#ifdef NGRAPH_STATIC_LIB_ENABLE
return "";
#else
#ifdef NGRAPH_DYNAMIC_COMPONENTS_ENABLE
#ifdef _WIN32
HMODULE hModule = GetModuleHandleW(L"ngraph.dll");
WCHAR wpath[MAX_PATH];
......@@ -55,6 +53,8 @@ static string find_my_pathname()
dladdr(reinterpret_cast<void*>(find_my_pathname), &dl_info);
return dl_info.dli_fname;
#endif
#else
return "";
#endif
}
......
......@@ -32,9 +32,7 @@
using namespace std;
using namespace ngraph;
#ifdef NGRAPH_STATIC_LIB_ENABLE
#define DLERROR() ""
#else
#ifdef NGRAPH_DYNAMIC_COMPONENTS_ENABLE
#ifdef _WIN32
#define CLOSE_LIBRARY(a) FreeLibrary(a)
#define DLSYM(a, b) GetProcAddress(a, b)
......@@ -44,6 +42,8 @@ using namespace ngraph;
#define DLSYM(a, b) dlsym(a, b)
#define DLERROR() dlerror()
#endif
#else
#define DLERROR() ""
#endif
unordered_map<string, runtime::BackendConstructor*>& runtime::BackendManager::get_registry()
......@@ -107,7 +107,7 @@ shared_ptr<runtime::Backend> runtime::BackendManager::create_backend(const std::
}
else
{
#ifndef NGRAPH_STATIC_LIB_ENABLE
#ifdef NGRAPH_DYNAMIC_COMPONENTS_ENABLE
DL_HANDLE handle = open_shared_library(type);
if (!handle)
{
......@@ -153,7 +153,7 @@ DL_HANDLE runtime::BackendManager::open_shared_library(string type)
string lib_suffix = SHARED_LIB_SUFFIX;
DL_HANDLE handle = nullptr;
#ifndef NGRAPH_STATIC_LIB_ENABLE
#ifdef NGRAPH_DYNAMIC_COMPONENTS_ENABLE
// strip off attributes, IE:CPU becomes IE
auto colon = type.find(":");
......@@ -190,7 +190,7 @@ DL_HANDLE runtime::BackendManager::open_shared_library(string type)
map<string, string> runtime::BackendManager::get_registered_device_map()
{
map<string, string> rc;
#ifndef NGRAPH_STATIC_LIB_ENABLE
#ifdef NGRAPH_DYNAMIC_COMPONENTS_ENABLE
string my_directory =
file_util::get_directory(Backend::get_backend_shared_library_search_directory());
vector<string> backend_list;
......
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