Tensor Tiling Library
 
Loading...
Searching...
No Matches
TTL_types.h
Go to the documentation of this file.
1/*
2 * TTL_types.h
3 *
4 * Copyright (c) 2023 Mobileye
5 *
6 * Licensed under the Apache License, Version 2.0 (the License);
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an AS IS BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 */
18
19/**
20 * @brief Description of a Shape
21 *
22 * A Shape is a 3D description of an object.
23 *
24 * The units are elements
25 */
26typedef struct {
27 TTL_dim_t width; ///< Number of elements along dimension x.
28 TTL_dim_t height; ///< Number of rows along dimension y
29 TTL_dim_t depth; ///< Number of planes along dimension z
31
32/**
33 * @brief Create a description of a Shape
34 *
35 * @see TTL_shape_t for more information.
36 *
37 * @param width The number of elements of the Tile Shape in the x-axis
38 * @param height The number of elements of the Tile Shape in the y-axis
39 * @param depth The number of elements of the Tile Shape in the z-axis
40 *
41 * @return A TTL_shape_t describing in Tile Shape requested.
42 */
43static inline TTL_shape_t __attribute__((overloadable)) TTL_create_shape(TTL_dim_t width, TTL_dim_t height,
44 TTL_dim_t depth) {
45 TTL_shape_t res = { width, height, depth };
46 return res;
47}
48
49/**
50 * @brief Create a 2D Description of a Tile Shape
51 *
52 * @see TTL_shape_t for more information.
53 *
54 * @param width The number of elements of the Tile Shape in the x-axis
55 * @param height The number of elements of the Tile Shape in the y-axis
56 *
57 * depth defaults to 1
58 *
59 * @return A TTL_shape_t describing in Tile Shape requested.
60 */
61static inline TTL_shape_t __attribute__((overloadable)) TTL_create_shape(TTL_dim_t width, TTL_dim_t height) {
62 return TTL_create_shape(width, height, 1);
63}
64
65/**
66 * @brief Create a 1D Description of a Tile Shape
67 *
68 * @see TTL_shape_t for more information.
69 *
70 * @param width The number of elements of the Tile Shape in the x-axis
71 *
72 * height and depth default to 1
73 *
74 * @return A TTL_shape_t describing in Tile Shape requested.
75 */
76static inline TTL_shape_t __attribute__((overloadable)) TTL_create_shape(TTL_dim_t width) {
77 return TTL_create_shape(width, 1, 1);
78}
79
80/**
81 * @brief A Shape is empty if its width is 0
82 */
83static inline bool TTL_shape_empty(TTL_shape_t shape) {
84 return shape.width == 0;
85}
86
87/******************************************************
88 * OFFSET
89 *****************************************************/
90
91/**
92 * @brief Description of the 3D offset of an object.
93 *
94 * A offset of an object from some other reference point.
95 *
96 * The units are elements
97 */
98typedef struct {
99 TTL_offset_dim_t x; ///< Offset in dimension x.
100 TTL_offset_dim_t y; ///< Offset in dimension y.
101 TTL_offset_dim_t z; ///< Offset in dimension z.
103
104/**
105 * @brief Returns a TTL_offset_t
106 *
107 * @param x The x offset
108 * @param y The y offset
109 * @param z The z offset
110 *
111 * @return x, y, z expressed as a TTL_offset_dim_t
112 */
113static inline __attribute__((overloadable)) TTL_offset_t TTL_create_offset(TTL_offset_dim_t x, TTL_offset_dim_t y,
115 const TTL_offset_t result = { x, y, z };
116
117 return result;
118}
119
120/**
121 * @brief Returns a TTL_offset_t
122 *
123 * @param x The x offset
124 * @param y The y offset
125 *
126 * @return x, y, z = 0 expressed as a TTL_offset_dim_t
127 */
128static inline __attribute__((overloadable)) TTL_offset_t TTL_create_offset(TTL_offset_dim_t x, TTL_offset_dim_t y) {
129 return TTL_create_offset(x, y, 0);
130}
131
132/**
133 * @brief Returns a TTL_offset_t
134 *
135 * @param x The x offset
136 *
137 * @return x, y = 0, z = 0 expressed as a TTL_offset_dim_t
138 */
139static inline __attribute__((overloadable)) TTL_offset_t TTL_create_offset(TTL_offset_dim_t x) {
140 return TTL_create_offset(x, 0, 0);
141}
142
143/**
144 * @brief Returns a TTL_offset_t
145 *
146 *
147 * @return x = 0, y = 0, z = 0 expressed as a TTL_offset_dim_t
148 */
149static inline __attribute__((overloadable)) TTL_offset_t TTL_create_offset(void) {
150 return TTL_create_offset(0, 0, 0);
151}
152
153/******************************************************
154 * OVERLAP
155 *****************************************************/
156
157typedef unsigned char TTL_overlap_dim_t; ///< Overlap of a "adjacent" tiles in
158 ///< the unit of elements
159/**
160 * @brief Description of the overlap in 3D space of adjacent tiles.
161 *
162 * TTL_overlap_t represents the number of overlapped elements between
163 * adjacent tiles in each dimension.
164 *
165 * For example, overlap.x=1 means that every horizontally-adjacent
166 * tiles share elements on one column.
167 *
168 * The type used to hold the overlap between adjacent tiles along all dimensions
169 */
170typedef struct {
171 TTL_overlap_dim_t width; ///< width overlap in elements
172 TTL_overlap_dim_t height; ///< height overlap in elements
173 TTL_overlap_dim_t depth; ///< depth overlap in elements
175
176/**
177 * @brief Create a 3D Description of a Tile overlap
178 *
179 * @see TTL_overlap_t for more information.
180 *
181 * @param width ///< Overlap width in elements
182 * @param height ///< Overlap height in elements
183 * @param depth ///< Overlap depth in elements
184 *
185 * @return A TTL_overlap_t describing in 3D the overlap requested.
186 */
187static inline TTL_overlap_t __attribute__((overloadable)) TTL_create_overlap(const TTL_overlap_dim_t width,
188 const TTL_overlap_dim_t height,
189 const TTL_overlap_dim_t depth) {
190 const TTL_overlap_t res = { width, height, depth };
191 return res;
192}
193
194/**
195 * @brief Create a 2D Description of a Tile overlap
196 *
197 * @see TTL_overlap_t for more information.
198 *
199 * @param width ///< Overlap width in elements
200 * @param height ///< Overlap height in elements
201 *
202 * depth defaults to 0
203 *
204 * @return A TTL_overlap_t describing in 3D the overlap requested.
205 */
206static inline TTL_overlap_t __attribute__((overloadable)) TTL_create_overlap(const TTL_overlap_dim_t width,
207 const TTL_overlap_dim_t height) {
208 return TTL_create_overlap(width, height, 0);
209}
210
211/**
212 * @brief Create a 1D Description of a Tile overlap
213 *
214 * @see TTL_overlap_t for more information.
215 *
216 * @param width ///< Overlap width in elements
217 *
218 * height and depth default to 0
219 *
220 * @return A TTL_overlap_t describing in 3D the overlap requested.
221 */
222static inline TTL_overlap_t __attribute__((overloadable)) TTL_create_overlap(const TTL_overlap_dim_t width) {
223 return TTL_create_overlap(width, 0, 0);
224}
static bool TTL_shape_empty(TTL_shape_t shape)
A Shape is empty if its width is 0.
Definition TTL_types.h:83
static TTL_overlap_t TTL_create_overlap(const TTL_overlap_dim_t width, const TTL_overlap_dim_t height, const TTL_overlap_dim_t depth)
Create a 3D Description of a Tile overlap.
Definition TTL_types.h:187
static TTL_shape_t TTL_create_shape(TTL_dim_t width, TTL_dim_t height, TTL_dim_t depth)
Create a description of a Shape.
Definition TTL_types.h:43
static TTL_offset_t TTL_create_offset(void)
Returns a TTL_offset_t.
Definition TTL_types.h:149
unsigned int TTL_dim_t
The type used to hold the size of an object along any dimension.
int TTL_offset_dim_t
The type used to hold offsets and origins.
Description of the 3D offset of an object.
Description of the overlap in 3D space of adjacent tiles.
Description of a Shape.
TTL_dim_t width
Number of elements along dimension x.
unsigned char TTL_overlap_dim_t