Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
cafa3a4
register backends
sindhu-nervana Dec 18, 2019
8158725
fix non static build
sindhu-nervana Dec 19, 2019
7299be4
Merge branch 'master' into sindhu/static_build
sindhu-nervana Dec 19, 2019
d9922af
minor
sindhu-nervana Dec 19, 2019
89fd3c7
cmake changes
sindhu-nervana Dec 19, 2019
34c8026
separate cpu and interpreter backend register
sindhu-nervana Dec 19, 2019
f046ea4
Merge branch 'master' into sindhu/static_build
sindhu-nervana Dec 19, 2019
faa1343
fix bazel
kanvi-nervana Dec 19, 2019
358e154
Merge branch 'sindhu/static_build' of https://github.com/tensorflow/n…
kanvi-nervana Dec 19, 2019
63da9ff
fix cpp example static linking
sindhu-nervana Dec 19, 2019
1f0c075
Update build_ngtf.py
sindhu-nervana Dec 19, 2019
7704247
address comments
sindhu-nervana Dec 20, 2019
b267ba1
Shrestha/var in compute (#388)
Dec 20, 2019
531c490
Merge branch 'master' into sindhu/static_build
sayantan-nervana Dec 20, 2019
da1adab
Update examples/cpp/inference/infer_multiple_networks.cc
sindhu-nervana Dec 20, 2019
6706cbf
code format
sindhu-nervana Dec 20, 2019
367d3db
Kanvi/Add asserts in some python tests (#398)
kanvi-nervana Dec 20, 2019
fdb3753
Merge branch 'master' into sindhu/static_build
sayantan-nervana Dec 20, 2019
f0ae2f9
Merge branch 'master' into sindhu/static_build
sindhu-nervana Dec 21, 2019
efcc707
Merge branch 'master' into sindhu/static_build
Dec 24, 2019
ce20965
Merge branch 'master' into sindhu/static_build
sayantan-nervana Dec 30, 2019
6adc41c
Merge branch 'master' into sindhu/static_build
sayantan-nervana Dec 30, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,9 @@ if (NOT USE_PRE_BUILT_NGRAPH)
endif()
set(NGRAPH_INSTALL_DIR ${NGRAPH_ARTIFACTS_DIR})

if(NGRAPH_BRIDGE_STATIC_LIB_ENABLE)
add_definitions(-DNGRAPH_BRIDGE_STATIC_LIB_ENABLE)
endif()

if(OS_VERSION STREQUAL "\"centos\"")
set(LIB "lib64")
Expand Down
1 change: 1 addition & 0 deletions bazel/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ cc_library(
"-Wno-strict-overflow",
'-D NGRAPH_BRIDGE_STATIC_LIB_ENABLE',
'-D NGRAPH_TF_USE_GRAPPLER_OPTIMIZER',
'-D NGRAPH_CPU_STATIC_LIB_ENABLE',
"-I ngraph_bridge",
"-I logging",
"-I external/ngraph/src",
Expand Down
1 change: 1 addition & 0 deletions build_ngtf.py
Original file line number Diff line number Diff line change
Expand Up @@ -412,6 +412,7 @@ def main():

if (arguments.use_ngraph_staticlibs):
ngraph_tf_cmake_flags.extend(["-DNGRAPH_BRIDGE_STATIC_LIB_ENABLE=TRUE"])

if (arguments.debug_build):
ngraph_tf_cmake_flags.extend(["-DCMAKE_BUILD_TYPE=Debug"])

Expand Down
4 changes: 4 additions & 0 deletions examples/cpp/inference/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,10 @@ if (APPLE)
add_definitions(-DTEST_SINGLE_INSTANCE)
endif()

if(NGRAPH_BRIDGE_STATIC_LIB_ENABLE)
add_definitions(-DNGRAPH_BRIDGE_STATIC_LIB_ENABLE)
endif()

if(NGRAPH_BRIDGE_STATIC_LIB_ENABLE)
target_link_libraries(${APP_NAME}
-Wl,--whole-archive
Expand Down
7 changes: 7 additions & 0 deletions examples/cpp/inference/infer_multiple_networks.cc
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,13 @@ int main(int argc, char** argv) {
return -1;
}

// Register cpu backend for static linking
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we need to register here, since we have a registration in create backend?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah it was failing otherwise because we are using set backend here

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TODO: Revisit this to see if we can remove registering here and register only in BackendManager.

// [TODO]: Revisit this to see if we can remove registering here and register
// only in BackendManager.
#if defined(NGRAPH_BRIDGE_STATIC_LIB_ENABLE)
ngraph_register_cpu_backend();
#endif

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right now we create only CPU backend here, hence the ifdef is only for CPU. But suggestions for future is we can query the backend we are trying to set/create and register just that backend if NGRAPH_BRIDGE_STATIC_LIB_ENABLE is enabled

const char* backend = "CPU";
if (SetNGraphBackend(backend) != tf::Status::OK()) {
std::cout << "Error: Cannot set the backend: " << backend << std::endl;
Expand Down
5 changes: 5 additions & 0 deletions examples/cpp/inference/infer_single_network.cc
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,11 @@ int main(int argc, char** argv) {
return -1;
}

// Register cpu backend for static linking
#if defined(NGRAPH_BRIDGE_STATIC_LIB_ENABLE)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same comment

ngraph_register_cpu_backend();
#endif

const char* backend = "CPU";
if (SetNGraphBackend(backend) != tf::Status::OK()) {
std::cout << "Error: Cannot set the backend: " << backend << std::endl;
Expand Down
12 changes: 12 additions & 0 deletions ngraph_bridge/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,18 @@ if(NGRAPH_TF_ENABLE_VARIABLES_AND_OPTIMIZERS)
add_definitions(-DNGRAPH_TF_ENABLE_VARIABLES_AND_OPTIMIZERS)
endif()

if(NGRAPH_BRIDGE_STATIC_LIB_ENABLE)
add_definitions(-DNGRAPH_BRIDGE_STATIC_LIB_ENABLE)
endif()

if(NGRAPH_CPU_STATIC_LIB_ENABLE)
add_definitions(-DNGRAPH_CPU_STATIC_LIB_ENABLE)
endif()

if(NGRAPH_INTERPRETER_STATIC_LIB_ENABLE)
add_definitions(-DNGRAPH_INTERPRETER_STATIC_LIB_ENABLE)
endif()


if(NGRAPH_TF_USE_GRAPPLER_OPTIMIZER)
list(REMOVE_ITEM SRC ngraph_rewrite_pass.cc)
Expand Down
8 changes: 8 additions & 0 deletions ngraph_bridge/ngraph_backend_manager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,14 @@ Status BackendManager::SetBackendName(const string& backend_name) {
}

Status BackendManager::CreateBackend(const string& backend_name) {
// Register backends for static linking
#if defined(NGRAPH_CPU_STATIC_LIB_ENABLE)
ngraph_register_cpu_backend();
#endif
#if defined(NGRAPH_INTERPRETER_STATIC_LIB_ENABLE)
ngraph_register_interpreter_backend();
#endif

std::lock_guard<std::mutex> lock(BackendManager::ng_backend_map_mutex_);
auto itr = BackendManager::ng_backend_map_.find(backend_name);
// if backend does not exist create it
Expand Down
4 changes: 4 additions & 0 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,10 @@ if (APPLE)
set(NGRAPH_TF_CXX11_ABI 0)
endif()

if(NGRAPH_BRIDGE_STATIC_LIB_ENABLE)
add_definitions(-DNGRAPH_BRIDGE_STATIC_LIB_ENABLE)
endif()

if(NGRAPH_BRIDGE_STATIC_LIB_ENABLE)
target_link_libraries(gtest_ngtf
-Wl,--whole-archive
Expand Down
3 changes: 1 addition & 2 deletions test/graph_rewrites/op_by_op_capability_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,7 @@ TEST(OpByOpCapability, Backend) {
ASSERT_OK(BackendManager::GetCurrentlySetBackendName(&ng_backend_type));

// Map with all the backends, and what the boolean is_supported should be
std::map<std::string, bool> backend_map{
{"CPU", true}, {"INTERPRETER", true}, {"NOP", false}};
std::map<std::string, bool> backend_map{{"CPU", true}, {"INTERPRETER", true}};
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed NOP case here because we do not have static library available for this backend, so we cannot register NOP with static builds - so this test will fail.


// Tests three cases of (Backend, is_supported=true/false)
// 1. CPU, true
Expand Down
3 changes: 2 additions & 1 deletion test/python/test_sign.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ def test_sign_1d(self, test_input, expected):
val = tf.placeholder(tf.float32, shape=(1,))
out = tf.sign(val)
sess_fn = lambda sess: sess.run((out,), feed_dict={val: (test_input,)})
np.allclose(self.with_ngraph(sess_fn), self.without_ngraph(sess_fn))
assert np.allclose(
self.with_ngraph(sess_fn), self.without_ngraph(sess_fn))
assert np.allclose(self.with_ngraph(sess_fn), expected)

def test_sign_2d(self):
Expand Down
7 changes: 7 additions & 0 deletions test/test_ngraph_exec.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,13 @@ class NGraphExecTest : public ::testing::Test {
GraphDef gdef;
TF_RETURN_IF_ERROR(ReadTextProto(Env::Default(), graph_pbtxt_file, &gdef));
GraphConstructorOptions opts;

// Register backends for static linking
#if defined(NGRAPH_BRIDGE_STATIC_LIB_ENABLE)
ngraph_register_cpu_backend();
ngraph_register_interpreter_backend();
#endif

// Set the allow_internal_ops to true so that graphs with node names such as
// _arg_Placeholder_1_0_1_0_arg are allowed. These op names are generated
// during the graph rewrite passes and considered internal
Expand Down