DPC++ Runtime
Runtime libraries for oneAPI DPC++
plugin_printers.hpp
Go to the documentation of this file.
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 
14 #include <sycl/detail/pi.hpp>
15 
16 #include <type_traits>
17 
18 namespace sycl {
19 inline namespace _V1 {
20 namespace detail {
21 namespace pi {
22 
23 template <typename T>
24 inline typename std::enable_if<!std::is_pointer<T>::value, void>::type
25 print(T val) {
26  std::cout << "<unknown> : " << val << std::endl;
27 }
28 
29 template <typename T>
30 inline typename std::enable_if<std::is_pointer<T>::value, void>::type
31 print(T val) {
32  std::cout << "<unknown> : " << reinterpret_cast<const void *>(val)
33  << std::endl;
34 }
35 
36 template <> inline void print<>(PiPlatform val) {
37  std::cout << "pi_platform : " << val << std::endl;
38 }
39 
40 template <> inline void print<>(PiEvent val) {
41  std::cout << "pi_event : " << val << std::endl;
42 }
43 
44 template <> inline void print<>(PiMem val) {
45  std::cout << "pi_mem : " << val << std::endl;
46 }
47 
48 template <> inline void print<>(PiEvent *val) {
49  std::cout << "pi_event * : " << val;
50  if (val)
51  std::cout << "[ " << *val << " ... ]";
52  else
53  std::cout << "[ nullptr ]";
54  std::cout << std::endl;
55 }
56 
57 template <> inline void print<>(const PiEvent *val) {
58  std::cout << "const pi_event * : " << val;
59  if (val)
60  std::cout << "[ " << *val << " ... ]";
61  else
62  std::cout << "[ nullptr ]";
63  std::cout << std::endl;
64 }
65 
66 template <> inline void print<>(pi_buffer_region rgn) {
67  std::cout << "pi_buffer_region origin/size : " << rgn->origin << "/"
68  << rgn->size << std::endl;
69 }
70 
71 template <> inline void print<>(pi_buff_rect_region rgn) {
72  std::cout << "pi_buff_rect_region width_bytes/height/depth : "
73  << rgn->width_bytes << "/" << rgn->height_scalar << "/"
74  << rgn->depth_scalar << std::endl;
75 }
76 
77 template <> inline void print<>(pi_buff_rect_offset off) {
78  std::cout << "pi_buff_rect_offset x_bytes/y/z : " << off->x_bytes << "/"
79  << off->y_scalar << "/" << off->z_scalar << std::endl;
80 }
81 
82 template <> inline void print<>(pi_image_region rgn) {
83  std::cout << "pi_image_region width/height/depth : " << rgn->width << "/"
84  << rgn->height << "/" << rgn->depth << std::endl;
85 }
86 
87 template <> inline void print<>(pi_image_offset off) {
88  std::cout << "pi_image_offset x/y/z : " << off->x << "/" << off->y << "/"
89  << off->z << std::endl;
90 }
91 
92 template <> inline void print<>(const pi_image_desc *desc) {
93  std::cout << "image_desc w/h/d : " << desc->image_width << " / "
94  << desc->image_height << " / " << desc->image_depth
95  << " -- arrSz/row/slice : " << desc->image_array_size << " / "
96  << desc->image_row_pitch << " / " << desc->image_slice_pitch
97  << " -- num_mip_lvls/num_smpls/image_type : "
98  << desc->num_mip_levels << " / " << desc->num_samples << " / "
99  << desc->image_type << std::endl;
100 }
101 
102 template <> inline void print<>(PiResult val) {
103  std::cout << "pi_result : ";
104  if (val == PI_SUCCESS)
105  std::cout << "PI_SUCCESS" << std::endl;
106  else
107  std::cout << val << std::endl;
108 }
109 
110 // cout does not resolve a nullptr.
111 template <> inline void print<>(std::nullptr_t) {
112  std::cout << "<nullptr>" << std::endl;
113 }
114 
115 template <> inline void print<>(char *val) {
116  std::cout << "<char * > : " << static_cast<void *>(val) << std::endl;
117 }
118 
119 template <> inline void print<>(const char *val) {
120  std::cout << "<const char *>: " << val << std::endl;
121 }
122 
123 inline void printArgs(void) {}
124 template <typename Arg0, typename... Args>
125 void printArgs(Arg0 arg0, Args... args) {
126  std::cout << "\t";
127  print(arg0);
128  pi::printArgs(std::forward<Args>(args)...);
129 }
130 
131 template <typename T> struct printOut {
132  printOut(T) {}
133 }; // Do nothing
134 
135 template <> struct printOut<PiEvent *> {
137  std::cout << "\t[out]pi_event * : " << val;
138  if (val)
139  std::cout << "[ " << *val << " ... ]";
140  else
141  std::cout << "[ nullptr ]";
142  std::cout << std::endl;
143  }
144 };
145 
146 template <> struct printOut<PiMem *> {
147  printOut(PiMem *val) {
148  std::cout << "\t[out]pi_mem * : " << val;
149  if (val)
150  std::cout << "[ " << *val << " ... ]";
151  else
152  std::cout << "[ nullptr ]";
153  std::cout << std::endl;
154  }
155 };
156 
157 template <> struct printOut<void *> {
158  printOut(void *val) { std::cout << "\t[out]void * : " << val << std::endl; }
159 };
160 
161 template <typename T> struct printOut<T **> {
162  printOut(T **val) {
163  std::cout << "\t[out]<unknown> ** : " << val;
164  if (val)
165  std::cout << "[ " << *val << " ... ]";
166  else
167  std::cout << "[ nullptr ]";
168  std::cout << std::endl;
169  }
170 };
171 
172 inline void printOuts(void) {}
173 template <typename Arg0, typename... Args>
174 void printOuts(Arg0 arg0, Args... args) {
175  using T = decltype(arg0);
176  printOut<T> a(arg0);
177  printOuts(std::forward<Args>(args)...);
178 }
179 
180 } // namespace pi
181 } // namespace detail
182 } // namespace _V1
183 } // namespace sycl
__SYCL_EXTERN_STREAM_ATTRS ostream cout
Linked to standard output.
std::enable_if<!std::is_pointer< T >::value, void >::type print(T val)
Definition: access.hpp:18
_pi_result
Definition: pi.h:250
C++ wrapper of extern "C" PI interfaces.
size_t image_slice_pitch
Definition: pi.h:1270
pi_uint32 num_mip_levels
Definition: pi.h:1271
size_t image_height
Definition: pi.h:1266
size_t image_row_pitch
Definition: pi.h:1269
pi_uint32 num_samples
Definition: pi.h:1272
size_t image_depth
Definition: pi.h:1267
size_t image_width
Definition: pi.h:1265
pi_mem_type image_type
Definition: pi.h:1264
size_t image_array_size
Definition: pi.h:1268