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 
13 #include <sycl/detail/pi.hpp>
14 
15 #include <type_traits>
16 
17 namespace sycl {
19 namespace detail {
20 namespace pi {
21 
22 template <typename T>
23 inline typename std::enable_if<!std::is_pointer<T>::value, void>::type
24 print(T val) {
25  std::cout << "<unknown> : " << val << std::endl;
26 }
27 
28 template <typename T>
29 inline typename std::enable_if<std::is_pointer<T>::value, void>::type
30 print(T val) {
31  std::cout << "<unknown> : " << reinterpret_cast<const void *>(val)
32  << std::endl;
33 }
34 
35 template <> inline void print<>(PiPlatform val) {
36  std::cout << "pi_platform : " << val << std::endl;
37 }
38 
39 template <> inline void print<>(PiEvent val) {
40  std::cout << "pi_event : " << val << std::endl;
41 }
42 
43 template <> inline void print<>(PiMem val) {
44  std::cout << "pi_mem : " << val << std::endl;
45 }
46 
47 template <> inline void print<>(PiEvent *val) {
48  std::cout << "pi_event * : " << val;
49  if (val)
50  std::cout << "[ " << *val << " ... ]";
51  else
52  std::cout << "[ nullptr ]";
53  std::cout << std::endl;
54 }
55 
56 template <> inline void print<>(const PiEvent *val) {
57  std::cout << "const pi_event * : " << val;
58  if (val)
59  std::cout << "[ " << *val << " ... ]";
60  else
61  std::cout << "[ nullptr ]";
62  std::cout << std::endl;
63 }
64 
65 template <> inline void print<>(pi_buffer_region rgn) {
66  std::cout << "pi_buffer_region origin/size : " << rgn->origin << "/"
67  << rgn->size << std::endl;
68 }
69 
70 template <> inline void print<>(pi_buff_rect_region rgn) {
71  std::cout << "pi_buff_rect_region width_bytes/height/depth : "
72  << rgn->width_bytes << "/" << rgn->height_scalar << "/"
73  << rgn->depth_scalar << std::endl;
74 }
75 
76 template <> inline void print<>(pi_buff_rect_offset off) {
77  std::cout << "pi_buff_rect_offset x_bytes/y/z : " << off->x_bytes << "/"
78  << off->y_scalar << "/" << off->z_scalar << std::endl;
79 }
80 
81 template <> inline void print<>(pi_image_region rgn) {
82  std::cout << "pi_image_region width/height/depth : " << rgn->width << "/"
83  << rgn->height << "/" << rgn->depth << std::endl;
84 }
85 
86 template <> inline void print<>(pi_image_offset off) {
87  std::cout << "pi_image_offset x/y/z : " << off->x << "/" << off->y << "/"
88  << off->z << std::endl;
89 }
90 
91 template <> inline void print<>(const pi_image_desc *desc) {
92  std::cout << "image_desc w/h/d : " << desc->image_width << " / "
93  << desc->image_height << " / " << desc->image_depth
94  << " -- arrSz/row/slice : " << desc->image_array_size << " / "
95  << desc->image_row_pitch << " / " << desc->image_slice_pitch
96  << " -- num_mip_lvls/num_smpls/image_type : "
97  << desc->num_mip_levels << " / " << desc->num_samples << " / "
98  << desc->image_type << std::endl;
99 }
100 
101 template <> inline void print<>(PiResult val) {
102  std::cout << "pi_result : ";
103  if (val == PI_SUCCESS)
104  std::cout << "PI_SUCCESS" << std::endl;
105  else
106  std::cout << val << std::endl;
107 }
108 
109 // cout does not resolve a nullptr.
110 template <> inline void print<>(std::nullptr_t) {
111  std::cout << "<nullptr>" << std::endl;
112 }
113 
114 template <> inline void print<>(char *val) {
115  std::cout << "<char * > : " << static_cast<void *>(val) << std::endl;
116 }
117 
118 template <> inline void print<>(const char *val) {
119  std::cout << "<const char *>: " << val << std::endl;
120 }
121 
122 inline void printArgs(void) {}
123 template <typename Arg0, typename... Args>
124 void printArgs(Arg0 arg0, Args... args) {
125  std::cout << "\t";
126  print(arg0);
127  pi::printArgs(std::forward<Args>(args)...);
128 }
129 
130 template <typename T> struct printOut {
131  printOut(T) {}
132 }; // Do nothing
133 
134 template <> struct printOut<PiEvent *> {
136  std::cout << "\t[out]pi_event * : " << 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<PiMem *> {
146  printOut(PiMem *val) {
147  std::cout << "\t[out]pi_mem * : " << val;
148  if (val)
149  std::cout << "[ " << *val << " ... ]";
150  else
151  std::cout << "[ nullptr ]";
152  std::cout << std::endl;
153  }
154 };
155 
156 template <> struct printOut<void *> {
157  printOut(void *val) { std::cout << "\t[out]void * : " << val << std::endl; }
158 };
159 
160 template <typename T> struct printOut<T **> {
161  printOut(T **val) {
162  std::cout << "\t[out]<unknown> ** : " << val;
163  if (val)
164  std::cout << "[ " << *val << " ... ]";
165  else
166  std::cout << "[ nullptr ]";
167  std::cout << std::endl;
168  }
169 };
170 
171 inline void printOuts(void) {}
172 template <typename Arg0, typename... Args>
173 void printOuts(Arg0 arg0, Args... args) {
174  using T = decltype(arg0);
175  printOut<T> a(arg0);
176  printOuts(std::forward<Args>(args)...);
177 }
178 
179 } // namespace pi
180 } // namespace detail
181 } // __SYCL_INLINE_VER_NAMESPACE(_V1)
182 } // namespace sycl
#define __SYCL_INLINE_VER_NAMESPACE(X)
__SYCL_EXTERN_STREAM_ATTRS ostream cout
Linked to standard output.
void printOuts(Arg0 arg0, Args... args)
void printArgs(Arg0 arg0, Args... args)
void print(const char *val)
---— Error handling, matching OpenCL plugin semantics.
Definition: access.hpp:14
_pi_result
Definition: pi.h:118
C++ wrapper of extern "C" PI interfaces.
PI Event mapping to CUevent.
Definition: pi_cuda.hpp:630
size_t image_slice_pitch
Definition: pi.h:934
pi_uint32 num_mip_levels
Definition: pi.h:935
size_t image_height
Definition: pi.h:930
size_t image_row_pitch
Definition: pi.h:933
pi_uint32 num_samples
Definition: pi.h:936
size_t image_depth
Definition: pi.h:931
size_t image_width
Definition: pi.h:929
pi_mem_type image_type
Definition: pi.h:928
size_t image_array_size
Definition: pi.h:932
PI Mem mapping to CUDA memory allocations, both data and texture/surface.
Definition: pi_cuda.hpp:222
A PI platform stores all known PI devices, in the CUDA plugin this is just a vector of available devi...
Definition: pi_cuda.hpp:73