Ginkgo Generated from branch based on master. Ginkgo version 1.8.0
A numerical linear algebra library targeting many-core architectures
Loading...
Searching...
No Matches
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
9#include <ginkgo/config.hpp>
10#include <ginkgo/core/base/array.hpp>
11
12
13namespace gko {
14
24template <typename T>
31 explicit segmented_array(std::shared_ptr<const Executor> exec);
32
40
48 const gko::array<int64>& sizes);
49
57
67 gko::array<int64> offsets);
68
75 segmented_array(std::shared_ptr<const Executor> exec,
76 const segmented_array& other);
77
84 segmented_array(std::shared_ptr<const Executor> exec,
85 segmented_array&& other);
86
87 segmented_array(const segmented_array& other);
88
89 segmented_array(segmented_array&& other) noexcept(false);
90
91 segmented_array& operator=(const segmented_array& other);
92
93 segmented_array& operator=(segmented_array&&) noexcept(false);
94
101
108
115
121 const T* get_const_flat_data() const;
122
128 const gko::array<int64>& get_offsets() const;
129
135 std::shared_ptr<const Executor> get_executor() const;
136
137private:
138 gko::array<T> buffer_;
139 gko::array<int64> offsets_;
140};
141
142
143namespace detail {
144
145
146template <typename T>
147struct temporary_clone_helper<segmented_array<T>> {
148 static std::unique_ptr<segmented_array<T>> create(
149 std::shared_ptr<const Executor> exec, segmented_array<T>* ptr,
150 bool copy_data)
151 {
152 if (copy_data) {
153 return std::make_unique<segmented_array<T>>(
154 make_array_view(exec, ptr->get_size(), ptr->get_flat_data()),
155 ptr->get_offsets());
156 } else {
157 return std::make_unique<segmented_array<T>>(std::move(exec),
158 ptr->get_offsets());
159 }
160 }
161};
162
163template <typename T>
164struct temporary_clone_helper<const segmented_array<T>> {
165 static std::unique_ptr<const segmented_array<T>> create(
166 std::shared_ptr<const Executor> exec, const segmented_array<T>* ptr,
167 bool)
168 {
169 return std::make_unique<segmented_array<T>>(
170 make_array_view(exec, ptr->get_size(), ptr->get_const_flat_data()),
171 ptr->get_offsets());
172 }
173};
174
175
176template <typename T>
177class copy_back_deleter<segmented_array<T>>
178 : public copy_back_deleter_from_assignment<segmented_array<T>> {
179public:
180 using copy_back_deleter_from_assignment<
181 segmented_array<T>>::copy_back_deleter_from_assignment;
182};
183
184
185} // namespace detail
186} // namespace gko
The first step in using the Ginkgo library consists of creating an executor.
Definition executor.hpp:616
An array is a container which encapsulates fixed-sized arrays, stored on the Executor tied to the arr...
Definition logger.hpp:25
The Ginkgo namespace.
Definition abstract_factory.hpp:20
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:788
std::int64_t int64
64-bit signed integral type.
Definition types.hpp:109
std::size_t size_type
Integral type used for allocation quantities.
Definition types.hpp:86
A minimal interface for a segmented array.
Definition segmented_array.hpp:25
const T * get_const_flat_data() const
Const-access to the flat buffer.
segmented_array(std::shared_ptr< const Executor > exec, const segmented_array &other)
Copies a segmented array to a different executor.
static segmented_array create_from_offsets(gko::array< T > buffer, gko::array< int64 > offsets)
Creates a segmented array from a flat buffer and offsets.
segmented_array(std::shared_ptr< const Executor > exec)
Create an empty segmented array.
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.
size_type get_segment_count() const
Get the number of segments.
segmented_array(std::shared_ptr< const Executor > exec, segmented_array &&other)
Moves a segmented array to a different executor.
T * get_flat_data()
Access to the flat buffer.
size_type get_size() const
Get the total size of the stored buffer.
std::shared_ptr< const Executor > get_executor() const
Access the executor.
static segmented_array create_from_sizes(const gko::array< int64 > &sizes)
Creates an uninitialized segmented array with predefined segment sizes.
const gko::array< int64 > & get_offsets() const
Access to the segment offsets.
static segmented_array create_from_offsets(gko::array< int64 > offsets)
Creates an uninitialized segmented array from offsets.