From 99bfc51dcdb77d6c01821370acb1189dd190be5d Mon Sep 17 00:00:00 2001 From: Kanvi Khanna Date: Fri, 3 Jan 2020 16:00:59 -0800 Subject: [PATCH 1/6] Initial commit to create a dummy backend for testing --- test/CMakeLists.txt | 1 + test/dummy_backend.cpp | 79 ++++++++++++++++++++++++++++++++++++++++++ test/dummy_backend.h | 61 ++++++++++++++++++++++++++++++++ 3 files changed, 141 insertions(+) create mode 100644 test/dummy_backend.cpp create mode 100644 test/dummy_backend.h diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 4109f5c57..751f674fc 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -69,6 +69,7 @@ set(SRC test_ngraph_tensor_manager.cpp test_capture_prefetch.cpp test_pipelined_tensor_store.cc + dummy_backend.cpp ) if(NGRAPH_TF_ENABLE_VARIABLES_AND_OPTIMIZERS) diff --git a/test/dummy_backend.cpp b/test/dummy_backend.cpp new file mode 100644 index 000000000..51197ddf9 --- /dev/null +++ b/test/dummy_backend.cpp @@ -0,0 +1,79 @@ +//***************************************************************************** +// Copyright 2017-2020 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/descriptor/layout/dense_tensor_layout.hpp" +#include "ngraph/except.hpp" +#include "ngraph/op/convert.hpp" +#include "ngraph/op/select.hpp" +#include "ngraph/op/util/binary_elementwise_comparison.hpp" +#include "ngraph/pass/assign_layout.hpp" +#include "ngraph/pass/like_replacement.hpp" +#include "ngraph/pass/liveness.hpp" +#include "ngraph/pass/manager.hpp" +#include "ngraph/runtime/backend_manager.hpp" +#include "ngraph/util.hpp" + +#include "test/dummy_backend.h" + +using namespace std; +namespace ng = ngraph; + +namespace ngraph { + + +// using descriptor::layout::DenseTensorLayout; + +shared_ptr runtime::dummy::DummyBackend::create_tensor(const ng::element::Type& type, + const ng::Shape& shape) +{ + return make_shared(type, shape, "external"); +} + +shared_ptr runtime::dummy::DummyBackend::create_tensor(const ng::element::Type& type, + const ng::Shape& shape, + void* memory_pointer) +{ + return make_shared(type, shape, memory_pointer, "external"); +} + +shared_ptr + runtime::dummy::DummyBackend::compile(shared_ptr function, + bool enable_performance_collection) +{ + return make_shared(function, enable_performance_collection); +} + +runtime::dummy::DummyExecutable::DummyExecutable(shared_ptr function, + bool /* enable_performance_collection */) +{ + cout << "DummyExecutable\n"; + // pass::Manager pass_manager; + // pass_manager.register_pass>(); + // pass_manager.run_passes(function); + + // set_parameters_and_results(*function); +} + +bool runtime::dummy::DummyExecutable::call(const vector>& /* outputs */, + const vector>& /* inputs */) +{ + return true; +} + +} // namespace ngraph + + diff --git a/test/dummy_backend.h b/test/dummy_backend.h new file mode 100644 index 000000000..ad3046332 --- /dev/null +++ b/test/dummy_backend.h @@ -0,0 +1,61 @@ +//***************************************************************************** +// Copyright 2017-2020 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 + +#include +#include +#include +#include + +#include "ngraph/runtime/backend.hpp" +#include "ngraph/runtime/host_tensor.hpp" +#include "ngraph/runtime/tensor.hpp" + +using namespace std; +namespace ng = ngraph; + +namespace ngraph { + + namespace runtime { + + namespace dummy { + + class DummyBackend; + class DummyExecutable; + } + } +} + +class ng::runtime::dummy::DummyBackend : public ng::runtime::Backend +{ +public: + std::shared_ptr + create_tensor(const ng::element::Type& type, const ng::Shape& shape, void* memory_pointer) override; + + std::shared_ptr create_tensor(const ng::element::Type& type, const ng::Shape& shape) override; + + std::shared_ptr compile(std::shared_ptr function, + bool enable_performance_data = false) override; +}; + +class ng::runtime::dummy::DummyExecutable : public ng::runtime::Executable +{ +public: + DummyExecutable(std::shared_ptr function, bool enable_performance_collection = false); + bool call(const std::vector>& outputs, + const std::vector>& inputs) override; +}; \ No newline at end of file From b0549a70a3f864885b23473c514a5a4ac185544b Mon Sep 17 00:00:00 2001 From: Kanvi Khanna Date: Fri, 3 Jan 2020 16:10:41 -0800 Subject: [PATCH 2/6] fix formatting --- test/dummy_backend.cpp | 53 ++++++++++++++++++------------------------ test/dummy_backend.h | 47 +++++++++++++++++++------------------ 2 files changed, 48 insertions(+), 52 deletions(-) diff --git a/test/dummy_backend.cpp b/test/dummy_backend.cpp index 51197ddf9..afaffc6f7 100644 --- a/test/dummy_backend.cpp +++ b/test/dummy_backend.cpp @@ -14,7 +14,6 @@ // limitations under the License. //***************************************************************************** - #include "ngraph/descriptor/layout/dense_tensor_layout.hpp" #include "ngraph/except.hpp" #include "ngraph/op/convert.hpp" @@ -34,46 +33,40 @@ namespace ng = ngraph; namespace ngraph { - // using descriptor::layout::DenseTensorLayout; -shared_ptr runtime::dummy::DummyBackend::create_tensor(const ng::element::Type& type, - const ng::Shape& shape) -{ - return make_shared(type, shape, "external"); +shared_ptr runtime::dummy::DummyBackend::create_tensor( + const ng::element::Type& type, const ng::Shape& shape) { + return make_shared(type, shape, "external"); } -shared_ptr runtime::dummy::DummyBackend::create_tensor(const ng::element::Type& type, - const ng::Shape& shape, - void* memory_pointer) -{ - return make_shared(type, shape, memory_pointer, "external"); +shared_ptr runtime::dummy::DummyBackend::create_tensor( + const ng::element::Type& type, const ng::Shape& shape, + void* memory_pointer) { + return make_shared(type, shape, memory_pointer, + "external"); } -shared_ptr - runtime::dummy::DummyBackend::compile(shared_ptr function, - bool enable_performance_collection) -{ - return make_shared(function, enable_performance_collection); +shared_ptr runtime::dummy::DummyBackend::compile( + shared_ptr function, bool enable_performance_collection) { + return make_shared(function, enable_performance_collection); } -runtime::dummy::DummyExecutable::DummyExecutable(shared_ptr function, - bool /* enable_performance_collection */) -{ - cout << "DummyExecutable\n"; - // pass::Manager pass_manager; - // pass_manager.register_pass>(); - // pass_manager.run_passes(function); +runtime::dummy::DummyExecutable::DummyExecutable( + shared_ptr function, + bool /* enable_performance_collection */) { + cout << "DummyExecutable\n"; + // pass::Manager pass_manager; + // pass_manager.register_pass>(); + // pass_manager.run_passes(function); - // set_parameters_and_results(*function); + // set_parameters_and_results(*function); } -bool runtime::dummy::DummyExecutable::call(const vector>& /* outputs */, - const vector>& /* inputs */) -{ - return true; +bool runtime::dummy::DummyExecutable::call( + const vector>& /* outputs */, + const vector>& /* inputs */) { + return true; } } // namespace ngraph - - diff --git a/test/dummy_backend.h b/test/dummy_backend.h index ad3046332..831926e56 100644 --- a/test/dummy_backend.h +++ b/test/dummy_backend.h @@ -30,32 +30,35 @@ namespace ng = ngraph; namespace ngraph { - namespace runtime { - - namespace dummy { - - class DummyBackend; - class DummyExecutable; - } - } +namespace runtime { + +namespace dummy { + +class DummyBackend; +class DummyExecutable; +} +} } -class ng::runtime::dummy::DummyBackend : public ng::runtime::Backend -{ -public: - std::shared_ptr - create_tensor(const ng::element::Type& type, const ng::Shape& shape, void* memory_pointer) override; +class ng::runtime::dummy::DummyBackend : public ng::runtime::Backend { + public: + std::shared_ptr create_tensor( + const ng::element::Type& type, const ng::Shape& shape, + void* memory_pointer) override; - std::shared_ptr create_tensor(const ng::element::Type& type, const ng::Shape& shape) override; + std::shared_ptr create_tensor( + const ng::element::Type& type, const ng::Shape& shape) override; - std::shared_ptr compile(std::shared_ptr function, - bool enable_performance_data = false) override; + std::shared_ptr compile( + std::shared_ptr function, + bool enable_performance_data = false) override; }; -class ng::runtime::dummy::DummyExecutable : public ng::runtime::Executable -{ -public: - DummyExecutable(std::shared_ptr function, bool enable_performance_collection = false); - bool call(const std::vector>& outputs, - const std::vector>& inputs) override; +class ng::runtime::dummy::DummyExecutable : public ng::runtime::Executable { + public: + DummyExecutable(std::shared_ptr function, + bool enable_performance_collection = false); + bool call( + const std::vector>& outputs, + const std::vector>& inputs) override; }; \ No newline at end of file From 4b7122204325936567900554faa993d1c5348bfb Mon Sep 17 00:00:00 2001 From: Kanvi Khanna Date: Fri, 3 Jan 2020 16:19:54 -0800 Subject: [PATCH 3/6] Add is_supported API + undo commented code --- test/dummy_backend.cpp | 15 +++++++++------ test/dummy_backend.h | 2 ++ 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/test/dummy_backend.cpp b/test/dummy_backend.cpp index afaffc6f7..a1e886b1f 100644 --- a/test/dummy_backend.cpp +++ b/test/dummy_backend.cpp @@ -33,7 +33,7 @@ namespace ng = ngraph; namespace ngraph { -// using descriptor::layout::DenseTensorLayout; +using descriptor::layout::DenseTensorLayout; shared_ptr runtime::dummy::DummyBackend::create_tensor( const ng::element::Type& type, const ng::Shape& shape) { @@ -52,15 +52,18 @@ shared_ptr runtime::dummy::DummyBackend::compile( return make_shared(function, enable_performance_collection); } +bool runtime::dummy::DummyBackend::is_supported(const Node& node) const { + return false; +} + runtime::dummy::DummyExecutable::DummyExecutable( shared_ptr function, bool /* enable_performance_collection */) { - cout << "DummyExecutable\n"; - // pass::Manager pass_manager; - // pass_manager.register_pass>(); - // pass_manager.run_passes(function); + pass::Manager pass_manager; + pass_manager.register_pass>(); + pass_manager.run_passes(function); - // set_parameters_and_results(*function); + set_parameters_and_results(*function); } bool runtime::dummy::DummyExecutable::call( diff --git a/test/dummy_backend.h b/test/dummy_backend.h index 831926e56..b4db6a3ad 100644 --- a/test/dummy_backend.h +++ b/test/dummy_backend.h @@ -52,6 +52,8 @@ class ng::runtime::dummy::DummyBackend : public ng::runtime::Backend { std::shared_ptr compile( std::shared_ptr function, bool enable_performance_data = false) override; + + bool is_supported(const ngraph::Node& node) const override; }; class ng::runtime::dummy::DummyExecutable : public ng::runtime::Executable { From f7e0bb554f234ea81338f77fb02a6f13da610e58 Mon Sep 17 00:00:00 2001 From: Kanvi Khanna Date: Fri, 3 Jan 2020 17:29:59 -0800 Subject: [PATCH 4/6] Add test for is_supported API --- test/CMakeLists.txt | 1 + test/dummy_backend.cpp | 7 +++++++ test/dummy_backend.h | 6 ++++++ 3 files changed, 14 insertions(+) diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 751f674fc..8d47f9a7f 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -70,6 +70,7 @@ set(SRC test_capture_prefetch.cpp test_pipelined_tensor_store.cc dummy_backend.cpp + test_dummy_backend.cpp ) if(NGRAPH_TF_ENABLE_VARIABLES_AND_OPTIMIZERS) diff --git a/test/dummy_backend.cpp b/test/dummy_backend.cpp index a1e886b1f..df99c4cab 100644 --- a/test/dummy_backend.cpp +++ b/test/dummy_backend.cpp @@ -34,6 +34,9 @@ namespace ng = ngraph; namespace ngraph { using descriptor::layout::DenseTensorLayout; +runtime::dummy::DummyBackend::DummyBackend() { + cout << "Dummy Backend constructor called " << endl; +} shared_ptr runtime::dummy::DummyBackend::create_tensor( const ng::element::Type& type, const ng::Shape& shape) { @@ -56,6 +59,10 @@ bool runtime::dummy::DummyBackend::is_supported(const Node& node) const { return false; } +runtime::dummy::DummyBackend::~DummyBackend() { + cout << "Dummy Backend destructor called " << endl; +} + runtime::dummy::DummyExecutable::DummyExecutable( shared_ptr function, bool /* enable_performance_collection */) { diff --git a/test/dummy_backend.h b/test/dummy_backend.h index b4db6a3ad..6290366fe 100644 --- a/test/dummy_backend.h +++ b/test/dummy_backend.h @@ -42,6 +42,11 @@ class DummyExecutable; class ng::runtime::dummy::DummyBackend : public ng::runtime::Backend { public: + DummyBackend(); + DummyBackend(const DummyBackend&) = delete; + DummyBackend(DummyBackend&&) = delete; + DummyBackend& operator=(const DummyBackend&) = delete; + std::shared_ptr create_tensor( const ng::element::Type& type, const ng::Shape& shape, void* memory_pointer) override; @@ -54,6 +59,7 @@ class ng::runtime::dummy::DummyBackend : public ng::runtime::Backend { bool enable_performance_data = false) override; bool is_supported(const ngraph::Node& node) const override; + ~DummyBackend() override; }; class ng::runtime::dummy::DummyExecutable : public ng::runtime::Executable { From 3910e66b6ea5c0ebde9f870879a335e80615a134 Mon Sep 17 00:00:00 2001 From: Kanvi Khanna Date: Mon, 6 Jan 2020 10:46:05 -0800 Subject: [PATCH 5/6] add the test file --- test/test_dummy_backend.cpp | 46 +++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 test/test_dummy_backend.cpp diff --git a/test/test_dummy_backend.cpp b/test/test_dummy_backend.cpp new file mode 100644 index 000000000..061f7c1ba --- /dev/null +++ b/test/test_dummy_backend.cpp @@ -0,0 +1,46 @@ +/******************************************************************************* + * 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 "gtest/gtest.h" + +#include "tensorflow/cc/client/client_session.h" +#include "tensorflow/cc/ops/standard_ops.h" +#include "tensorflow/core/framework/tensor.h" +#include "tensorflow/core/public/session.h" + +#include "logging/tf_graph_writer.h" +#include "test/dummy_backend.h" +#include "test/test_utilities.h" + +using namespace std; +namespace ng = ngraph; + +namespace tensorflow { + +namespace ngraph_bridge { + +namespace testing { + +// Test is_supported API +TEST(DummyBackend, Test_is_supported) { + ngraph::runtime::dummy::DummyBackend db; + auto add = std::make_shared(); + ASSERT_EQ(db.is_supported(*add), false); +} + +} // namespace testing +} // namespace ngraph_bridge +} // namespace tensorflow From 8589d3711e8a168b6a58f990228e33d53b50b1fd Mon Sep 17 00:00:00 2001 From: Kanvi Khanna Date: Tue, 7 Jan 2020 13:12:29 -0800 Subject: [PATCH 6/6] address comments --- test/dummy_backend.cpp | 11 ++--------- test/dummy_backend.h | 6 +++++- test/test_dummy_backend.cpp | 4 ++-- 3 files changed, 9 insertions(+), 12 deletions(-) diff --git a/test/dummy_backend.cpp b/test/dummy_backend.cpp index df99c4cab..901c5cf9d 100644 --- a/test/dummy_backend.cpp +++ b/test/dummy_backend.cpp @@ -15,9 +15,6 @@ //***************************************************************************** #include "ngraph/descriptor/layout/dense_tensor_layout.hpp" -#include "ngraph/except.hpp" -#include "ngraph/op/convert.hpp" -#include "ngraph/op/select.hpp" #include "ngraph/op/util/binary_elementwise_comparison.hpp" #include "ngraph/pass/assign_layout.hpp" #include "ngraph/pass/like_replacement.hpp" @@ -34,9 +31,7 @@ namespace ng = ngraph; namespace ngraph { using descriptor::layout::DenseTensorLayout; -runtime::dummy::DummyBackend::DummyBackend() { - cout << "Dummy Backend constructor called " << endl; -} +runtime::dummy::DummyBackend::DummyBackend() {} shared_ptr runtime::dummy::DummyBackend::create_tensor( const ng::element::Type& type, const ng::Shape& shape) { @@ -59,9 +54,7 @@ bool runtime::dummy::DummyBackend::is_supported(const Node& node) const { return false; } -runtime::dummy::DummyBackend::~DummyBackend() { - cout << "Dummy Backend destructor called " << endl; -} +runtime::dummy::DummyBackend::~DummyBackend() {} runtime::dummy::DummyExecutable::DummyExecutable( shared_ptr function, diff --git a/test/dummy_backend.h b/test/dummy_backend.h index 6290366fe..1e6218d25 100644 --- a/test/dummy_backend.h +++ b/test/dummy_backend.h @@ -13,6 +13,8 @@ // See the License for the specific language governing permissions and // limitations under the License. //***************************************************************************** +#ifndef NGRAPH_TF_BRIDGE_DUMMYBACKEND_H_ +#define NGRAPH_TF_BRIDGE_DUMMYBACKEND_H_ #pragma once @@ -69,4 +71,6 @@ class ng::runtime::dummy::DummyExecutable : public ng::runtime::Executable { bool call( const std::vector>& outputs, const std::vector>& inputs) override; -}; \ No newline at end of file +}; + +#endif // NGRAPH_TF_BRIDGE_DUMMYBACKEND_H_ \ No newline at end of file diff --git a/test/test_dummy_backend.cpp b/test/test_dummy_backend.cpp index 061f7c1ba..7423ada00 100644 --- a/test/test_dummy_backend.cpp +++ b/test/test_dummy_backend.cpp @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright 2017-2019 Intel Corporation + * Copyright 2017-2020 Intel Corporation * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -35,7 +35,7 @@ namespace ngraph_bridge { namespace testing { // Test is_supported API -TEST(DummyBackend, Test_is_supported) { +TEST(DummyBackend, IsSupported) { ngraph::runtime::dummy::DummyBackend db; auto add = std::make_shared(); ASSERT_EQ(db.is_supported(*add), false);