Skip to content

Commit 19f5ad6

Browse files
authored
[SYCL] Enhance PI tracing with printing output (pointer) arguments (#1523)
Signed-off-by: Artur Gainullin <[email protected]>
1 parent 929a764 commit 19f5ad6

File tree

3 files changed

+174
-81
lines changed

3 files changed

+174
-81
lines changed

sycl/include/CL/sycl/detail/pi.hpp

Lines changed: 0 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -169,87 +169,6 @@ uint64_t emitFunctionBeginTrace(const char *FName);
169169
/// \param FName The name of the PI API call
170170
void emitFunctionEndTrace(uint64_t CorrelationID, const char *FName);
171171

172-
// Helper utilities for PI Tracing
173-
// The run-time tracing of PI calls.
174-
// Print functions used by Trace class.
175-
template <typename T> inline void print(T val) {
176-
std::cout << "<unknown> : " << val << std::endl;
177-
}
178-
179-
template <typename Ret, typename... Args>
180-
inline void print(Ret (*val)(Args...)) {
181-
std::cout << "<FuncPtr>" << reinterpret_cast<const void *>(val) << std::endl;
182-
}
183-
184-
template <> inline void print<>(PiPlatform val) {
185-
std::cout << "pi_platform : " << val << std::endl;
186-
}
187-
188-
template <> inline void print<>(pi_buffer_region rgn) {
189-
std::cout << "pi_buffer_region origin/size : " << rgn->origin << "/"
190-
<< rgn->size << std::endl;
191-
}
192-
193-
template <> inline void print<>(pi_buff_rect_region rgn) {
194-
std::cout << "pi_buff_rect_region width_bytes/height/depth : "
195-
<< rgn->width_bytes << "/" << rgn->height_scalar << "/"
196-
<< rgn->depth_scalar << std::endl;
197-
}
198-
199-
template <> inline void print<>(pi_buff_rect_offset off) {
200-
std::cout << "pi_buff_rect_offset x_bytes/y/z : " << off->x_bytes << "/"
201-
<< off->y_scalar << "/" << off->z_scalar << std::endl;
202-
}
203-
204-
template <> inline void print<>(pi_image_region rgn) {
205-
std::cout << "pi_image_region width/height/depth : " << rgn->width << "/"
206-
<< rgn->height << "/" << rgn->depth << std::endl;
207-
}
208-
209-
template <> inline void print<>(pi_image_offset off) {
210-
std::cout << "pi_image_offset x/y/z : " << off->x << "/" << off->y << "/"
211-
<< off->z << std::endl;
212-
}
213-
214-
template <> inline void print<>(const pi_image_desc *desc) {
215-
std::cout << "image_desc w/h/d : " << desc->image_width << " / "
216-
<< desc->image_height << " / " << desc->image_depth
217-
<< " -- arrSz/row/slice : " << desc->image_array_size << " / "
218-
<< desc->image_row_pitch << " / " << desc->image_slice_pitch
219-
<< " -- num_mip_lvls/num_smpls/image_type : "
220-
<< desc->num_mip_levels << " / " << desc->num_samples << " / "
221-
<< desc->image_type << std::endl;
222-
}
223-
224-
template <> inline void print<>(PiResult val) {
225-
std::cout << "pi_result : ";
226-
if (val == PI_SUCCESS)
227-
std::cout << "PI_SUCCESS" << std::endl;
228-
else
229-
std::cout << val << std::endl;
230-
}
231-
232-
// cout does not resolve a nullptr.
233-
template <> inline void print<>(std::nullptr_t) {
234-
std::cout << "<nullptr>" << std::endl;
235-
}
236-
237-
template <> inline void print<>(char *val) {
238-
std::cout << "<char * > : " << static_cast<void *>(val) << std::endl;
239-
}
240-
241-
template <> inline void print<>(const char *val) {
242-
std::cout << "<const char *>: " << val << std::endl;
243-
}
244-
245-
inline void printArgs(void) {}
246-
template <typename Arg0, typename... Args>
247-
void printArgs(Arg0 arg0, Args... args) {
248-
std::cout << " ";
249-
print(arg0);
250-
pi::printArgs(std::forward<Args>(args)...);
251-
}
252-
253172
// A wrapper for passing around byte array properties
254173
class ByteArray {
255174
public:

sycl/source/detail/plugin.hpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include <CL/sycl/detail/common.hpp>
1212
#include <CL/sycl/detail/pi.hpp>
1313
#include <CL/sycl/stl.hpp>
14+
#include <detail/plugin_printers.hpp>
1415

1516
#ifdef XPTI_ENABLE_INSTRUMENTATION
1617
// Include the headers necessary for emitting traces using the trace framework
@@ -81,6 +82,8 @@ class plugin {
8182
if (pi::trace(pi::TraceLevel::PI_TRACE_CALLS)) {
8283
std::cout << ") ---> ";
8384
RT::printArgs(R);
85+
RT::printOuts(Args...);
86+
std::cout << std::endl;
8487
}
8588
#ifdef XPTI_ENABLE_INSTRUMENTATION
8689
// Close the function begin with a call to function end
Lines changed: 171 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,171 @@
1+
//==--------- plugin_printers.hpp - Printers for the Plugin Interface ------==//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
// Print functions used for the Plguin Interface tracing.
10+
11+
#pragma once
12+
13+
#include <CL/sycl/detail/pi.hpp>
14+
15+
__SYCL_INLINE_NAMESPACE(cl) {
16+
namespace sycl {
17+
namespace detail {
18+
namespace pi {
19+
20+
template <typename T> inline void print(T val) {
21+
std::cout << "<unknown> : " << val << std::endl;
22+
}
23+
24+
template <> inline void print<>(PiPlatform val) {
25+
std::cout << "pi_platform : " << val << std::endl;
26+
}
27+
28+
template <> inline void print<>(PiEvent val) {
29+
std::cout << "pi_event : " << val << std::endl;
30+
}
31+
32+
template <> inline void print<>(PiMem val) {
33+
std::cout << "pi_mem : " << val << std::endl;
34+
}
35+
36+
template <> inline void print<>(PiEvent *val) {
37+
std::cout << "pi_event * : " << val;
38+
if (val)
39+
std::cout << "[ " << *val << " ... ]";
40+
else
41+
std::cout << "[ nullptr ]";
42+
std::cout << std::endl;
43+
}
44+
45+
template <> inline void print<>(const PiEvent *val) {
46+
std::cout << "const pi_event * : " << val;
47+
if (val)
48+
std::cout << "[ " << *val << " ... ]";
49+
else
50+
std::cout << "[ nullptr ]";
51+
std::cout << std::endl;
52+
}
53+
54+
template <> inline void print<>(pi_buffer_region rgn) {
55+
std::cout << "pi_buffer_region origin/size : " << rgn->origin << "/"
56+
<< rgn->size << std::endl;
57+
}
58+
59+
template <> inline void print<>(pi_buff_rect_region rgn) {
60+
std::cout << "pi_buff_rect_region width_bytes/height/depth : "
61+
<< rgn->width_bytes << "/" << rgn->height_scalar << "/"
62+
<< rgn->depth_scalar << std::endl;
63+
}
64+
65+
template <> inline void print<>(pi_buff_rect_offset off) {
66+
std::cout << "pi_buff_rect_offset x_bytes/y/z : " << off->x_bytes << "/"
67+
<< off->y_scalar << "/" << off->z_scalar << std::endl;
68+
}
69+
70+
template <> inline void print<>(pi_image_region rgn) {
71+
std::cout << "pi_image_region width/height/depth : " << rgn->width << "/"
72+
<< rgn->height << "/" << rgn->depth << std::endl;
73+
}
74+
75+
template <> inline void print<>(pi_image_offset off) {
76+
std::cout << "pi_image_offset x/y/z : " << off->x << "/" << off->y << "/"
77+
<< off->z << std::endl;
78+
}
79+
80+
template <> inline void print<>(const pi_image_desc *desc) {
81+
std::cout << "image_desc w/h/d : " << desc->image_width << " / "
82+
<< desc->image_height << " / " << desc->image_depth
83+
<< " -- arrSz/row/slice : " << desc->image_array_size << " / "
84+
<< desc->image_row_pitch << " / " << desc->image_slice_pitch
85+
<< " -- num_mip_lvls/num_smpls/image_type : "
86+
<< desc->num_mip_levels << " / " << desc->num_samples << " / "
87+
<< desc->image_type << std::endl;
88+
}
89+
90+
template <> inline void print<>(PiResult val) {
91+
std::cout << "pi_result : ";
92+
if (val == PI_SUCCESS)
93+
std::cout << "PI_SUCCESS" << std::endl;
94+
else
95+
std::cout << val << std::endl;
96+
}
97+
98+
// cout does not resolve a nullptr.
99+
template <> inline void print<>(std::nullptr_t) {
100+
std::cout << "<nullptr>" << std::endl;
101+
}
102+
103+
template <> inline void print<>(char *val) {
104+
std::cout << "<char * > : " << static_cast<void *>(val) << std::endl;
105+
}
106+
107+
template <> inline void print<>(const char *val) {
108+
std::cout << "<const char *>: " << val << std::endl;
109+
}
110+
111+
inline void printArgs(void) {}
112+
template <typename Arg0, typename... Args>
113+
void printArgs(Arg0 arg0, Args... args) {
114+
std::cout << "\t";
115+
print(arg0);
116+
pi::printArgs(std::forward<Args>(args)...);
117+
}
118+
119+
template <typename T> struct printOut {
120+
printOut(T val) {}
121+
}; // Do nothing
122+
123+
template <> struct printOut<PiEvent *> {
124+
printOut(PiEvent *val) {
125+
std::cout << "\t[out]pi_event * : " << val;
126+
if (val)
127+
std::cout << "[ " << *val << " ... ]";
128+
else
129+
std::cout << "[ nullptr ]";
130+
std::cout << std::endl;
131+
}
132+
};
133+
134+
template <> struct printOut<PiMem *> {
135+
printOut(PiMem *val) {
136+
std::cout << "\t[out]pi_mem * : " << val;
137+
if (val)
138+
std::cout << "[ " << *val << " ... ]";
139+
else
140+
std::cout << "[ nullptr ]";
141+
std::cout << std::endl;
142+
}
143+
};
144+
145+
template <> struct printOut<void *> {
146+
printOut(void *val) { std::cout << "\t[out]void * : " << val << std::endl; }
147+
};
148+
149+
template <typename T> struct printOut<T **> {
150+
printOut(T **val) {
151+
std::cout << "\t[out]<unknown> ** : " << val;
152+
if (val)
153+
std::cout << "[ " << *val << " ... ]";
154+
else
155+
std::cout << "[ nullptr ]";
156+
std::cout << std::endl;
157+
}
158+
};
159+
160+
inline void printOuts(void) {}
161+
template <typename Arg0, typename... Args>
162+
void printOuts(Arg0 arg0, Args... args) {
163+
using T = decltype(arg0);
164+
printOut<T> a(arg0);
165+
printOuts(std::forward<Args>(args)...);
166+
}
167+
168+
} // namespace pi
169+
} // namespace detail
170+
} // namespace sycl
171+
} // __SYCL_INLINE_NAMESPACE(cl)

0 commit comments

Comments
 (0)