Commit f95d7167 authored by pruthvi's avatar pruthvi

- add methods to create and register backend statically

- Option in parent CMakeLists to build cpu as static backend
parent 05763edb
...@@ -183,6 +183,7 @@ option(NGRAPH_FAST_MATH_ENABLE "Enable fast math" ON) ...@@ -183,6 +183,7 @@ 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 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 static library" FALSE)
option(NGRAPH_CPU_STATIC_LIB_ENABLE "Enable build CPU backend static library" FALSE)
if (NGRAPH_CPU_ENABLE if (NGRAPH_CPU_ENABLE
AND AND
......
...@@ -23,6 +23,7 @@ ...@@ -23,6 +23,7 @@
#include "ngraph/runtime/cpu/cpu_call_frame.hpp" #include "ngraph/runtime/cpu/cpu_call_frame.hpp"
#include "ngraph/runtime/cpu/cpu_external_function.hpp" #include "ngraph/runtime/cpu/cpu_external_function.hpp"
#include "ngraph/runtime/cpu/cpu_tensor_view.hpp" #include "ngraph/runtime/cpu/cpu_tensor_view.hpp"
#include "ngraph/runtime/cpu/static_initialize.hpp"
#include "ngraph/util.hpp" #include "ngraph/util.hpp"
#ifdef NGRAPH_MLIR_ENABLE #ifdef NGRAPH_MLIR_ENABLE
...@@ -32,7 +33,7 @@ ...@@ -32,7 +33,7 @@
using namespace ngraph; using namespace ngraph;
using namespace std; 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 class CPU_BackendConstructor : public runtime::BackendConstructor
{ {
...@@ -50,6 +51,23 @@ extern "C" runtime::BackendConstructor* get_backend_constructor_pointer() ...@@ -50,6 +51,23 @@ extern "C" runtime::BackendConstructor* get_backend_constructor_pointer()
return s_backend_constructor.get(); return s_backend_constructor.get();
} }
#ifndef CPU_BACKEND_STATIC
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 namespace
{ {
static class CPUStaticInit static class CPUStaticInit
......
...@@ -24,6 +24,7 @@ ...@@ -24,6 +24,7 @@
#include "ngraph/pass/pass_config.hpp" #include "ngraph/pass/pass_config.hpp"
#include "ngraph/runtime/allocator.hpp" #include "ngraph/runtime/allocator.hpp"
#include "ngraph/runtime/backend.hpp" #include "ngraph/runtime/backend.hpp"
#include "ngraph/runtime/backend_manager.hpp"
namespace ngraph namespace ngraph
{ {
...@@ -33,7 +34,7 @@ namespace ngraph ...@@ -33,7 +34,7 @@ namespace ngraph
{ {
class CPU_ExternalFunction; class CPU_ExternalFunction;
class CPU_CallFrame; class CPU_CallFrame;
ngraph::runtime::BackendConstructor* get_backend_constructor_pointer();
class CPU_BACKEND_API CPU_Backend : public runtime::Backend class CPU_BACKEND_API CPU_Backend : public runtime::Backend
{ {
public: public:
......
//*****************************************************************************
// 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 cpu
{
void static_initialize();
}
}
}
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