Laurent Carlier | 749294b | 2020-06-01 09:03:17 +0100 | [diff] [blame] | 1 | // |
Colm Donelan | b4ef163 | 2024-02-01 15:00:43 +0000 | [diff] [blame] | 2 | // Copyright © 2017, 2024 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 | |
| 12 | namespace armnn |
| 13 | { |
| 14 | |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 15 | // 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] | 16 | template <typename DataType> |
| 17 | class TensorBufferArrayView |
| 18 | { |
| 19 | public: |
Matteo Martincigh | 2135015 | 2018-11-28 16:22:22 +0000 | [diff] [blame] | 20 | TensorBufferArrayView(const TensorShape& shape, DataType* data, |
| 21 | armnnUtils::DataLayoutIndexed dataLayout = DataLayout::NCHW) |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 22 | : m_Shape(shape) |
| 23 | , m_Data(data) |
James Conroy | 5954082 | 2018-10-11 12:39:05 +0100 | [diff] [blame] | 24 | , m_DataLayout(dataLayout) |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 25 | { |
Colm Donelan | b4ef163 | 2024-02-01 15:00:43 +0000 | [diff] [blame] | 26 | ARMNN_THROW_INVALIDARG_MSG_IF_FALSE(m_Shape.GetNumDimensions() == 4, |
| 27 | "Only $d tensors are supported by TensorBufferArrayView."); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 28 | } |
| 29 | |
| 30 | DataType& Get(unsigned int b, unsigned int c, unsigned int h, unsigned int w) const |
| 31 | { |
Matteo Martincigh | ee423ce | 2019-06-05 09:02:41 +0100 | [diff] [blame] | 32 | return m_Data[m_DataLayout.GetIndex(m_Shape, b, c, h, w)]; |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 33 | } |
| 34 | |
| 35 | private: |
Matteo Martincigh | 2135015 | 2018-11-28 16:22:22 +0000 | [diff] [blame] | 36 | const TensorShape m_Shape; |
| 37 | DataType* m_Data; |
| 38 | armnnUtils::DataLayoutIndexed m_DataLayout; |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 39 | }; |
| 40 | |
| 41 | } //namespace armnn |