From: Ilya Churaev Date: Mon, 17 Aug 2020 03:05:08 +0000 (+0300) Subject: Remove nGraph layout (#1763) X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=4270153ad2c514cfe81429b000e9b01fa0d95132;p=platform%2Fupstream%2Fdldt.git Remove nGraph layout (#1763) --- 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 index daa326a..0000000 --- a/ngraph/core/include/ngraph/descriptor/layout/dense_tensor_layout.hpp +++ /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 -#include - -#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& 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 index 1cfec65..0000000 --- a/ngraph/core/include/ngraph/descriptor/layout/tensor_layout.hpp +++ /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 -#include - -#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& 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; - }; - } - } -} diff --git a/ngraph/core/include/ngraph/descriptor/tensor.hpp b/ngraph/core/include/ngraph/descriptor/tensor.hpp index 1a48712..58978c4 100644 --- a/ngraph/core/include/ngraph/descriptor/tensor.hpp +++ b/ngraph/core/include/ngraph/descriptor/tensor.hpp @@ -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& get_tensor_layout() const - { - return m_tensor_layout; - } - - void set_tensor_layout(const std::shared_ptr& 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 m_tensor_layout; size_t m_pool_offset{0}; }; diff --git a/ngraph/core/include/ngraph/ngraph.hpp b/ngraph/core/include/ngraph/ngraph.hpp index 27d81bc..3594135 100644 --- a/ngraph/core/include/ngraph/ngraph.hpp +++ b/ngraph/core/include/ngraph/ngraph.hpp @@ -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" diff --git a/ngraph/core/include/ngraph/runtime/tensor.hpp b/ngraph/core/include/ngraph/runtime/tensor.hpp index eb2f50c..9bbadb1 100644 --- a/ngraph/core/include/ngraph/runtime/tensor.hpp +++ b/ngraph/core/include/ngraph/runtime/tensor.hpp @@ -19,7 +19,6 @@ #include #include -#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 get_tensor_layout() const; - - /// \brief Set tensor layout - /// \param layout Layout to set - void set_tensor_layout(const std::shared_ptr& 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 index a6d7c49..0000000 --- a/ngraph/core/src/descriptor/layout/dense_tensor_layout.cpp +++ /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& 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(&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 index cffea66..0000000 --- a/ngraph/core/src/descriptor/layout/tensor_layout.cpp +++ /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(); -} diff --git a/ngraph/core/src/descriptor/tensor.cpp b/ngraph/core/src/descriptor/tensor.cpp index 944d304..f0b2e5b 100644 --- a/ngraph/core/src/descriptor/tensor.cpp +++ b/ngraph/core/src/descriptor/tensor.cpp @@ -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& 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 diff --git a/ngraph/core/src/node.cpp b/ngraph/core/src/node.cpp index 6a40c66..6843861 100644 --- a/ngraph/core/src/node.cpp +++ b/ngraph/core/src/node.cpp @@ -20,7 +20,6 @@ #include #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" diff --git a/ngraph/core/src/runtime/host_tensor.cpp b/ngraph/core/src/runtime/host_tensor.cpp index f4e89f4..a1b624c 100644 --- a/ngraph/core/src/runtime/host_tensor.cpp +++ b/ngraph/core/src/runtime/host_tensor.cpp @@ -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(*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; diff --git a/ngraph/core/src/runtime/tensor.cpp b/ngraph/core/src/runtime/tensor.cpp index 946167c..6b653f0 100644 --- a/ngraph/core/src/runtime/tensor.cpp +++ b/ngraph/core/src/runtime/tensor.cpp @@ -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 runtime::Tensor::get_tensor_layout() const -{ - return m_descriptor->get_tensor_layout(); -} - -void runtime::Tensor::set_tensor_layout(const shared_ptr& layout) -{ - m_descriptor->set_tensor_layout(layout); -} - size_t runtime::Tensor::get_element_count() const { return shape_size(m_descriptor->get_shape()); diff --git a/ngraph/core/src/util.cpp b/ngraph/core/src/util.cpp index 6e1a73f..5cedea1 100644 --- a/ngraph/core/src/util.cpp +++ b/ngraph/core/src/util.cpp @@ -479,7 +479,7 @@ void ngraph::parse_version_string( vector read_float_vector(shared_ptr tv) { vector 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 read_float_vector(shared_ptr tv) vector read_index_vector(shared_ptr tv) { vector 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) { diff --git a/ngraph/test/runtime/dynamic/dynamic_backend.cpp b/ngraph/test/runtime/dynamic/dynamic_backend.cpp index 9448371..fd60a76 100644 --- a/ngraph/test/runtime/dynamic/dynamic_backend.cpp +++ b/ngraph/test/runtime/dynamic/dynamic_backend.cpp @@ -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, diff --git a/ngraph/test/runtime/dynamic/dynamic_backend.hpp b/ngraph/test/runtime/dynamic/dynamic_backend.hpp index e127f10..0886e84 100644 --- a/ngraph/test/runtime/dynamic/dynamic_backend.hpp +++ b/ngraph/test/runtime/dynamic/dynamic_backend.hpp @@ -132,7 +132,6 @@ public: DynamicTensor(const element::Type& element_type, const PartialShape& shape, const std::shared_ptr& 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; diff --git a/ngraph/test/runtime/ie/ie_tensor.cpp b/ngraph/test/runtime/ie/ie_tensor.cpp index a5a8757..2c7474e 100644 --- a/ngraph/test/runtime/ie/ie_tensor.cpp +++ b/ngraph/test/runtime/ie/ie_tensor.cpp @@ -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(element_type, shape, "")) { - m_descriptor->set_tensor_layout( - make_shared(*m_descriptor)); } runtime::ie::IETensor::IETensor(const element::Type& element_type, const Shape& shape) : runtime::Tensor(make_shared(element_type, shape, "")) , m_data(shape_size(shape) * element_type.size()) { - m_descriptor->set_tensor_layout( - make_shared(*m_descriptor)); } void runtime::ie::IETensor::write(const void* src, size_t bytes) diff --git a/ngraph/test/runtime/interpreter/int_executable.cpp b/ngraph/test/runtime/interpreter/int_executable.cpp index 70e0d8a..3400e70 100644 --- a/ngraph/test/runtime/interpreter/int_executable.cpp +++ b/ngraph/test/runtime/interpreter/int_executable.cpp @@ -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(); diff --git a/ngraph/test/util/all_close.hpp b/ngraph/test/util/all_close.hpp index d4c27b7..3e4fb32 100644 --- a/ngraph/test/util/all_close.hpp +++ b/ngraph/test/util/all_close.hpp @@ -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() diff --git a/ngraph/test/util/all_close_f.cpp b/ngraph/test/util/all_close_f.cpp index 1ce486a..ad019bb 100644 --- a/ngraph/test/util/all_close_f.cpp +++ b/ngraph/test/util/all_close_f.cpp @@ -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"; diff --git a/ngraph/test/util/test_tools.hpp b/ngraph/test/util/test_tools.hpp index 0eccc85..7f505b2 100644 --- a/ngraph/test/util/test_tools.hpp +++ b/ngraph/test/util/test_tools.hpp @@ -26,7 +26,6 @@ #include #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"