Ginkgo: ginkgo/core/base/segmented_array.hpp Source File

| Ginkgo Generated from branch based on main. Ginkgo version 1.11.0 A numerical linear algebra library targeting many-core architectures

Loading...
Searching...
No Matches
segmented_array.hpp
1// SPDX-FileCopyrightText: 2017 - 2025 The Ginkgo authors
2//
3// SPDX-License-Identifier: BSD-3-Clause
4
5#ifndef GKO_PUBLIC_CORE_BASE_SEGMENTED_ARRAY_HPP_
6#define GKO_PUBLIC_CORE_BASE_SEGMENTED_ARRAY_HPP_
7
8
9#include <numeric>
10
11#include <ginkgo/config.hpp>
12#include <ginkgo/core/base/array.hpp>
13
14
15namespace gko {
16
26template <typename T>
27 struct segmented_array {
33 explicit segmented_array(std::shared_ptr<const Executor> exec);
34
41 static segmented_array create_from_sizes(const gko::array<int64>& sizes);
42
49 static segmented_array create_from_sizes(gko::array<T> buffer,
50 const gko::array<int64>& sizes);
51
58 static segmented_array create_from_offsets(gko::array<int64> offsets);
59
68 static segmented_array create_from_offsets(gko::array<T> buffer,
69 gko::array<int64> offsets);
70
77 segmented_array(std::shared_ptr<const Executor> exec,
78 const segmented_array& other);
79
86 segmented_array(std::shared_ptr<const Executor> exec,
87 segmented_array&& other);
88
89 segmented_array(const segmented_array& other);
90
91 segmented_array(segmented_array&& other) noexcept(false);
92
93 segmented_array& operator=(const segmented_array& other);
94
95 segmented_array& operator=(segmented_array&&) noexcept(false);
96
102 size_type get_size() const;
103
109 size_type get_segment_count() const;
110
116 T* get_flat_data();
117
123 const T* get_const_flat_data() const;
124
130 const gko::array<int64>& get_offsets() const;
131
137 std::shared_ptr<const Executor> get_executor() const;
138
139private:
140 gko::array<T> buffer_;
141 gko::array<int64> offsets_;
142};
143
144
145namespace detail {
146
147
148template <typename T>
149struct temporary_clone_helper<segmented_array<T>> {
150 static std::unique_ptr<segmented_array<T>> create(
151 std::shared_ptr<const Executor> exec, segmented_array<T>* ptr,
152 bool copy_data)
153 {
154 if (copy_data) {
155 return std::make_unique<segmented_array<T>>(std::move(exec), *ptr);
156 } else {
157 return std::unique_ptr<segmented_array<T>>(
158 new segmented_array<T>(segmented_array<T>::create_from_offsets(
159 array<int64>(std::move(exec), ptr->get_offsets()))));
160 }
161 }
162};
163
164template <typename T>
165struct temporary_clone_helper<const segmented_array<T>> {
166 static std::unique_ptr<const segmented_array<T>> create(
167 std::shared_ptr<const Executor> exec, const segmented_array<T>* ptr,
168 bool)
169 {
170 return std::make_unique<segmented_array<T>>(std::move(exec), *ptr);
171 }
172};
173
174
175template <typename T>
176class copy_back_deleter<segmented_array<T>>
177 : public copy_back_deleter_from_assignment<segmented_array<T>> {
178public:
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
186
187#endif // GKO_PUBLIC_CORE_BASE_SEGMENTED_ARRAY_HPP_
gko::Executor
The first step in using the Ginkgo library consists of creating an executor.
Definition executor.hpp:615
gko::array
An array is a container which encapsulates fixed-sized arrays, stored on the Executor tied to the arr...
Definition array.hpp:166
gko
The Ginkgo namespace.
Definition abstract_factory.hpp:20
gko::int64
std::int64_t int64
64-bit signed integral type.
Definition types.hpp:113
gko::size_type
std::size_t size_type
Integral type used for allocation quantities.
Definition types.hpp:90
std
STL namespace.
gko::segmented_array::get_const_flat_data
const T * get_const_flat_data() const
Const-access to the flat buffer.
gko::segmented_array::segmented_array
segmented_array(std::shared_ptr< const Executor > exec, const segmented_array &other)
Copies a segmented array to a different executor.
gko::segmented_array::create_from_offsets
static segmented_array create_from_offsets(gko::array< T > buffer, gko::array< int64 > offsets)
Creates a segmented array from a flat buffer and offsets.
gko::segmented_array::segmented_array
segmented_array(std::shared_ptr< const Executor > exec)
Create an empty segmented array.
gko::segmented_array::create_from_sizes
static segmented_array create_from_sizes(gko::array< T > buffer, const gko::array< int64 > &sizes)
Creates a segmented array from a flat buffer and segment sizes.
gko::segmented_array::get_segment_count
size_type get_segment_count() const
Get the number of segments.
gko::segmented_array::segmented_array
segmented_array(std::shared_ptr< const Executor > exec, segmented_array &&other)
Moves a segmented array to a different executor.
gko::segmented_array::get_flat_data
T * get_flat_data()
Access to the flat buffer.
gko::segmented_array::get_size
size_type get_size() const
Get the total size of the stored buffer.
gko::segmented_array::get_executor
std::shared_ptr< const Executor > get_executor() const
Access the executor.
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_offsets
const gko::array< int64 > & get_offsets() const
Access to the segment offsets.
gko::segmented_array::create_from_offsets
static segmented_array create_from_offsets(gko::array< int64 > offsets)
Creates an uninitialized segmented array from offsets.