Tensor Tiling Library
 
Loading...
Searching...
No Matches
TTL_cpp/TTL_debug.h
Go to the documentation of this file.
1/*
2 * TTL_debug.h
3 *
4 * Copyright (c) 2025 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_tensors.h"
22#include "TTL_tiles.h"
23#include "TTL_types.h"
24
25#if __TTL_DEBUG > 0
26
27/**
28 * @brief Print a debug copy of a TTL_shape type
29 *
30 * Output debug of the TTL_shape passed using printf
31 *
32 * @param ttl_shape The tile to print debug info for.
33 */
34static inline void __TTL_dump_shape_t(const TTL_shape *const ttl_shape) {
35 printf("TTL_shape: %d,%d,%d ", ttl_shape->width, ttl_shape->height, ttl_shape->depth);
36}
37
38/**
39 * @brief Print a debug copy of a TTL_layout type
40 *
41 * Output debug of the TTL_layout passed using printf
42 *
43 * @param ttl_layout The tile to print debug info for.
44 */
45static inline void __TTL_dump_layout_t(const TTL_layout *const ttl_layout) {
46 printf("TTL_layout: %d,%d ", ttl_layout->row_spacing, ttl_layout->plane_spacing);
47}
48
49/**
50 * @brief Print a debug copy of a TTL_offset type
51 *
52 * Output debug of the TTL_offset passed using printf
53 *
54 * @param ttl_offset The offset 3d to print debug info for.
55 */
56static inline void __TTL_dump_offset_t(const TTL_offset *const ttl_offset) {
57 printf("TTL_offset: %d,%d,%d ", ttl_offset->x, ttl_offset->y, ttl_offset->z);
58}
59
60/**
61 * @brief Print a debug copy of a TTL_overlap type
62 *
63 * Output debug of the TTL_overlap passed using printf
64 *
65 * @param ttl_overlap The overlap to print debug info for.
66 */
67static inline void __TTL_dump_overlap_t(const TTL_overlap *const ttl_overlap) {
68 printf("TTL_overlap: %d,%d,%d ", ttl_overlap->width, ttl_overlap->height, ttl_overlap->depth);
69}
70
71/**
72 * @brief Print a debug copy of a TTL_augmentation type
73 *
74 * Output debug of the TTL_augmentation passed using printf
75 *
76 * @param ttl_augmented The overlap to print debug info for.
77 */
78static inline void __TTL_dump_augmentation_t(const TTL_augmentation *const ttl_augmented) {
79 printf("TTL_augmentation: (%d,%d),(%d,%d),(%d,%d), ",
80 ttl_augmented->left,
81 ttl_augmented->right,
82 ttl_augmented->top,
83 ttl_augmented->bottom,
84 ttl_augmented->front,
85 ttl_augmented->back);
86}
87
88/**
89 * @brief Print a debug copy of a TTL_tile type
90 *
91 * Output debug of the TTL_tile passed using printf
92 *
93 * @param ttl_tile The tile to print debug info for.
94 */
95static inline void __TTL_dump_tile_t(const TTL_tile *const ttl_tile) {
96 printf("TTL_tile: ");
97 __TTL_dump_shape_t(&ttl_tile->shape);
98 __TTL_dump_offset_t(&ttl_tile->offset);
99}
100
101/**
102 * @brief Print a debug copy of a TTL_tensor type
103 *
104 * Output debug of the TTL_tile passed using printf
105 *
106 * @param ttl_int_tensor The internal tensor to print debug info for.
107 */
108template <typename TENSORTYPE>
109static inline void __TTL_dump_tensor(const TTL_tensor<TENSORTYPE> *const ttl_int_tensor) {
110 printf("TTL_int_tensor_t: %p,%d ", ttl_int_tensor->base, ttl_int_tensor->elem_size);
111 __TTL_dump_layout_t(&ttl_int_tensor->layout);
112 __TTL_dump_shape_t(&ttl_int_tensor->shape);
113}
114
115/**
116 * @brief Print a debug copy of a TTL_sub_tensor type
117 *
118 * Output debug of the TTL_sub_tensor passed using printf
119 *
120 * @param ttl_int_sub_tensor The internal tensor to print debug info for.
121 */
122template <typename TENSORTYPE>
123static inline void __TTL_dump_sub_tensor(const TTL_sub_tensor<TENSORTYPE> *const ttl_int_sub_tensor) {
124 printf("TTL_int_sub_tensor_t: ");
125 __TTL_dump_int_tensor_t(&ttl_int_sub_tensor->tensor);
126 __TTL_dump_shape(&ttl_int_sub_tensor->origin.shape);
127 __TTL_dump_offset_t(&ttl_int_sub_tensor->origin.sub_offset);
128}
129
130/**
131 * @brief Print a debug copy of a TTL_tiler type
132 *
133 * Output debug of the TTL_tiler passed using printf
134 *
135 * @param ttl_tiler The tiler to print debug info for.
136 */
137static inline void __TTL_dump_tiler_t(const TTL_tiler *const ttl_tiler) {
138 printf("TTL_tiler: ");
139 __TTL_dump_shape_t(&ttl_tiler->space);
140 __TTL_dump_shape_t(&ttl_tiler->tile);
141 __TTL_dump_overlap_t(&ttl_tiler->overlap);
142 printf("Cache: %d,%d,%d,%d,%d ",
143 ttl_tiler->cache.number_of_tiles,
144 ttl_tiler->cache.tiles_in_width,
145 ttl_tiler->cache.tiles_in_height,
146 ttl_tiler->cache.tiles_in_depth,
147 ttl_tiler->cache.tiles_in_plane);
148}
149
150/**
151 * @brief Internal non-API helper function to allow debugging of exports and
152 * imports
153 *
154 * @param is_export
155 * @param internal_tensor
156 * @param external_tensor
157 * @param access_type
158 * @param event
159 * @param line
160 */
161template <typename INT_TENSORTYPE, typename EXT_TENSORTYPE>
162static inline void __TTL_dump_transaction(const bool is_export, const TTL_tensor<INT_TENSORTYPE> *const internal_tensor,
163 const TTL_tensor<EXT_TENSORTYPE> *const external_tensor,
164 const int access_type, const TTL_event *const event,
165 const unsigned int line) {
166 printf(is_export ? "Export " : "Import ");
167 __TTL_dump_shape_t(&internal_tensor->shape);
168 __TTL_dump_event(event);
169 printf(" AccessType: %d\n ", access_type);
170 __TTL_dump_const_ext_tensor_t(external_tensor);
171 printf("\n ");
172 __TTL_dump_const_int_tensor_t(internal_tensor);
173 printf("\n line: %d\n", line);
174}
175
176static inline void __TTL_dump_wait(int num_events, TTL_event *events, const unsigned int line) {
177 printf("TTL_WAIT: ");
178 for (int i = 0; i < num_events; i++) {
179 __TTL_dump_event(&events[i]);
180 }
181 printf("\n line: %d\n", line);
182}
183#else // NOT __TTL_DEBUG
184
185static inline void __TTL_dump_wait(int /*num_events*/, TTL_event * /*events*/, const unsigned int /*line*/) {}
186
187template <typename INT_TENSORTYPE, typename EXT_TENSORTYPE>
188static inline void __TTL_dump_transaction(const bool /*is_export*/,
189 const TTL_tensor<INT_TENSORTYPE> & /*internal_tensor*/,
190 const TTL_tensor<EXT_TENSORTYPE> & /*external_tensor*/,
191 const int /*access_type*/, const TTL_event *const /*event*/,
192 const unsigned int /*line*/){};
193
194#endif // __TTL_DEBUG
event_t TTL_event
TTL_event is a pseudonym for OpenCL event_t.
3D description of the augmented margins
TTL_augmented_dim right
Right hand augmentation in elements.
TTL_augmented_dim bottom
Bottom augmentation in elements.
TTL_augmented_dim back
Back augmentation in elements.
TTL_augmented_dim front
Front augmentation in elements.
TTL_augmented_dim top
Top augmentation in elements.
TTL_augmented_dim left
Left hand augmentation in elements.
Description of a Tensor layout in memory.
TTL_dim plane_spacing
The distance between the start of consequtive planes in units of elements.
TTL_dim row_spacing
The distance between the start of consequtive rows in units of elements.
Description of the 3D offset of an object.
TTL_offset_dim z
Offset in dimension z.
TTL_offset_dim y
Offset in dimension y.
TTL_offset_dim x
Offset in dimension x.
Description of the overlap in 3D space of adjacent tiles.
TTL_overlap_dim depth
depth overlap in elements
TTL_overlap_dim height
height overlap in elements
TTL_overlap_dim width
width overlap in elements
Description of a Shape.
TTL_dim height
Number of rows along dimension y.
TTL_dim depth
Number of planes along dimension z.
TTL_dim width
Number of elements along dimension x.
TTL_offset sub_offset
The offset of the sub tensor from the origin sensor.
TTL_shape shape
The shape of the origin tensor in 3 dimensions.
A tensor plus its reference to its parent tensor.
TTL_tensor< TENSORTYPE > tensor
A poor mans base class for an a tensor in the passed address space.
TENSORTYPE * base
TTL_offset offset
TTL_shape shape
TTL_tiler is the basic unit that describes how a tile is subdivided.
TTL_shape space
Represents the space to be tiled such as an image.
TTL_overlap overlap
When zeroes represent no overlap.
TTL_dim tiles_in_height
TTL_dim tiles_in_width
TTL_dim tiles_in_depth
struct TTL_tiler::@153017064222336267371240241203244373062067161267 cache
Precomputed information to speed up later reuse.
TTL_dim number_of_tiles
TTL_dim tiles_in_plane