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

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

Composable Kernel: /home/docs/checkouts/readthedocs.org/user_builds/advanced-micro-devices-composable-kernel/checkouts/develop/include/ck_tile/core/utility/to_sequence.hpp Source File
to_sequence.hpp
Go to the documentation of this file.
1 // SPDX-License-Identifier: MIT
2 // Copyright (c) 2018-2024, Advanced Micro Devices, Inc. All rights reserved.
3 
4 #pragma once
6 // TODO: use c++20 nontype template with struct to implement this
7 
8 #if 1
9 // clang happen to support this feature (__cpp_generic_lambdas >= 201707) in c++17 mode
10 #define TO_SEQUENCE(a, n) \
11  _Pragma("clang diagnostic push") _Pragma( \
12  "clang diagnostic ignored \"-Wc++20-extensions\"")[a]<ck_tile::index_t... IDX_IDX_>( \
13  ck_tile::sequence<IDX_IDX_...>) \
14  { \
15  return ck_tile::sequence<a.at(ck_tile::number<IDX_IDX_>{})...>{}; \
16  } \
17  (ck_tile::make_index_sequence<n>{}); \
18  _Pragma("clang diagnostic pop")
19 
20 #else
21 // Macro function
22 // convert constexpr array to sequence, both a/n need to be constexpr (can't be a rvalue like 2)
23 #define TO_SEQUENCE(a, n) \
24  [a, n] { \
25  static_assert(a.size() >= n, "wrong! out of bound"); \
26  static_assert(n <= 10, "not implemented"); \
27  if constexpr(n == 0) \
28  { \
29  return ck_tile::sequence<>{}; \
30  } \
31  else if constexpr(n == 1) \
32  { \
33  return ck_tile::sequence<a[0]>{}; \
34  } \
35  else if constexpr(n == 2) \
36  { \
37  return ck_tile::sequence<a[0], a[1]>{}; \
38  } \
39  else if constexpr(n == 3) \
40  { \
41  return ck_tile::sequence<a[0], a[1], a[2]>{}; \
42  } \
43  else if constexpr(n == 4) \
44  { \
45  return ck_tile::sequence<a[0], a[1], a[2], a[3]>{}; \
46  } \
47  else if constexpr(n == 5) \
48  { \
49  return ck_tile::sequence<a[0], a[1], a[2], a[3], a[4]>{}; \
50  } \
51  else if constexpr(n == 6) \
52  { \
53  return ck_tile::sequence<a[0], a[1], a[2], a[3], a[4], a[5]>{}; \
54  } \
55  else if constexpr(n == 7) \
56  { \
57  return ck_tile::sequence<a[0], a[1], a[2], a[3], a[4], a[5], a[6]>{}; \
58  } \
59  else if constexpr(n == 8) \
60  { \
61  return ck_tile::sequence<a[0], a[1], a[2], a[3], a[4], a[5], a[6], a[7]>{}; \
62  } \
63  else if constexpr(n == 9) \
64  { \
65  return ck_tile::sequence<a[0], a[1], a[2], a[3], a[4], a[5], a[6], a[7], a[8]>{}; \
66  } \
67  else if constexpr(n == 10) \
68  { \
69  return ck_tile:: \
70  sequence<a[0], a[1], a[2], a[3], a[4], a[5], a[6], a[7], a[8], a[9]>{}; \
71  } \
72  }()
73 #endif