blob: 606dec35353be920f612d5f4929209489d4d80c1 [file] [log] [blame]
Viet-Hoa Dobd4f6b92023-05-30 09:34:32 +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
Viet-Hoa Doce3c48c2023-07-03 13:44:43 +010025#ifndef CKW_PROTOTYPE_INCLUDE_CKW_TENSORTILESAMPLER_H
26#define CKW_PROTOTYPE_INCLUDE_CKW_TENSORTILESAMPLER_H
Viet-Hoa Dobd4f6b92023-05-30 09:34:32 +010027
Nikolaj Jensen5ff48022023-06-27 14:13:24 +010028#include "ckw/types/TensorSamplerTypes.h"
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +010029
Viet-Hoa Dobd4f6b92023-05-30 09:34:32 +010030#include <functional>
31
32namespace ckw
33{
34
35class TileOperand;
36
37/** Tensor sampler
38 *
39 * It contains information about how the result tile should be stored to tensor memory.
40 * It can also be used to dictate how the subsequent operators fetch the input tensor.
41 */
42class TensorTileSampler
43{
44public:
45 /** Initialize a new instance of @ref TensorSampler class. */
46 TensorTileSampler();
47
48 /** Initialize a new instance of @ref TensorSampler class.
49 *
50 * @param[in] x The coordinate in the x dimension.
51 * @param[in] y The coordinate in the y dimension.
52 * @param[in] z The coordinate in the z dimension.
53 * @param[in] b The coordinate in the batch dimension.
54 * @param[in] format The tensor data format.
55 * @param[in] address_mode_x The address mode of the x dimension.
56 * @param[in] address_mode_y The address mode of the y dimension.
57 * @param[in] address_mode_z The address mode of the z dimension.
58 */
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +010059 TensorTileSampler(TileOperand &x,
60 TileOperand &y,
61 TileOperand &z,
62 TileOperand &b,
63 TensorSamplerFormat format,
64 TensorSamplerAddressModeX address_mode_x,
65 TensorSamplerAddressModeY address_mode_y,
66 TensorSamplerAddressModeZ address_mode_z);
Viet-Hoa Dobd4f6b92023-05-30 09:34:32 +010067
68 /** Initialize a new instance of @ref TensorSampler class.
69 *
70 * @param[in] x The coordinate in the x dimension.
71 * @param[in] y The coordinate in the y dimension.
72 * @param[in] z The coordinate in the z dimension.
73 * @param[in] b The coordinate in the batch dimension.
74 * @param[in] height The height of the tile.
75 * @param[in] width The width of the tile.
76 * @param[in] format The tensor data format.
77 * @param[in] address_mode_x The address mode of the x dimension.
78 * @param[in] address_mode_y The address mode of the y dimension.
79 * @param[in] address_mode_z The address mode of the z dimension.
80 */
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +010081 TensorTileSampler(TileOperand &x,
82 TileOperand &y,
83 TileOperand &z,
84 TileOperand &b,
85 int32_t height,
86 int32_t width,
87 TensorSamplerFormat format,
88 TensorSamplerAddressModeX address_mode_x,
89 TensorSamplerAddressModeY address_mode_y,
90 TensorSamplerAddressModeZ address_mode_z);
Viet-Hoa Dobd4f6b92023-05-30 09:34:32 +010091
92 /** Get the coordinate in the x dimension. */
93 const TileOperand &x() const;
94
95 /** Set the coordinate in the x dimension. */
96 TensorTileSampler &x(TileOperand &x);
97
98 /** Get the coordinate in the y dimension. */
99 const TileOperand &y() const;
100
101 /** Set the coordinate in the y dimension. */
102 TensorTileSampler &y(TileOperand &y);
103
104 /** Get the coordinate in the z dimension. */
105 const TileOperand &z() const;
106
107 /** Set the coordinate in the z dimension. */
108 TensorTileSampler &z(TileOperand &z);
109
110 /** Get the coordinate in the batch dimension. */
111 const TileOperand &b() const;
112
113 /** Set the coordinate in the batch dimension. */
114 TensorTileSampler &b(TileOperand &b);
115
116 /** Get the width of the tile. */
117 int32_t width() const;
118
119 /** Set the width of the tile. */
120 TensorTileSampler &width(int32_t width);
121
122 /** Get the height of the tile. */
123 int32_t height() const;
124
125 /** Set the height of the tile. */
126 TensorTileSampler &height(int32_t height);
127
128 /** Get the format of the tensor. */
129 TensorSamplerFormat format() const;
130
131 /** Set the format of the tensor. */
132 TensorTileSampler &format(TensorSamplerFormat format);
133
134 /** Get the address mode of the x dimension. */
135 TensorSamplerAddressModeX address_mode_x() const;
136
137 /** Set the address mode of the x-dimension. */
138 TensorTileSampler &address_mode_x(TensorSamplerAddressModeX address_mode_x);
139
140 /** Get the address mode of the y dimension. */
141 TensorSamplerAddressModeY address_mode_y() const;
142
143 /** Set the address mode of the y dimension. */
144 TensorTileSampler &address_mode_y(TensorSamplerAddressModeY address_mode_y);
145
146 /** Get the address mode of the z dimension. */
147 TensorSamplerAddressModeZ address_mode_z() const;
148
149 /** Set the address mode of the z dimension. */
150 TensorTileSampler &address_mode_z(TensorSamplerAddressModeZ address_mode_z);
151
152private:
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +0100153 TileOperand *_x{nullptr};
154 TileOperand *_y{nullptr};
155 TileOperand *_z{nullptr};
156 TileOperand *_b{nullptr};
Viet-Hoa Dobd4f6b92023-05-30 09:34:32 +0100157
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +0100158 int32_t _height{0};
159 int32_t _width{0};
Viet-Hoa Dobd4f6b92023-05-30 09:34:32 +0100160
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +0100161 TensorSamplerFormat _format{TensorSamplerFormat::Unknown};
162 TensorSamplerAddressModeX _address_mode_x{TensorSamplerAddressModeX::Unknown};
163 TensorSamplerAddressModeY _address_mode_y{TensorSamplerAddressModeY::Unknown};
164 TensorSamplerAddressModeZ _address_mode_z{TensorSamplerAddressModeZ::Unknown};
Viet-Hoa Dobd4f6b92023-05-30 09:34:32 +0100165};
166
167} // namespace ckw
168
Viet-Hoa Doce3c48c2023-07-03 13:44:43 +0100169#endif // CKW_PROTOTYPE_INCLUDE_CKW_TENSORTILESAMPLER_H