Remove nGraph layout (#1763)
authorIlya Churaev <ilya.churaev@intel.com>
Mon, 17 Aug 2020 03:05:08 +0000 (06:05 +0300)
committerGitHub <noreply@github.com>
Mon, 17 Aug 2020 03:05:08 +0000 (06:05 +0300)
19 files changed:
ngraph/core/include/ngraph/descriptor/layout/dense_tensor_layout.hpp [deleted file]
ngraph/core/include/ngraph/descriptor/layout/tensor_layout.hpp [deleted file]
ngraph/core/include/ngraph/descriptor/tensor.hpp
ngraph/core/include/ngraph/ngraph.hpp
ngraph/core/include/ngraph/runtime/tensor.hpp
ngraph/core/src/descriptor/layout/dense_tensor_layout.cpp [deleted file]
ngraph/core/src/descriptor/layout/tensor_layout.cpp [deleted file]
ngraph/core/src/descriptor/tensor.cpp
ngraph/core/src/node.cpp
ngraph/core/src/runtime/host_tensor.cpp
ngraph/core/src/runtime/tensor.cpp
ngraph/core/src/util.cpp
ngraph/test/runtime/dynamic/dynamic_backend.cpp
ngraph/test/runtime/dynamic/dynamic_backend.hpp
ngraph/test/runtime/ie/ie_tensor.cpp
ngraph/test/runtime/interpreter/int_executable.cpp
ngraph/test/util/all_close.hpp
ngraph/test/util/all_close_f.cpp
ngraph/test/util/test_tools.hpp

diff --git a/ngraph/core/include/ngraph/descriptor/layout/dense_tensor_layout.hpp b/ngraph/core/include/ngraph/descriptor/layout/dense_tensor_layout.hpp
deleted file mode 100644 (file)
index daa326a..0000000
+++ /dev/null
@@ -1,52 +0,0 @@
-//*****************************************************************************
-// 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 <cstddef>
-#include <vector>
-
-#include "ngraph/descriptor/layout/tensor_layout.hpp"
-
-namespace ngraph
-{
-    namespace descriptor
-    {
-        class Tensor;
-
-        namespace layout
-        {
-            /// \brief The standard strided layout, used for row-major and column-major, their
-            ///        permutations and slices.
-            ///
-            /// The linearized offset of an index I is dot(I, strides) + offset.
-            class NGRAPH_API DenseTensorLayout : public TensorLayout
-            {
-            public:
-                ~DenseTensorLayout() override {}
-                DenseTensorLayout(const Tensor& tensor);
-
-                size_t get_offset() const { return m_offset; }
-                virtual size_t get_index_offset(const std::vector<size_t>& indices) override;
-                Strides get_strides() const override;
-                virtual bool operator==(const TensorLayout& other) const override;
-
-            protected:
-                size_t m_offset{0};
-            };
-        }
-    }
-}
diff --git a/ngraph/core/include/ngraph/descriptor/layout/tensor_layout.hpp b/ngraph/core/include/ngraph/descriptor/layout/tensor_layout.hpp
deleted file mode 100644 (file)
index 1cfec65..0000000
+++ /dev/null
@@ -1,70 +0,0 @@
-//*****************************************************************************
-// 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 <memory>
-#include <vector>
-
-#include "ngraph/descriptor/tensor.hpp"
-
-namespace ngraph
-{
-    namespace element
-    {
-        class Type;
-    }
-
-    namespace descriptor
-    {
-        namespace layout
-        {
-            /// \brief Interface for describing implementations of tensors.
-            ///
-            /// Kernel selection will need to pay attention to the layout.
-            class NGRAPH_API TensorLayout
-            {
-            protected:
-                TensorLayout(const ngraph::descriptor::Tensor& tensor);
-                TensorLayout(const TensorLayout&) = delete;
-                TensorLayout& operator=(const TensorLayout&) = delete;
-
-            public:
-                virtual ~TensorLayout() {}
-                /// Extent of this tensor in buffer.
-                ///
-                /// When we support non-linear buffers, this will need to be something other than
-                /// size_t.
-                size_t get_size() const;
-                virtual size_t get_allocated_size();
-                /// Offset of an index; useful for slice implementation.
-                ///
-                /// With non-linear buffers, this will need to be something other than size_t.
-                virtual size_t get_index_offset(const std::vector<size_t>& indices) = 0;
-
-                const element::Type& get_element_type() const;
-                const Shape& get_shape() const;
-                virtual Strides get_strides() const = 0;
-                /// \brief Return true if this and other have the same element interpretation
-                virtual bool operator==(const TensorLayout& other) const = 0;
-                bool operator!=(const TensorLayout& other) const { return !(*this == other); }
-            protected:
-                const element::Type m_element_type;
-                const Shape m_shape;
-            };
-        }
-    }
-}
index 1a48712..58978c4 100644 (file)
@@ -29,11 +29,6 @@ namespace ngraph
 
     namespace descriptor
     {
-        namespace layout
-        {
-            class TensorLayout;
-        }
-
         /// \brief Compile-time descriptor of a first-class value that is a tensor.
         class NGRAPH_API Tensor
         {
@@ -58,13 +53,6 @@ namespace ngraph
             const element::Type& get_element_type() const { return m_element_type; }
             const Shape& get_shape() const;
             const PartialShape& get_partial_shape() const { return m_partial_shape; }
-            const std::shared_ptr<layout::TensorLayout>& get_tensor_layout() const
-            {
-                return m_tensor_layout;
-            }
-
-            void set_tensor_layout(const std::shared_ptr<layout::TensorLayout>& tensor_layout);
-
             void set_pool_offset(size_t);
             size_t get_pool_offset() const;
 
@@ -83,7 +71,6 @@ namespace ngraph
             size_t m_node_output_number{0};
 
             std::string m_name;
-            std::shared_ptr<layout::TensorLayout> m_tensor_layout;
             size_t m_pool_offset{0};
         };
 
index 27d81bc..3594135 100644 (file)
@@ -72,8 +72,6 @@ namespace ngraph
 #include "ngraph/builder/reshape.hpp"
 #include "ngraph/coordinate_transform.hpp"
 #include "ngraph/descriptor/input.hpp"
-#include "ngraph/descriptor/layout/dense_tensor_layout.hpp"
-#include "ngraph/descriptor/layout/tensor_layout.hpp"
 #include "ngraph/descriptor/output.hpp"
 #include "ngraph/descriptor/tensor.hpp"
 #include "ngraph/dimension.hpp"
index eb2f50c..9bbadb1 100644 (file)
@@ -19,7 +19,6 @@
 #include <memory>
 #include <vector>
 
-#include "ngraph/descriptor/layout/tensor_layout.hpp"
 #include "ngraph/descriptor/tensor.hpp"
 #include "ngraph/shape.hpp"
 #include "ngraph/strides.hpp"
@@ -50,10 +49,6 @@ namespace ngraph
             /// \return const reference to a PartialShape
             const ngraph::PartialShape& get_partial_shape() const;
 
-            /// \brief Get tensor strides
-            /// \return Strides
-            virtual ngraph::Strides get_strides() const;
-
             /// \brief Get tensor element type
             /// \return element::Type
             virtual const element::Type& get_element_type() const;
@@ -70,14 +65,6 @@ namespace ngraph
             /// \return tensor's name
             const std::string& get_name() const;
 
-            /// \brief Get tensor layout
-            /// \return tensor layout
-            std::shared_ptr<descriptor::layout::TensorLayout> get_tensor_layout() const;
-
-            /// \brief Set tensor layout
-            /// \param layout Layout to set
-            void set_tensor_layout(const std::shared_ptr<descriptor::layout::TensorLayout>& layout);
-
             /// \brief Get the stale value of the tensor. A tensor is stale if its data is
             /// changed.
             /// \return true if there is new data in this tensor
diff --git a/ngraph/core/src/descriptor/layout/dense_tensor_layout.cpp b/ngraph/core/src/descriptor/layout/dense_tensor_layout.cpp
deleted file mode 100644 (file)
index a6d7c49..0000000
+++ /dev/null
@@ -1,65 +0,0 @@
-//*****************************************************************************
-// 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/shape.hpp"
-#include "ngraph/type/element_type.hpp"
-
-using namespace ngraph;
-
-descriptor::layout::DenseTensorLayout::DenseTensorLayout(const Tensor& tensor)
-    : TensorLayout(tensor)
-{
-}
-
-size_t descriptor::layout::DenseTensorLayout::get_index_offset(const std::vector<size_t>& indices)
-{
-    auto strides = get_strides();
-    if (indices.size() != strides.size())
-    {
-        throw ngraph_error("Indices have the incorrect rank.");
-    }
-    size_t result = 0;
-    for (uint64_t i = 0; i < indices.size(); i++)
-    {
-        result += strides[i] * indices[i];
-    }
-    return result;
-}
-
-Strides descriptor::layout::DenseTensorLayout::get_strides() const
-{
-    return ngraph::row_major_strides(get_shape());
-}
-
-bool descriptor::layout::DenseTensorLayout::operator==(const TensorLayout& other) const
-{
-    const DenseTensorLayout* p_other = dynamic_cast<const DenseTensorLayout*>(&other);
-    if (nullptr == p_other)
-        return false;
-
-    if (get_element_type() != p_other->get_element_type())
-        return false;
-
-    if (get_strides() != p_other->get_strides())
-        return false;
-
-    if (get_offset() != p_other->get_offset())
-        return false;
-
-    return true;
-}
diff --git a/ngraph/core/src/descriptor/layout/tensor_layout.cpp b/ngraph/core/src/descriptor/layout/tensor_layout.cpp
deleted file mode 100644 (file)
index cffea66..0000000
+++ /dev/null
@@ -1,47 +0,0 @@
-//*****************************************************************************
-// 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/tensor_layout.hpp"
-#include "ngraph/descriptor/tensor.hpp"
-#include "ngraph/type/element_type.hpp"
-
-using namespace ngraph;
-
-descriptor::layout::TensorLayout::TensorLayout(const descriptor::Tensor& tensor)
-    : m_element_type(tensor.get_element_type())
-    , m_shape(tensor.get_shape())
-{
-}
-
-const element::Type& descriptor::layout::TensorLayout::get_element_type() const
-{
-    return m_element_type;
-}
-
-const Shape& descriptor::layout::TensorLayout::get_shape() const
-{
-    return m_shape;
-}
-
-size_t descriptor::layout::TensorLayout::get_size() const
-{
-    return ngraph::shape_size(get_shape());
-}
-
-size_t descriptor::layout::TensorLayout::get_allocated_size()
-{
-    return get_size() * get_element_type().size();
-}
index 944d304..f0b2e5b 100644 (file)
@@ -15,7 +15,6 @@
 //*****************************************************************************
 
 #include "ngraph/descriptor/tensor.hpp"
-#include "ngraph/descriptor/layout/tensor_layout.hpp"
 #include "ngraph/node.hpp"
 
 using namespace ngraph;
@@ -98,30 +97,7 @@ size_t descriptor::Tensor::get_pool_offset() const
 
 size_t descriptor::Tensor::size() const
 {
-    if (auto tvl = get_tensor_layout())
-    {
-        return tvl->get_allocated_size();
-    }
-    else
-    {
-        return shape_size(get_shape()) * m_element_type.size();
-    }
-}
-
-void descriptor::Tensor::set_tensor_layout(
-    const std::shared_ptr<layout::TensorLayout>& tensor_layout)
-{
-    NGRAPH_CHECK(tensor_layout->get_shape() == get_shape(),
-                 "Setting tensor's layout to a layout with a different shape : ",
-                 get_shape(),
-                 " -> ",
-                 tensor_layout->get_shape());
-    NGRAPH_CHECK(tensor_layout->get_element_type() == get_element_type(),
-                 "Setting tensor's layout to a layout with a different element type : ",
-                 get_element_type(),
-                 " -> ",
-                 tensor_layout->get_element_type());
-    m_tensor_layout = tensor_layout;
+    return shape_size(get_shape()) * m_element_type.size();
 }
 
 const std::string& descriptor::Tensor::get_name() const
index 6a40c66..6843861 100644 (file)
@@ -20,7 +20,6 @@
 #include <typeinfo>
 
 #include "ngraph/descriptor/input.hpp"
-#include "ngraph/descriptor/layout/tensor_layout.hpp"
 #include "ngraph/graph_util.hpp"
 #include "ngraph/itt.hpp"
 #include "ngraph/node.hpp"
index f4e89f4..a1b624c 100644 (file)
@@ -19,7 +19,6 @@
 
 #include "host_tensor.hpp"
 #include "ngraph/chrome_trace.hpp"
-#include "ngraph/descriptor/layout/dense_tensor_layout.hpp"
 #include "ngraph/op/constant.hpp"
 #include "ngraph/util.hpp"
 
@@ -75,9 +74,7 @@ void runtime::HostTensor::allocate_buffer()
     NGRAPH_CHECK(get_element_type().is_static(),
                  "Attempt to allocate buffer for tensor with dynamic type: ",
                  get_element_type());
-    m_descriptor->set_tensor_layout(
-        std::make_shared<ngraph::descriptor::layout::DenseTensorLayout>(*m_descriptor));
-    m_buffer_size = m_descriptor->get_tensor_layout()->get_size() * get_element_type().size();
+    m_buffer_size = shape_size(m_descriptor->get_shape()) * get_element_type().size();
     if (m_memory_pointer != nullptr)
     {
         m_aligned_buffer_pool = m_memory_pointer;
index 946167c..6b653f0 100644 (file)
@@ -15,7 +15,6 @@
 //*****************************************************************************
 
 #include "tensor.hpp"
-#include "ngraph/descriptor/layout/tensor_layout.hpp"
 #include "ngraph/log.hpp"
 #include "ngraph/runtime/aligned_buffer.hpp"
 #include "ngraph/type/element_type.hpp"
@@ -33,26 +32,11 @@ const PartialShape& runtime::Tensor::get_partial_shape() const
     return m_descriptor->get_partial_shape();
 }
 
-Strides runtime::Tensor::get_strides() const
-{
-    return m_descriptor->get_tensor_layout()->get_strides();
-}
-
 const element::Type& runtime::Tensor::get_element_type() const
 {
     return m_descriptor->get_element_type();
 }
 
-shared_ptr<descriptor::layout::TensorLayout> runtime::Tensor::get_tensor_layout() const
-{
-    return m_descriptor->get_tensor_layout();
-}
-
-void runtime::Tensor::set_tensor_layout(const shared_ptr<descriptor::layout::TensorLayout>& layout)
-{
-    m_descriptor->set_tensor_layout(layout);
-}
-
 size_t runtime::Tensor::get_element_count() const
 {
     return shape_size(m_descriptor->get_shape());
index 6e1a73f..5cedea1 100644 (file)
@@ -479,7 +479,7 @@ void ngraph::parse_version_string(
 vector<float> read_float_vector(shared_ptr<runtime::Tensor> tv)
 {
     vector<float> float_vec;
-    element::Type element_type = tv->get_tensor_layout()->get_element_type();
+    element::Type element_type = tv->get_element_type();
 
     if (element_type == element::boolean)
     {
@@ -595,7 +595,7 @@ vector<float> read_float_vector(shared_ptr<runtime::Tensor> tv)
 vector<int64_t> read_index_vector(shared_ptr<runtime::Tensor> tv)
 {
     vector<int64_t> index_vec;
-    element::Type element_type = tv->get_tensor_layout()->get_element_type();
+    element::Type element_type = tv->get_element_type();
 
     if (element_type == element::boolean)
     {
index 9448371..fd60a76 100644 (file)
@@ -329,13 +329,6 @@ runtime::dynamic::DynamicTensor::DynamicTensor(
 {
 }
 
-Strides runtime::dynamic::DynamicTensor::get_strides() const
-{
-    NGRAPH_CHECK(m_wrapped_tensor != nullptr,
-                 "asked for strides of a dynamic tensor with no allocated storage");
-    return ngraph::row_major_strides(m_wrapped_tensor->get_shape());
-}
-
 size_t runtime::dynamic::DynamicTensor::get_size_in_bytes() const
 {
     NGRAPH_CHECK(m_wrapped_tensor != nullptr,
index e127f10..0886e84 100644 (file)
@@ -132,7 +132,6 @@ public:
     DynamicTensor(const element::Type& element_type,
                   const PartialShape& shape,
                   const std::shared_ptr<runtime::Backend>& wrapped_backend);
-    virtual ngraph::Strides get_strides() const override;
     virtual size_t get_size_in_bytes() const override;
     virtual size_t get_element_count() const override;
     virtual const element::Type& get_element_type() const override;
index a5a8757..2c7474e 100644 (file)
@@ -20,7 +20,6 @@
 
 #include "ie_tensor.hpp"
 #include "ngraph/check.hpp"
-#include "ngraph/descriptor/layout/dense_tensor_layout.hpp"
 #include "ngraph/except.hpp"
 #include "ngraph/util.hpp"
 
@@ -30,16 +29,12 @@ using namespace std;
 runtime::ie::IETensor::IETensor(const element::Type& element_type, const PartialShape& shape)
     : runtime::Tensor(make_shared<descriptor::Tensor>(element_type, shape, ""))
 {
-    m_descriptor->set_tensor_layout(
-        make_shared<descriptor::layout::DenseTensorLayout>(*m_descriptor));
 }
 
 runtime::ie::IETensor::IETensor(const element::Type& element_type, const Shape& shape)
     : runtime::Tensor(make_shared<descriptor::Tensor>(element_type, shape, ""))
     , m_data(shape_size(shape) * element_type.size())
 {
-    m_descriptor->set_tensor_layout(
-        make_shared<descriptor::layout::DenseTensorLayout>(*m_descriptor));
 }
 
 void runtime::ie::IETensor::write(const void* src, size_t bytes)
index 70e0d8a..3400e70 100644 (file)
@@ -17,7 +17,6 @@
 #include "int_executable.hpp"
 #include "backend_manager.hpp"
 #include "ngraph/chrome_trace.hpp"
-#include "ngraph/descriptor/layout/dense_tensor_layout.hpp"
 #include "ngraph/except.hpp"
 #include "ngraph/op/util/op_types.hpp"
 #include "ngraph/ops.hpp"
@@ -34,8 +33,6 @@ using namespace ngraph;
 
 NGRAPH_SUPPRESS_DEPRECATED_START
 
-using descriptor::layout::DenseTensorLayout;
-
 runtime::interpreter::OP_TYPEID runtime::interpreter::INTExecutable::get_typeid(const Node& node)
 {
     const NodeTypeInfo& type_info = node.get_type_info();
index d4c27b7..3e4fb32 100644 (file)
@@ -114,13 +114,6 @@ namespace ngraph
                                              T rtol = 1e-5f,
                                              T atol = 1e-8f)
         {
-            // Check that the layouts are compatible
-            if (*a->get_tensor_layout() != *b->get_tensor_layout())
-            {
-                return ::testing::AssertionFailure()
-                       << "Cannot compare tensors with different layouts";
-            }
-
             if (a->get_shape() != b->get_shape())
             {
                 return ::testing::AssertionFailure()
index 1ce486a..ad019bb 100644 (file)
@@ -590,10 +590,6 @@ uint32_t test::matching_mantissa_bits(uint64_t distance)
                                              float min_signal)
 {
     // Check that the layouts are compatible
-    if (*a->get_tensor_layout() != *b->get_tensor_layout())
-    {
-        return ::testing::AssertionFailure() << "Cannot compare tensors with different layouts";
-    }
     if (a->get_shape() != b->get_shape())
     {
         return ::testing::AssertionFailure() << "Cannot compare tensors with different shapes";
index 0eccc85..7f505b2 100644 (file)
@@ -26,7 +26,6 @@
 #include <vector>
 
 #include "gtest/gtest.h"
-#include "ngraph/descriptor/layout/tensor_layout.hpp"
 #include "ngraph/file_util.hpp"
 #include "ngraph/log.hpp"
 #include "ngraph/op/op.hpp"