diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 4109f5c57..8d47f9a7f 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -69,6 +69,8 @@ set(SRC test_ngraph_tensor_manager.cpp 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 new file mode 100644 index 000000000..901c5cf9d --- /dev/null +++ b/test/dummy_backend.cpp @@ -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::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); +} + +bool runtime::dummy::DummyBackend::is_supported(const Node& node) const { + return false; +} + +runtime::dummy::DummyBackend::~DummyBackend() {} + +runtime::dummy::DummyExecutable::DummyExecutable( + shared_ptr function, + bool /* enable_performance_collection */) { + 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..1e6218d25 --- /dev/null +++ b/test/dummy_backend.h @@ -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 +#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: + 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; + + 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; + + 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 function, + bool enable_performance_collection = false); + bool call( + const std::vector>& outputs, + const std::vector>& inputs) override; +}; + +#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 new file mode 100644 index 000000000..7423ada00 --- /dev/null +++ b/test/test_dummy_backend.cpp @@ -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(); + ASSERT_EQ(db.is_supported(*add), false); +} + +} // namespace testing +} // namespace ngraph_bridge +} // namespace tensorflow