OpenLB 1.7
Loading...
Searching...
No Matches
column.h
Go to the documentation of this file.
1/* This file is part of the OpenLB library
2 *
3 * Copyright (C) 2022 Adrian Kummerlaender
4 *
5 * E-mail contact: info@openlb.net
6 * The most recent release of OpenLB can be downloaded at
7 * <http://www.openlb.net/>
8 *
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License
11 * as published by the Free Software Foundation; either version 2
12 * of the License, or (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public
20 * License along with this program; if not, write to the Free
21 * Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
22 * Boston, MA 02110-1301, USA.
23*/
24
25#ifndef GPU_CUDA_COLUMN_H
26#define GPU_CUDA_COLUMN_H
27
28#include <memory>
29
31#include "core/serializer.h"
33
34namespace olb {
35
36namespace gpu {
37
38namespace cuda {
39
40namespace device {
41
42struct Stream;
43
44}
45
47template<typename T>
48class Column final : public AbstractColumn<T>
49 , public Serializable {
50private:
51 std::size_t _count;
52
53 struct Data;
54 std::unique_ptr<Data> _data;
55
56public:
57 using value_t = T;
58
59 Column(std::size_t count);
60 Column(Column<T>&& rhs);
61 Column(const Column<T>& rhs);
62 ~Column();
63
64 const T& operator[](std::size_t i) const override;
65 T& operator[](std::size_t i) override;
66
67 std::size_t size() const;
68
69 const T* data() const;
70 T* data();
71
72 const T* deviceData() const;
73 T* deviceData();
74
76 void clear();
77 void resize(std::size_t newCount);
78 void push_back(T value);
80 void deduplicate();
81
84
86 std::size_t getNblock() const override;
88 std::size_t getSerializableSize() const override;
90 bool* getBlock(std::size_t iBlock, std::size_t& sizeBlock, bool loadingMode) override;
91
92};
93
94
96
100template<typename T>
101class CyclicColumn final : public AbstractCyclicColumn<T>
102 , public Serializable {
103private:
104 const std::ptrdiff_t _count;
105 const std::size_t _size;
106
107 struct Data;
108 std::unique_ptr<Data> _data;
109
110 T* _deviceBase;
111 T* _devicePopulation;
112
113 std::ptrdiff_t _shift;
114
115public:
116 using value_t = T;
117
118 CyclicColumn(std::size_t count);
120
121 const T& operator[](std::size_t i) const override;
122 T& operator[](std::size_t i) override;
123
124 const T* deviceData() const
125 {
126 return _devicePopulation;
127 }
128
130 {
131 return _devicePopulation;
132 }
133
134 std::size_t size() const
135 {
136 return _count;
137 }
138
139 void refresh()
140 {
141 _devicePopulation = _deviceBase + _shift;
142 }
143
144 void rotate(std::ptrdiff_t offset)
145 {
146 _shift -= offset;
147 if (_shift >= _count) {
148 _shift -= _count;
149 }
150 else if (_shift < 0) {
151 _shift += _count;
152 }
153 refresh();
154 }
155
156 void resize(std::size_t count)
157 {
158 throw std::logic_error("Cyclic column can not be resized");
159 }
160
162
164 std::size_t getNblock() const override;
166 std::size_t getSerializableSize() const override;
168 bool* getBlock(std::size_t iBlock, std::size_t& sizeBlock, bool loadingMode) override;
169 void postLoad() override { refresh(); }
170
171};
172
173}
174
175}
176
177
179template <typename T>
183
185template <typename T>
189
190
192
198template <typename T>
199class ConcreteCommunicatable<gpu::cuda::Column<T>> final : public Communicatable {
200private:
201 gpu::cuda::Column<T>& _column;
202
203public:
205 _column{column} { }
206
208 std::size_t size(ConstSpan<CellID> indices) const
209 {
210 return indices.size() * sizeof(T);
211 }
212
214 std::size_t serialize(ConstSpan<CellID> indices,
215 std::uint8_t* buffer) const;
216
218 std::size_t deserialize(ConstSpan<CellID> indices,
219 const std::uint8_t* buffer);
220
221};
222
224template <typename T>
225class ConcreteCommunicatable<gpu::cuda::CyclicColumn<T>> final : public Communicatable {
226private:
228
229public:
231 _column{column} { }
232
234 std::size_t size(ConstSpan<CellID> indices) const
235 {
236 return indices.size() * sizeof(T);
237 }
238
240 std::size_t serialize(ConstSpan<CellID> indices,
241 std::uint8_t* buffer) const;
242
244 std::size_t deserialize(ConstSpan<CellID> indices,
245 const std::uint8_t* buffer);
246
247};
248
249}
250
251#endif
ConcreteCommunicatable(gpu::cuda::Column< T > &column)
Definition column.h:204
std::size_t size(ConstSpan< CellID > indices) const
Get serialized size for data at locations indices
Definition column.h:208
ConcreteCommunicatable(gpu::cuda::CyclicColumn< T > &column)
Definition column.h:230
std::size_t size(ConstSpan< CellID > indices) const
Get serialized size for data at locations indices
Definition column.h:234
std::size_t deserialize(ConstSpan< CellID > indices, const std::uint8_t *buffer) override
Deserialize data at locations indices to buffer
std::size_t serialize(ConstSpan< CellID > indices, std::uint8_t *buffer) const override
Serialize data at locations indices to buffer
std::size_t size() const
Base class for serializable objects of constant size. For dynamic size use BufferSerializable.
Definition serializer.h:145
Plain column for CUDA GPU targets.
Definition column.h:49
std::size_t getNblock() const override
Number of data blocks for the serializable interface.
Definition column.hh:190
void deduplicate()
Combined ascending sort and removal of duplicate entries.
Definition column.hh:109
void clear()
Reset size to zero.
Definition column.hh:87
const T * deviceData() const
Definition column.hh:146
std::size_t getSerializableSize() const override
Binary size for the serializer.
Definition column.hh:196
const T * data() const
Definition column.hh:134
void setProcessingContext(ProcessingContext)
Definition column.hh:158
void push_back(T value)
Definition column.hh:102
const T & operator[](std::size_t i) const override
Definition column.hh:116
void resize(std::size_t newCount)
Definition column.hh:95
bool * getBlock(std::size_t iBlock, std::size_t &sizeBlock, bool loadingMode) override
Return a pointer to the memory of the current block and its size for the serializable interface.
Definition column.hh:202
std::size_t size() const
Definition column.hh:128
Virtual memory based cyclic column for usage in ColumnVector.
Definition column.h:102
void setProcessingContext(ProcessingContext)
Definition column.hh:286
std::size_t getNblock() const override
Number of data blocks for the serializable interface.
Definition column.hh:299
void postLoad() override
Definition column.h:169
std::size_t size() const
Definition column.h:134
std::size_t getSerializableSize() const override
Binary size for the serializer.
Definition column.hh:305
const T * deviceData() const
Definition column.h:124
const T & operator[](std::size_t i) const override
Definition column.hh:274
void rotate(std::ptrdiff_t offset)
Definition column.h:144
bool * getBlock(std::size_t iBlock, std::size_t &sizeBlock, bool loadingMode) override
Return a pointer to the memory of the current block and its size for the serializable interface.
Definition column.hh:311
void resize(std::size_t count)
Definition column.h:156
Basic wrapper for device stream.
Definition device.h:121
Top level namespace for all of OpenLB.
ProcessingContext
OpenLB processing contexts.
Definition platform.h:55
cpu::sisd::CyclicColumn< T > CyclicColumn
Use CPU SISD as default CyclicColumn.
Definition column.h:245
Platform
OpenLB execution targets.
Definition platform.h:36
@ GPU_CUDA
Vector CPU (AVX2 / AVX-512 collision)
cpu::sisd::Column< T > Column
Use CPU SISD as default Column.
Definition column.h:241
Abstract declarator of Column-like storage.
Definition column.h:34
Abstract declarator of cyclic Column-like storage.
Definition column.h:43
Specializable declarator for concrete implementations of abstract storage types.
Definition column.h:52