Laurent Carlier | 749294b | 2020-06-01 09:03:17 +0100 | [diff] [blame] | 1 | // |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 2 | // Copyright © 2017 Arm Ltd. All rights reserved. |
David Beck | ecb56cd | 2018-09-05 12:52:57 +0100 | [diff] [blame] | 3 | // SPDX-License-Identifier: MIT |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 4 | // |
| 5 | |
Matteo Martincigh | ada9cb2 | 2018-10-17 14:45:07 +0100 | [diff] [blame] | 6 | #pragma once |
| 7 | |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 8 | #include <armnn/Tensor.hpp> |
| 9 | |
Matteo Martincigh | e011d20 | 2019-11-28 11:35:47 +0000 | [diff] [blame] | 10 | #include <armnnUtils/DataLayoutIndexed.hpp> |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 11 | |
Narumol Prangnawarat | ac2770a | 2020-04-01 16:51:23 +0100 | [diff] [blame] | 12 | #include <armnn/utility/Assert.hpp> |
Matteo Martincigh | 2135015 | 2018-11-28 16:22:22 +0000 | [diff] [blame] | 13 | |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 14 | namespace armnn |
| 15 | { |
| 16 | |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 17 | // Utility class providing access to raw tensor memory based on indices along each dimension. |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 18 | template <typename DataType> |
| 19 | class TensorBufferArrayView |
| 20 | { |
| 21 | public: |
Matteo Martincigh | 2135015 | 2018-11-28 16:22:22 +0000 | [diff] [blame] | 22 | TensorBufferArrayView(const TensorShape& shape, DataType* data, |
| 23 | armnnUtils::DataLayoutIndexed dataLayout = DataLayout::NCHW) |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 24 | : m_Shape(shape) |
| 25 | , m_Data(data) |
James Conroy | 5954082 | 2018-10-11 12:39:05 +0100 | [diff] [blame] | 26 | , m_DataLayout(dataLayout) |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 27 | { |
Narumol Prangnawarat | ac2770a | 2020-04-01 16:51:23 +0100 | [diff] [blame] | 28 | ARMNN_ASSERT(m_Shape.GetNumDimensions() == 4); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 29 | } |
| 30 | |
| 31 | DataType& Get(unsigned int b, unsigned int c, unsigned int h, unsigned int w) const |
| 32 | { |
Matteo Martincigh | ee423ce | 2019-06-05 09:02:41 +0100 | [diff] [blame] | 33 | return m_Data[m_DataLayout.GetIndex(m_Shape, b, c, h, w)]; |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 34 | } |
| 35 | |
| 36 | private: |
Matteo Martincigh | 2135015 | 2018-11-28 16:22:22 +0000 | [diff] [blame] | 37 | const TensorShape m_Shape; |
| 38 | DataType* m_Data; |
| 39 | armnnUtils::DataLayoutIndexed m_DataLayout; |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 40 | }; |
| 41 | |
| 42 | } //namespace armnn |