Commit 1a1edef9 authored by Pruthvi's avatar Pruthvi Committed by Scott Cyphers

Don't enable dl use in static builds for r0.25 (#3394)

* Don't enable dl use in static builds

remove dladdr in static

* Swap dlerror defs

* - add NGRAPH_INTERPRETER_STATIC_LIB_ENABLE && NGRAPH_CPU_STATIC_LIB_ENABLE as compiler definitions

* Don't look for backends if static

* - add dummy function to register quantized concat and max_pool for static build

* Fix ifdef
parent 2aa508b4
......@@ -398,6 +398,10 @@ if (NGRAPH_MLIR_ENABLE)
set(NGRAPH_MLIR_SOURCE_DIR ${CMAKE_SOURCE_DIR}/src/contrib/mlir)
endif()
if (NGRAPH_STATIC_LIB_ENABLE)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DNGRAPH_STATIC_LIB_ENABLE")
endif()
if (NGRAPH_PLAIDML_ENABLE)
find_package(PlaidML CONFIG)
if (NOT PLAIDML_FOUND)
......
......@@ -521,6 +521,14 @@ if(NOT NGRAPH_JSON_ENABLE)
target_compile_definitions(ngraph PUBLIC NGRAPH_JSON_DISABLE)
endif()
if(NGRAPH_INTERPRETER_STATIC_LIB_ENABLE)
target_compile_definitions(ngraph PUBLIC NGRAPH_INTERPRETER_STATIC_LIB_ENABLE)
endif()
if(NGRAPH_CPU_STATIC_LIB_ENABLE)
target_compile_definitions(ngraph PUBLIC NGRAPH_CPU_STATIC_LIB_ENABLE)
endif()
if(NGRAPH_DISTRIBUTED_ENABLE)
if(NGRAPH_DISTRIBUTED_MLSL_ENABLE)
target_include_directories(ngraph SYSTEM PRIVATE libmlsl)
......
......@@ -37,6 +37,9 @@ 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 _WIN32
HMODULE hModule = GetModuleHandleW(L"ngraph.dll");
WCHAR wpath[MAX_PATH];
......@@ -52,6 +55,7 @@ static string find_my_pathname()
dladdr(reinterpret_cast<void*>(find_my_pathname), &dl_info);
return dl_info.dli_fname;
#endif
#endif
}
runtime::Backend::~Backend()
......
......@@ -32,12 +32,18 @@
using namespace std;
using namespace ngraph;
#ifdef NGRAPH_STATIC_LIB_ENABLE
#define DLERROR() ""
#else
#ifdef _WIN32
#define CLOSE_LIBRARY(a) FreeLibrary(a)
#define DLSYM(a, b) GetProcAddress(a, b)
#define DLERROR() ""
#else
#define CLOSE_LIBRARY(a) dlclose(a)
#define DLSYM(a, b) dlsym(a, b)
#define DLERROR() dlerror()
#endif
#endif
unordered_map<string, runtime::BackendConstructor*>& runtime::BackendManager::get_registry()
......@@ -101,19 +107,19 @@ shared_ptr<runtime::Backend> runtime::BackendManager::create_backend(const std::
}
else
{
#ifndef NGRAPH_STATIC_LIB_ENABLE
DL_HANDLE handle = open_shared_library(type);
if (!handle)
{
stringstream ss;
ss << "Backend '" << type << "' not registered. Error:";
#ifndef _WIN32
ss << dlerror();
ss << DLERROR();
#endif
throw runtime_error(ss.str());
}
#ifndef _WIN32
dlerror(); // Clear any pending errors
DLERROR(); // Clear any pending errors
#endif
function<runtime::BackendConstructor*()> get_backend_constructor_pointer =
reinterpret_cast<runtime::BackendConstructor* (*)()>(
......@@ -127,7 +133,7 @@ shared_ptr<runtime::Backend> runtime::BackendManager::create_backend(const std::
{
string error;
#ifndef _WIN32
const char* err = dlerror();
const char* err = DLERROR();
error = (err ? err : "");
#endif
CLOSE_LIBRARY(handle);
......@@ -136,6 +142,7 @@ shared_ptr<runtime::Backend> runtime::BackendManager::create_backend(const std::
"library.\nError='" +
error + "'");
}
#endif
}
return backend;
}
......@@ -146,6 +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
// strip off attributes, IE:CPU becomes IE
auto colon = type.find(":");
......@@ -163,9 +171,9 @@ DL_HANDLE runtime::BackendManager::open_shared_library(string type)
SetDllDirectory((LPCSTR)my_directory.c_str());
handle = LoadLibrary(library_path.c_str());
#else
dlerror(); // Clear any pending errors
DLERROR(); // Clear any pending errors
handle = dlopen(library_path.c_str(), RTLD_NOW | RTLD_GLOBAL);
const char* err = dlerror();
const char* err = DLERROR();
error = (err ? err : "");
#endif
if (!handle)
......@@ -175,12 +183,14 @@ DL_HANDLE runtime::BackendManager::open_shared_library(string type)
ss << "\nOpen error message '" << error << "'";
throw runtime_error(ss.str());
}
#endif
return handle;
}
map<string, string> runtime::BackendManager::get_registered_device_map()
{
map<string, string> rc;
#ifndef NGRAPH_STATIC_LIB_ENABLE
string my_directory =
file_util::get_directory(Backend::get_backend_shared_library_search_directory());
vector<string> backend_list;
......@@ -197,6 +207,7 @@ map<string, string> runtime::BackendManager::get_registered_device_map()
}
};
file_util::iterate_files(my_directory, f, false, true);
#endif
return rc;
}
......
......@@ -95,6 +95,9 @@ namespace ngraph
}
}
REGISTER_OP_BUILDER(QuantizedConcat);
#ifdef NGRAPH_CPU_STATIC_LIB_ENABLE
void register_builders_quantized_concat_cpp() {}
#endif
}
}
}
......@@ -69,6 +69,9 @@ namespace ngraph
}
}
REGISTER_OP_BUILDER(QuantizedMaxPool);
#ifdef NGRAPH_CPU_STATIC_LIB_ENABLE
void register_builders_quantized_max_pool_cpp() {}
#endif
}
}
}
......@@ -77,6 +77,8 @@ namespace ngraph
register_builders_tile_cpp();
register_builders_topk_cpp();
register_builders_update_slice_cpp();
register_builders_quantized_concat_cpp();
register_builders_quantized_max_pool_cpp();
}
}
}
......
......@@ -76,6 +76,8 @@ namespace ngraph
void register_builders_tile_cpp();
void register_builders_topk_cpp();
void register_builders_update_slice_cpp();
void register_builders_quantized_concat_cpp();
void register_builders_quantized_max_pool_cpp();
}
}
}
......
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