|
| 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