Tensor Tiling Library
 
Loading...
Searching...
No Matches
tensors/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#pragma once
20
21#include "TTL_macros.h"
22
23/**
24 * @brief Description of a Shape
25 *
26 * A Shape is a 3D description of an object.
27 *
28 * The units are elements
29 */
30typedef struct {
31 TTL_dim_t width; ///< Number of elements along dimension x.
32 TTL_dim_t height; ///< Number of rows along dimension y
33 TTL_dim_t depth; ///< Number of planes along dimension z
35
36/**
37 * @brief Create a description of a Shape
38 *
39 * @see TTL_shape_t for more information.
40 *
41 * @param width The number of elements of the Tile Shape in the x-axis
42 * @param height The number of elements of the Tile Shape in the y-axis
43 * @param depth The number of elements of the Tile Shape in the z-axis
44 *
45 * @return A TTL_shape_t describing in Tile Shape requested.
46 */
47static inline TTL_shape_t __attribute__((overloadable))
49 TTL_shape_t res = { width, height, depth };
50 return res;
51}
52
53/**
54 * @brief Create a 2D Description of a Tile Shape
55 *
56 * @see TTL_shape_t for more information.
57 *
58 * @param width The number of elements of the Tile Shape in the x-axis
59 * @param height The number of elements of the Tile Shape in the y-axis
60 *
61 * depth defaults to 1
62 *
63 * @return A TTL_shape_t describing in Tile Shape requested.
64 */
65static inline TTL_shape_t __attribute__((overloadable)) TTL_create_shape(TTL_dim_t width, TTL_dim_t height) {
66 return TTL_create_shape(width, height, 1);
67}
68
69/**
70 * @brief Create a 1D Description of a Tile Shape
71 *
72 * @see TTL_shape_t for more information.
73 *
74 * @param width The number of elements of the Tile Shape in the x-axis
75 *
76 * height and depth default to 1
77 *
78 * @return A TTL_shape_t describing in Tile Shape requested.
79 */
80static inline TTL_shape_t __attribute__((overloadable)) TTL_create_shape(TTL_dim_t width) {
81 return TTL_create_shape(width, 1, 1);
82}
83
84/**
85 * @brief A Shape is empty if its width is 0
86 */
87static inline bool TTL_shape_empty(TTL_shape_t shape) {
88 return shape.width == 0;
89}
90
91/******************************************************
92 * OFFSET
93 *****************************************************/
94
95/**
96 * @brief Description of the 3D offset of an object.
97 *
98 * A offset of an object from some other reference point.
99 *
100 * The units are elements
101 */
102typedef struct {
103 TTL_offset_dim_t x; ///< Offset in dimension x.
104 TTL_offset_dim_t y; ///< Offset in dimension y.
105 TTL_offset_dim_t z; ///< Offset in dimension z.
107
108/**
109 * @brief Returns a TTL_offset_t
110 *
111 * @param x The x offset
112 * @param y The y offset
113 * @param z The z offset
114 *
115 * @return x, y, z expressed as a TTL_offset_dim_t
116 */
117static inline __attribute__((overloadable)) TTL_offset_t TTL_create_offset(TTL_offset_dim_t x, TTL_offset_dim_t y,
119 const TTL_offset_t result = { x, y, z };
120
121 return result;
122}
123
124/**
125 * @brief Returns a TTL_offset_t
126 *
127 * @param x The x offset
128 * @param y The y offset
129 *
130 * @return x, y, z = 0 expressed as a TTL_offset_dim_t
131 */
132static inline __attribute__((overloadable)) TTL_offset_t TTL_create_offset(TTL_offset_dim_t x, TTL_offset_dim_t y) {
133 return TTL_create_offset(x, y, 0);
134}
135
136/**
137 * @brief Returns a TTL_offset_t
138 *
139 * @param x The x offset
140 *
141 * @return x, y = 0, z = 0 expressed as a TTL_offset_dim_t
142 */
143static inline __attribute__((overloadable)) TTL_offset_t TTL_create_offset(TTL_offset_dim_t x) {
144 return TTL_create_offset(x, 0, 0);
145}
146
147/**
148 * @brief Returns a TTL_offset_t
149 *
150 *
151 * @return x = 0, y = 0, z = 0 expressed as a TTL_offset_dim_t
152 */
153static inline __attribute__((overloadable)) TTL_offset_t TTL_create_offset(__TTL_NO_PARAMETERS) {
154 return TTL_create_offset(0, 0, 0);
155}
156
157/******************************************************
158 * OVERLAP
159 *****************************************************/
160
161typedef unsigned char TTL_overlap_dim_t; ///< Overlap of a "adjacent" tiles in
162 ///< the unit of elements
163/**
164 * @brief Description of the overlap in 3D space of adjacent tiles.
165 *
166 * TTL_overlap_t represents the number of overlapped elements between
167 * adjacent tiles in each dimension.
168 *
169 * For example, overlap.x=1 means that every horizontally-adjacent
170 * tiles share elements on one column.
171 *
172 * The type used to hold the overlap between adjacent tiles along all dimensions
173 */
174typedef struct {
175 TTL_overlap_dim_t width; ///< width overlap in elements
176 TTL_overlap_dim_t height; ///< height overlap in elements
177 TTL_overlap_dim_t depth; ///< depth overlap in elements
179
180/**
181 * @brief Create a 3D Description of a Tile overlap
182 *
183 * @see TTL_overlap_t for more information.
184 *
185 * @param width ///< Overlap width in elements
186 * @param height ///< Overlap height in elements
187 * @param depth ///< Overlap depth in elements
188 *
189 * @return A TTL_overlap_t describing in 3D the overlap requested.
190 */
191static inline TTL_overlap_t __attribute__((overloadable))
193 const TTL_overlap_t res = { width, height, depth };
194 return res;
195}
196
197/**
198 * @brief Create a 2D Description of a Tile overlap
199 *
200 * @see TTL_overlap_t for more information.
201 *
202 * @param width ///< Overlap width in elements
203 * @param height ///< Overlap height in elements
204 *
205 * depth defaults to 0
206 *
207 * @return A TTL_overlap_t describing in 3D the overlap requested.
208 */
209static inline TTL_overlap_t __attribute__((overloadable))
211 return TTL_create_overlap(width, height, 0);
212}
213
214/**
215 * @brief Create a 1D Description of a Tile overlap
216 *
217 * @see TTL_overlap_t for more information.
218 *
219 * @param width ///< Overlap width in elements
220 *
221 * height and depth default to 0
222 *
223 * @return A TTL_overlap_t describing in 3D the overlap requested.
224 */
225static inline TTL_overlap_t __attribute__((overloadable)) TTL_create_overlap(const TTL_overlap_dim_t width) {
226 return TTL_create_overlap(width, 0, 0);
227}
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.
TTL_offset_dim_t z
Offset in dimension z.
TTL_offset_dim_t y
Offset in dimension y.
TTL_offset_dim_t x
Offset in dimension x.
Description of the overlap in 3D space of adjacent tiles.
TTL_overlap_dim_t depth
depth overlap in elements
TTL_overlap_dim_t height
height overlap in elements
TTL_overlap_dim_t width
width overlap in elements
Description of a Shape.
TTL_dim_t depth
Number of planes along dimension z.
TTL_dim_t width
Number of elements along dimension x.
TTL_dim_t height
Number of rows along dimension y.
static bool TTL_shape_empty(TTL_shape_t shape)
A Shape is empty if its width is 0.
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.
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.
static TTL_offset_t TTL_create_offset(void)
Returns a TTL_offset_t.
unsigned char TTL_overlap_dim_t