-
Notifications
You must be signed in to change notification settings - Fork 63
Kanvi/create a dummy backend for testing #420
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
99bfc51
b0549a7
4b71222
f7e0bb5
3910e66
a36afa7
8589d37
12fb948
f065332
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,75 @@ | ||
| //***************************************************************************** | ||
| // 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/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; | ||
| runtime::dummy::DummyBackend::DummyBackend() {} | ||
|
|
||
| shared_ptr<runtime::Tensor> runtime::dummy::DummyBackend::create_tensor( | ||
| const ng::element::Type& type, const ng::Shape& shape) { | ||
| return make_shared<runtime::HostTensor>(type, shape, "external"); | ||
| } | ||
|
|
||
| shared_ptr<runtime::Tensor> runtime::dummy::DummyBackend::create_tensor( | ||
| const ng::element::Type& type, const ng::Shape& shape, | ||
| void* memory_pointer) { | ||
| return make_shared<runtime::HostTensor>(type, shape, memory_pointer, | ||
| "external"); | ||
| } | ||
|
|
||
| shared_ptr<runtime::Executable> runtime::dummy::DummyBackend::compile( | ||
| shared_ptr<ng::Function> function, bool enable_performance_collection) { | ||
| return make_shared<DummyExecutable>(function, enable_performance_collection); | ||
| } | ||
|
|
||
| bool runtime::dummy::DummyBackend::is_supported(const Node& node) const { | ||
| return false; | ||
| } | ||
|
|
||
| runtime::dummy::DummyBackend::~DummyBackend() {} | ||
|
|
||
| runtime::dummy::DummyExecutable::DummyExecutable( | ||
| shared_ptr<ng::Function> function, | ||
| bool /* enable_performance_collection */) { | ||
| pass::Manager pass_manager; | ||
| pass_manager.register_pass<pass::AssignLayout<DenseTensorLayout>>(); | ||
| pass_manager.run_passes(function); | ||
|
|
||
| set_parameters_and_results(*function); | ||
| } | ||
|
|
||
| bool runtime::dummy::DummyExecutable::call( | ||
| const vector<shared_ptr<runtime::Tensor>>& /* outputs */, | ||
| const vector<shared_ptr<runtime::Tensor>>& /* inputs */) { | ||
| return true; | ||
| } | ||
|
|
||
| } // namespace ngraph |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,76 @@ | ||
| //***************************************************************************** | ||
| // 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. | ||
| //***************************************************************************** | ||
| #ifndef NGRAPH_TF_BRIDGE_DUMMYBACKEND_H_ | ||
| #define NGRAPH_TF_BRIDGE_DUMMYBACKEND_H_ | ||
|
|
||
| #pragma once | ||
|
|
||
| #include <memory> | ||
| #include <sstream> | ||
| #include <string> | ||
| #include <vector> | ||
|
|
||
| #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: | ||
| DummyBackend(); | ||
| DummyBackend(const DummyBackend&) = delete; | ||
| DummyBackend(DummyBackend&&) = delete; | ||
| DummyBackend& operator=(const DummyBackend&) = delete; | ||
|
|
||
| std::shared_ptr<ng::runtime::Tensor> create_tensor( | ||
| const ng::element::Type& type, const ng::Shape& shape, | ||
| void* memory_pointer) override; | ||
|
|
||
| std::shared_ptr<ng::runtime::Tensor> create_tensor( | ||
| const ng::element::Type& type, const ng::Shape& shape) override; | ||
|
|
||
| std::shared_ptr<ng::runtime::Executable> compile( | ||
| std::shared_ptr<ng::Function> function, | ||
| 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 { | ||
| public: | ||
| DummyExecutable(std::shared_ptr<ng::Function> function, | ||
| bool enable_performance_collection = false); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. curious: will we be able to create a backend like we create the other backends? maybe not.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. probably not. these need |
||
| bool call( | ||
| const std::vector<std::shared_ptr<ng::runtime::Tensor>>& outputs, | ||
| const std::vector<std::shared_ptr<ng::runtime::Tensor>>& inputs) override; | ||
| }; | ||
|
|
||
| #endif // NGRAPH_TF_BRIDGE_DUMMYBACKEND_H_ | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| /******************************************************************************* | ||
| * 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 "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, IsSupported) { | ||
| ngraph::runtime::dummy::DummyBackend db; | ||
| auto add = std::make_shared<ngraph::op::Add>(); | ||
| ASSERT_EQ(db.is_supported(*add), false); | ||
| } | ||
|
|
||
| } // namespace testing | ||
| } // namespace ngraph_bridge | ||
| } // namespace tensorflow |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
missing header guard