/home/docs/checkouts/readthedocs.org/user_builds/advanced-micro-devices-composable-kernel/checkouts/develop/include/ck_tile/core/utility/print.hpp Source File

/home/docs/checkouts/readthedocs.org/user_builds/advanced-micro-devices-composable-kernel/checkouts/develop/include/ck_tile/core/utility/print.hpp Source File#

Composable Kernel: /home/docs/checkouts/readthedocs.org/user_builds/advanced-micro-devices-composable-kernel/checkouts/develop/include/ck_tile/core/utility/print.hpp Source File
print.hpp
Go to the documentation of this file.
1 // Copyright (c) Advanced Micro Devices, Inc., or its affiliates.
2 // SPDX-License-Identifier: MIT
3 
4 #pragma once
5 
7 
8 namespace ck_tile {
9 
10 namespace str_literal_detail {
11 template <size_t... Idx>
12 constexpr std::tuple<std::integral_constant<size_t, Idx>...>
13 makeTuple(std::index_sequence<Idx...>) noexcept
14 {
15  return {};
16 }
17 constexpr size_t constexpr_strlen(const char* c)
18 {
19  size_t t = 0;
20  while(*c++)
21  ++t;
22  return t;
23 }
24 } // namespace str_literal_detail
25 
26 template <char... Xs>
28 {
29  static constexpr const char data[] = {Xs..., '\0'};
30  static constexpr const size_t size = sizeof...(Xs);
31 
32  template <char... Ys>
33  CK_TILE_HOST_DEVICE constexpr auto operator+(str_literal<Ys...> /*rhs*/) const
34  {
35  return str_literal<Xs..., Ys...>{};
36  }
37 
38  template <size_t N, char... Ys>
39  CK_TILE_HOST_DEVICE static constexpr auto duplicate_n(const str_literal<Ys...> sep)
40  {
41  if constexpr(N == 0)
42  return str_literal<>{};
43  else if constexpr(N == 1)
44  return str_literal<Xs...>{};
45  else
46  return duplicate_n<N - 1>(sep) + str_literal<Ys..., Xs...>{};
47  }
48 };
49 
50 #define make_str_literal(lit_) \
51  std::apply([](auto... indices) { return str_literal<(lit_)[decltype(indices)::value]...>{}; }, \
52  str_literal_detail::makeTuple( \
53  std::make_index_sequence<str_literal_detail::constexpr_strlen(lit_)>()))
54 
57 template <typename T>
58 CK_TILE_HOST_DEVICE void print(const T&)
59 {
60  static_assert(sizeof(T) == 0,
61  "No print implementation available for this type. Please specialize "
62  "ck_tile::print for your type.");
63 }
64 
66 template <>
68 {
69  printf("%d", value);
70 }
71 
73 template <>
74 CK_TILE_HOST_DEVICE void print(const float& value)
75 {
76  printf("%f", value);
77 }
78 
80 template <>
81 CK_TILE_HOST_DEVICE void print(const double& value)
82 {
83  printf("%f", value);
84 }
85 
87 template <>
88 CK_TILE_HOST_DEVICE void print(const long& value)
89 {
90  printf("%ld", value);
91 }
92 
94 template <>
95 CK_TILE_HOST_DEVICE void print(const unsigned int& value)
96 {
97  printf("%u", value);
98 }
99 
101 template <>
102 CK_TILE_HOST_DEVICE void print(const char& value)
103 {
104  printf("%c", value);
105 }
106 
108 template <typename T, size_t N>
109 CK_TILE_HOST_DEVICE void print(const T (&value)[N])
110 {
111  printf("[");
112  for(size_t i = 0; i < N; ++i)
113  {
114  if(i > 0)
115  printf(", ");
116  print(value[i]); // Recursively call print for each element
117  }
118  printf("]");
119 }
120 
121 } // namespace ck_tile
#define CK_TILE_HOST_DEVICE
Definition: config.hpp:46
constexpr std::tuple< std::integral_constant< size_t, Idx >... > makeTuple(std::index_sequence< Idx... >) noexcept
Definition: print.hpp:13
constexpr size_t constexpr_strlen(const char *c)
Definition: print.hpp:17
Definition: cluster_descriptor.hpp:13
CK_TILE_HOST_DEVICE void print(const tile_distribution_encoding_pattern_2d< BlockSize, YPerTile, XPerTile, VecSize, DistributionPattern, NumWaveGroups > &)
Definition: static_encoding_pattern.hpp:341
const GenericPointer< typename T::ValueType > T2 value
Definition: pointer.h:1697
Definition: print.hpp:28
static constexpr const size_t size
Definition: print.hpp:30
constexpr CK_TILE_HOST_DEVICE auto operator+(str_literal< Ys... >) const
Definition: print.hpp:33
static constexpr const char data[]
Definition: print.hpp:29
static constexpr CK_TILE_HOST_DEVICE auto duplicate_n(const str_literal< Ys... > sep)
Definition: print.hpp:39