Unverified Commit 9035fb09 authored by Scott Cyphers's avatar Scott Cyphers Committed by GitHub

Cyphers/static (#3497)

* Static linking refactorization

* File name changed

* Update changes.md

* Merge error

* revert

* Review comments
parent 67483af0
...@@ -186,9 +186,10 @@ option(NGRAPH_PLAIDML_ENABLE "Enable the PlaidML backend" ${PLAIDML_FOUND}) ...@@ -186,9 +186,10 @@ option(NGRAPH_PLAIDML_ENABLE "Enable the PlaidML backend" ${PLAIDML_FOUND})
option(NGRAPH_DISTRIBUTED_ENABLE "Enable distributed training using MLSL/OpenMPI" OFF) option(NGRAPH_DISTRIBUTED_ENABLE "Enable distributed training using MLSL/OpenMPI" OFF)
option(NGRAPH_FAST_MATH_ENABLE "Enable fast math" ON) option(NGRAPH_FAST_MATH_ENABLE "Enable fast math" ON)
option(NGRAPH_JSON_ENABLE "Enable JSON based serialization and tracing features" TRUE) 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_STATIC_LIB_ENABLE "Enable build nGraph as a static library" FALSE)
option(NGRAPH_INTERPRETER_STATIC_LIB_ENABLE "Enable build INTERPRETER backend static library" FALSE) option(NGRAPH_INTERPRETER_STATIC_LIB_ENABLE "Enable build INTERPRETER backend as a static library" FALSE)
option(NGRAPH_CPU_STATIC_LIB_ENABLE "Enable build CPU backend static library" FALSE) option(NGRAPH_CPU_STATIC_LIB_ENABLE "Enable build CPU backend as a static library" FALSE)
option(NGRAPH_PLAIDML_STATIC_LIB_ENABLE "Enable build PlaidML backend as a static library" FALSE)
option(NGRAPH_DYNAMIC_COMPONENTS_ENABLE "Enable dynamic loading of components" TRUE) option(NGRAPH_DYNAMIC_COMPONENTS_ENABLE "Enable dynamic loading of components" TRUE)
if (NGRAPH_CPU_ENABLE if (NGRAPH_CPU_ENABLE
...@@ -290,6 +291,7 @@ message(STATUS "NGRAPH_JSON_ENABLE: ${NGRAPH_JSON_ENABLE}") ...@@ -290,6 +291,7 @@ message(STATUS "NGRAPH_JSON_ENABLE: ${NGRAPH_JSON_ENABLE}")
message(STATUS "NGRAPH_STATIC_LIB_ENABLE: ${NGRAPH_STATIC_LIB_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_INTERPRETER_STATIC_LIB_ENABLE: ${NGRAPH_INTERPRETER_STATIC_LIB_ENABLE}")
message(STATUS "NGRAPH_CPU_STATIC_LIB_ENABLE: ${NGRAPH_CPU_STATIC_LIB_ENABLE}") message(STATUS "NGRAPH_CPU_STATIC_LIB_ENABLE: ${NGRAPH_CPU_STATIC_LIB_ENABLE}")
message(STATUS "NGRAPH_PLAIDML_STATIC_LIB_ENABLE: ${NGRAPH_PLAIDML_STATIC_LIB_ENABLE}")
message(STATUS "NGRAPH_DYNAMIC_COMPONENTS_ENABLE: ${NGRAPH_DYNAMIC_COMPONENTS_ENABLE}") message(STATUS "NGRAPH_DYNAMIC_COMPONENTS_ENABLE: ${NGRAPH_DYNAMIC_COMPONENTS_ENABLE}")
#----------------------------------------------------------------------------------------------- #-----------------------------------------------------------------------------------------------
......
# API Changes # API Changes
## Backend library interface
* Each backend `BACKEND` needs to define the macro `${BACKEND}_API` appropriately to import symbols
referenced from outside the library and to export them from within the library. See any
of the `${backend}_backend_visibility.hpp` files for an example.
* The `CMakeLists.txt` file for a backend defines `${BACKEND}_BACKEND_DLL_EXPORTS`.
`target_compile_definitions(${backend}_backend PRIVATE ${BACKEND}_BACKEND_DLL_EXPORTS)`
* Each backend must define a function `ngraph_register_${backend}_backend` that registers a
backend constructor function and ensures that initializations are performed.
`ngraph/src/runtime/cpu/cpu_backend.cpp` has an example that includes initializations.
Remove the old backend constructor code.
## Passes ## Passes
* `LikeReplacement` pass must be run by all transformers. * `LikeReplacement` pass must be run by all transformers.
* `ngraph::pass::FusionType` is now an enum class. Constant values defined by `FusionType` are created for backward compatibility and will be removed in future releases. * `ngraph::pass::FusionType` is now an enum class. Constant values defined by `FusionType` are created for backward compatibility and will be removed in future releases.
......
...@@ -54,6 +54,7 @@ set (SRC ...@@ -54,6 +54,7 @@ set (SRC
builder/tensor_mask.hpp builder/tensor_mask.hpp
check.hpp check.hpp
code_writer.hpp code_writer.hpp
component_manager.hpp
coordinate.cpp coordinate.cpp
coordinate.hpp coordinate.hpp
coordinate_diff.cpp coordinate_diff.cpp
......
...@@ -16,13 +16,15 @@ ...@@ -16,13 +16,15 @@
#pragma once #pragma once
namespace ngraph #include <string>
{
namespace runtime #include "ngraph/ngraph_visibility.hpp"
{ #include "ngraph/runtime/cpu/cpu_backend_visibility.h"
namespace interpreter #include "ngraph/runtime/interpreter/int_backend_visibility.hpp"
{ #include "ngraph/runtime/nop/nop_backend_visibility.hpp"
void static_initialize(); #include "ngraph/runtime/plaidml/plaidml_backend_visibility.hpp"
}
} extern "C" CPU_BACKEND_API void ngraph_register_cpu_backend();
} extern "C" INTERPRETER_BACKEND_API void ngraph_register_interpreter_backend();
extern "C" PLAIDML_BACKEND_API void ngraph_register_plaidml_backend();
extern "C" NOP_BACKEND_API void ngraph_register_nop_backend();
...@@ -71,6 +71,7 @@ namespace ngraph ...@@ -71,6 +71,7 @@ namespace ngraph
#include "ngraph/builder/reduce_ops.hpp" #include "ngraph/builder/reduce_ops.hpp"
#include "ngraph/builder/reshape.hpp" #include "ngraph/builder/reshape.hpp"
#include "ngraph/builder/tensor_mask.hpp" #include "ngraph/builder/tensor_mask.hpp"
#include "ngraph/component_manager.hpp"
#include "ngraph/coordinate_transform.hpp" #include "ngraph/coordinate_transform.hpp"
#include "ngraph/descriptor/input.hpp" #include "ngraph/descriptor/input.hpp"
#include "ngraph/descriptor/layout/dense_tensor_layout.hpp" #include "ngraph/descriptor/layout/dense_tensor_layout.hpp"
......
...@@ -25,8 +25,6 @@ ...@@ -25,8 +25,6 @@
#include "ngraph/file_util.hpp" #include "ngraph/file_util.hpp"
#include "ngraph/runtime/backend.hpp" #include "ngraph/runtime/backend.hpp"
#include "ngraph/runtime/backend_manager.hpp" #include "ngraph/runtime/backend_manager.hpp"
#include "ngraph/runtime/cpu/static_initialize.hpp"
#include "ngraph/runtime/interpreter/static_initialize.hpp"
#include "ngraph/util.hpp" #include "ngraph/util.hpp"
using namespace std; using namespace std;
...@@ -40,26 +38,29 @@ using namespace ngraph; ...@@ -40,26 +38,29 @@ using namespace ngraph;
#else #else
#define CLOSE_LIBRARY(a) dlclose(a) #define CLOSE_LIBRARY(a) dlclose(a)
#define DLSYM(a, b) dlsym(a, b) #define DLSYM(a, b) dlsym(a, b)
#define DLERROR() dlerror() string DLERROR()
{
const char* error = dlerror();
return error == nullptr ? "" : error;
}
#endif #endif
#else #else
#define DLERROR() "" #define DLERROR() ""
#endif #endif
unordered_map<string, runtime::BackendConstructor*>& runtime::BackendManager::get_registry() unordered_map<string, runtime::BackendConstructor>& runtime::BackendManager::get_registry()
{ {
static unordered_map<string, BackendConstructor*> s_registered_backend; static unordered_map<string, BackendConstructor> s_registered_backend;
return s_registered_backend; return s_registered_backend;
} }
void runtime::BackendManager::register_backend(const string& name, BackendConstructor* new_backend) void runtime::BackendManager::register_backend(const string& name, BackendConstructor new_backend)
{ {
get_registry()[name] = new_backend; get_registry()[name] = new_backend;
} }
vector<string> runtime::BackendManager::get_registered_backends() vector<string> runtime::BackendManager::get_registered_backends()
{ {
initialize_backends();
vector<string> rc; vector<string> rc;
for (const auto& p : get_registry()) for (const auto& p : get_registry())
{ {
...@@ -74,21 +75,9 @@ vector<string> runtime::BackendManager::get_registered_backends() ...@@ -74,21 +75,9 @@ vector<string> runtime::BackendManager::get_registered_backends()
} }
return rc; return rc;
} }
void runtime::BackendManager::initialize_backends()
{
#ifdef NGRAPH_INTERPRETER_STATIC_LIB_ENABLE
runtime::interpreter::static_initialize();
#endif
#ifdef NGRAPH_CPU_STATIC_LIB_ENABLE
runtime::cpu::static_initialize();
#endif
}
shared_ptr<runtime::Backend> runtime::BackendManager::create_backend(const std::string& config) shared_ptr<runtime::Backend> runtime::BackendManager::create_backend(const std::string& config)
{ {
initialize_backends();
shared_ptr<runtime::Backend> backend;
string type = config; string type = config;
// strip off attributes, IE:CPU becomes IE // strip off attributes, IE:CPU becomes IE
...@@ -98,62 +87,65 @@ shared_ptr<runtime::Backend> runtime::BackendManager::create_backend(const std:: ...@@ -98,62 +87,65 @@ shared_ptr<runtime::Backend> runtime::BackendManager::create_backend(const std::
type = type.substr(0, colon); type = type.substr(0, colon);
} }
auto registry = get_registry(); auto& registry = get_registry();
auto it = registry.find(type); auto it = registry.find(type);
if (it != registry.end()) string error;
{
BackendConstructor* new_backend = it->second;
backend = new_backend->create(config);
}
else
{
#ifdef NGRAPH_DYNAMIC_COMPONENTS_ENABLE #ifdef NGRAPH_DYNAMIC_COMPONENTS_ENABLE
if (it == registry.end())
{
DL_HANDLE handle = open_shared_library(type); DL_HANDLE handle = open_shared_library(type);
if (!handle) if (!handle)
{ {
stringstream ss; error = DLERROR();
ss << "Backend '" << type << "' not registered. Error:";
#ifndef _WIN32
ss << DLERROR();
#endif
throw runtime_error(ss.str());
} }
#ifndef _WIN32 else
{
DLERROR(); // Clear any pending errors DLERROR(); // Clear any pending errors
#endif string register_function_name =
function<runtime::BackendConstructor*()> get_backend_constructor_pointer = string("ngraph_register_") + to_lower(type) + "_backend";
reinterpret_cast<runtime::BackendConstructor* (*)()>( auto register_function =
DLSYM(handle, "get_backend_constructor_pointer")); reinterpret_cast<void (*)()>(DLSYM(handle, register_function_name.c_str()));
if (get_backend_constructor_pointer) if (register_function)
{ {
backend = get_backend_constructor_pointer()->create(config); register_function();
register_backend(type, get_backend_constructor_pointer()); it = registry.find(type);
} }
else else
{ {
string error; error = DLERROR();
#ifndef _WIN32
const char* err = DLERROR();
error = (err ? err : "");
#endif
CLOSE_LIBRARY(handle); CLOSE_LIBRARY(handle);
throw runtime_error( stringstream ss;
"Failed to find symbol 'get_backend_constructor_pointer' in backend " ss << "Failed to find symbol 'get_backend_constructor_pointer' in backend library."
"library.\nError='" + << endl;
error + "'"); if (error.size() > 0)
{
ss << "\nError: " << error;
}
error = ss.str();
}
}
} }
#endif #endif
if (it == registry.end())
{
stringstream ss;
ss << "Backend '" << type << "' not registered.";
if (error.size() > 0)
{
ss << "\n Error: " << DLERROR();
} }
return backend; throw runtime_error(ss.str());
}
return it->second(config);
} }
DL_HANDLE runtime::BackendManager::open_shared_library(string type) DL_HANDLE runtime::BackendManager::open_shared_library(string type)
{ {
string lib_prefix = SHARED_LIB_PREFIX;
string lib_suffix = SHARED_LIB_SUFFIX;
DL_HANDLE handle = nullptr; DL_HANDLE handle = nullptr;
#ifdef NGRAPH_DYNAMIC_COMPONENTS_ENABLE #ifdef NGRAPH_DYNAMIC_COMPONENTS_ENABLE
string lib_prefix = SHARED_LIB_PREFIX;
string lib_suffix = SHARED_LIB_SUFFIX;
// strip off attributes, IE:CPU becomes IE // strip off attributes, IE:CPU becomes IE
auto colon = type.find(":"); auto colon = type.find(":");
...@@ -166,21 +158,22 @@ DL_HANDLE runtime::BackendManager::open_shared_library(string type) ...@@ -166,21 +158,22 @@ DL_HANDLE runtime::BackendManager::open_shared_library(string type)
string my_directory = string my_directory =
file_util::get_directory(Backend::get_backend_shared_library_search_directory()); file_util::get_directory(Backend::get_backend_shared_library_search_directory());
string library_path = file_util::path_join(my_directory, library_name); string library_path = file_util::path_join(my_directory, library_name);
string error;
#ifdef _WIN32 #ifdef _WIN32
SetDllDirectory((LPCSTR)my_directory.c_str()); SetDllDirectory((LPCSTR)my_directory.c_str());
handle = LoadLibrary(library_path.c_str()); handle = LoadLibrary(library_path.c_str());
#else #else
DLERROR(); // Clear any pending errors DLERROR(); // Clear any pending errors
handle = dlopen(library_path.c_str(), RTLD_NOW | RTLD_GLOBAL); handle = dlopen(library_path.c_str(), RTLD_NOW | RTLD_GLOBAL);
const char* err = DLERROR();
error = (err ? err : "");
#endif #endif
string error = DLERROR();
if (!handle) if (!handle)
{ {
stringstream ss; stringstream ss;
ss << "Unable to find backend '" << type << "' as file '" << library_path << "'"; ss << "Unable to find backend '" << type << "' as file '" << library_path << "'";
if (error.size() > 0)
{
ss << "\nOpen error message '" << error << "'"; ss << "\nOpen error message '" << error << "'";
}
throw runtime_error(ss.str()); throw runtime_error(ss.str());
} }
#endif #endif
......
...@@ -30,23 +30,19 @@ ...@@ -30,23 +30,19 @@
#define DL_HANDLE void* #define DL_HANDLE void*
#endif #endif
#include "ngraph/ngraph_visibility.hpp"
namespace ngraph namespace ngraph
{ {
namespace runtime namespace runtime
{ {
class Backend; class Backend;
class BackendManager; class BackendManager;
class BackendConstructor; using BackendConstructor =
std::function<std::shared_ptr<ngraph::runtime::Backend>(const std::string& config)>;
} }
} }
class ngraph::runtime::BackendConstructor
{
public:
virtual ~BackendConstructor() {}
virtual std::shared_ptr<Backend> create(const std::string& config) = 0;
};
class ngraph::runtime::BackendManager class ngraph::runtime::BackendManager
{ {
friend class Backend; friend class Backend;
...@@ -57,7 +53,8 @@ public: ...@@ -57,7 +53,8 @@ public:
/// \param name The name of the registering backend in UPPER CASE. /// \param name The name of the registering backend in UPPER CASE.
/// \param backend_constructor A BackendConstructor which will be called to /// \param backend_constructor A BackendConstructor which will be called to
//// construct an instance of the registered backend. //// construct an instance of the registered backend.
static void register_backend(const std::string& name, BackendConstructor* backend_constructor); static NGRAPH_API void register_backend(const std::string& name,
BackendConstructor backend_constructor);
/// \brief Query the list of registered devices /// \brief Query the list of registered devices
/// \returns A vector of all registered devices. /// \returns A vector of all registered devices.
...@@ -66,9 +63,9 @@ public: ...@@ -66,9 +63,9 @@ public:
private: private:
static void initialize_backends(); static void initialize_backends();
static std::shared_ptr<runtime::Backend> create_backend(const std::string& type); static std::shared_ptr<runtime::Backend> create_backend(const std::string& type);
static std::unordered_map<std::string, BackendConstructor*>& get_registry(); static std::unordered_map<std::string, BackendConstructor>& get_registry();
static std::unordered_map<std::string, BackendConstructor*> s_registered_backend; static std::unordered_map<std::string, BackendConstructor> s_registered_backend;
static DL_HANDLE open_shared_library(std::string type); static DL_HANDLE 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();
......
...@@ -18,6 +18,7 @@ ...@@ -18,6 +18,7 @@
#include "cpu_backend_visibility.h" #include "cpu_backend_visibility.h"
#include "ngraph/component_manager.hpp"
#include "ngraph/graph_util.hpp" #include "ngraph/graph_util.hpp"
#include "ngraph/runtime/backend_manager.hpp" #include "ngraph/runtime/backend_manager.hpp"
#include "ngraph/runtime/cpu/cpu_backend.hpp" #include "ngraph/runtime/cpu/cpu_backend.hpp"
...@@ -35,58 +36,18 @@ ...@@ -35,58 +36,18 @@
using namespace ngraph; using namespace ngraph;
using namespace std; using namespace std;
runtime::BackendConstructor* runtime::cpu::get_backend_constructor_pointer() extern "C" CPU_BACKEND_API void ngraph_register_cpu_backend()
{ {
class CPU_BackendConstructor : public runtime::BackendConstructor runtime::BackendManager::register_backend("CPU", [](const std::string& config) {
static bool is_initialized = false;
if (!is_initialized)
{ {
public:
std::shared_ptr<runtime::Backend> create(const std::string& config) override
{
static bool s_is_initialized = false;
if (!s_is_initialized)
{
s_is_initialized = true;
tbb::TBB_runtime_interface_version(); tbb::TBB_runtime_interface_version();
ngraph::runtime::cpu::register_builders(); ngraph::runtime::cpu::register_builders();
is_initialized = true;
} }
return make_shared<runtime::cpu::CPU_Backend>(); return make_shared<runtime::cpu::CPU_Backend>();
} });
};
static unique_ptr<runtime::BackendConstructor> s_backend_constructor(
new CPU_BackendConstructor());
return s_backend_constructor.get();
}
#if !defined(NGRAPH_CPU_STATIC_LIB_ENABLE)
extern "C" CPU_BACKEND_API runtime::BackendConstructor* get_backend_constructor_pointer()
{
return runtime::cpu::get_backend_constructor_pointer();
}
#endif
void runtime::cpu::static_initialize()
{
static bool s_is_initialized = false;
if (!s_is_initialized)
{
s_is_initialized = true;
BackendManager::register_backend("CPU", runtime::cpu::get_backend_constructor_pointer());
}
}
namespace
{
static class CPUStaticInit
{
public:
CPUStaticInit()
{
runtime::BackendManager::register_backend(
"CPU", runtime::cpu::get_backend_constructor_pointer());
}
~CPUStaticInit() {}
} s_cpu_static_init;
} }
runtime::cpu::CPU_Backend::~CPU_Backend() runtime::cpu::CPU_Backend::~CPU_Backend()
......
...@@ -34,7 +34,7 @@ namespace ngraph ...@@ -34,7 +34,7 @@ namespace ngraph
{ {
class CPU_ExternalFunction; class CPU_ExternalFunction;
class CPU_CallFrame; class CPU_CallFrame;
BackendConstructor* get_backend_constructor_pointer(); BackendConstructor CPU_BACKEND_API get_backend_constructor_pointer();
class CPU_BACKEND_API CPU_Backend : public runtime::Backend class CPU_BACKEND_API CPU_Backend : public runtime::Backend
{ {
public: public:
......
...@@ -14,9 +14,11 @@ ...@@ -14,9 +14,11 @@
// limitations under the License. // limitations under the License.
//***************************************************************************** //*****************************************************************************
#include "ngraph/runtime/generic_cpu/gcpu_backend.hpp" #include "ngraph/runtime/generic_cpu/gcpu_backend_visibility.hpp"
#include "ngraph/except.hpp" #include "ngraph/except.hpp"
#include "ngraph/runtime/backend_manager.hpp" #include "ngraph/runtime/backend_manager.hpp"
#include "ngraph/runtime/generic_cpu/gcpu_backend.hpp"
#include "ngraph/runtime/generic_cpu/gcpu_executable.hpp" #include "ngraph/runtime/generic_cpu/gcpu_executable.hpp"
#include "ngraph/runtime/host_tensor.hpp" #include "ngraph/runtime/host_tensor.hpp"
#include "ngraph/util.hpp" #include "ngraph/util.hpp"
...@@ -24,20 +26,11 @@ ...@@ -24,20 +26,11 @@
using namespace std; using namespace std;
using namespace ngraph; using namespace ngraph;
extern "C" runtime::BackendConstructor* get_backend_constructor_pointer() extern "C" GCPU_BACKEND_API void ngraph_register_gcpu_backend()
{ {
class LocalBackendConstructor : public runtime::BackendConstructor runtime::BackendManager::register_backend("GCPU", [](const std::string& config) {
{
public:
std::shared_ptr<runtime::Backend> create(const std::string& config) override
{
return std::make_shared<runtime::gcpu::GCPUBackend>(); return std::make_shared<runtime::gcpu::GCPUBackend>();
} });
};
static unique_ptr<runtime::BackendConstructor> s_backend_constructor(
new LocalBackendConstructor());
return s_backend_constructor.get();
} }
runtime::gcpu::GCPUBackend::GCPUBackend() runtime::gcpu::GCPUBackend::GCPUBackend()
......
...@@ -41,24 +41,7 @@ ...@@ -41,24 +41,7 @@
#include <CPP/softmax.hpp> #include <CPP/softmax.hpp>
#include <CPP/topology.hpp> #include <CPP/topology.hpp>
#include "ngraph/pass/algebraic_simplification.hpp" #include "ngraph/runtime/intelgpu/intelgpu_backend_visibility.hpp"
#include "ngraph/pass/batch_fusion.hpp"
#include "ngraph/pass/core_fusion.hpp"
#include "ngraph/pass/cse.hpp"
#include "ngraph/pass/fused_op_decomposition.hpp"
#include "ngraph/pass/get_output_element_elimination.hpp"
#include "ngraph/pass/implicit_broadcast_elimination.hpp"
#include "ngraph/pass/manager.hpp"
#include "ngraph/pass/nop_elimination.hpp"
#include "ngraph/pass/reshape_elimination.hpp"
#include "ngraph/runtime/backend_manager.hpp"
#include "ngraph/runtime/intelgpu/intelgpu_backend.hpp"
#include "ngraph/runtime/intelgpu/intelgpu_executable.hpp"
#include "ngraph/runtime/intelgpu/intelgpu_kernels.hpp"
#include "ngraph/runtime/intelgpu/intelgpu_layout.hpp"
#include "ngraph/runtime/intelgpu/intelgpu_op_custom_kernels.hpp"
#include "ngraph/runtime/intelgpu/intelgpu_tensor_view.hpp"
#include "ngraph/runtime/intelgpu/visualize_tree.hpp"
#include "ngraph/file_util.hpp" #include "ngraph/file_util.hpp"
#include "ngraph/function.hpp" #include "ngraph/function.hpp"
...@@ -122,6 +105,24 @@ ...@@ -122,6 +105,24 @@
#include "ngraph/op/softmax.hpp" #include "ngraph/op/softmax.hpp"
#include "ngraph/op/sum.hpp" #include "ngraph/op/sum.hpp"
#include "ngraph/op/topk.hpp" #include "ngraph/op/topk.hpp"
#include "ngraph/pass/algebraic_simplification.hpp"
#include "ngraph/pass/batch_fusion.hpp"
#include "ngraph/pass/core_fusion.hpp"
#include "ngraph/pass/cse.hpp"
#include "ngraph/pass/fused_op_decomposition.hpp"
#include "ngraph/pass/get_output_element_elimination.hpp"
#include "ngraph/pass/implicit_broadcast_elimination.hpp"
#include "ngraph/pass/manager.hpp"
#include "ngraph/pass/nop_elimination.hpp"
#include "ngraph/pass/reshape_elimination.hpp"
#include "ngraph/runtime/backend_manager.hpp"
#include "ngraph/runtime/intelgpu/intelgpu_backend.hpp"
#include "ngraph/runtime/intelgpu/intelgpu_executable.hpp"
#include "ngraph/runtime/intelgpu/intelgpu_kernels.hpp"
#include "ngraph/runtime/intelgpu/intelgpu_layout.hpp"
#include "ngraph/runtime/intelgpu/intelgpu_op_custom_kernels.hpp"
#include "ngraph/runtime/intelgpu/intelgpu_tensor_view.hpp"
#include "ngraph/runtime/intelgpu/visualize_tree.hpp"
#include "ngraph/util.hpp" #include "ngraph/util.hpp"
using namespace std; using namespace std;
...@@ -129,6 +130,13 @@ using namespace ngraph; ...@@ -129,6 +130,13 @@ using namespace ngraph;
using intelgpu_space = runtime::intelgpu::IntelGPULayout; using intelgpu_space = runtime::intelgpu::IntelGPULayout;
extern "C" INTELGPU_BACKEND_API void ngraph_register_intelgpu_backend()
{
runtime::BackendManager::register_backend("INTELGPU", [](const std::string& config) {
return std::make_shared<runtime::intelgpu::IntelGPUBackend>();
});
}
// This expands the op list in op_tbl.hpp into a list of enumerations that look like this: // This expands the op list in op_tbl.hpp into a list of enumerations that look like this:
// Abs, // Abs,
// Acos, // Acos,
......
...@@ -14,51 +14,26 @@ ...@@ -14,51 +14,26 @@
// limitations under the License. // limitations under the License.
//***************************************************************************** //*****************************************************************************
#include "ngraph/runtime/interpreter/int_backend.hpp" #include "ngraph/runtime/interpreter/int_backend_visibility.hpp"
#include "ngraph/component_manager.hpp"
#include "ngraph/cpio.hpp" #include "ngraph/cpio.hpp"
#include "ngraph/except.hpp" #include "ngraph/except.hpp"
#include "ngraph/runtime/backend_manager.hpp" #include "ngraph/runtime/backend_manager.hpp"
#include "ngraph/runtime/host_tensor.hpp" #include "ngraph/runtime/host_tensor.hpp"
#include "ngraph/runtime/interpreter/int_backend.hpp"
#include "ngraph/runtime/interpreter/int_executable.hpp" #include "ngraph/runtime/interpreter/int_executable.hpp"
#include "ngraph/runtime/interpreter/static_initialize.hpp"
#include "ngraph/serializer.hpp" #include "ngraph/serializer.hpp"
#include "ngraph/util.hpp" #include "ngraph/util.hpp"
using namespace std; using namespace std;
using namespace ngraph; using namespace ngraph;
runtime::BackendConstructor* runtime::interpreter::get_backend_constructor_pointer() extern "C" INTERPRETER_BACKEND_API void ngraph_register_interpreter_backend()
{ {
class INTBackendConstructor : public runtime::BackendConstructor runtime::BackendManager::register_backend("INTERPRETER", [](const std::string& config) {
{
public:
std::shared_ptr<runtime::Backend> create(const std::string& config) override
{
return std::make_shared<runtime::interpreter::INTBackend>(); return std::make_shared<runtime::interpreter::INTBackend>();
} });
};
static unique_ptr<runtime::BackendConstructor> s_backend_constructor(
new INTBackendConstructor());
return s_backend_constructor.get();
}
#ifndef NGRAPH_INTERPRETER_STATIC_LIB_ENABLE
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() runtime::interpreter::INTBackend::INTBackend()
......
...@@ -22,6 +22,8 @@ ...@@ -22,6 +22,8 @@
#include <string> #include <string>
#include <vector> #include <vector>
#include "ngraph/runtime/interpreter/int_backend_visibility.hpp"
#include "ngraph/runtime/backend_manager.hpp" #include "ngraph/runtime/backend_manager.hpp"
#include "ngraph/runtime/tensor.hpp" #include "ngraph/runtime/tensor.hpp"
...@@ -34,7 +36,6 @@ namespace ngraph ...@@ -34,7 +36,6 @@ namespace ngraph
class INTBackend; class INTBackend;
class INTExecutable; class INTExecutable;
class INTBackendConstructor; 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.
//*****************************************************************************
// https://gcc.gnu.org/wiki/Visibility
// Generic helper definitions for shared library support
#if defined _WIN32 || defined __CYGWIN__
#define INTERPRETER_HELPER_DLL_IMPORT __declspec(dllimport)
#define INTERPRETER_HELPER_DLL_EXPORT __declspec(dllexport)
#define INTERPRETER_HELPER_DLL_LOCAL
#else
#if __GNUC__ >= 4
#define INTERPRETER_HELPER_DLL_IMPORT __attribute__((visibility("default")))
#define INTERPRETER_HELPER_DLL_EXPORT __attribute__((visibility("default")))
#define INTERPRETER_HELPER_DLL_LOCAL __attribute__((visibility("hidden")))
#else
#define INTERPRETER_HELPER_DLL_IMPORT
#define INTERPRETER_HELPER_DLL_EXPORT
#define INTERPRETER_HELPER_DLL_LOCAL
#endif
#endif
// Now we use the generic helper definitions above to define INTERPRETER_API and INTERPRETER_LOCAL.
// INTERPRETER_API is used for the public API symbols. It either DLL imports or DLL exports
// (or does nothing for static build)
// INTERPRETER_LOCAL is used for non-api symbols.
// #ifdef INTERPRETER_DLL // defined if INTERPRETER is compiled as a DLL
#ifdef INTERPRETER_DLL_EXPORTS // defined if we are building the INTERPRETER DLL (instead of using
// it)
#define INTERPRETER_API INTERPRETER_HELPER_DLL_EXPORT
#else
#define INTERPRETER_API INTERPRETER_HELPER_DLL_IMPORT
#endif // INTERPRETER_DLL_EXPORTS
#define INTERPRETER_LOCAL INTERPRETER_HELPER_DLL_LOCAL
// #else // INTERPRETER_DLL is not defined: this means INTERPRETER is a static lib.
// #define INTERPRETER_API
// #define INTERPRETER_LOCAL
// #endif // INTERPRETER_DLL
...@@ -14,7 +14,8 @@ ...@@ -14,7 +14,8 @@
// limitations under the License. // limitations under the License.
//***************************************************************************** //*****************************************************************************
#include "ngraph/runtime/nop/nop_backend.hpp" #include "ngraph/runtime/nop/nop_backend_visibility.hpp"
#include "ngraph/descriptor/layout/dense_tensor_layout.hpp" #include "ngraph/descriptor/layout/dense_tensor_layout.hpp"
#include "ngraph/except.hpp" #include "ngraph/except.hpp"
#include "ngraph/op/convert.hpp" #include "ngraph/op/convert.hpp"
...@@ -25,6 +26,7 @@ ...@@ -25,6 +26,7 @@
#include "ngraph/pass/liveness.hpp" #include "ngraph/pass/liveness.hpp"
#include "ngraph/pass/manager.hpp" #include "ngraph/pass/manager.hpp"
#include "ngraph/runtime/backend_manager.hpp" #include "ngraph/runtime/backend_manager.hpp"
#include "ngraph/runtime/nop/nop_backend.hpp"
#include "ngraph/util.hpp" #include "ngraph/util.hpp"
using namespace std; using namespace std;
...@@ -32,20 +34,11 @@ using namespace ngraph; ...@@ -32,20 +34,11 @@ using namespace ngraph;
using descriptor::layout::DenseTensorLayout; using descriptor::layout::DenseTensorLayout;
extern "C" runtime::BackendConstructor* get_backend_constructor_pointer() extern "C" NOP_BACKEND_API void ngraph_register_nop_backend()
{ {
class LocalBackendConstructor : public runtime::BackendConstructor runtime::BackendManager::register_backend("NOP", [](const std::string& config) {
{
public:
std::shared_ptr<runtime::Backend> create(const std::string& config) override
{
return std::make_shared<runtime::nop::NOPBackend>(); return std::make_shared<runtime::nop::NOPBackend>();
} });
};
static unique_ptr<runtime::BackendConstructor> s_backend_constructor(
new LocalBackendConstructor());
return s_backend_constructor.get();
} }
shared_ptr<runtime::Tensor> runtime::nop::NOPBackend::create_tensor(const element::Type& type, shared_ptr<runtime::Tensor> runtime::nop::NOPBackend::create_tensor(const element::Type& type,
......
...@@ -14,38 +14,14 @@ ...@@ -14,38 +14,14 @@
// limitations under the License. // limitations under the License.
//***************************************************************************** //*****************************************************************************
#include "ngraph/runtime/backend_manager.hpp"
#include "ngraph/runtime/plaidml/plaidml_backend.hpp" #include "ngraph/runtime/plaidml/plaidml_backend.hpp"
#include "ngraph/runtime/plaidml/plaidml_backend_visibility.hpp"
namespace ngraph
{
namespace runtime
{
namespace plaidml
{
class PlaidML_BackendConstructor;
}
}
}
class ngraph::runtime::plaidml::PlaidML_BackendConstructor final #include "ngraph/runtime/backend_manager.hpp"
: public runtime::BackendConstructor #include "ngraph/runtime/plaidml/plaidml_backend_visibility.hpp"
{
public:
~PlaidML_BackendConstructor() final {}
std::shared_ptr<Backend> create(const std::string& config) final;
};
std::shared_ptr<ngraph::runtime::Backend>
ngraph::runtime::plaidml::PlaidML_BackendConstructor::create(const std::string& config)
{
return std::make_shared<PlaidML_Backend>(config);
}
extern "C" PLAIDML_BACKEND_API ngraph::runtime::BackendConstructor* extern "C" PLAIDML_BACKEND_API void ngraph_register_plaidml_backend()
get_backend_constructor_pointer()
{ {
static ngraph::runtime::plaidml::PlaidML_BackendConstructor backend_constructor; ngraph::runtime::BackendManager::register_backend("PlaidML", [](const std::string& config) {
return &backend_constructor; return std::make_shared<ngraph::runtime::plaidml::PlaidML_Backend>(config);
});
} }
...@@ -451,7 +451,7 @@ if (MSVS) ...@@ -451,7 +451,7 @@ if (MSVS)
) )
else() else()
add_custom_target(unit-test-check add_custom_target(unit-test-check
COMMAND ${PROJECT_BINARY_DIR}/test/unit-test \${ARGS} COMMAND ${PROJECT_BINARY_DIR}/test/unit-test --cpath ${EXTERNAL_PROJECTS_ROOT}/src/ngraph/ \${ARGS}
DEPENDS unit-test DEPENDS unit-test
) )
endif() endif()
......
...@@ -19,22 +19,17 @@ ...@@ -19,22 +19,17 @@
#include "gtest/gtest.h" #include "gtest/gtest.h"
#include "ngraph/log.hpp" #include "ngraph/log.hpp"
#include "ngraph/ngraph.hpp"
#include "ngraph/runtime/backend.hpp"
#include "ngraph/runtime/backend_manager.hpp" #include "ngraph/runtime/backend_manager.hpp"
#include "ngraph/runtime/interpreter/int_backend.hpp" #include "ngraph/runtime/interpreter/int_backend.hpp"
using namespace std; 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) int main(int argc, char** argv)
{ {
configure_static_backends(); const string cpath_flag{"--cpath"};
string cpath;
const char* exclude = "--gtest_filter=-benchmark.*"; const char* exclude = "--gtest_filter=-benchmark.*";
vector<char*> argv_vector; vector<char*> argv_vector;
argv_vector.push_back(argv[0]); argv_vector.push_back(argv[0]);
...@@ -43,9 +38,22 @@ int main(int argc, char** argv) ...@@ -43,9 +38,22 @@ int main(int argc, char** argv)
{ {
argv_vector.push_back(argv[i]); argv_vector.push_back(argv[i]);
} }
argc++; argc = argv_vector.size();
::testing::InitGoogleTest(&argc, argv_vector.data()); ::testing::InitGoogleTest(&argc, argv_vector.data());
for (int i = 1; i < argc; i++)
{
if (cpath_flag == argv[i] && (++i) < argc)
{
cpath = argv[i];
}
}
ngraph::runtime::Backend::set_backend_shared_library_search_directory(cpath);
#ifdef NGRAPH_CPU_ENABLE
ngraph_register_cpu_backend();
#endif
#ifdef NGRAPH_INTERPRETER_ENABLE
ngraph_register_interpreter_backend();
#endif
auto start = std::chrono::system_clock::now(); auto start = std::chrono::system_clock::now();
int rc = RUN_ALL_TESTS(); int rc = RUN_ALL_TESTS();
auto elapsed = std::chrono::duration_cast<std::chrono::milliseconds>( auto elapsed = std::chrono::duration_cast<std::chrono::milliseconds>(
......
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