Commit be99cb7f authored by pruthvi's avatar pruthvi

Merge remote-tracking branch 'origin/bob/static_backend_init' into pruthvi/cpu_static_backend

parents 824d6144 2688f37c
......@@ -182,6 +182,7 @@ option(NGRAPH_DISTRIBUTED_ENABLE "Enable distributed training using MLSL/OpenMPI
option(NGRAPH_FAST_MATH_ENABLE "Enable fast math" ON)
option(NGRAPH_JSON_ENABLE "Enable JSON based serialization and tracing features" TRUE)
option(NGRAPH_STATIC_LIB_ENABLE "Enable build nGraph static library" FALSE)
option(NGRAPH_INTERPRETER_STATIC_LIB_ENABLE "Enable build INTERPRETER backend static library" FALSE)
if (NGRAPH_CPU_ENABLE
AND
......@@ -257,29 +258,33 @@ NORMALIZE_BOOL(NGRAPH_PYTHON_BUILD_ENABLE)
NORMALIZE_BOOL(NGRAPH_USE_PREBUILT_LLVM)
NORMALIZE_BOOL(NGRAPH_PLAIDML_ENABLE)
NORMALIZE_BOOL(NGRAPH_JSON_ENABLE)
message(STATUS "NGRAPH_UNIT_TEST_ENABLE: ${NGRAPH_UNIT_TEST_ENABLE}")
message(STATUS "NGRAPH_TOOLS_ENABLE: ${NGRAPH_TOOLS_ENABLE}")
message(STATUS "NGRAPH_CPU_ENABLE: ${NGRAPH_CPU_ENABLE}")
message(STATUS "NGRAPH_MLIR_ENABLE: ${NGRAPH_MLIR_ENABLE}")
message(STATUS "NGRAPH_INTELGPU_ENABLE: ${NGRAPH_INTELGPU_ENABLE}")
message(STATUS "NGRAPH_GPU_ENABLE: ${NGRAPH_GPU_ENABLE}")
message(STATUS "NGRAPH_INTERPRETER_ENABLE: ${NGRAPH_INTERPRETER_ENABLE}")
message(STATUS "NGRAPH_NOP_ENABLE: ${NGRAPH_NOP_ENABLE}")
message(STATUS "NGRAPH_GPUH_ENABLE: ${NGRAPH_GPUH_ENABLE}")
message(STATUS "NGRAPH_GENERIC_CPU_ENABLE: ${NGRAPH_GENERIC_CPU_ENABLE}")
message(STATUS "NGRAPH_DEBUG_ENABLE: ${NGRAPH_DEBUG_ENABLE}")
message(STATUS "NGRAPH_DEPRECATED_ENABLE: ${NGRAPH_DEPRECATED_ENABLE}")
message(STATUS "NGRAPH_ONNX_IMPORT_ENABLE: ${NGRAPH_ONNX_IMPORT_ENABLE}")
message(STATUS "NGRAPH_DEX_ONLY: ${NGRAPH_DEX_ONLY}")
message(STATUS "NGRAPH_ENABLE_CPU_CONV_AUTO: ${NGRAPH_ENABLE_CPU_CONV_AUTO}")
message(STATUS "NGRAPH_CODE_COVERAGE_ENABLE: ${NGRAPH_CODE_COVERAGE_ENABLE}")
message(STATUS "NGRAPH_LIB_VERSIONING_ENABLE: ${NGRAPH_LIB_VERSIONING_ENABLE}")
message(STATUS "NGRAPH_PYTHON_BUILD_ENABLE: ${NGRAPH_PYTHON_BUILD_ENABLE}")
message(STATUS "NGRAPH_USE_PREBUILT_LLVM: ${NGRAPH_USE_PREBUILT_LLVM}")
message(STATUS "NGRAPH_PLAIDML_ENABLE: ${NGRAPH_PLAIDML_ENABLE}")
message(STATUS "NGRAPH_DISTRIBUTED_ENABLE: ${NGRAPH_DISTRIBUTED_ENABLE}")
message(STATUS "NGRAPH_JSON_ENABLE: ${NGRAPH_JSON_ENABLE}")
NORMALIZE_BOOL(NGRAPH_STATIC_LIB_ENABLE)
NORMALIZE_BOOL(NGRAPH_INTERPRETER_STATIC_LIB_ENABLE)
message(STATUS "NGRAPH_UNIT_TEST_ENABLE: ${NGRAPH_UNIT_TEST_ENABLE}")
message(STATUS "NGRAPH_TOOLS_ENABLE: ${NGRAPH_TOOLS_ENABLE}")
message(STATUS "NGRAPH_CPU_ENABLE: ${NGRAPH_CPU_ENABLE}")
message(STATUS "NGRAPH_MLIR_ENABLE: ${NGRAPH_MLIR_ENABLE}")
message(STATUS "NGRAPH_INTELGPU_ENABLE: ${NGRAPH_INTELGPU_ENABLE}")
message(STATUS "NGRAPH_GPU_ENABLE: ${NGRAPH_GPU_ENABLE}")
message(STATUS "NGRAPH_INTERPRETER_ENABLE: ${NGRAPH_INTERPRETER_ENABLE}")
message(STATUS "NGRAPH_NOP_ENABLE: ${NGRAPH_NOP_ENABLE}")
message(STATUS "NGRAPH_GPUH_ENABLE: ${NGRAPH_GPUH_ENABLE}")
message(STATUS "NGRAPH_GENERIC_CPU_ENABLE: ${NGRAPH_GENERIC_CPU_ENABLE}")
message(STATUS "NGRAPH_DEBUG_ENABLE: ${NGRAPH_DEBUG_ENABLE}")
message(STATUS "NGRAPH_DEPRECATED_ENABLE: ${NGRAPH_DEPRECATED_ENABLE}")
message(STATUS "NGRAPH_ONNX_IMPORT_ENABLE: ${NGRAPH_ONNX_IMPORT_ENABLE}")
message(STATUS "NGRAPH_DEX_ONLY: ${NGRAPH_DEX_ONLY}")
message(STATUS "NGRAPH_ENABLE_CPU_CONV_AUTO: ${NGRAPH_ENABLE_CPU_CONV_AUTO}")
message(STATUS "NGRAPH_CODE_COVERAGE_ENABLE: ${NGRAPH_CODE_COVERAGE_ENABLE}")
message(STATUS "NGRAPH_LIB_VERSIONING_ENABLE: ${NGRAPH_LIB_VERSIONING_ENABLE}")
message(STATUS "NGRAPH_PYTHON_BUILD_ENABLE: ${NGRAPH_PYTHON_BUILD_ENABLE}")
message(STATUS "NGRAPH_USE_PREBUILT_LLVM: ${NGRAPH_USE_PREBUILT_LLVM}")
message(STATUS "NGRAPH_PLAIDML_ENABLE: ${NGRAPH_PLAIDML_ENABLE}")
message(STATUS "NGRAPH_DISTRIBUTED_ENABLE: ${NGRAPH_DISTRIBUTED_ENABLE}")
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}")
#-----------------------------------------------------------------------------------------------
# Installation logic...
......
......@@ -14,6 +14,12 @@
// limitations under the License.
//*****************************************************************************
#ifdef _WIN32
#include <windows.h>
#else
#include <dlfcn.h>
#endif
#include <sstream>
#include "ngraph/file_util.hpp"
......@@ -25,6 +31,28 @@
using namespace std;
using namespace ngraph;
std::string runtime::Backend::s_backend_shared_library_search_directory;
// This finds the full path of the containing shared library
static string find_my_file()
{
#ifdef _WIN32
HMODULE hModule = GetModuleHandleW(L"ngraph.dll");
WCHAR wpath[MAX_PATH];
GetModuleFileNameW(hModule, wpath, MAX_PATH);
wstring ws(wpath);
string path(ws.begin(), ws.end());
replace(path.begin(), path.end(), '\\', '/');
path = file_util::get_directory(path);
path += "/";
return path;
#else
Dl_info dl_info;
dladdr(reinterpret_cast<void*>(find_my_file), &dl_info);
return dl_info.dli_fname;
#endif
}
runtime::Backend::~Backend()
{
}
......@@ -86,6 +114,11 @@ void runtime::Backend::remove_compiled_function(std::shared_ptr<Executable> exec
{
}
std::shared_ptr<runtime::Executable> runtime::Backend::load(istream& input_stream)
{
throw runtime_error("load opertion unimplemented.");
}
bool runtime::Backend::is_device_memory(void* ptr)
{
// override this method for each supported backend to determine if the passed pointer is in
......@@ -93,9 +126,18 @@ bool runtime::Backend::is_device_memory(void* ptr)
return false;
}
std::shared_ptr<runtime::Executable> runtime::Backend::load(istream& input_stream)
void runtime::Backend::set_backend_shared_library_search_directory(const string& path)
{
throw runtime_error("load opertion unimplemented.");
s_backend_shared_library_search_directory = path;
}
const string& runtime::Backend::get_backend_shared_library_search_directory()
{
if (s_backend_shared_library_search_directory.empty())
{
s_backend_shared_library_search_directory = find_my_file();
}
return s_backend_shared_library_search_directory;
}
bool runtime::Backend::set_config(const map<string, string>& config, string& error)
......
......@@ -142,6 +142,18 @@ public:
/// \returns a shared pointer to the op if found, else nullptr
virtual std::shared_ptr<ngraph::Node> get_backend_op(const std::string& op_name, ...);
/// \brief Allows sending backend specific configuration. The map contains key, value pairs
/// specific to a particluar backend. The definition of these key, value pairs is
/// defined by each backend.
/// \param config The configuration map sent to the backend
/// \param error An error string describing any error encountered
/// \returns true if the configuration is supported, false otherwise. On false the error
/// parameter value is valid.
virtual bool set_config(const std::map<std::string, std::string>& config, std::string& error);
static void set_backend_shared_library_search_directory(const std::string& path);
static const std::string& get_backend_shared_library_search_directory();
/// \brief Returns memory allocator used by backend for host allocations
virtual Allocator* get_host_memory_allocator() { return nullptr; }
/// \brief Set the host memory allocator to be used by the backend
......@@ -159,12 +171,6 @@ public:
/// \param ptr pointer to the memory to determine if its in device memory or not
virtual bool is_device_memory(void* ptr);
/// \brief Allows sending backend specific configuration. The map contains key, value pairs
/// specific to a particluar backend. The definition of these key, value pairs is
/// defined by each backend.
/// \param config The configuration map sent to the backend
/// \param error An error string describing any error encountered
/// \returns true if the configuration is supported, false otherwise. On false the error
/// parameter value is valid.
virtual bool set_config(const std::map<std::string, std::string>& config, std::string& error);
private:
static std::string s_backend_shared_library_search_directory;
};
......@@ -25,6 +25,7 @@
#include "ngraph/file_util.hpp"
#include "ngraph/runtime/backend.hpp"
#include "ngraph/runtime/backend_manager.hpp"
#include "ngraph/runtime/interpreter/static_initialize.hpp"
#include "ngraph/util.hpp"
using namespace std;
......@@ -107,6 +108,7 @@ shared_ptr<runtime::Backend> runtime::BackendManager::create_backend(const std::
if (get_backend_constructor_pointer)
{
backend = get_backend_constructor_pointer()->create(config);
register_backend(type, get_backend_constructor_pointer());
}
else
{
......@@ -125,26 +127,6 @@ shared_ptr<runtime::Backend> runtime::BackendManager::create_backend(const std::
return backend;
}
// This doodad finds the full path of the containing shared library
static string find_my_file()
{
#ifdef _WIN32
HMODULE hModule = GetModuleHandleW(L"ngraph.dll");
WCHAR wpath[MAX_PATH];
GetModuleFileNameW(hModule, wpath, MAX_PATH);
wstring ws(wpath);
string path(ws.begin(), ws.end());
replace(path.begin(), path.end(), '\\', '/');
path = file_util::get_directory(path);
path += "/";
return path;
#else
Dl_info dl_info;
dladdr(reinterpret_cast<void*>(find_my_file), &dl_info);
return dl_info.dli_fname;
#endif
}
DL_HANDLE runtime::BackendManager::open_shared_library(string type)
{
string lib_prefix = SHARED_LIB_PREFIX;
......@@ -160,7 +142,8 @@ DL_HANDLE runtime::BackendManager::open_shared_library(string type)
}
string library_name = lib_prefix + to_lower(type) + "_backend" + lib_suffix;
string my_directory = file_util::get_directory(find_my_file());
string my_directory =
file_util::get_directory(Backend::get_backend_shared_library_search_directory());
string library_path = file_util::path_join(my_directory, library_name);
string error;
#ifdef _WIN32
......@@ -185,7 +168,8 @@ DL_HANDLE runtime::BackendManager::open_shared_library(string type)
map<string, string> runtime::BackendManager::get_registered_device_map()
{
map<string, string> rc;
string my_directory = file_util::get_directory(find_my_file());
string my_directory =
file_util::get_directory(Backend::get_backend_shared_library_search_directory());
vector<string> backend_list;
auto f = [&](const string& file, bool is_dir) {
......
......@@ -14,14 +14,21 @@
# limitations under the License.
# ******************************************************************************
if (NGRAPH_INTERPRETER_STATIC_LIB_ENABLE)
set(LIBRARY_TYPE STATIC)
else()
set(LIBRARY_TYPE SHARED)
endif()
if (NGRAPH_INTERPRETER_ENABLE)
add_library(interpreter_backend SHARED int_backend.cpp node_wrapper.cpp int_executable.cpp)
add_library(interpreter_backend ${LIBRARY_TYPE} int_backend.cpp node_wrapper.cpp int_executable.cpp)
if(NGRAPH_LIB_VERSIONING_ENABLE)
set_target_properties(interpreter_backend PROPERTIES
VERSION ${NGRAPH_VERSION}
SOVERSION ${NGRAPH_API_VERSION})
endif()
target_link_libraries(interpreter_backend PUBLIC ngraph)
target_compile_definitions(interpreter_backend PUBLIC NGRAPH_INTERPRETER_STATIC_LIB_ENABLE)
install(TARGETS interpreter_backend
LIBRARY DESTINATION "${NGRAPH_INSTALL_LIB}"
......
......@@ -20,13 +20,14 @@
#include "ngraph/runtime/backend_manager.hpp"
#include "ngraph/runtime/host_tensor.hpp"
#include "ngraph/runtime/interpreter/int_executable.hpp"
#include "ngraph/runtime/interpreter/static_initialize.hpp"
#include "ngraph/serializer.hpp"
#include "ngraph/util.hpp"
using namespace std;
using namespace ngraph;
extern "C" runtime::BackendConstructor* get_backend_constructor_pointer()
runtime::BackendConstructor* runtime::interpreter::get_backend_constructor_pointer()
{
class INTBackendConstructor : public runtime::BackendConstructor
{
......@@ -42,6 +43,24 @@ extern "C" runtime::BackendConstructor* get_backend_constructor_pointer()
return s_backend_constructor.get();
}
#ifndef INTERPRETER_BACKEND_STATIC
extern "C" runtime::BackendConstructor* get_backend_constructor_pointer()
{
return runtime::interpreter::get_backend_constructor_pointer();
}
#endif
void runtime::interpreter::static_initialize()
{
static bool s_is_initialized = false;
if (!s_is_initialized)
{
s_is_initialized = true;
BackendManager::register_backend("INTERPRETER",
runtime::interpreter::get_backend_constructor_pointer());
}
}
runtime::interpreter::INTBackend::INTBackend()
{
}
......
......@@ -34,6 +34,7 @@ namespace ngraph
class INTBackend;
class INTExecutable;
class INTBackendConstructor;
BackendConstructor* get_backend_constructor_pointer();
}
}
}
......
//*****************************************************************************
// Copyright 2017-2019 Intel Corporation
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//*****************************************************************************
#pragma once
namespace ngraph
{
namespace runtime
{
namespace interpreter
{
void static_initialize();
}
}
}
......@@ -33,12 +33,22 @@
#include "ngraph/pass/memory_layout.hpp"
#include "ngraph/pass/visualize_tree.hpp"
#include "ngraph/runtime/backend.hpp"
#include "ngraph/runtime/backend_manager.hpp"
#include "ngraph/runtime/interpreter/int_backend.hpp"
#include "ngraph/serializer.hpp"
#include "ngraph/util.hpp"
using namespace std;
using namespace ngraph;
static void configure_static_backends()
{
#ifdef NGRAPH_INTERPRETER_STATIC_LIB_ENABLE
ngraph::runtime::BackendManager::register_backend(
"INTERPRETER", ngraph::runtime::interpreter::get_backend_constructor_pointer());
#endif
}
class PerfShape : public ngraph::runtime::PerformanceCounter
{
public:
......@@ -182,6 +192,7 @@ int main(int argc, char** argv)
bool copy_data = true;
bool dot_file = false;
configure_static_backends();
for (size_t i = 1; i < argc; i++)
{
string arg = argv[i];
......
......@@ -19,11 +19,22 @@
#include "gtest/gtest.h"
#include "ngraph/log.hpp"
#include "ngraph/runtime/backend_manager.hpp"
#include "ngraph/runtime/interpreter/int_backend.hpp"
using namespace std;
static void configure_static_backends()
{
#ifdef NGRAPH_INTERPRETER_STATIC_LIB_ENABLE
ngraph::runtime::BackendManager::register_backend(
"INTERPRETER", ngraph::runtime::interpreter::get_backend_constructor_pointer());
#endif
}
int main(int argc, char** argv)
{
configure_static_backends();
const char* exclude = "--gtest_filter=-benchmark.*";
vector<char*> argv_vector;
argv_vector.push_back(argv[0]);
......
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