blob: 0b448e6196ac3b2dbf26456d8bb005ba132fc424 [file] [log] [blame]
Laurent Carlier749294b2020-06-01 09:03:17 +01001//
telsoa014fcda012018-03-09 14:13:49 +00002// Copyright © 2017 Arm Ltd. All rights reserved.
David Beckecb56cd2018-09-05 12:52:57 +01003// SPDX-License-Identifier: MIT
telsoa014fcda012018-03-09 14:13:49 +00004//
5
Matteo Martincighada9cb22018-10-17 14:45:07 +01006#pragma once
7
telsoa014fcda012018-03-09 14:13:49 +00008#include <armnn/Tensor.hpp>
9
Matteo Martincighe011d202019-11-28 11:35:47 +000010#include <armnnUtils/DataLayoutIndexed.hpp>
telsoa014fcda012018-03-09 14:13:49 +000011
Narumol Prangnawaratac2770a2020-04-01 16:51:23 +010012#include <armnn/utility/Assert.hpp>
Matteo Martincigh21350152018-11-28 16:22:22 +000013
telsoa014fcda012018-03-09 14:13:49 +000014namespace armnn
15{
16
telsoa01c577f2c2018-08-31 09:22:23 +010017// Utility class providing access to raw tensor memory based on indices along each dimension.
telsoa014fcda012018-03-09 14:13:49 +000018template <typename DataType>
19class TensorBufferArrayView
20{
21public:
Matteo Martincigh21350152018-11-28 16:22:22 +000022 TensorBufferArrayView(const TensorShape& shape, DataType* data,
23 armnnUtils::DataLayoutIndexed dataLayout = DataLayout::NCHW)
telsoa014fcda012018-03-09 14:13:49 +000024 : m_Shape(shape)
25 , m_Data(data)
James Conroy59540822018-10-11 12:39:05 +010026 , m_DataLayout(dataLayout)
telsoa014fcda012018-03-09 14:13:49 +000027 {
Narumol Prangnawaratac2770a2020-04-01 16:51:23 +010028 ARMNN_ASSERT(m_Shape.GetNumDimensions() == 4);
telsoa014fcda012018-03-09 14:13:49 +000029 }
30
31 DataType& Get(unsigned int b, unsigned int c, unsigned int h, unsigned int w) const
32 {
Matteo Martincighee423ce2019-06-05 09:02:41 +010033 return m_Data[m_DataLayout.GetIndex(m_Shape, b, c, h, w)];
telsoa014fcda012018-03-09 14:13:49 +000034 }
35
36private:
Matteo Martincigh21350152018-11-28 16:22:22 +000037 const TensorShape m_Shape;
38 DataType* m_Data;
39 armnnUtils::DataLayoutIndexed m_DataLayout;
telsoa014fcda012018-03-09 14:13:49 +000040};
41
42} //namespace armnn