OpenLB
1.7
Loading...
Searching...
No Matches
src
core
platform
cpu
simd
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
30
namespace
olb
{
31
32
template
<
typename
T>
33
class
ConcreteBlockMask
<T,
Platform
::
CPU_SIMD
> final :
public
Serializable
{
34
private
:
35
const
std::size_t _size;
36
std::size_t _weight;
37
cpu::simd::Column<bool>
_mask;
38
39
const
std::size_t _serializedSize;
40
std::unique_ptr<typename cpu::simd::Mask<T>::storage_t[]> _serialized;
41
42
bool
_modified;
43
44
public
:
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
54
ConcreteBlockMask
(
const
ConcreteBlockMask
& rhs):
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
94
void
setProcessingContext
(
ProcessingContext
) {
95
if
(_modified) {
96
for
(std::size_t i=0; i < _size; i += cpu::simd::Mask<T>::storage_size) {
97
_serialized[i /
cpu::simd::Mask<T>::storage_size
] =
cpu::simd::Mask<T>::encode
(_mask.
data
() + i);
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
112
template
<
typename
T>
113
std::size_t
ConcreteBlockMask<T,Platform::CPU_SIMD>::getNblock
()
const
114
{
115
return
1 + _mask.getNblock();
116
}
117
118
template
<
typename
T>
119
std::size_t
ConcreteBlockMask<T,Platform::CPU_SIMD>::getSerializableSize
()
const
120
{
121
return
sizeof
(_weight) + _mask.getSerializableSize();
122
}
123
124
template
<
typename
T>
125
bool
*
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
olb::ConcreteBlockMask< T, Platform::CPU_SIMD >::setProcessingContext
void setProcessingContext(ProcessingContext)
Definition
mask.h:94
olb::ConcreteBlockMask< T, Platform::CPU_SIMD >::ConcreteBlockMask
ConcreteBlockMask(const ConcreteBlockMask &rhs)
Definition
mask.h:54
olb::ConcreteBlockMask< T, Platform::CPU_SIMD >::operator[]
bool operator[](std::size_t i) const
Definition
mask.h:67
olb::ConcreteBlockMask< T, Platform::CPU_SIMD >::raw
auto * raw()
Definition
mask.h:85
olb::ConcreteBlockMask< T, Platform::CPU_SIMD >::weight
std::size_t weight() const
Definition
mask.h:71
olb::ConcreteBlockMask< T, Platform::CPU_SIMD >::set
void set(std::size_t i, bool active)
Definition
mask.h:75
olb::ConcreteBlockMask< T, Platform::CPU_SIMD >::ConcreteBlockMask
ConcreteBlockMask(std::size_t size)
Definition
mask.h:45
olb::ConcreteBlockMask
Definition
blockDynamicsMap.h:39
olb::Serializable
Base class for serializable objects of constant size. For dynamic size use BufferSerializable.
Definition
serializer.h:145
olb::cpu::simd::Column
Plain column for SIMD CPU targets.
Definition
column.h:53
olb::cpu::simd::Column::data
const T * data() const
Definition
column.h:109
olb::cpu::simd::Mask
Definition
256.h:38
column.h
olb
Top level namespace for all of OpenLB.
Definition
boundaryPostProcessors2D.h:34
olb::ProcessingContext
ProcessingContext
OpenLB processing contexts.
Definition
platform.h:55
olb::Platform
Platform
OpenLB execution targets.
Definition
platform.h:36
olb::Platform::CPU_SIMD
@ CPU_SIMD
Basic scalar CPU.
pack.h
Generated on Tue Mar 5 2024 09:57:45 for OpenLB by
1.10.0