OpenLB 1.7
Loading...
Searching...
No Matches
mask.h
Go to the documentation of this file.
1/* This file is part of the OpenLB library
2 *
3 * Copyright (C) 2021 Adrian Kummerlaender
4 * E-mail contact: info@openlb.net
5 * The most recent release of OpenLB can be downloaded at
6 * <http://www.openlb.net/>
7 *
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * as published by the Free Software Foundation; either version 2
11 * of the License, or (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public
19 * License along with this program; if not, write to the Free
20 * Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
21 * Boston, MA 02110-1301, USA.
22*/
23
24#ifndef CPU_SIMD_MASK_H_
25#define CPU_SIMD_MASK_H_
26
27#include "pack.h"
28#include "column.h"
29
30namespace olb {
31
32template <typename T>
34private:
35 const std::size_t _size;
36 std::size_t _weight;
38
39 const std::size_t _serializedSize;
40 std::unique_ptr<typename cpu::simd::Mask<T>::storage_t[]> _serialized;
41
42 bool _modified;
43
44public:
45 ConcreteBlockMask(std::size_t size):
46 _size(size + cpu::simd::Pack<T>::size),
47 _weight(0),
48 _mask(_size),
49 _serializedSize((_size + cpu::simd::Pack<T>::size - 1) / cpu::simd::Mask<T>::storage_size + 1),
50 _serialized(new typename cpu::simd::Mask<T>::storage_t[_serializedSize] { }),
51 _modified(true)
52 { }
53
55 _size(rhs._size),
56 _weight(rhs._size),
57 _mask(rhs._mask),
58 _serializedSize(rhs._serializedSize),
59 _serialized(new typename cpu::simd::Mask<T>::storage_t[_serializedSize] { }),
60 _modified(rhs._modified)
61 {
62 std::copy(rhs._serialized.get(),
63 rhs._serialized.get() + _serializedSize,
64 _serialized.get());
65 }
66
67 bool operator[](std::size_t i) const {
68 return _mask[i];
69 }
70
71 std::size_t weight() const {
72 return _weight;
73 }
74
75 void set(std::size_t i, bool active) {
76 if ( _mask[i] && !active) {
77 _weight -= 1;
78 } else if (!_mask[i] && active) {
79 _weight += 1;
80 }
81 _mask[i] = active;
82 _modified = true;
83 }
84
85 auto* raw()
86 {
87 if constexpr (cpu::simd::Mask<T>::storage_size == 1) {
88 return _mask.data(); // Transparently convert bools to std::uint64_t for AVX2
89 } else {
90 return _serialized.get(); // Use serialized bit-mask for AVX-512
91 }
92 }
93
95 if (_modified) {
96 for (std::size_t i=0; i < _size; i += cpu::simd::Mask<T>::storage_size) {
98 }
99 _modified = false;
100 }
101 }
102
104 std::size_t getNblock() const override;
106 std::size_t getSerializableSize() const override;
108 bool* getBlock(std::size_t iBlock, std::size_t& sizeBlock, bool loadingMode) override;
109
110};
111
112template<typename T>
114{
115 return 1 + _mask.getNblock();
116}
117
118template<typename T>
120{
121 return sizeof(_weight) + _mask.getSerializableSize();
122}
123
124template<typename T>
125bool* ConcreteBlockMask<T,Platform::CPU_SIMD>::getBlock(std::size_t iBlock, std::size_t& sizeBlock, bool loadingMode)
126{
127 std::size_t currentBlock = 0;
128 bool* dataPtr = nullptr;
129
130 registerVar(iBlock, sizeBlock, currentBlock, dataPtr, _weight);
131 registerSerializableOfConstSize(iBlock, sizeBlock, currentBlock, dataPtr, _mask, loadingMode);
132
133 return dataPtr;
134}
135
136
137}
138
139#endif
void setProcessingContext(ProcessingContext)
Definition mask.h:94
ConcreteBlockMask(const ConcreteBlockMask &rhs)
Definition mask.h:54
bool operator[](std::size_t i) const
Definition mask.h:67
void set(std::size_t i, bool active)
Definition mask.h:75
Base class for serializable objects of constant size. For dynamic size use BufferSerializable.
Definition serializer.h:145
Plain column for SIMD CPU targets.
Definition column.h:53
const T * data() const
Definition column.h:109
Top level namespace for all of OpenLB.
ProcessingContext
OpenLB processing contexts.
Definition platform.h:55
Platform
OpenLB execution targets.
Definition platform.h:36
@ CPU_SIMD
Basic scalar CPU.