blob: 1b51636edbb4c7f15bdfa45ec0efa29ccc1e6183 [file] [log] [blame]
Gunes Bayire4211672023-07-25 10:37:13 +01001/*
2 * Copyright (c) 2023 Arm Limited.
3 *
4 * SPDX-License-Identifier: MIT
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to
8 * deal in the Software without restriction, including without limitation the
9 * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
10 * sell copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included in all
14 * copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 * SOFTWARE.
23 */
24
25#ifndef CKW_INCLUDE_CKW_TENSORSAMPLER_H
26#define CKW_INCLUDE_CKW_TENSORSAMPLER_H
27
28#include "ckw/types/TensorStorageType.h"
29#include "ckw/types/TensorSamplerTypes.h"
30
31namespace ckw
32{
33
34/** Tensor sampler
35 *
36 * It contains information about how the tensor is sampled. It can be used to
37 * tell how a tile should be stored to tensor memory, and how a tensor should be
38 * sampled to get the values stored in a tile. Where to sample the tensor is
39 * defined with the coordinates respecting the addressing modes, storage type and
40 * the tensor format defined in this class.
41 */
42class TensorSampler
43{
44public:
45 /** Initialize a new instance of @ref TensorSampler class. */
46 TensorSampler();
47
48 /** Initialize a new instance of @ref TensorSampler class.
49 *
50 * @param[in] storage Tensor storage to load/store the tensor from/to
51 * @param[in] format The tensor data format.
52 * @param[in] address_mode_x The address mode of the x dimension.
53 * @param[in] address_mode_y The address mode of the y dimension.
54 * @param[in] address_mode_z The address mode of the z dimension.
55 */
56 TensorSampler(
57 TensorStorageType storage,
58 TensorSamplerFormat format,
59 TensorSamplerAddressModeX address_mode_x,
60 TensorSamplerAddressModeY address_mode_y,
61 TensorSamplerAddressModeZ address_mode_z);
62
63 /** Get the storage for the tensor */
64 TensorStorageType storage() const;
65
66 /** Set the storage for the tensor */
67 TensorSampler &storage(TensorStorageType storage);
68
69 /** Get the format of the tensor. */
70 TensorSamplerFormat format() const;
71
72 /** Set the format of the tensor. */
73 TensorSampler &format(TensorSamplerFormat format);
74
75 /** Get the address mode of the x dimension. */
76 TensorSamplerAddressModeX address_mode_x() const;
77
78 /** Set the address mode of the x dimension. */
79 TensorSampler &address_mode_x(TensorSamplerAddressModeX address_mode_x);
80
81 /** Get the address mode of the y dimension. */
82 TensorSamplerAddressModeY address_mode_y() const;
83
84 /** Set the address mode of the y dimension. */
85 TensorSampler &address_mode_y(TensorSamplerAddressModeY address_mode_y);
86
87 /** Get the address mode of the z dimension. */
88 TensorSamplerAddressModeZ address_mode_z() const;
89
90 /** Set the address mode of the z dimension. */
91 TensorSampler &address_mode_z(TensorSamplerAddressModeZ address_mode_z);
92
93private:
94 TensorStorageType _storage { TensorStorageType::BufferUint8Ptr };
95 TensorSamplerFormat _format { TensorSamplerFormat::Unknown };
96 TensorSamplerAddressModeX _address_mode_x { TensorSamplerAddressModeX::Unknown };
97 TensorSamplerAddressModeY _address_mode_y { TensorSamplerAddressModeY::Unknown };
98 TensorSamplerAddressModeZ _address_mode_z { TensorSamplerAddressModeZ::Unknown };
99};
100
101} // namespace ckw
102
103#endif // CKW_PROTOTYPE_INCLUDE_CKW_TENSORSAMPLER_H