+++ /dev/null
-//*****************************************************************************
-// 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};
- };
- }
- }
-}
+++ /dev/null
-//*****************************************************************************
-// 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;
- };
- }
- }
-}
namespace descriptor
{
- namespace layout
- {
- class TensorLayout;
- }
-
/// \brief Compile-time descriptor of a first-class value that is a tensor.
class NGRAPH_API Tensor
{
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;
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};
};
#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"
#include <memory>
#include <vector>
-#include "ngraph/descriptor/layout/tensor_layout.hpp"
#include "ngraph/descriptor/tensor.hpp"
#include "ngraph/shape.hpp"
#include "ngraph/strides.hpp"
/// \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;
/// \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
+++ /dev/null
-//*****************************************************************************
-// 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;
-}
+++ /dev/null
-//*****************************************************************************
-// 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();
-}
//*****************************************************************************
#include "ngraph/descriptor/tensor.hpp"
-#include "ngraph/descriptor/layout/tensor_layout.hpp"
#include "ngraph/node.hpp"
using namespace ngraph;
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
#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"
#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"
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;
//*****************************************************************************
#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"
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());
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)
{
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)
{
{
}
-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,
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;
#include "ie_tensor.hpp"
#include "ngraph/check.hpp"
-#include "ngraph/descriptor/layout/dense_tensor_layout.hpp"
#include "ngraph/except.hpp"
#include "ngraph/util.hpp"
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)
#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"
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();
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()
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";
#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"