Unverified Commit 8bab36fb authored by Scott Cyphers's avatar Scott Cyphers Committed by GitHub

Merge descriptor::TensorView into descriptor::Tensor (#1536)

* Merge descriptor::TensorView into descriptor::Tensot

* fix GPU build
parent 62e470b2
...@@ -29,7 +29,6 @@ set (SRC ...@@ -29,7 +29,6 @@ set (SRC
descriptor/layout/tensor_view_layout.cpp descriptor/layout/tensor_view_layout.cpp
descriptor/output.cpp descriptor/output.cpp
descriptor/tensor.cpp descriptor/tensor.cpp
descriptor/tensor_view.cpp
file_util.cpp file_util.cpp
function.cpp function.cpp
log.cpp log.cpp
......
...@@ -25,7 +25,7 @@ namespace ngraph ...@@ -25,7 +25,7 @@ namespace ngraph
{ {
namespace descriptor namespace descriptor
{ {
class TensorView; class Tensor;
namespace layout namespace layout
{ {
...@@ -36,7 +36,7 @@ namespace ngraph ...@@ -36,7 +36,7 @@ namespace ngraph
{ {
public: public:
~DenseTensorViewLayout() override {} ~DenseTensorViewLayout() override {}
DenseTensorViewLayout(const TensorView& tensor_view); DenseTensorViewLayout(const Tensor& tensor);
virtual size_t get_size() override { return m_size; } virtual size_t get_size() override { return m_size; }
size_t get_offset() const { return m_offset; } size_t get_offset() const { return m_offset; }
......
...@@ -15,7 +15,7 @@ ...@@ -15,7 +15,7 @@
//***************************************************************************** //*****************************************************************************
#include "ngraph/descriptor/layout/tensor_view_layout.hpp" #include "ngraph/descriptor/layout/tensor_view_layout.hpp"
#include "ngraph/descriptor/tensor_view.hpp" #include "ngraph/descriptor/tensor.hpp"
#include "ngraph/type/element_type.hpp" #include "ngraph/type/element_type.hpp"
using namespace ngraph; using namespace ngraph;
......
...@@ -19,7 +19,7 @@ ...@@ -19,7 +19,7 @@
#include <memory> #include <memory>
#include <vector> #include <vector>
#include "ngraph/descriptor/tensor_view.hpp" #include "ngraph/descriptor/tensor.hpp"
namespace ngraph namespace ngraph
{ {
......
...@@ -21,10 +21,10 @@ ...@@ -21,10 +21,10 @@
using namespace std; using namespace std;
using namespace ngraph; using namespace ngraph;
descriptor::Output::Output(Node* node, size_t index, const shared_ptr<TensorView>& tensor_view) descriptor::Output::Output(Node* node, size_t index, const shared_ptr<Tensor>& tensor)
: m_node(node) : m_node(node)
, m_index(index) , m_index(index)
, m_tensor_view(tensor_view) , m_tensor(tensor)
{ {
} }
...@@ -46,15 +46,15 @@ shared_ptr<Node> descriptor::Output::get_node() const ...@@ -46,15 +46,15 @@ shared_ptr<Node> descriptor::Output::get_node() const
descriptor::Tensor& descriptor::Output::get_tensor() const descriptor::Tensor& descriptor::Output::get_tensor() const
{ {
return m_tensor_view->get_tensor(); return *m_tensor;
} }
const Shape& descriptor::Output::get_shape() const const Shape& descriptor::Output::get_shape() const
{ {
return m_tensor_view->get_shape(); return m_tensor->get_shape();
} }
const element::Type& descriptor::Output::get_element_type() const const element::Type& descriptor::Output::get_element_type() const
{ {
return m_tensor_view->get_element_type(); return m_tensor->get_element_type();
} }
...@@ -20,7 +20,7 @@ ...@@ -20,7 +20,7 @@
#include <set> #include <set>
#include "ngraph/descriptor/input.hpp" #include "ngraph/descriptor/input.hpp"
#include "ngraph/descriptor/tensor_view.hpp" #include "ngraph/descriptor/tensor.hpp"
namespace ngraph namespace ngraph
{ {
...@@ -39,16 +39,13 @@ namespace ngraph ...@@ -39,16 +39,13 @@ namespace ngraph
public: public:
/// \param node Node that owns this output. /// \param node Node that owns this output.
/// \param index Position of the output tensor in all output tensors /// \param index Position of the output tensor in all output tensors
/// \param tensor_view The view of this tensor; where the value will be written /// \param tensor The view of this tensor; where the value will be written
Output(Node* node, size_t index, const std::shared_ptr<TensorView>& tensor_view); Output(Node* node, size_t index, const std::shared_ptr<Tensor>& tensor);
std::shared_ptr<Node> get_node() const; std::shared_ptr<Node> get_node() const;
size_t get_index() const { return m_index; } size_t get_index() const { return m_index; }
std::shared_ptr<TensorView> get_tensor_view() const { return m_tensor_view; } std::shared_ptr<Tensor> get_tensor_view() const { return m_tensor; }
void set_tensor_view(const std::shared_ptr<TensorView>& tensor_view) void set_tensor_view(const std::shared_ptr<Tensor>& tensor) { m_tensor = tensor; }
{
m_tensor_view = tensor_view;
}
void add_input(Input* input); void add_input(Input* input);
void remove_input(Input* input); void remove_input(Input* input);
const std::set<Input*>& get_inputs() const { return m_inputs; } const std::set<Input*>& get_inputs() const { return m_inputs; }
...@@ -62,7 +59,7 @@ namespace ngraph ...@@ -62,7 +59,7 @@ namespace ngraph
protected: protected:
Node* m_node; Node* m_node;
size_t m_index; size_t m_index;
std::shared_ptr<TensorView> m_tensor_view; std::shared_ptr<Tensor> m_tensor;
std::set<Input*> m_inputs; std::set<Input*> m_inputs;
private: private:
......
...@@ -22,23 +22,22 @@ using namespace ngraph; ...@@ -22,23 +22,22 @@ using namespace ngraph;
using namespace std; using namespace std;
descriptor::Tensor::Tensor(const element::Type& element_type, descriptor::Tensor::Tensor(const element::Type& element_type,
TensorView* tensor_view, const Shape& shape,
const string& name) const std::string& name)
: m_element_type(element_type) : m_element_type(element_type)
, m_tensor_view(tensor_view) , m_shape(shape)
, m_name{name} , m_name(name)
, m_next_view_id{0}
{ {
} }
string descriptor::Tensor::make_tensor_name(const Node* node, size_t value_index) void descriptor::Tensor::set_tensor_view_type(const element::Type& element_type, const Shape& shape)
{ {
return node->get_name() + "_" + to_string(value_index); m_shape = shape;
} m_element_type = element_type;
if (nullptr != m_tensor_view_layout)
string descriptor::Tensor::get_next_view_name() {
{ m_tensor_view_layout->set_tensor_view_type(element_type, shape);
return m_name + "_TV" + to_string(m_next_view_id++); }
} }
void descriptor::Tensor::set_pool_offset(size_t offset) void descriptor::Tensor::set_pool_offset(size_t offset)
...@@ -53,21 +52,16 @@ size_t descriptor::Tensor::get_pool_offset() const ...@@ -53,21 +52,16 @@ size_t descriptor::Tensor::get_pool_offset() const
size_t descriptor::Tensor::size() const size_t descriptor::Tensor::size() const
{ {
if (auto tvl = m_tensor_view->get_tensor_view_layout()) if (auto tvl = get_tensor_view_layout())
{ {
return tvl->get_allocated_size(); return tvl->get_allocated_size();
} }
else else
{ {
return shape_size(m_tensor_view->get_shape()) * m_element_type.size(); return shape_size(get_shape()) * m_element_type.size();
} }
} }
void descriptor::Tensor::set_element_type(const element::Type& element_type)
{
m_element_type = element_type;
}
ostream& operator<<(ostream& out, const descriptor::Tensor& tensor) ostream& operator<<(ostream& out, const descriptor::Tensor& tensor)
{ {
out << "Tensor(" << tensor.get_name() << ")"; out << "Tensor(" << tensor.get_name() << ")";
......
...@@ -16,10 +16,10 @@ ...@@ -16,10 +16,10 @@
#pragma once #pragma once
#include <iostream>
#include <memory> #include <memory>
#include <vector> #include <string>
#include "ngraph/descriptor/tensor.hpp"
#include "ngraph/shape.hpp" #include "ngraph/shape.hpp"
#include "ngraph/type/element_type.hpp" #include "ngraph/type/element_type.hpp"
...@@ -27,44 +27,58 @@ namespace ngraph ...@@ -27,44 +27,58 @@ namespace ngraph
{ {
class Node; class Node;
namespace element
{
class Type;
}
namespace descriptor namespace descriptor
{ {
class TensorView; namespace layout
class Tensor; {
class TensorViewLayout;
} }
}
class ngraph::descriptor::Tensor
{
friend class TensorView;
private: /// \brief Compile-time descriptor of a first-class value that is a view of a tensor.
class Tensor
{
Tensor(const Tensor&) = delete; Tensor(const Tensor&) = delete;
Tensor& operator=(const Tensor&) = delete; Tensor& operator=(const Tensor&) = delete;
Tensor(const element::Type& element_type, TensorView* tensor_view, const std::string& name); public:
std::string get_next_view_name(); Tensor(const element::Type& element_type, const Shape& shape, const std::string& name);
public:
const std::string& get_name() const { return m_name; } const std::string& get_name() const { return m_name; }
void set_tensor_view_type(const element::Type& element_type, const Shape& shape);
const element::Type& get_element_type() const { return m_element_type; }
const Shape& get_shape() const { return m_shape; }
const std::shared_ptr<layout::TensorViewLayout>& get_tensor_view_layout() const
{
return m_tensor_view_layout;
}
void set_tensor_view_layout(
const std::shared_ptr<layout::TensorViewLayout>& tensor_view_layout)
{
m_tensor_view_layout = tensor_view_layout;
}
void set_pool_offset(size_t); void set_pool_offset(size_t);
size_t size() const;
size_t get_pool_offset() const; size_t get_pool_offset() const;
const element::Type& get_element_type() const { return m_element_type; }
void set_element_type(const element::Type& element_type);
static std::string make_tensor_name(const Node* node, size_t value_index);
protected: size_t size() const;
const Tensor& get_tensor() const { return *this; }
Tensor& get_tensor() { return *this; }
const Tensor& get_tensor_view() const { return *this; }
Tensor& get_tensor_view() { return *this; }
protected:
element::Type m_element_type; element::Type m_element_type;
TensorView* m_tensor_view; Shape m_shape;
std::string m_name; std::string m_name;
size_t m_next_view_id; std::shared_ptr<layout::TensorViewLayout> m_tensor_view_layout;
size_t m_pool_offset; size_t m_pool_offset;
}; };
using TensorView = Tensor;
std::ostream& operator<<(std::ostream&, const ngraph::descriptor::Tensor&); using TensorViewPtrs = std::vector<std::shared_ptr<TensorView>>;
std::ostream& operator<<(std::ostream&, const ngraph::descriptor::Tensor&);
}
}
//*****************************************************************************
// Copyright 2017-2018 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/tensor_view.hpp"
#include "ngraph/descriptor/layout/tensor_view_layout.hpp"
using namespace ngraph;
using namespace std;
descriptor::TensorView::TensorView(const element::Type& element_type,
const Shape& shape,
const std::string& name)
: m_element_type(element_type)
, m_shape(shape)
, m_tensor(m_element_type, this, name)
{
// Set the name in the parent TensorView.
// This can't be done until after the m_tensor is constructed.
m_name = m_tensor.get_next_view_name();
}
const element::Type& descriptor::TensorView::get_element_type() const
{
return m_element_type;
}
const Shape& descriptor::TensorView::get_shape() const
{
return m_shape;
}
const descriptor::Tensor& descriptor::TensorView::get_tensor() const
{
return m_tensor;
}
descriptor::Tensor& descriptor::TensorView::get_tensor()
{
return m_tensor;
}
void descriptor::TensorView::set_tensor_view_type(const element::Type& element_type,
const Shape& shape)
{
m_shape = shape;
m_element_type = element_type;
m_tensor.set_element_type(element_type);
if (nullptr != m_tensor_view_layout)
{
m_tensor_view_layout->set_tensor_view_type(element_type, shape);
}
}
//*****************************************************************************
// Copyright 2017-2018 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 <memory>
#include <string>
#include "ngraph/descriptor/tensor.hpp"
#include "ngraph/shape.hpp"
#include "ngraph/type/element_type.hpp"
namespace ngraph
{
class Node;
namespace descriptor
{
namespace layout
{
class Tensor;
class TensorViewLayout;
}
/// \brief Compile-time descriptor of a first-class value that is a view of a tensor.
class TensorView
{
TensorView(const TensorView&) = delete;
TensorView& operator=(const TensorView&) = delete;
public:
TensorView(const element::Type& element_type,
const Shape& shape,
const std::string& name);
const Tensor& get_tensor() const;
Tensor& get_tensor();
const std::string& get_name() const { return m_name; }
void set_tensor_view_type(const element::Type& element_type, const Shape& shape);
const element::Type& get_element_type() const;
const Shape& get_shape() const;
const std::shared_ptr<layout::TensorViewLayout>& get_tensor_view_layout() const
{
return m_tensor_view_layout;
}
void set_tensor_view_layout(
const std::shared_ptr<layout::TensorViewLayout>& tensor_view_layout)
{
m_tensor_view_layout = tensor_view_layout;
}
protected:
element::Type m_element_type;
Shape m_shape;
std::shared_ptr<layout::TensorViewLayout> m_tensor_view_layout;
std::string m_name;
Tensor m_tensor;
};
using TensorViewPtrs = std::vector<std::shared_ptr<TensorView>>;
}
}
...@@ -53,7 +53,6 @@ ...@@ -53,7 +53,6 @@
#include "ngraph/descriptor/layout/tensor_view_layout.hpp" #include "ngraph/descriptor/layout/tensor_view_layout.hpp"
#include "ngraph/descriptor/output.hpp" #include "ngraph/descriptor/output.hpp"
#include "ngraph/descriptor/tensor.hpp" #include "ngraph/descriptor/tensor.hpp"
#include "ngraph/descriptor/tensor_view.hpp"
#include "ngraph/except.hpp" #include "ngraph/except.hpp"
#include "ngraph/function.hpp" #include "ngraph/function.hpp"
#include "ngraph/node.hpp" #include "ngraph/node.hpp"
......
...@@ -75,7 +75,7 @@ void Node::set_output_size(size_t n) ...@@ -75,7 +75,7 @@ void Node::set_output_size(size_t n)
for (size_t i = m_outputs.size(); i < n; ++i) for (size_t i = m_outputs.size(); i < n; ++i)
{ {
auto tensor_view_descriptor = make_shared<descriptor::TensorView>( auto tensor_view_descriptor = make_shared<descriptor::TensorView>(
element::unspecified, Shape(), ngraph::descriptor::Tensor::make_tensor_name(this, i)); element::unspecified, Shape(), get_name() + "_" + to_string(i));
m_outputs.emplace_back(this, i, tensor_view_descriptor); m_outputs.emplace_back(this, i, tensor_view_descriptor);
} }
} }
......
...@@ -18,7 +18,7 @@ ...@@ -18,7 +18,7 @@
#include <memory> #include <memory>
#include "ngraph/descriptor/tensor_view.hpp" #include "ngraph/descriptor/tensor.hpp"
#include "ngraph/type/element_type.hpp" #include "ngraph/type/element_type.hpp"
namespace ngraph namespace ngraph
......
...@@ -23,36 +23,36 @@ using namespace ngraph; ...@@ -23,36 +23,36 @@ using namespace ngraph;
runtime::gpu::GPU_TensorViewWrapper::GPU_TensorViewWrapper( runtime::gpu::GPU_TensorViewWrapper::GPU_TensorViewWrapper(
const shared_ptr<descriptor::TensorView>& tv, const string& alias) const shared_ptr<descriptor::TensorView>& tv, const string& alias)
: m_tensor_view(tv) : m_tensor(tv)
, m_alias(alias) , m_alias(alias)
{ {
} }
size_t runtime::gpu::GPU_TensorViewWrapper::get_size() const size_t runtime::gpu::GPU_TensorViewWrapper::get_size() const
{ {
return m_tensor_view->get_tensor_view_layout()->get_size(); return m_tensor->get_tensor_view_layout()->get_size();
} }
const Shape& runtime::gpu::GPU_TensorViewWrapper::get_shape() const const Shape& runtime::gpu::GPU_TensorViewWrapper::get_shape() const
{ {
return m_tensor_view->get_tensor_view_layout()->get_shape(); return m_tensor->get_tensor_view_layout()->get_shape();
} }
const Strides& runtime::gpu::GPU_TensorViewWrapper::get_strides() const const Strides& runtime::gpu::GPU_TensorViewWrapper::get_strides() const
{ {
return m_tensor_view->get_tensor_view_layout()->get_strides(); return m_tensor->get_tensor_view_layout()->get_strides();
} }
const element::Type& runtime::gpu::GPU_TensorViewWrapper::get_element_type() const const element::Type& runtime::gpu::GPU_TensorViewWrapper::get_element_type() const
{ {
return m_tensor_view->get_tensor_view_layout()->get_element_type(); return m_tensor->get_tensor_view_layout()->get_element_type();
} }
const std::string& runtime::gpu::GPU_TensorViewWrapper::get_name() const const std::string& runtime::gpu::GPU_TensorViewWrapper::get_name() const
{ {
if (m_alias.empty()) if (m_alias.empty())
{ {
return m_tensor_view->get_tensor().get_name(); return m_tensor->get_tensor().get_name();
} }
else else
{ {
......
...@@ -18,7 +18,7 @@ ...@@ -18,7 +18,7 @@
#include <memory> #include <memory>
#include "ngraph/descriptor/tensor_view.hpp" #include "ngraph/descriptor/tensor.hpp"
#include "ngraph/type/element_type.hpp" #include "ngraph/type/element_type.hpp"
namespace ngraph namespace ngraph
...@@ -35,7 +35,7 @@ namespace ngraph ...@@ -35,7 +35,7 @@ namespace ngraph
class ngraph::runtime::gpu::GPU_TensorViewWrapper class ngraph::runtime::gpu::GPU_TensorViewWrapper
{ {
public: public:
GPU_TensorViewWrapper(const std::shared_ptr<descriptor::TensorView>&, GPU_TensorViewWrapper(const std::shared_ptr<descriptor::Tensor>&,
const std::string& alias = ""); const std::string& alias = "");
size_t get_size() const; size_t get_size() const;
...@@ -46,6 +46,6 @@ public: ...@@ -46,6 +46,6 @@ public:
const std::string& get_type() const; const std::string& get_type() const;
private: private:
std::shared_ptr<descriptor::TensorView> m_tensor_view; std::shared_ptr<descriptor::Tensor> m_tensor;
std::string m_alias; std::string m_alias;
}; };
...@@ -19,7 +19,7 @@ ...@@ -19,7 +19,7 @@
#include <memory> #include <memory>
#include <vector> #include <vector>
#include "ngraph/descriptor/tensor_view.hpp" #include "ngraph/descriptor/tensor.hpp"
#include "ngraph/shape.hpp" #include "ngraph/shape.hpp"
#include "ngraph/strides.hpp" #include "ngraph/strides.hpp"
#include "ngraph/type/element_type.hpp" #include "ngraph/type/element_type.hpp"
...@@ -36,7 +36,7 @@ namespace ngraph ...@@ -36,7 +36,7 @@ namespace ngraph
class TensorView class TensorView
{ {
protected: protected:
TensorView(const std::shared_ptr<ngraph::descriptor::TensorView>& descriptor) TensorView(const std::shared_ptr<ngraph::descriptor::Tensor>& descriptor)
: m_descriptor(descriptor) : m_descriptor(descriptor)
, m_stale(true) , m_stale(true)
{ {
...@@ -46,8 +46,7 @@ namespace ngraph ...@@ -46,8 +46,7 @@ namespace ngraph
virtual ~TensorView() {} virtual ~TensorView() {}
TensorView& operator=(const TensorView&) = default; TensorView& operator=(const TensorView&) = default;
std::shared_ptr<const ngraph::descriptor::TensorView> std::shared_ptr<const ngraph::descriptor::Tensor> get_tensor_view_descriptor() const;
get_tensor_view_descriptor() const;
virtual std::shared_ptr<descriptor::TensorView> get_descriptor() const; virtual std::shared_ptr<descriptor::TensorView> get_descriptor() const;
...@@ -74,7 +73,7 @@ namespace ngraph ...@@ -74,7 +73,7 @@ namespace ngraph
virtual void read(void* p, size_t tensor_offset, size_t n) const = 0; virtual void read(void* p, size_t tensor_offset, size_t n) const = 0;
protected: protected:
std::shared_ptr<ngraph::descriptor::TensorView> m_descriptor; std::shared_ptr<ngraph::descriptor::Tensor> m_descriptor;
bool m_stale; bool m_stale;
}; };
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment