Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 2 additions & 0 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
75 changes: 75 additions & 0 deletions test/dummy_backend.cpp
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
76 changes: 76 additions & 0 deletions test/dummy_backend.h
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_

Copy link
Contributor

Choose a reason for hiding this comment

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

missing header guard

#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);
Copy link
Contributor

Choose a reason for hiding this comment

The 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.
https://github.com/tensorflow/ngraph-bridge/blob/master/ngraph_bridge/ngraph_backend_manager.cc#L62

Copy link
Contributor

@sayantan-nervana sayantan-nervana Jan 7, 2020

Choose a reason for hiding this comment

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

probably not. these need .so. Kanvi's example just creates a backend class/object on the fly

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_
46 changes: 46 additions & 0 deletions test/test_dummy_backend.cpp
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