/home/docs/checkouts/readthedocs.org/user_builds/advanced-micro-devices-composable-kernel/checkouts/docs-6.4.3/include/ck_tile/core/container/meta_data_buffer.hpp Source File

/home/docs/checkouts/readthedocs.org/user_builds/advanced-micro-devices-composable-kernel/checkouts/docs-6.4.3/include/ck_tile/core/container/meta_data_buffer.hpp Source File#

Composable Kernel: /home/docs/checkouts/readthedocs.org/user_builds/advanced-micro-devices-composable-kernel/checkouts/docs-6.4.3/include/ck_tile/core/container/meta_data_buffer.hpp Source File
meta_data_buffer.hpp
Go to the documentation of this file.
1 // SPDX-License-Identifier: MIT
2 // Copyright (c) 2018-2023, Advanced Micro Devices, Inc. All rights reserved.
3 
4 #pragma once
5 
9 #include <cstddef>
10 
11 namespace ck_tile {
12 
13 // TODO: this structure is not intented to be used by user
14 template <index_t MaxSize>
16 {
18 
19  template <typename X, typename... Xs>
20  CK_TILE_HOST_DEVICE constexpr meta_data_buffer(const X& x, const Xs&... xs)
21  : buffer_{}, size_{0}
22  {
23  push(x, xs...);
24  }
25 
26  template <typename T>
27  CK_TILE_HOST_DEVICE constexpr void push(const T& data)
28  {
29  if constexpr(!std::is_empty_v<T>)
30  {
31  constexpr index_t size = sizeof(T);
32 
33  auto tmp = ck_tile::bit_cast<array<std::byte, size>>(data);
34 
35  for(int i = 0; i < size; i++)
36  {
37  buffer_(size_) = tmp[i];
38 
39  size_++;
40  }
41  }
42  }
43 
44  template <typename X, typename... Xs>
45  CK_TILE_HOST_DEVICE constexpr void push(const X& x, const Xs&... xs)
46  {
47  push(x);
48  push(xs...);
49  }
50 
51  template <typename T>
52  CK_TILE_HOST_DEVICE constexpr T pop(index_t& pos) const
53  {
54  T data;
55 
56  if constexpr(!std::is_empty_v<T>)
57  {
58  constexpr index_t size = sizeof(T);
59 
61 
62  for(int i = 0; i < size; i++)
63  {
64  tmp(i) = buffer_[pos];
65 
66  pos++;
67  }
68 
69  data = ck_tile::bit_cast<T>(tmp);
70  }
71 
72  return data;
73  }
74 
75  template <typename T>
76  CK_TILE_HOST_DEVICE constexpr T get(index_t pos) const
77  {
78  constexpr index_t size = sizeof(T);
79 
81 
82  for(int i = 0; i < size; i++)
83  {
84  tmp(i) = buffer_[pos];
85 
86  pos++;
87  }
88 
89  auto data = ck_tile::bit_cast<T>(tmp);
90 
91  return data;
92  }
93 
94  //
97 };
98 
99 } // namespace ck_tile
#define CK_TILE_HOST_DEVICE
Definition: config.hpp:41
Definition: cluster_descriptor.hpp:13
int32_t index_t
Definition: integer.hpp:9
Definition: array.hpp:24
Definition: meta_data_buffer.hpp:16
constexpr CK_TILE_HOST_DEVICE T get(index_t pos) const
Definition: meta_data_buffer.hpp:76
constexpr CK_TILE_HOST_DEVICE meta_data_buffer(const X &x, const Xs &... xs)
Definition: meta_data_buffer.hpp:20
constexpr CK_TILE_HOST_DEVICE void push(const T &data)
Definition: meta_data_buffer.hpp:27
constexpr CK_TILE_HOST_DEVICE T pop(index_t &pos) const
Definition: meta_data_buffer.hpp:52
array< std::byte, MaxSize > buffer_
Definition: meta_data_buffer.hpp:95
index_t size_
Definition: meta_data_buffer.hpp:96
constexpr CK_TILE_HOST_DEVICE meta_data_buffer()
Definition: meta_data_buffer.hpp:17
constexpr CK_TILE_HOST_DEVICE void push(const X &x, const Xs &... xs)
Definition: meta_data_buffer.hpp:45