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