XeTLA v0.3.6
IntelĀ® Xe Templates for Linear Algebra - API Definition Document
 
Loading...
Searching...
No Matches
debug.hpp
Go to the documentation of this file.
1/*******************************************************************************
2* Copyright (c) 2022-2023 Intel Corporation
3*
4* Licensed under the Apache License, Version 2.0 (the "License");
5* you may not use this file except in compliance with the License.
6* You may obtain a copy of the License at
7*
8* http://www.apache.org/licenses/LICENSE-2.0
9*
10* Unless required by applicable law or agreed to in writing, software
11* distributed under the License is distributed on an "AS IS" BASIS,
12* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13* See the License for the specific language governing permissions and
14* limitations under the License.
15*******************************************************************************/
16
17#pragma once
18
20#include <CL/sycl.hpp>
21#include <ext/intel/esimd.hpp>
22
23namespace gpu::xetla {
24
25// debug context
26// =========================================================
27#if defined DEBUG && defined LOG_PRINT
28namespace debug_ctx {
29
30static constexpr size_t reg_start = 128 * 64; // start from GRF128 and down
31
32namespace nd_item {
33using element_type = uint16_t;
34static constexpr size_t element_num = 8;
35static constexpr size_t max_dims = 3;
36static constexpr size_t dims_pos = 0;
37static constexpr size_t dims_global_start = 1;
38static constexpr size_t dims_local_start = 1 + max_dims;
39
40static constexpr size_t nd_item_offset
41 = reg_start - element_num * sizeof(element_type);
42static inline ESIMD_PRIVATE ESIMD_REGISTER(nd_item_offset)
43 __ESIMD_NS::simd<element_type, element_num> saved_nd_item;
44
45template <size_t dims>
46static inline void set(sycl::nd_item<dims> item) {
47 static_assert(dims <= max_dims);
48
49 saved_nd_item[dims_pos] = dims;
50
51#pragma unroll
52 for (auto i = 0; i < dims; i++) {
53 saved_nd_item[dims_global_start + i] = item.get_group(i);
54 }
55
56#pragma unroll
57 for (auto i = 0; i < dims; i++) {
58 saved_nd_item[dims_local_start + i] = item.get_local_id(i);
59 }
60}
61
62static inline uint16_t get_dims() {
63 return saved_nd_item[dims_pos];
64}
65
66static inline int16_t get_group_id(size_t dim) {
67 return saved_nd_item[dims_global_start + dim];
68}
69
70static inline int16_t get_local_id(size_t dim) {
71 return saved_nd_item[dims_local_start + dim];
72}
73}; // namespace nd_item
74}; // namespace debug_ctx
75#endif
76
77// EOT message
78// =========================================================
79#if 0 // has bug in current driver, will open this in next driver
80static constexpr size_t exit_offset = reg_start - 8 * sizeof(int);
81ESIMD_PRIVATE ESIMD_REGISTER(exit_offset) __ESIMD_NS::simd<int, 8> reg_exit;
82ESIMD_INLINE void xetla_thread_exit() {
83 constexpr uint32_t exDesc = 0x0;
84 constexpr uint32_t desc = 0x02000010;
85 constexpr uint8_t execSize = 0x83;
86 constexpr uint8_t sfid = 0x3;
87 constexpr uint8_t numSrc0 = 0x1;
88 constexpr uint8_t numSrc1 = 0x0;
89 constexpr uint8_t isEOT = 0x1;
90 return sycl::ext::intel::experimental::esimd::raw_send(
91 reg_exit, exDesc, desc, execSize, sfid, numSrc0, isEOT);
92}
93#endif
94
95// 1. define XETLA_PRINTF
96// =========================================================
97#ifdef LOG_PRINT
98// log on
99#define STR_APPEND(a, b, c) a b c
100#ifdef __SYCL_DEVICE_ONLY__
101// kernel printf
102#ifdef DEBUG
103#define XETLA_PRINTF(s, ...) \
104 do { \
105 const __attribute__((opencl_constant)) char f[] = STR_APPEND( \
106 "[XeTLA] [KERNEL] [group(%d, %d, %d), local(%d, " \
107 "%d, %d)] : ", \
108 s, "\n"); \
109 sycl::ext::oneapi::experimental::printf(f, \
110 debug_ctx::nd_item::get_group_id(0), \
111 debug_ctx::nd_item::get_group_id(1), \
112 debug_ctx::nd_item::get_group_id(2), \
113 debug_ctx::nd_item::get_local_id(0), \
114 debug_ctx::nd_item::get_local_id(1), \
115 debug_ctx::nd_item::get_local_id(2), ##__VA_ARGS__); \
116 } while (0)
117#else
118#define XETLA_PRINTF(s, ...) \
119 do { \
120 const __attribute__((opencl_constant)) char f[] \
121 = STR_APPEND("[XeTLA] [KERNEL] : ", s, "\n"); \
122 sycl::ext::oneapi::experimental::printf(f, ##__VA_ARGS__); \
123 } while (0)
124#endif
125#else
126// host printf
127#define XETLA_PRINTF(s, ...) \
128 do { \
129 const char *f = STR_APPEND("[XeTLA] [HOST] : ", s, "\n"); \
130 printf(f, ##__VA_ARGS__); \
131 } while (0)
132#endif
133
134#else
135// log off
136#define XETLA_PRINTF(s, ...) \
137 do { \
138 } while (0)
139#endif
140
141// 2. define XETLA_ASSERT
142// =========================================================
143#ifdef __SYCL_DEVICE_ONLY__
144// kernel assert
145#define XETLA_ASSERT(c, s, ...) \
146 do { \
147 } while (0)
148#else
149// host asset
150#ifdef DEBUG
151// host assert in debug version
152#define XETLA_ASSERT(c, s, ...) \
153 do { \
154 if (!(c)) { XETLA_PRINTF(s, ##__VA_ARGS__); } \
155 } while (0)
156#else
157// host assert in release version
158#define XETLA_ASSERT(c, s, ...) \
159 do { \
160 } while (0)
161#endif
162#endif
163
164// 3. define DEBUG_INVOKE
165// =========================================================
166#ifdef DEBUG
167enum class dbg_level : uint8_t {
168 kernel = 0,
169 workgroup = 1,
170 subgroup = 2,
171 core = 3
172};
173#define DEBUG_INVOKE(level, ...) \
174 do { \
175 if constexpr (DEBUG >= static_cast<uint8_t>(level)) { \
176 if (!(__VA_ARGS__)) { XETLA_PRINTF("L%d: " #__VA_ARGS__, level); } \
177 } \
178 } while (0)
179#else
180#define DEBUG_INVOKE(level, ...) \
181 do { \
182 } while (0)
183#endif
184
185} // namespace gpu::xetla
set(TARGET gemm_universal) add_executable($
Definition CMakeLists.txt:1
C++ API.
Definition arch_config.hpp:24