ArmNN
 24.08
TensorBufferArrayView.hpp
Go to the documentation of this file.
1 //
2 // Copyright © 2017, 2024 Arm Ltd. All rights reserved.
3 // SPDX-License-Identifier: MIT
4 //
5 
6 #pragma once
7 
8 #include <armnn/Tensor.hpp>
9 
11 
12 namespace armnn
13 {
14 
15 // Utility class providing access to raw tensor memory based on indices along each dimension.
16 template <typename DataType>
18 {
19 public:
22  : m_Shape(shape)
23  , m_Data(data)
24  , m_DataLayout(dataLayout)
25  {
27  "Only $d tensors are supported by TensorBufferArrayView.");
28  }
29 
30  DataType& Get(unsigned int b, unsigned int c, unsigned int h, unsigned int w) const
31  {
32  return m_Data[m_DataLayout.GetIndex(m_Shape, b, c, h, w)];
33  }
34 
35 private:
36  const TensorShape m_Shape;
37  DataType* m_Data;
38  armnnUtils::DataLayoutIndexed m_DataLayout;
39 };
40 
41 } //namespace armnn
armnn::TensorBufferArrayView::TensorBufferArrayView
TensorBufferArrayView(const TensorShape &shape, DataType *data, armnnUtils::DataLayoutIndexed dataLayout=DataLayout::NCHW)
Definition: TensorBufferArrayView.hpp:20
armnnUtils::DataLayoutIndexed
Provides access to the appropriate indexes for Channels, Height and Width based on DataLayout.
Definition: DataLayoutIndexed.hpp:17
armnn::TensorShape
Definition: Tensor.hpp:20
armnn::TensorShape::GetNumDimensions
unsigned int GetNumDimensions() const
Function that returns the tensor rank.
Definition: Tensor.cpp:174
armnn::DataType
DataType
Definition: Types.hpp:48
Tensor.hpp
armnn
Copyright (c) 2021 ARM Limited and Contributors.
Definition: 01_00_quick_start.dox:6
armnn::TensorBufferArrayView::Get
DataType & Get(unsigned int b, unsigned int c, unsigned int h, unsigned int w) const
Definition: TensorBufferArrayView.hpp:30
armnn::TensorBufferArrayView
Definition: TensorBufferArrayView.hpp:17
armnnUtils::DataLayoutIndexed::GetIndex
unsigned int GetIndex(const armnn::TensorShape &shape, unsigned int batchIndex, unsigned int channelIndex, unsigned int heightIndex, unsigned int widthIndex) const
Definition: DataLayoutIndexed.hpp:28
DataLayoutIndexed.hpp
armnn::DataLayout::NCHW
@ NCHW
ARMNN_THROW_INVALIDARG_MSG_IF_FALSE
#define ARMNN_THROW_INVALIDARG_MSG_IF_FALSE(_cond, _str)
Definition: Exceptions.hpp:210