Ginkgo  Generated from pipelines/1554403166 branch based on develop. Ginkgo version 1.9.0
A numerical linear algebra library targeting many-core architectures
segmented_array.hpp
1 // SPDX-FileCopyrightText: 2017 - 2024 The Ginkgo authors
2 //
3 // SPDX-License-Identifier: BSD-3-Clause
4 
5 #pragma once
6 #include <numeric>
7 
8 #include <ginkgo/config.hpp>
9 #include <ginkgo/core/base/array.hpp>
10 
11 
12 namespace gko {
13 
23 template <typename T>
30  explicit segmented_array(std::shared_ptr<const Executor> exec);
31 
39 
47  const gko::array<int64>& sizes);
48 
56 
66  gko::array<int64> offsets);
67 
74  segmented_array(std::shared_ptr<const Executor> exec,
75  const segmented_array& other);
76 
83  segmented_array(std::shared_ptr<const Executor> exec,
84  segmented_array&& other);
85 
86  segmented_array(const segmented_array& other);
87 
88  segmented_array(segmented_array&& other) noexcept(false);
89 
90  segmented_array& operator=(const segmented_array& other);
91 
92  segmented_array& operator=(segmented_array&&) noexcept(false);
93 
99  size_type get_size() const;
100 
107 
113  T* get_flat_data();
114 
120  const T* get_const_flat_data() const;
121 
127  const gko::array<int64>& get_offsets() const;
128 
134  std::shared_ptr<const Executor> get_executor() const;
135 
136 private:
137  gko::array<T> buffer_;
138  gko::array<int64> offsets_;
139 };
140 
141 
142 namespace detail {
143 
144 
145 template <typename T>
146 struct temporary_clone_helper<segmented_array<T>> {
147  static std::unique_ptr<segmented_array<T>> create(
148  std::shared_ptr<const Executor> exec, segmented_array<T>* ptr,
149  bool copy_data)
150  {
151  if (copy_data) {
152  return std::make_unique<segmented_array<T>>(
153  make_array_view(exec, ptr->get_size(), ptr->get_flat_data()),
154  ptr->get_offsets());
155  } else {
156  return std::make_unique<segmented_array<T>>(std::move(exec),
157  ptr->get_offsets());
158  }
159  }
160 };
161 
162 template <typename T>
163 struct temporary_clone_helper<const segmented_array<T>> {
164  static std::unique_ptr<const segmented_array<T>> create(
165  std::shared_ptr<const Executor> exec, const segmented_array<T>* ptr,
166  bool)
167  {
168  return std::make_unique<segmented_array<T>>(
169  make_array_view(exec, ptr->get_size(), ptr->get_const_flat_data()),
170  ptr->get_offsets());
171  }
172 };
173 
174 
175 template <typename T>
176 class copy_back_deleter<segmented_array<T>>
177  : public copy_back_deleter_from_assignment<segmented_array<T>> {
178 public:
179  using copy_back_deleter_from_assignment<
180  segmented_array<T>>::copy_back_deleter_from_assignment;
181 };
182 
183 
184 } // namespace detail
185 } // namespace gko
gko::segmented_array::segmented_array
segmented_array(std::shared_ptr< const Executor > exec)
Create an empty segmented array.
gko::size_type
std::size_t size_type
Integral type used for allocation quantities.
Definition: types.hpp:86
gko::segmented_array::create_from_offsets
static segmented_array create_from_offsets(gko::array< int64 > offsets)
Creates an uninitialized segmented array from offsets.
gko::segmented_array::create_from_sizes
static segmented_array create_from_sizes(const gko::array< int64 > &sizes)
Creates an uninitialized segmented array with predefined segment sizes.
gko::segmented_array::get_flat_data
T * get_flat_data()
Access to the flat buffer.
gko::segmented_array::get_offsets
const gko::array< int64 > & get_offsets() const
Access to the segment offsets.
gko::segmented_array::get_segment_count
size_type get_segment_count() const
Get the number of segments.
gko
The Ginkgo namespace.
Definition: abstract_factory.hpp:20
gko::segmented_array::get_size
size_type get_size() const
Get the total size of the stored buffer.
gko::array< int64 >
gko::segmented_array::get_const_flat_data
const T * get_const_flat_data() const
Const-access to the flat buffer.
gko::segmented_array::get_executor
std::shared_ptr< const Executor > get_executor() const
Access the executor.
gko::segmented_array
A minimal interface for a segmented array.
Definition: segmented_array.hpp:24
gko::make_array_view
array< ValueType > make_array_view(std::shared_ptr< const Executor > exec, size_type size, ValueType *data)
Helper function to create an array view deducing the value type.
Definition: array.hpp:787