Tensor Tiling Library
 
Loading...
Searching...
No Matches
TTL_tensor_rw.h
Go to the documentation of this file.
1/*
2 * TTL_tensors_common.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 Read a value from a tensor
21 *
22 * @param tensor A TTL_int_[type]_tensor_t describing the internal tensor.
23 * @param x The offset in the x dimension
24 * @param y The offset in the y dimension
25 * @param z The offset in the z dimension
26 *
27 * No bounds checking is performed.
28 *
29 * @return The value read
30 */
31static inline char __attribute__((overloadable)) TTL_read_tensor(const TTL_int_char_tensor_t tensor,
32 const unsigned int x, const unsigned int y,
33 const unsigned int z) {
34 return tensor.base[x + (tensor.layout.row_spacing * y) + (tensor.layout.plane_spacing * z)];
35}
36
37static inline char __attribute__((overloadable)) TTL_read_tensor(const TTL_int_char_tensor_t tensor,
38 const unsigned int x, const unsigned int y) {
39 return TTL_read_tensor(tensor, x, y, 0);
40}
41
42static inline char __attribute__((overloadable)) TTL_read_tensor(const TTL_int_char_tensor_t tensor,
43 const unsigned int x) {
44 return TTL_read_tensor(tensor, x, 0, 0);
45}
46
47/**
48 * @brief Read a value from a tensor
49 *
50 * @param sub_tensor A TTL_int_[type]_sub_tensor_t describing the internal tensor.
51 * @param x The offset in the x dimension
52 * @param y The offset in the y dimension
53 * @param z The offset in the z dimension
54 *
55 * No bounds checking is performed.
56 *
57 * @return The value read
58 */
59static inline char __attribute__((overloadable)) TTL_read_tensor(const TTL_int_char_sub_tensor_t sub_tensor,
60 const unsigned int x, const unsigned int y,
61 const unsigned int z) {
62 return TTL_read_tensor(sub_tensor.tensor, x, y, z);
63}
64
65static inline char __attribute__((overloadable)) TTL_read_tensor(const TTL_int_char_sub_tensor_t sub_tensor,
66 const unsigned int x, const unsigned int y) {
67 return TTL_read_tensor(sub_tensor.tensor, x, y, 0);
68}
69
70static inline char __attribute__((overloadable)) TTL_read_tensor(const TTL_int_char_sub_tensor_t sub_tensor,
71 const unsigned int x) {
72 return TTL_read_tensor(sub_tensor.tensor, x, 0, 0);
73}
74
75/**
76 * @brief Write a value from a tensor
77 *
78 * @param tensor A TTL_int_[type]_tensor_t describing the internal tensor.
79 * @param value The value to right
80 * @param x The offset in the x dimension
81 * @param y The offset in the y dimension
82 * @param z The offset in the z dimension
83 */
84static inline void __attribute__((overloadable)) TTL_write_tensor(const TTL_int_char_tensor_t tensor, const char value,
85 const unsigned int x, const unsigned int y,
86 const unsigned int z) {
87 tensor.base[x + (tensor.layout.row_spacing * y) + (tensor.layout.plane_spacing * z)] = value;
88}
89
90static inline void __attribute__((overloadable)) TTL_write_tensor(const TTL_int_char_tensor_t tensor, const char value,
91 unsigned int x, const unsigned int y) {
92 TTL_write_tensor(tensor, value, x, y, 0);
93}
94
95static inline void __attribute__((overloadable)) TTL_write_tensor(const TTL_int_char_tensor_t tensor, const char value,
96 const unsigned int x) {
97 TTL_write_tensor(tensor, value, x, 0, 0);
98}
99
100/**
101 * @brief Write a value from a tensor
102 *
103 * @param sub_tensor A TTL_int_[type]_tensor_t describing the internal tensor.
104 * @param value The value to right
105 * @param x The offset in the x dimension
106 * @param y The offset in the y dimension
107 * @param z The offset in the z dimension
108 */
109static inline void __attribute__((overloadable)) TTL_write_tensor(const TTL_int_char_sub_tensor_t sub_tensor,
110 const char value, const unsigned int x,
111 const unsigned int y, const unsigned int z) {
112 TTL_write_tensor(sub_tensor.tensor, value, x, y, z);
113}
114
115static inline void __attribute__((overloadable)) TTL_write_tensor(const TTL_int_char_sub_tensor_t sub_tensor,
116 const char value, unsigned int x,
117 const unsigned int y) {
118 TTL_write_tensor(sub_tensor.tensor, value, x, y, 0);
119}
120
121static inline void __attribute__((overloadable)) TTL_write_tensor(const TTL_int_char_sub_tensor_t sub_tensor,
122 const char value, const unsigned int x) {
123 TTL_write_tensor(sub_tensor.tensor, value, x, 0, 0);
124}
125/*
126 * TTL_tensors_common.h
127 *
128 * Copyright (c) 2023 Mobileye
129 *
130 * Licensed under the Apache License, Version 2.0 (the License);
131 * you may not use this file except in compliance with the License.
132 * You may obtain a copy of the License at
133 *
134 * http://www.apache.org/licenses/LICENSE-2.0
135 *
136 * Unless required by applicable law or agreed to in writing, software
137 * distributed under the License is distributed on an AS IS BASIS,
138 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
139 * See the License for the specific language governing permissions and
140 * limitations under the License.
141 */
142
143/**
144 * @brief Read a value from a tensor
145 *
146 * @param tensor A TTL_int_[type]_tensor_t describing the internal tensor.
147 * @param x The offset in the x dimension
148 * @param y The offset in the y dimension
149 * @param z The offset in the z dimension
150 *
151 * No bounds checking is performed.
152 *
153 * @return The value read
154 */
155static inline uchar __attribute__((overloadable)) TTL_read_tensor(const TTL_int_uchar_tensor_t tensor,
156 const unsigned int x, const unsigned int y,
157 const unsigned int z) {
158 return tensor.base[x + (tensor.layout.row_spacing * y) + (tensor.layout.plane_spacing * z)];
159}
160
161static inline uchar __attribute__((overloadable)) TTL_read_tensor(const TTL_int_uchar_tensor_t tensor,
162 const unsigned int x, const unsigned int y) {
163 return TTL_read_tensor(tensor, x, y, 0);
164}
165
166static inline uchar __attribute__((overloadable)) TTL_read_tensor(const TTL_int_uchar_tensor_t tensor,
167 const unsigned int x) {
168 return TTL_read_tensor(tensor, x, 0, 0);
169}
170
171/**
172 * @brief Read a value from a tensor
173 *
174 * @param sub_tensor A TTL_int_[type]_sub_tensor_t describing the internal tensor.
175 * @param x The offset in the x dimension
176 * @param y The offset in the y dimension
177 * @param z The offset in the z dimension
178 *
179 * No bounds checking is performed.
180 *
181 * @return The value read
182 */
183static inline uchar __attribute__((overloadable)) TTL_read_tensor(const TTL_int_uchar_sub_tensor_t sub_tensor,
184 const unsigned int x, const unsigned int y,
185 const unsigned int z) {
186 return TTL_read_tensor(sub_tensor.tensor, x, y, z);
187}
188
189static inline uchar __attribute__((overloadable)) TTL_read_tensor(const TTL_int_uchar_sub_tensor_t sub_tensor,
190 const unsigned int x, const unsigned int y) {
191 return TTL_read_tensor(sub_tensor.tensor, x, y, 0);
192}
193
194static inline uchar __attribute__((overloadable)) TTL_read_tensor(const TTL_int_uchar_sub_tensor_t sub_tensor,
195 const unsigned int x) {
196 return TTL_read_tensor(sub_tensor.tensor, x, 0, 0);
197}
198
199/**
200 * @brief Write a value from a tensor
201 *
202 * @param tensor A TTL_int_[type]_tensor_t describing the internal tensor.
203 * @param value The value to right
204 * @param x The offset in the x dimension
205 * @param y The offset in the y dimension
206 * @param z The offset in the z dimension
207 */
208static inline void __attribute__((overloadable)) TTL_write_tensor(const TTL_int_uchar_tensor_t tensor,
209 const uchar value, const unsigned int x,
210 const unsigned int y, const unsigned int z) {
211 tensor.base[x + (tensor.layout.row_spacing * y) + (tensor.layout.plane_spacing * z)] = value;
212}
213
214static inline void __attribute__((overloadable)) TTL_write_tensor(const TTL_int_uchar_tensor_t tensor,
215 const uchar value, unsigned int x,
216 const unsigned int y) {
217 TTL_write_tensor(tensor, value, x, y, 0);
218}
219
220static inline void __attribute__((overloadable)) TTL_write_tensor(const TTL_int_uchar_tensor_t tensor,
221 const uchar value, const unsigned int x) {
222 TTL_write_tensor(tensor, value, x, 0, 0);
223}
224
225/**
226 * @brief Write a value from a tensor
227 *
228 * @param sub_tensor A TTL_int_[type]_tensor_t describing the internal tensor.
229 * @param value The value to right
230 * @param x The offset in the x dimension
231 * @param y The offset in the y dimension
232 * @param z The offset in the z dimension
233 */
234static inline void __attribute__((overloadable)) TTL_write_tensor(const TTL_int_uchar_sub_tensor_t sub_tensor,
235 const uchar value, const unsigned int x,
236 const unsigned int y, const unsigned int z) {
237 TTL_write_tensor(sub_tensor.tensor, value, x, y, z);
238}
239
240static inline void __attribute__((overloadable)) TTL_write_tensor(const TTL_int_uchar_sub_tensor_t sub_tensor,
241 const uchar value, unsigned int x,
242 const unsigned int y) {
243 TTL_write_tensor(sub_tensor.tensor, value, x, y, 0);
244}
245
246static inline void __attribute__((overloadable)) TTL_write_tensor(const TTL_int_uchar_sub_tensor_t sub_tensor,
247 const uchar value, const unsigned int x) {
248 TTL_write_tensor(sub_tensor.tensor, value, x, 0, 0);
249}
250/*
251 * TTL_tensors_common.h
252 *
253 * Copyright (c) 2023 Mobileye
254 *
255 * Licensed under the Apache License, Version 2.0 (the License);
256 * you may not use this file except in compliance with the License.
257 * You may obtain a copy of the License at
258 *
259 * http://www.apache.org/licenses/LICENSE-2.0
260 *
261 * Unless required by applicable law or agreed to in writing, software
262 * distributed under the License is distributed on an AS IS BASIS,
263 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
264 * See the License for the specific language governing permissions and
265 * limitations under the License.
266 */
267
268/**
269 * @brief Read a value from a tensor
270 *
271 * @param tensor A TTL_int_[type]_tensor_t describing the internal tensor.
272 * @param x The offset in the x dimension
273 * @param y The offset in the y dimension
274 * @param z The offset in the z dimension
275 *
276 * No bounds checking is performed.
277 *
278 * @return The value read
279 */
280static inline int __attribute__((overloadable)) TTL_read_tensor(const TTL_int_int_tensor_t tensor, const unsigned int x,
281 const unsigned int y, const unsigned int z) {
282 return tensor.base[x + (tensor.layout.row_spacing * y) + (tensor.layout.plane_spacing * z)];
283}
284
285static inline int __attribute__((overloadable)) TTL_read_tensor(const TTL_int_int_tensor_t tensor, const unsigned int x,
286 const unsigned int y) {
287 return TTL_read_tensor(tensor, x, y, 0);
288}
289
290static inline int __attribute__((overloadable)) TTL_read_tensor(const TTL_int_int_tensor_t tensor,
291 const unsigned int x) {
292 return TTL_read_tensor(tensor, x, 0, 0);
293}
294
295/**
296 * @brief Read a value from a tensor
297 *
298 * @param sub_tensor A TTL_int_[type]_sub_tensor_t describing the internal tensor.
299 * @param x The offset in the x dimension
300 * @param y The offset in the y dimension
301 * @param z The offset in the z dimension
302 *
303 * No bounds checking is performed.
304 *
305 * @return The value read
306 */
307static inline int __attribute__((overloadable)) TTL_read_tensor(const TTL_int_int_sub_tensor_t sub_tensor,
308 const unsigned int x, const unsigned int y,
309 const unsigned int z) {
310 return TTL_read_tensor(sub_tensor.tensor, x, y, z);
311}
312
313static inline int __attribute__((overloadable)) TTL_read_tensor(const TTL_int_int_sub_tensor_t sub_tensor,
314 const unsigned int x, const unsigned int y) {
315 return TTL_read_tensor(sub_tensor.tensor, x, y, 0);
316}
317
318static inline int __attribute__((overloadable)) TTL_read_tensor(const TTL_int_int_sub_tensor_t sub_tensor,
319 const unsigned int x) {
320 return TTL_read_tensor(sub_tensor.tensor, x, 0, 0);
321}
322
323/**
324 * @brief Write a value from a tensor
325 *
326 * @param tensor A TTL_int_[type]_tensor_t describing the internal tensor.
327 * @param value The value to right
328 * @param x The offset in the x dimension
329 * @param y The offset in the y dimension
330 * @param z The offset in the z dimension
331 */
332static inline void __attribute__((overloadable)) TTL_write_tensor(const TTL_int_int_tensor_t tensor, const int value,
333 const unsigned int x, const unsigned int y,
334 const unsigned int z) {
335 tensor.base[x + (tensor.layout.row_spacing * y) + (tensor.layout.plane_spacing * z)] = value;
336}
337
338static inline void __attribute__((overloadable)) TTL_write_tensor(const TTL_int_int_tensor_t tensor, const int value,
339 unsigned int x, const unsigned int y) {
340 TTL_write_tensor(tensor, value, x, y, 0);
341}
342
343static inline void __attribute__((overloadable)) TTL_write_tensor(const TTL_int_int_tensor_t tensor, const int value,
344 const unsigned int x) {
345 TTL_write_tensor(tensor, value, x, 0, 0);
346}
347
348/**
349 * @brief Write a value from a tensor
350 *
351 * @param sub_tensor A TTL_int_[type]_tensor_t describing the internal tensor.
352 * @param value The value to right
353 * @param x The offset in the x dimension
354 * @param y The offset in the y dimension
355 * @param z The offset in the z dimension
356 */
357static inline void __attribute__((overloadable)) TTL_write_tensor(const TTL_int_int_sub_tensor_t sub_tensor,
358 const int value, const unsigned int x,
359 const unsigned int y, const unsigned int z) {
360 TTL_write_tensor(sub_tensor.tensor, value, x, y, z);
361}
362
363static inline void __attribute__((overloadable)) TTL_write_tensor(const TTL_int_int_sub_tensor_t sub_tensor,
364 const int value, unsigned int x,
365 const unsigned int y) {
366 TTL_write_tensor(sub_tensor.tensor, value, x, y, 0);
367}
368
369static inline void __attribute__((overloadable)) TTL_write_tensor(const TTL_int_int_sub_tensor_t sub_tensor,
370 const int value, const unsigned int x) {
371 TTL_write_tensor(sub_tensor.tensor, value, x, 0, 0);
372}
373/*
374 * TTL_tensors_common.h
375 *
376 * Copyright (c) 2023 Mobileye
377 *
378 * Licensed under the Apache License, Version 2.0 (the License);
379 * you may not use this file except in compliance with the License.
380 * You may obtain a copy of the License at
381 *
382 * http://www.apache.org/licenses/LICENSE-2.0
383 *
384 * Unless required by applicable law or agreed to in writing, software
385 * distributed under the License is distributed on an AS IS BASIS,
386 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
387 * See the License for the specific language governing permissions and
388 * limitations under the License.
389 */
390
391/**
392 * @brief Read a value from a tensor
393 *
394 * @param tensor A TTL_int_[type]_tensor_t describing the internal tensor.
395 * @param x The offset in the x dimension
396 * @param y The offset in the y dimension
397 * @param z The offset in the z dimension
398 *
399 * No bounds checking is performed.
400 *
401 * @return The value read
402 */
403static inline uint __attribute__((overloadable)) TTL_read_tensor(const TTL_int_uint_tensor_t tensor,
404 const unsigned int x, const unsigned int y,
405 const unsigned int z) {
406 return tensor.base[x + (tensor.layout.row_spacing * y) + (tensor.layout.plane_spacing * z)];
407}
408
409static inline uint __attribute__((overloadable)) TTL_read_tensor(const TTL_int_uint_tensor_t tensor,
410 const unsigned int x, const unsigned int y) {
411 return TTL_read_tensor(tensor, x, y, 0);
412}
413
414static inline uint __attribute__((overloadable)) TTL_read_tensor(const TTL_int_uint_tensor_t tensor,
415 const unsigned int x) {
416 return TTL_read_tensor(tensor, x, 0, 0);
417}
418
419/**
420 * @brief Read a value from a tensor
421 *
422 * @param sub_tensor A TTL_int_[type]_sub_tensor_t describing the internal tensor.
423 * @param x The offset in the x dimension
424 * @param y The offset in the y dimension
425 * @param z The offset in the z dimension
426 *
427 * No bounds checking is performed.
428 *
429 * @return The value read
430 */
431static inline uint __attribute__((overloadable)) TTL_read_tensor(const TTL_int_uint_sub_tensor_t sub_tensor,
432 const unsigned int x, const unsigned int y,
433 const unsigned int z) {
434 return TTL_read_tensor(sub_tensor.tensor, x, y, z);
435}
436
437static inline uint __attribute__((overloadable)) TTL_read_tensor(const TTL_int_uint_sub_tensor_t sub_tensor,
438 const unsigned int x, const unsigned int y) {
439 return TTL_read_tensor(sub_tensor.tensor, x, y, 0);
440}
441
442static inline uint __attribute__((overloadable)) TTL_read_tensor(const TTL_int_uint_sub_tensor_t sub_tensor,
443 const unsigned int x) {
444 return TTL_read_tensor(sub_tensor.tensor, x, 0, 0);
445}
446
447/**
448 * @brief Write a value from a tensor
449 *
450 * @param tensor A TTL_int_[type]_tensor_t describing the internal tensor.
451 * @param value The value to right
452 * @param x The offset in the x dimension
453 * @param y The offset in the y dimension
454 * @param z The offset in the z dimension
455 */
456static inline void __attribute__((overloadable)) TTL_write_tensor(const TTL_int_uint_tensor_t tensor, const uint value,
457 const unsigned int x, const unsigned int y,
458 const unsigned int z) {
459 tensor.base[x + (tensor.layout.row_spacing * y) + (tensor.layout.plane_spacing * z)] = value;
460}
461
462static inline void __attribute__((overloadable)) TTL_write_tensor(const TTL_int_uint_tensor_t tensor, const uint value,
463 unsigned int x, const unsigned int y) {
464 TTL_write_tensor(tensor, value, x, y, 0);
465}
466
467static inline void __attribute__((overloadable)) TTL_write_tensor(const TTL_int_uint_tensor_t tensor, const uint value,
468 const unsigned int x) {
469 TTL_write_tensor(tensor, value, x, 0, 0);
470}
471
472/**
473 * @brief Write a value from a tensor
474 *
475 * @param sub_tensor A TTL_int_[type]_tensor_t describing the internal tensor.
476 * @param value The value to right
477 * @param x The offset in the x dimension
478 * @param y The offset in the y dimension
479 * @param z The offset in the z dimension
480 */
481static inline void __attribute__((overloadable)) TTL_write_tensor(const TTL_int_uint_sub_tensor_t sub_tensor,
482 const uint value, const unsigned int x,
483 const unsigned int y, const unsigned int z) {
484 TTL_write_tensor(sub_tensor.tensor, value, x, y, z);
485}
486
487static inline void __attribute__((overloadable)) TTL_write_tensor(const TTL_int_uint_sub_tensor_t sub_tensor,
488 const uint value, unsigned int x,
489 const unsigned int y) {
490 TTL_write_tensor(sub_tensor.tensor, value, x, y, 0);
491}
492
493static inline void __attribute__((overloadable)) TTL_write_tensor(const TTL_int_uint_sub_tensor_t sub_tensor,
494 const uint value, const unsigned int x) {
495 TTL_write_tensor(sub_tensor.tensor, value, x, 0, 0);
496}
497/*
498 * TTL_tensors_common.h
499 *
500 * Copyright (c) 2023 Mobileye
501 *
502 * Licensed under the Apache License, Version 2.0 (the License);
503 * you may not use this file except in compliance with the License.
504 * You may obtain a copy of the License at
505 *
506 * http://www.apache.org/licenses/LICENSE-2.0
507 *
508 * Unless required by applicable law or agreed to in writing, software
509 * distributed under the License is distributed on an AS IS BASIS,
510 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
511 * See the License for the specific language governing permissions and
512 * limitations under the License.
513 */
514
515/**
516 * @brief Read a value from a tensor
517 *
518 * @param tensor A TTL_int_[type]_tensor_t describing the internal tensor.
519 * @param x The offset in the x dimension
520 * @param y The offset in the y dimension
521 * @param z The offset in the z dimension
522 *
523 * No bounds checking is performed.
524 *
525 * @return The value read
526 */
527static inline short __attribute__((overloadable)) TTL_read_tensor(const TTL_int_short_tensor_t tensor,
528 const unsigned int x, const unsigned int y,
529 const unsigned int z) {
530 return tensor.base[x + (tensor.layout.row_spacing * y) + (tensor.layout.plane_spacing * z)];
531}
532
533static inline short __attribute__((overloadable)) TTL_read_tensor(const TTL_int_short_tensor_t tensor,
534 const unsigned int x, const unsigned int y) {
535 return TTL_read_tensor(tensor, x, y, 0);
536}
537
538static inline short __attribute__((overloadable)) TTL_read_tensor(const TTL_int_short_tensor_t tensor,
539 const unsigned int x) {
540 return TTL_read_tensor(tensor, x, 0, 0);
541}
542
543/**
544 * @brief Read a value from a tensor
545 *
546 * @param sub_tensor A TTL_int_[type]_sub_tensor_t describing the internal tensor.
547 * @param x The offset in the x dimension
548 * @param y The offset in the y dimension
549 * @param z The offset in the z dimension
550 *
551 * No bounds checking is performed.
552 *
553 * @return The value read
554 */
555static inline short __attribute__((overloadable)) TTL_read_tensor(const TTL_int_short_sub_tensor_t sub_tensor,
556 const unsigned int x, const unsigned int y,
557 const unsigned int z) {
558 return TTL_read_tensor(sub_tensor.tensor, x, y, z);
559}
560
561static inline short __attribute__((overloadable)) TTL_read_tensor(const TTL_int_short_sub_tensor_t sub_tensor,
562 const unsigned int x, const unsigned int y) {
563 return TTL_read_tensor(sub_tensor.tensor, x, y, 0);
564}
565
566static inline short __attribute__((overloadable)) TTL_read_tensor(const TTL_int_short_sub_tensor_t sub_tensor,
567 const unsigned int x) {
568 return TTL_read_tensor(sub_tensor.tensor, x, 0, 0);
569}
570
571/**
572 * @brief Write a value from a tensor
573 *
574 * @param tensor A TTL_int_[type]_tensor_t describing the internal tensor.
575 * @param value The value to right
576 * @param x The offset in the x dimension
577 * @param y The offset in the y dimension
578 * @param z The offset in the z dimension
579 */
580static inline void __attribute__((overloadable)) TTL_write_tensor(const TTL_int_short_tensor_t tensor,
581 const short value, const unsigned int x,
582 const unsigned int y, const unsigned int z) {
583 tensor.base[x + (tensor.layout.row_spacing * y) + (tensor.layout.plane_spacing * z)] = value;
584}
585
586static inline void __attribute__((overloadable)) TTL_write_tensor(const TTL_int_short_tensor_t tensor,
587 const short value, unsigned int x,
588 const unsigned int y) {
589 TTL_write_tensor(tensor, value, x, y, 0);
590}
591
592static inline void __attribute__((overloadable)) TTL_write_tensor(const TTL_int_short_tensor_t tensor,
593 const short value, const unsigned int x) {
594 TTL_write_tensor(tensor, value, x, 0, 0);
595}
596
597/**
598 * @brief Write a value from a tensor
599 *
600 * @param sub_tensor A TTL_int_[type]_tensor_t describing the internal tensor.
601 * @param value The value to right
602 * @param x The offset in the x dimension
603 * @param y The offset in the y dimension
604 * @param z The offset in the z dimension
605 */
606static inline void __attribute__((overloadable)) TTL_write_tensor(const TTL_int_short_sub_tensor_t sub_tensor,
607 const short value, const unsigned int x,
608 const unsigned int y, const unsigned int z) {
609 TTL_write_tensor(sub_tensor.tensor, value, x, y, z);
610}
611
612static inline void __attribute__((overloadable)) TTL_write_tensor(const TTL_int_short_sub_tensor_t sub_tensor,
613 const short value, unsigned int x,
614 const unsigned int y) {
615 TTL_write_tensor(sub_tensor.tensor, value, x, y, 0);
616}
617
618static inline void __attribute__((overloadable)) TTL_write_tensor(const TTL_int_short_sub_tensor_t sub_tensor,
619 const short value, const unsigned int x) {
620 TTL_write_tensor(sub_tensor.tensor, value, x, 0, 0);
621}
622/*
623 * TTL_tensors_common.h
624 *
625 * Copyright (c) 2023 Mobileye
626 *
627 * Licensed under the Apache License, Version 2.0 (the License);
628 * you may not use this file except in compliance with the License.
629 * You may obtain a copy of the License at
630 *
631 * http://www.apache.org/licenses/LICENSE-2.0
632 *
633 * Unless required by applicable law or agreed to in writing, software
634 * distributed under the License is distributed on an AS IS BASIS,
635 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
636 * See the License for the specific language governing permissions and
637 * limitations under the License.
638 */
639
640/**
641 * @brief Read a value from a tensor
642 *
643 * @param tensor A TTL_int_[type]_tensor_t describing the internal tensor.
644 * @param x The offset in the x dimension
645 * @param y The offset in the y dimension
646 * @param z The offset in the z dimension
647 *
648 * No bounds checking is performed.
649 *
650 * @return The value read
651 */
652static inline ushort __attribute__((overloadable)) TTL_read_tensor(const TTL_int_ushort_tensor_t tensor,
653 const unsigned int x, const unsigned int y,
654 const unsigned int z) {
655 return tensor.base[x + (tensor.layout.row_spacing * y) + (tensor.layout.plane_spacing * z)];
656}
657
658static inline ushort __attribute__((overloadable)) TTL_read_tensor(const TTL_int_ushort_tensor_t tensor,
659 const unsigned int x, const unsigned int y) {
660 return TTL_read_tensor(tensor, x, y, 0);
661}
662
663static inline ushort __attribute__((overloadable)) TTL_read_tensor(const TTL_int_ushort_tensor_t tensor,
664 const unsigned int x) {
665 return TTL_read_tensor(tensor, x, 0, 0);
666}
667
668/**
669 * @brief Read a value from a tensor
670 *
671 * @param sub_tensor A TTL_int_[type]_sub_tensor_t describing the internal tensor.
672 * @param x The offset in the x dimension
673 * @param y The offset in the y dimension
674 * @param z The offset in the z dimension
675 *
676 * No bounds checking is performed.
677 *
678 * @return The value read
679 */
680static inline ushort __attribute__((overloadable)) TTL_read_tensor(const TTL_int_ushort_sub_tensor_t sub_tensor,
681 const unsigned int x, const unsigned int y,
682 const unsigned int z) {
683 return TTL_read_tensor(sub_tensor.tensor, x, y, z);
684}
685
686static inline ushort __attribute__((overloadable)) TTL_read_tensor(const TTL_int_ushort_sub_tensor_t sub_tensor,
687 const unsigned int x, const unsigned int y) {
688 return TTL_read_tensor(sub_tensor.tensor, x, y, 0);
689}
690
691static inline ushort __attribute__((overloadable)) TTL_read_tensor(const TTL_int_ushort_sub_tensor_t sub_tensor,
692 const unsigned int x) {
693 return TTL_read_tensor(sub_tensor.tensor, x, 0, 0);
694}
695
696/**
697 * @brief Write a value from a tensor
698 *
699 * @param tensor A TTL_int_[type]_tensor_t describing the internal tensor.
700 * @param value The value to right
701 * @param x The offset in the x dimension
702 * @param y The offset in the y dimension
703 * @param z The offset in the z dimension
704 */
705static inline void __attribute__((overloadable)) TTL_write_tensor(const TTL_int_ushort_tensor_t tensor,
706 const ushort value, const unsigned int x,
707 const unsigned int y, const unsigned int z) {
708 tensor.base[x + (tensor.layout.row_spacing * y) + (tensor.layout.plane_spacing * z)] = value;
709}
710
711static inline void __attribute__((overloadable)) TTL_write_tensor(const TTL_int_ushort_tensor_t tensor,
712 const ushort value, unsigned int x,
713 const unsigned int y) {
714 TTL_write_tensor(tensor, value, x, y, 0);
715}
716
717static inline void __attribute__((overloadable)) TTL_write_tensor(const TTL_int_ushort_tensor_t tensor,
718 const ushort value, const unsigned int x) {
719 TTL_write_tensor(tensor, value, x, 0, 0);
720}
721
722/**
723 * @brief Write a value from a tensor
724 *
725 * @param sub_tensor A TTL_int_[type]_tensor_t describing the internal tensor.
726 * @param value The value to right
727 * @param x The offset in the x dimension
728 * @param y The offset in the y dimension
729 * @param z The offset in the z dimension
730 */
731static inline void __attribute__((overloadable)) TTL_write_tensor(const TTL_int_ushort_sub_tensor_t sub_tensor,
732 const ushort value, const unsigned int x,
733 const unsigned int y, const unsigned int z) {
734 TTL_write_tensor(sub_tensor.tensor, value, x, y, z);
735}
736
737static inline void __attribute__((overloadable)) TTL_write_tensor(const TTL_int_ushort_sub_tensor_t sub_tensor,
738 const ushort value, unsigned int x,
739 const unsigned int y) {
740 TTL_write_tensor(sub_tensor.tensor, value, x, y, 0);
741}
742
743static inline void __attribute__((overloadable)) TTL_write_tensor(const TTL_int_ushort_sub_tensor_t sub_tensor,
744 const ushort value, const unsigned int x) {
745 TTL_write_tensor(sub_tensor.tensor, value, x, 0, 0);
746}
747/*
748 * TTL_tensors_common.h
749 *
750 * Copyright (c) 2023 Mobileye
751 *
752 * Licensed under the Apache License, Version 2.0 (the License);
753 * you may not use this file except in compliance with the License.
754 * You may obtain a copy of the License at
755 *
756 * http://www.apache.org/licenses/LICENSE-2.0
757 *
758 * Unless required by applicable law or agreed to in writing, software
759 * distributed under the License is distributed on an AS IS BASIS,
760 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
761 * See the License for the specific language governing permissions and
762 * limitations under the License.
763 */
764
765/**
766 * @brief Read a value from a tensor
767 *
768 * @param tensor A TTL_int_[type]_tensor_t describing the internal tensor.
769 * @param x The offset in the x dimension
770 * @param y The offset in the y dimension
771 * @param z The offset in the z dimension
772 *
773 * No bounds checking is performed.
774 *
775 * @return The value read
776 */
777static inline long __attribute__((overloadable)) TTL_read_tensor(const TTL_int_long_tensor_t tensor,
778 const unsigned int x, const unsigned int y,
779 const unsigned int z) {
780 return tensor.base[x + (tensor.layout.row_spacing * y) + (tensor.layout.plane_spacing * z)];
781}
782
783static inline long __attribute__((overloadable)) TTL_read_tensor(const TTL_int_long_tensor_t tensor,
784 const unsigned int x, const unsigned int y) {
785 return TTL_read_tensor(tensor, x, y, 0);
786}
787
788static inline long __attribute__((overloadable)) TTL_read_tensor(const TTL_int_long_tensor_t tensor,
789 const unsigned int x) {
790 return TTL_read_tensor(tensor, x, 0, 0);
791}
792
793/**
794 * @brief Read a value from a tensor
795 *
796 * @param sub_tensor A TTL_int_[type]_sub_tensor_t describing the internal tensor.
797 * @param x The offset in the x dimension
798 * @param y The offset in the y dimension
799 * @param z The offset in the z dimension
800 *
801 * No bounds checking is performed.
802 *
803 * @return The value read
804 */
805static inline long __attribute__((overloadable)) TTL_read_tensor(const TTL_int_long_sub_tensor_t sub_tensor,
806 const unsigned int x, const unsigned int y,
807 const unsigned int z) {
808 return TTL_read_tensor(sub_tensor.tensor, x, y, z);
809}
810
811static inline long __attribute__((overloadable)) TTL_read_tensor(const TTL_int_long_sub_tensor_t sub_tensor,
812 const unsigned int x, const unsigned int y) {
813 return TTL_read_tensor(sub_tensor.tensor, x, y, 0);
814}
815
816static inline long __attribute__((overloadable)) TTL_read_tensor(const TTL_int_long_sub_tensor_t sub_tensor,
817 const unsigned int x) {
818 return TTL_read_tensor(sub_tensor.tensor, x, 0, 0);
819}
820
821/**
822 * @brief Write a value from a tensor
823 *
824 * @param tensor A TTL_int_[type]_tensor_t describing the internal tensor.
825 * @param value The value to right
826 * @param x The offset in the x dimension
827 * @param y The offset in the y dimension
828 * @param z The offset in the z dimension
829 */
830static inline void __attribute__((overloadable)) TTL_write_tensor(const TTL_int_long_tensor_t tensor, const long value,
831 const unsigned int x, const unsigned int y,
832 const unsigned int z) {
833 tensor.base[x + (tensor.layout.row_spacing * y) + (tensor.layout.plane_spacing * z)] = value;
834}
835
836static inline void __attribute__((overloadable)) TTL_write_tensor(const TTL_int_long_tensor_t tensor, const long value,
837 unsigned int x, const unsigned int y) {
838 TTL_write_tensor(tensor, value, x, y, 0);
839}
840
841static inline void __attribute__((overloadable)) TTL_write_tensor(const TTL_int_long_tensor_t tensor, const long value,
842 const unsigned int x) {
843 TTL_write_tensor(tensor, value, x, 0, 0);
844}
845
846/**
847 * @brief Write a value from a tensor
848 *
849 * @param sub_tensor A TTL_int_[type]_tensor_t describing the internal tensor.
850 * @param value The value to right
851 * @param x The offset in the x dimension
852 * @param y The offset in the y dimension
853 * @param z The offset in the z dimension
854 */
855static inline void __attribute__((overloadable)) TTL_write_tensor(const TTL_int_long_sub_tensor_t sub_tensor,
856 const long value, const unsigned int x,
857 const unsigned int y, const unsigned int z) {
858 TTL_write_tensor(sub_tensor.tensor, value, x, y, z);
859}
860
861static inline void __attribute__((overloadable)) TTL_write_tensor(const TTL_int_long_sub_tensor_t sub_tensor,
862 const long value, unsigned int x,
863 const unsigned int y) {
864 TTL_write_tensor(sub_tensor.tensor, value, x, y, 0);
865}
866
867static inline void __attribute__((overloadable)) TTL_write_tensor(const TTL_int_long_sub_tensor_t sub_tensor,
868 const long value, const unsigned int x) {
869 TTL_write_tensor(sub_tensor.tensor, value, x, 0, 0);
870}
871/*
872 * TTL_tensors_common.h
873 *
874 * Copyright (c) 2023 Mobileye
875 *
876 * Licensed under the Apache License, Version 2.0 (the License);
877 * you may not use this file except in compliance with the License.
878 * You may obtain a copy of the License at
879 *
880 * http://www.apache.org/licenses/LICENSE-2.0
881 *
882 * Unless required by applicable law or agreed to in writing, software
883 * distributed under the License is distributed on an AS IS BASIS,
884 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
885 * See the License for the specific language governing permissions and
886 * limitations under the License.
887 */
888
889/**
890 * @brief Read a value from a tensor
891 *
892 * @param tensor A TTL_int_[type]_tensor_t describing the internal tensor.
893 * @param x The offset in the x dimension
894 * @param y The offset in the y dimension
895 * @param z The offset in the z dimension
896 *
897 * No bounds checking is performed.
898 *
899 * @return The value read
900 */
901static inline ulong __attribute__((overloadable)) TTL_read_tensor(const TTL_int_ulong_tensor_t tensor,
902 const unsigned int x, const unsigned int y,
903 const unsigned int z) {
904 return tensor.base[x + (tensor.layout.row_spacing * y) + (tensor.layout.plane_spacing * z)];
905}
906
907static inline ulong __attribute__((overloadable)) TTL_read_tensor(const TTL_int_ulong_tensor_t tensor,
908 const unsigned int x, const unsigned int y) {
909 return TTL_read_tensor(tensor, x, y, 0);
910}
911
912static inline ulong __attribute__((overloadable)) TTL_read_tensor(const TTL_int_ulong_tensor_t tensor,
913 const unsigned int x) {
914 return TTL_read_tensor(tensor, x, 0, 0);
915}
916
917/**
918 * @brief Read a value from a tensor
919 *
920 * @param sub_tensor A TTL_int_[type]_sub_tensor_t describing the internal tensor.
921 * @param x The offset in the x dimension
922 * @param y The offset in the y dimension
923 * @param z The offset in the z dimension
924 *
925 * No bounds checking is performed.
926 *
927 * @return The value read
928 */
929static inline ulong __attribute__((overloadable)) TTL_read_tensor(const TTL_int_ulong_sub_tensor_t sub_tensor,
930 const unsigned int x, const unsigned int y,
931 const unsigned int z) {
932 return TTL_read_tensor(sub_tensor.tensor, x, y, z);
933}
934
935static inline ulong __attribute__((overloadable)) TTL_read_tensor(const TTL_int_ulong_sub_tensor_t sub_tensor,
936 const unsigned int x, const unsigned int y) {
937 return TTL_read_tensor(sub_tensor.tensor, x, y, 0);
938}
939
940static inline ulong __attribute__((overloadable)) TTL_read_tensor(const TTL_int_ulong_sub_tensor_t sub_tensor,
941 const unsigned int x) {
942 return TTL_read_tensor(sub_tensor.tensor, x, 0, 0);
943}
944
945/**
946 * @brief Write a value from a tensor
947 *
948 * @param tensor A TTL_int_[type]_tensor_t describing the internal tensor.
949 * @param value The value to right
950 * @param x The offset in the x dimension
951 * @param y The offset in the y dimension
952 * @param z The offset in the z dimension
953 */
954static inline void __attribute__((overloadable)) TTL_write_tensor(const TTL_int_ulong_tensor_t tensor,
955 const ulong value, const unsigned int x,
956 const unsigned int y, const unsigned int z) {
957 tensor.base[x + (tensor.layout.row_spacing * y) + (tensor.layout.plane_spacing * z)] = value;
958}
959
960static inline void __attribute__((overloadable)) TTL_write_tensor(const TTL_int_ulong_tensor_t tensor,
961 const ulong value, unsigned int x,
962 const unsigned int y) {
963 TTL_write_tensor(tensor, value, x, y, 0);
964}
965
966static inline void __attribute__((overloadable)) TTL_write_tensor(const TTL_int_ulong_tensor_t tensor,
967 const ulong value, const unsigned int x) {
968 TTL_write_tensor(tensor, value, x, 0, 0);
969}
970
971/**
972 * @brief Write a value from a tensor
973 *
974 * @param sub_tensor A TTL_int_[type]_tensor_t describing the internal tensor.
975 * @param value The value to right
976 * @param x The offset in the x dimension
977 * @param y The offset in the y dimension
978 * @param z The offset in the z dimension
979 */
980static inline void __attribute__((overloadable)) TTL_write_tensor(const TTL_int_ulong_sub_tensor_t sub_tensor,
981 const ulong value, const unsigned int x,
982 const unsigned int y, const unsigned int z) {
983 TTL_write_tensor(sub_tensor.tensor, value, x, y, z);
984}
985
986static inline void __attribute__((overloadable)) TTL_write_tensor(const TTL_int_ulong_sub_tensor_t sub_tensor,
987 const ulong value, unsigned int x,
988 const unsigned int y) {
989 TTL_write_tensor(sub_tensor.tensor, value, x, y, 0);
990}
991
992static inline void __attribute__((overloadable)) TTL_write_tensor(const TTL_int_ulong_sub_tensor_t sub_tensor,
993 const ulong value, const unsigned int x) {
994 TTL_write_tensor(sub_tensor.tensor, value, x, 0, 0);
995}
static void TTL_write_tensor(const TTL_int_char_tensor_t tensor, const char value, const unsigned int x, const unsigned int y, const unsigned int z)
Write a value from a tensor.
static char TTL_read_tensor(const TTL_int_char_tensor_t tensor, const unsigned int x, const unsigned int y, const unsigned int z)
Read a value from a tensor.
unsigned char uchar
opencl and so TTL supports a type called uchar which is not part of C
Definition c/TTL_types.h:25
unsigned long ulong
OpenCL supports ulong so provide the same in c.
Definition c/TTL_types.h:32
unsigned int uint
OpenCL supports uint so provide the same in c.
Definition c/TTL_types.h:30
unsigned short ushort
OpenCL supports ushort so provide the same in c.
Definition c/TTL_types.h:31
const and non-const sub tensors in the appropriate address space
const and non-const tensors in the appropriate address space
const and non-const sub tensors in the appropriate address space
const and non-const tensors in the appropriate address space
const and non-const sub tensors in the appropriate address space
const and non-const tensors in the appropriate address space
const and non-const sub tensors in the appropriate address space
const and non-const tensors in the appropriate address space
const and non-const sub tensors in the appropriate address space
const and non-const tensors in the appropriate address space
const and non-const sub tensors in the appropriate address space
const and non-const tensors in the appropriate address space
const and non-const sub tensors in the appropriate address space
const and non-const tensors in the appropriate address space
const and non-const sub tensors in the appropriate address space
const and non-const tensors in the appropriate address space
TTL_dim_t row_spacing
The distance between the start of consequtive rows in units of elements.
TTL_dim_t plane_spacing
The distance between the start of consequtive planes in units of elements.