Unverified Commit c0ab7d42 authored by Scott Cyphers's avatar Scott Cyphers Committed by GitHub

Merge pull request #3251 from NervanaSystems/pruthvi/cpu_static_backend

pruthvi/cpu static backend
parents 410d6e61 7a4cc10c
......@@ -182,6 +182,8 @@ 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)
option(NGRAPH_CPU_STATIC_LIB_ENABLE "Enable build CPU backend static library" FALSE)
if (NGRAPH_CPU_ENABLE
AND
......@@ -257,29 +259,35 @@ 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)
NORMALIZE_BOOL(NGRAPH_CPU_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}")
message(STATUS "NGRAPH_CPU_STATIC_LIB_ENABLE: ${NGRAPH_CPU_STATIC_LIB_ENABLE}")
#-----------------------------------------------------------------------------------------------
# Installation logic...
......
......@@ -14,6 +14,12 @@
// limitations under the License.
//*****************************************************************************
#ifdef _WIN32
#include <windows.h>
#elif defined(__linux) || defined(__APPLE__)
#include <dlfcn.h>
#endif
#include <sstream>
#include "ngraph/file_util.hpp"
......@@ -25,6 +31,29 @@
using namespace std;
using namespace ngraph;
std::mutex runtime::Backend::m_mtx;
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 _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;
#elif defined(__linux) || defined(__APPLE__)
Dl_info dl_info;
dladdr(reinterpret_cast<void*>(find_my_pathname), &dl_info);
return dl_info.dli_fname;
#endif
}
runtime::Backend::~Backend()
{
}
......@@ -86,6 +115,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 operation 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 +127,19 @@ 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.");
std::lock_guard<std::mutex> lock(runtime::Backend::m_mtx);
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_pathname();
}
return s_backend_shared_library_search_directory;
}
bool runtime::Backend::set_config(const map<string, string>& config, string& error)
......
......@@ -17,6 +17,7 @@
#pragma once
#include <memory>
#include <mutex>
#include "ngraph/function.hpp"
#include "ngraph/pass/pass_config.hpp"
......@@ -142,6 +143,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 +172,8 @@ 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:
// mutex to modify s_backend_shared_library_search_directory thread safe
static std::mutex m_mtx;
static std::string s_backend_shared_library_search_directory;
};
......@@ -25,6 +25,8 @@
#include "ngraph/file_util.hpp"
#include "ngraph/runtime/backend.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"
using namespace std;
......@@ -68,6 +70,14 @@ vector<string> runtime::BackendManager::get_registered_backends()
shared_ptr<runtime::Backend> runtime::BackendManager::create_backend(const std::string& config)
{
#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> backend;
string type = config;
......@@ -107,6 +117,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 +136,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 +151,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 +177,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) {
......
......@@ -16,9 +16,16 @@
include(FindOpenMP)
if (NGRAPH_CPU_STATIC_LIB_ENABLE)
set(LIBRARY_TYPE STATIC)
else()
set(LIBRARY_TYPE SHARED)
endif()
set(SRC
cpu_backend.cpp
cpu_builder.cpp
cpu_builder_registry.cpp
cpu_call_frame.cpp
cpu_executor.cpp
cpu_external_function.cpp
......@@ -124,7 +131,6 @@ set(SRC
pass/cpu_post_layout_optimizations.cpp
pass/cpu_rnn_fusion.cpp
pass/cpu_workspace_insertion.cpp
ngraph_version.cpp
)
if (NOT NGRAPH_DEX_ONLY)
......@@ -156,7 +162,10 @@ endif()
if (NGRAPH_CPU_ENABLE)
set(NGRAPH_CPU_DEBUGINFO_ENABLE 0 CACHE STRING "Enable debuginfo in the CPU backend")
add_library(cpu_backend SHARED ${SRC})
add_library(cpu_backend ${LIBRARY_TYPE} ${SRC})
if (NGRAPH_CPU_STATIC_LIB_ENABLE)
target_compile_definitions(cpu_backend PRIVATE "NGRAPH_CPU_STATIC_LIB_ENABLE")
endif()
if(NGRAPH_LIB_VERSIONING_ENABLE)
set_target_properties(cpu_backend PROPERTIES
VERSION ${NGRAPH_VERSION}
......
......@@ -79,6 +79,10 @@ namespace ngraph
}
REGISTER_OP_BUILDER(Add);
#ifdef NGRAPH_CPU_STATIC_LIB_ENABLE
void register_builders_add_cpp() {}
#endif
}
}
}
......@@ -69,6 +69,10 @@ namespace ngraph
}
REGISTER_OP_BUILDER(AllReduce);
#ifdef NGRAPH_CPU_STATIC_LIB_ENABLE
void register_builders_allreduce_cpp() {}
#endif
}
}
}
......@@ -210,6 +210,10 @@ namespace ngraph
}
REGISTER_OP_BUILDER(ArgMax);
#ifdef NGRAPH_CPU_STATIC_LIB_ENABLE
void register_builders_argmax_cpp() {}
#endif
}
}
}
......@@ -210,6 +210,9 @@ namespace ngraph
}
REGISTER_OP_BUILDER(ArgMin);
#ifdef NGRAPH_CPU_STATIC_LIB_ENABLE
void register_builders_argmin_cpp() {}
#endif
}
}
}
......@@ -197,6 +197,10 @@ namespace ngraph
}
REGISTER_OP_BUILDER(AvgPool);
REGISTER_OP_BUILDER(AvgPoolBackprop);
#ifdef NGRAPH_CPU_STATIC_LIB_ENABLE
void register_builders_avg_pool_cpp() {}
#endif
}
}
}
......@@ -508,6 +508,10 @@ namespace ngraph
REGISTER_OP_BUILDER(BatchNormTrainingRelu);
REGISTER_OP_BUILDER(BatchNormInferenceRelu);
REGISTER_OP_BUILDER(BatchNormTrainingBackprop);
#ifdef NGRAPH_CPU_STATIC_LIB_ENABLE
void register_builders_batch_norm_cpp() {}
#endif
}
}
}
......@@ -88,6 +88,9 @@ namespace ngraph
}
}
REGISTER_OP_BUILDER(BoundedRelu);
#ifdef NGRAPH_CPU_STATIC_LIB_ENABLE
void register_builders_bounded_relu_cpp() {}
#endif
}
}
}
......@@ -232,6 +232,9 @@ namespace ngraph
}
REGISTER_OP_BUILDER(Broadcast);
#ifdef NGRAPH_CPU_STATIC_LIB_ENABLE
void register_builders_broadcast_cpp() {}
#endif
}
}
}
......@@ -44,6 +44,9 @@ namespace ngraph
functors.emplace_back(functor);
}
REGISTER_OP_BUILDER(BroadcastDistributed);
#ifdef NGRAPH_CPU_STATIC_LIB_ENABLE
void register_builders_broadcast_distributed_cpp() {}
#endif
}
}
}
......@@ -170,6 +170,9 @@ namespace ngraph
}
REGISTER_OP_BUILDER(Concat);
#ifdef NGRAPH_CPU_STATIC_LIB_ENABLE
void register_builders_concat_cpp() {}
#endif
}
}
}
......@@ -115,6 +115,9 @@ namespace ngraph
}
REGISTER_OP_BUILDER(Convert);
#ifdef NGRAPH_CPU_STATIC_LIB_ENABLE
void register_builders_convert_cpp() {}
#endif
}
}
}
......@@ -104,6 +104,9 @@ namespace ngraph
functors.emplace_back(functor);
}
REGISTER_CPU_OP_BUILDER(ConvertLayout);
#ifdef NGRAPH_CPU_STATIC_LIB_ENABLE
void register_builders_convert_layout_cpp() {}
#endif
}
}
}
......@@ -832,6 +832,10 @@ namespace ngraph
REGISTER_OP_BUILDER(ConvolutionAdd);
REGISTER_OP_BUILDER(GroupConvolutionBias);
REGISTER_OP_BUILDER(DeconvolutionBias)
#ifdef NGRAPH_CPU_STATIC_LIB_ENABLE
void register_builders_convolution_cpp() {}
#endif
} // namespace cpu
} // namespace runtime
} // namespace ngraph
......@@ -258,6 +258,9 @@ namespace ngraph
}
REGISTER_OP_BUILDER(Dot);
#ifdef NGRAPH_CPU_STATIC_LIB_ENABLE
void register_builders_dot_cpp() {}
#endif
}
}
}
......@@ -127,6 +127,9 @@ namespace ngraph
}
REGISTER_OP_BUILDER(Dropout);
#ifdef NGRAPH_CPU_STATIC_LIB_ENABLE
void register_builders_dropout_cpp() {}
#endif
}
}
}
......@@ -245,6 +245,9 @@ namespace ngraph
}
REGISTER_OP_BUILDER(EmbeddingLookup);
#ifdef NGRAPH_CPU_STATIC_LIB_ENABLE
void register_builders_embedding_lookup_cpp() {}
#endif
}
}
}
......@@ -72,6 +72,9 @@ namespace ngraph
}
}
REGISTER_OP_BUILDER(Erf);
#ifdef NGRAPH_CPU_STATIC_LIB_ENABLE
void register_builders_erf_cpp() {}
#endif
}
}
}
......@@ -237,6 +237,9 @@ namespace ngraph
}
REGISTER_OP_BUILDER(Gather);
#ifdef NGRAPH_CPU_STATIC_LIB_ENABLE
void register_builders_gather_cpp() {}
#endif
} // namespace cpu
} // namespace runtime
} // namespace ngraph
......@@ -139,6 +139,9 @@ namespace ngraph
}
REGISTER_OP_BUILDER(GatherND);
#ifdef NGRAPH_CPU_STATIC_LIB_ENABLE
void register_builders_gather_nd_cpp() {}
#endif
}
}
}
......@@ -48,6 +48,9 @@ namespace ngraph
}
REGISTER_OP_BUILDER(GetOutputElement);
#ifdef NGRAPH_CPU_STATIC_LIB_ENABLE
void register_builders_get_output_element_cpp() {}
#endif
}
}
}
......@@ -86,6 +86,9 @@ namespace ngraph
}
}
REGISTER_OP_BUILDER(CPULeakyRelu);
#ifdef NGRAPH_CPU_STATIC_LIB_ENABLE
void register_builders_leaky_relu_cpp() {}
#endif
}
}
}
......@@ -123,6 +123,9 @@ namespace ngraph
}
REGISTER_OP_BUILDER(LRN);
#ifdef NGRAPH_CPU_STATIC_LIB_ENABLE
void register_builders_lrn_cpp() {}
#endif
}
}
}
......@@ -108,6 +108,9 @@ namespace ngraph
functors.emplace_back(functor);
}
REGISTER_OP_BUILDER(Lstm);
#ifdef NGRAPH_CPU_STATIC_LIB_ENABLE
void register_builders_lstm_cpp() {}
#endif
}
}
}
......@@ -396,6 +396,9 @@ namespace ngraph
REGISTER_OP_BUILDER(MatmulBias);
REGISTER_OP_BUILDER(BatchMatMul);
REGISTER_OP_BUILDER(BatchMatMulTranspose);
#ifdef NGRAPH_CPU_STATIC_LIB_ENABLE
void register_builders_matmul_bias_cpp() {}
#endif
}
}
}
......@@ -38,6 +38,9 @@ namespace ngraph
}
REGISTER_OP_BUILDER(Max);
#ifdef NGRAPH_CPU_STATIC_LIB_ENABLE
void register_builders_max_cpp() {}
#endif
}
}
}
......@@ -337,6 +337,9 @@ namespace ngraph
REGISTER_OP_BUILDER(MaxPoolBackprop);
REGISTER_OP_BUILDER(MaxPoolWithIndices);
REGISTER_OP_BUILDER(MaxPoolWithIndicesBackprop);
#ifdef NGRAPH_CPU_STATIC_LIB_ENABLE
void register_builders_max_pool_cpp() {}
#endif
}
}
}
......@@ -38,6 +38,9 @@ namespace ngraph
}
REGISTER_OP_BUILDER(Min);
#ifdef NGRAPH_CPU_STATIC_LIB_ENABLE
void register_builders_min_cpp() {}
#endif
}
}
}
......@@ -109,6 +109,9 @@ namespace ngraph
}
REGISTER_OP_BUILDER(OneHot);
#ifdef NGRAPH_CPU_STATIC_LIB_ENABLE
void register_builders_one_hot_cpp() {}
#endif
}
}
}
......@@ -171,6 +171,9 @@ namespace ngraph
}
}
REGISTER_CF_BUILDER(Pad);
#ifdef NGRAPH_CPU_STATIC_LIB_ENABLE
void register_builders_pad_cpp() {}
#endif
}
}
}
......@@ -38,6 +38,9 @@ namespace ngraph
}
REGISTER_OP_BUILDER(Product);
#ifdef NGRAPH_CPU_STATIC_LIB_ENABLE
void register_builders_product_cpp() {}
#endif
}
}
}
......@@ -585,6 +585,9 @@ namespace ngraph
REGISTER_OP_BUILDER(Dequantize);
REGISTER_OP_BUILDER(Quantize);
#ifdef NGRAPH_CPU_STATIC_LIB_ENABLE
void register_builders_quantization_cpp() {}
#endif
}
}
}
......@@ -69,6 +69,9 @@ namespace ngraph
}
}
REGISTER_OP_BUILDER(QuantizedAvgPool);
#ifdef NGRAPH_CPU_STATIC_LIB_ENABLE
void register_builders_quantized_avg_pool_cpp() {}
#endif
}
}
}
......@@ -708,6 +708,9 @@ namespace ngraph
REGISTER_OP_BUILDER(QuantizedConvolutionBias);
REGISTER_OP_BUILDER(QuantizedConvolutionBiasAdd);
REGISTER_OP_BUILDER(QuantizedConvolutionBiasSignedAdd);
#ifdef NGRAPH_CPU_STATIC_LIB_ENABLE
void register_builders_quantized_conv_cpp() {}
#endif
}
}
}
......@@ -163,6 +163,9 @@ namespace ngraph
}
REGISTER_OP_BUILDER(QuantizedDotBias);
REGISTER_OP_BUILDER(QuantizedDot);
#ifdef NGRAPH_CPU_STATIC_LIB_ENABLE
void register_builders_quantized_dot_cpp() {}
#endif
}
}
}
......@@ -103,6 +103,9 @@ namespace ngraph
}
}
REGISTER_OP_BUILDER(QuantizedMatmul);
#ifdef NGRAPH_CPU_STATIC_LIB_ENABLE
void register_builders_quantized_matmul_cpp() {}
#endif
}
}
}
......@@ -84,6 +84,9 @@ namespace ngraph
REGISTER_OP_BUILDER(Any);
REGISTER_OP_BUILDER(All);
#ifdef NGRAPH_CPU_STATIC_LIB_ENABLE
void register_builders_reduce_function_cpp() {}
#endif
}
}
}
......@@ -134,6 +134,9 @@ namespace ngraph
REGISTER_OP_BUILDER(Relu);
REGISTER_OP_BUILDER(ReluBackprop);
#ifdef NGRAPH_CPU_STATIC_LIB_ENABLE
void register_builders_relu_cpp() {}
#endif
}
}
}
......@@ -135,6 +135,9 @@ namespace ngraph
}
REGISTER_OP_BUILDER(ReplaceSlice);
#ifdef NGRAPH_CPU_STATIC_LIB_ENABLE
void register_builders_replace_slice_cpp() {}
#endif
}
}
}
......@@ -248,6 +248,9 @@ namespace ngraph
}
REGISTER_OP_BUILDER(Reshape);
#ifdef NGRAPH_CPU_STATIC_LIB_ENABLE
void register_builders_reshape_cpp() {}
#endif
}
}
}
......@@ -63,6 +63,9 @@ namespace ngraph
}
REGISTER_OP_BUILDER(Reverse);
#ifdef NGRAPH_CPU_STATIC_LIB_ENABLE
void register_builders_reverse_cpp() {}
#endif
}
}
}
......@@ -80,6 +80,9 @@ namespace ngraph
}
REGISTER_OP_BUILDER(ReverseSequence);
#ifdef NGRAPH_CPU_STATIC_LIB_ENABLE
void register_builders_reverse_sequence_cpp() {}
#endif
}
}
}
......@@ -103,6 +103,9 @@ namespace ngraph
functors.emplace_back(functor);
}
REGISTER_OP_BUILDER(Rnn);
#ifdef NGRAPH_CPU_STATIC_LIB_ENABLE
void register_builders_rnn_cpp() {}
#endif
}
}
}
......@@ -140,6 +140,9 @@ namespace ngraph
}
}
REGISTER_OP_BUILDER(ScatterAdd);
#ifdef NGRAPH_CPU_STATIC_LIB_ENABLE
void register_builders_scatter_add_cpp() {}
#endif
}
}
}
......@@ -157,6 +157,9 @@ namespace ngraph
}
REGISTER_OP_BUILDER(ScatterNDAdd);
#ifdef NGRAPH_CPU_STATIC_LIB_ENABLE
void register_builders_scatter_nd_add_cpp() {}
#endif
}
}
}
......@@ -63,6 +63,9 @@ namespace ngraph
}
REGISTER_OP_BUILDER(Select);
#ifdef NGRAPH_CPU_STATIC_LIB_ENABLE
void register_builders_select_cpp() {}
#endif
}
}
}
......@@ -189,6 +189,9 @@ namespace ngraph
REGISTER_OP_BUILDER(SigmoidBackprop);
REGISTER_OP_BUILDER(SigmoidMultiply);
REGISTER_OP_BUILDER(SigmoidMultiplyBackprop);
#ifdef NGRAPH_CPU_STATIC_LIB_ENABLE
void register_builders_sigmoid_cpp() {}
#endif
}
}
}
......@@ -188,6 +188,9 @@ namespace ngraph
}
REGISTER_OP_BUILDER(Slice);
#ifdef NGRAPH_CPU_STATIC_LIB_ENABLE
void register_builders_slice_cpp() {}
#endif
}
}
}
......@@ -196,6 +196,9 @@ namespace ngraph
}
REGISTER_OP_BUILDER(Softmax);
#ifdef NGRAPH_CPU_STATIC_LIB_ENABLE
void register_builders_softmax_cpp() {}
#endif
}
}
}
......@@ -140,6 +140,9 @@ namespace ngraph
}
REGISTER_OP_BUILDER(GenerateMask);
#ifdef NGRAPH_CPU_STATIC_LIB_ENABLE
void register_builders_state_cpp() {}
#endif
}
}
}
......@@ -38,6 +38,9 @@ namespace ngraph
}
REGISTER_OP_BUILDER(Sum);
#ifdef NGRAPH_CPU_STATIC_LIB_ENABLE
void register_builders_sum_cpp() {}
#endif
}
}
}
......@@ -76,6 +76,9 @@ namespace ngraph
}
REGISTER_OP_BUILDER(Tile);
#ifdef NGRAPH_CPU_STATIC_LIB_ENABLE
void register_builders_tile_cpp() {}
#endif
}
}
}
......@@ -161,6 +161,9 @@ namespace ngraph
}
REGISTER_OP_BUILDER(TopK);
#ifdef NGRAPH_CPU_STATIC_LIB_ENABLE
void register_builders_topk_cpp() {}
#endif
}
}
}
......@@ -125,6 +125,9 @@ namespace ngraph
}
REGISTER_OP_BUILDER(UpdateSlice);
#ifdef NGRAPH_CPU_STATIC_LIB_ENABLE
void register_builders_update_slice_cpp() {}
#endif
}
}
}
......@@ -23,6 +23,7 @@
#include "ngraph/runtime/cpu/cpu_call_frame.hpp"
#include "ngraph/runtime/cpu/cpu_external_function.hpp"
#include "ngraph/runtime/cpu/cpu_tensor_view.hpp"
#include "ngraph/runtime/cpu/static_initialize.hpp"
#include "ngraph/util.hpp"
#ifdef NGRAPH_MLIR_ENABLE
......@@ -32,7 +33,7 @@
using namespace ngraph;
using namespace std;
extern "C" runtime::BackendConstructor* get_backend_constructor_pointer()
runtime::BackendConstructor* runtime::cpu::get_backend_constructor_pointer()
{
class CPU_BackendConstructor : public runtime::BackendConstructor
{
......@@ -50,6 +51,23 @@ extern "C" runtime::BackendConstructor* get_backend_constructor_pointer()
return s_backend_constructor.get();
}
#if !defined(NGRAPH_CPU_STATIC_LIB_ENABLE)
extern "C" 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
......@@ -57,7 +75,8 @@ namespace
public:
CPUStaticInit()
{
runtime::BackendManager::register_backend("CPU", get_backend_constructor_pointer());
runtime::BackendManager::register_backend(
"CPU", runtime::cpu::get_backend_constructor_pointer());
}
~CPUStaticInit() {}
} s_cpu_static_init;
......
......@@ -24,6 +24,7 @@
#include "ngraph/pass/pass_config.hpp"
#include "ngraph/runtime/allocator.hpp"
#include "ngraph/runtime/backend.hpp"
#include "ngraph/runtime/backend_manager.hpp"
namespace ngraph
{
......@@ -33,7 +34,7 @@ namespace ngraph
{
class CPU_ExternalFunction;
class CPU_CallFrame;
BackendConstructor* get_backend_constructor_pointer();
class CPU_BACKEND_API CPU_Backend : public runtime::Backend
{
public:
......
......@@ -65,6 +65,7 @@
#include "ngraph/op/subtract.hpp"
#include "ngraph/op/tan.hpp"
#include "ngraph/op/tanh.hpp"
#include "ngraph/runtime/cpu/cpu_builder_registry.hpp"
#include "ngraph/runtime/cpu/cpu_kernels.hpp"
#include "ngraph/runtime/cpu/cpu_op_annotations.hpp"
#include "ngraph/runtime/cpu/kernel/abs.hpp"
......
//*****************************************************************************
// 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.
//*****************************************************************************
#include "ngraph/runtime/cpu/cpu_builder_registry.hpp"
#ifdef NGRAPH_CPU_STATIC_LIB_ENABLE
namespace ngraph
{
namespace runtime
{
namespace cpu
{
void register_builders()
{
register_builders_add_cpp();
register_builders_allreduce_cpp();
register_builders_argmax_cpp();
register_builders_argmin_cpp();
register_builders_avg_pool_cpp();
register_builders_batch_norm_cpp();
register_builders_bounded_relu_cpp();
register_builders_broadcast_cpp();
register_builders_broadcast_distributed_cpp();
register_builders_concat_cpp();
register_builders_convert_cpp();
register_builders_convert_layout_cpp();
register_builders_convolution_cpp();
register_builders_dot_cpp();
register_builders_dropout_cpp();
register_builders_embedding_lookup_cpp();
register_builders_erf_cpp();
register_builders_gather_cpp();
register_builders_gather_nd_cpp();
register_builders_get_output_element_cpp();
register_builders_leaky_relu_cpp();
register_builders_lrn_cpp();
register_builders_lstm_cpp();
register_builders_matmul_bias_cpp();
register_builders_max_cpp();
register_builders_max_pool_cpp();
register_builders_min_cpp();
register_builders_one_hot_cpp();
register_builders_pad_cpp();
register_builders_product_cpp();
register_builders_quantization_cpp();
register_builders_quantized_avg_pool_cpp();
register_builders_quantized_conv_cpp();
register_builders_quantized_dot_cpp();
register_builders_quantized_matmul_cpp();
register_builders_reduce_function_cpp();
register_builders_relu_cpp();
register_builders_replace_slice_cpp();
register_builders_reshape_cpp();
register_builders_reverse_cpp();
register_builders_reverse_sequence_cpp();
register_builders_rnn_cpp();
register_builders_scatter_add_cpp();
register_builders_scatter_nd_add_cpp();
register_builders_select_cpp();
register_builders_state_cpp();
register_builders_sigmoid_cpp();
register_builders_slice_cpp();
register_builders_softmax_cpp();
register_builders_sum_cpp();
register_builders_tile_cpp();
register_builders_topk_cpp();
register_builders_update_slice_cpp();
}
}
}
}
#endif
//*****************************************************************************
// 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
#ifdef NGRAPH_CPU_STATIC_LIB_ENABLE
namespace ngraph
{
namespace runtime
{
namespace cpu
{
void register_builders();
void register_builders_add_cpp();
void register_builders_allreduce_cpp();
void register_builders_argmax_cpp();
void register_builders_argmin_cpp();
void register_builders_avg_pool_cpp();
void register_builders_batch_norm_cpp();
void register_builders_bounded_relu_cpp();
void register_builders_broadcast_cpp();
void register_builders_broadcast_distributed_cpp();
void register_builders_concat_cpp();
void register_builders_convert_cpp();
void register_builders_convert_layout_cpp();
void register_builders_convolution_cpp();
void register_builders_dot_cpp();
void register_builders_dropout_cpp();
void register_builders_embedding_lookup_cpp();
void register_builders_erf_cpp();
void register_builders_gather_cpp();
void register_builders_gather_nd_cpp();
void register_builders_get_output_element_cpp();
void register_builders_leaky_relu_cpp();
void register_builders_lrn_cpp();
void register_builders_lstm_cpp();
void register_builders_matmul_bias_cpp();
void register_builders_max_cpp();
void register_builders_max_pool_cpp();
void register_builders_min_cpp();
void register_builders_one_hot_cpp();
void register_builders_pad_cpp();
void register_builders_product_cpp();
void register_builders_quantization_cpp();
void register_builders_quantized_avg_pool_cpp();
void register_builders_quantized_conv_cpp();
void register_builders_quantized_dot_cpp();
void register_builders_quantized_matmul_cpp();
void register_builders_reduce_function_cpp();
void register_builders_relu_cpp();
void register_builders_replace_slice_cpp();
void register_builders_reshape_cpp();
void register_builders_reverse_cpp();
void register_builders_reverse_sequence_cpp();
void register_builders_rnn_cpp();
void register_builders_scatter_add_cpp();
void register_builders_scatter_nd_add_cpp();
void register_builders_select_cpp();
void register_builders_state_cpp();
void register_builders_sigmoid_cpp();
void register_builders_slice_cpp();
void register_builders_softmax_cpp();
void register_builders_sum_cpp();
void register_builders_tile_cpp();
void register_builders_topk_cpp();
void register_builders_update_slice_cpp();
}
}
}
#endif
......@@ -156,6 +156,7 @@
#include "ngraph/runtime/aligned_buffer.hpp"
#include "ngraph/runtime/cpu/cpu_backend.hpp"
#include "ngraph/runtime/cpu/cpu_builder.hpp"
#include "ngraph/runtime/cpu/cpu_builder_registry.hpp"
#include "ngraph/runtime/cpu/cpu_call_frame.hpp"
#include "ngraph/runtime/cpu/cpu_cse.hpp"
#include "ngraph/runtime/cpu/cpu_emitter.hpp"
......@@ -1354,6 +1355,11 @@ void runtime::cpu::CPU_ExternalFunction::build(ngraph::pass::PassConfig& pass_co
"enabled due to concurrent graph execution");
}
// reference all the builders for static library
#ifdef NGRAPH_CPU_STATIC_LIB_ENABLE
ngraph::runtime::cpu::register_builders();
#endif
// stream writer to dump the debug manifest for the DEX
static const string s_debug_dir = "cpu_codegen";
static StaticInitializers s_static_initializers(s_debug_dir);
......
......@@ -13,9 +13,16 @@
// See the License for the specific language governing permissions and
// limitations under the License.
//*****************************************************************************
#include "cpu_backend_visibility.h"
extern "C" CPU_BACKEND_API const char* get_ngraph_version_string()
#pragma once
namespace ngraph
{
return NGRAPH_VERSION;
namespace runtime
{
namespace cpu
{
void static_initialize();
}
}
}
......@@ -14,15 +14,23 @@
# 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)
if(NGRAPH_INTERPRETER_STATIC_LIB_ENABLE)
target_compile_definitions(interpreter_backend PUBLIC NGRAPH_INTERPRETER_STATIC_LIB_ENABLE)
endif()
install(TARGETS interpreter_backend
LIBRARY DESTINATION "${NGRAPH_INSTALL_LIB}"
ARCHIVE 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 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()
{
}
......
......@@ -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();
}
}
}
......@@ -34,12 +34,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:
......@@ -184,6 +194,7 @@ int main(int argc, char** argv)
bool dot_file = false;
bool double_buffer = 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