OpenLB 1.8.1
Loading...
Searching...
No Matches
olb::introspection Namespace Reference

Functions

template<typename DYNAMICS >
std::optional< std::size_t > getArithmeticOperationCount ()
 
template<typename OPERATOR , typename DESCRIPTOR >
std::optional< std::size_t > getArithmeticOperationCount ()
 
template<typename DYNAMICS >
std::optional< std::size_t > getComplexity ()
 
template<concepts::IntrospectableDynamics DYNAMICS>
bool isOptimizable ()
 
template<typename OPERATOR , typename DESCRIPTOR >
bool isOptimizable ()
 
template<typename DYNAMICS >
requires (!concepts::IntrospectableDynamics<DYNAMICS>)
bool isOptimizable ()
 
template<typename T , typename DESCRIPTOR , typename DYNAMICS >
std::set< FieldTypePromise< T, DESCRIPTOR > > getFieldsAccessedByDynamics ()
 
template<typename T , typename DESCRIPTOR , typename DYNAMICS >
std::set< FieldTypePromise< T, DESCRIPTOR > > getFieldsAccessedByCollision ()
 
template<typename T , typename DESCRIPTOR , typename OPERATOR >
std::set< FieldTypePromise< T, DESCRIPTOR > > getFieldsAccessedByOperator ()
 
template<typename DYNAMICS >
std::optional< std::size_t > getMemoryBandwidthOfCollision ()
 Returns estimate of number of scalar reads and writes for DYNAMICS::collide.
 
std::string getSimplifiedDynamicsName (std::string name)
 Return reduced and reasonable newline-separated version of given full dynamics name.
 

Function Documentation

◆ getArithmeticOperationCount() [1/2]

template<typename DYNAMICS >
std::optional< std::size_t > olb::introspection::getArithmeticOperationCount ( )

Definition at line 45 of file introspection.h.

45 {
47 try {
48 using DESCRIPTOR = typename DYNAMICS::descriptor_t;
50 exprLattice.setStatisticsEnabled(false);
51 exprLattice.setIntrospectability(false);
52 exprLattice.setDynamics(0, meta::id<typename DYNAMICS::template exchange_value_type<Expr>>{});
53 Expr::reset();
54 exprLattice.collide();
55 return Expr::count();
56 }
57 catch (std::domain_error& error) {
58 return std::nullopt;
59 }
60 } else {
61 return std::nullopt;
62 }
63}
Implementation of BlockLattice on a concrete PLATFORM.
Identity type to pass non-constructible types as value.
Definition meta.h:79

References olb::ConcreteBlockLattice< T, DESCRIPTOR, PLATFORM >::collide(), olb::Expr::count(), olb::Expr::reset(), olb::ConcreteBlockLattice< T, DESCRIPTOR, PLATFORM >::setDynamics(), olb::BlockLattice< T, DESCRIPTOR >::setIntrospectability(), and olb::BlockLattice< T, DESCRIPTOR >::setStatisticsEnabled().

+ Here is the call graph for this function:

◆ getArithmeticOperationCount() [2/2]

template<typename OPERATOR , typename DESCRIPTOR >
std::optional< std::size_t > olb::introspection::getArithmeticOperationCount ( )

Definition at line 67 of file introspection.h.

67 {
68 try {
69 const int r = 3;
70 Vector<int,DESCRIPTOR::d> extend(r*2+1);
73 exprLattice.setStatisticsEnabled(false);
74 exprLattice.setIntrospectability(false);
75 if (OPERATOR::scope == OperatorScope::PerBlock) {
76 exprLattice.addPostProcessor(typeid(stage::CSE),
78 } else {
79 exprLattice.addPostProcessor(typeid(stage::CSE),
80 center,
81 meta::id<OPERATOR>{});
82 }
83 Expr::reset();
84 exprLattice.postProcess(typeid(stage::CSE));
85 return Expr::count();
86 }
87 catch (std::domain_error& error) {
88 return std::nullopt;
89 }
90}
Plain old scalar vector.
Seperate step only used for extracting expression tree.
Definition stages.h:61

References olb::ConcreteBlockLattice< T, DESCRIPTOR, PLATFORM >::addPostProcessor(), olb::Expr::count(), olb::PerBlock, olb::ConcreteBlockLattice< T, DESCRIPTOR, PLATFORM >::postProcess(), olb::Expr::reset(), olb::BlockLattice< T, DESCRIPTOR >::setIntrospectability(), and olb::BlockLattice< T, DESCRIPTOR >::setStatisticsEnabled().

+ Here is the call graph for this function:

◆ getComplexity()

template<typename DYNAMICS >
std::optional< std::size_t > olb::introspection::getComplexity ( )

Definition at line 94 of file introspection.h.

94 {
96 try {
97 using DESCRIPTOR = typename DYNAMICS::descriptor_t;
99 exprLattice.setStatisticsEnabled(false);
100 exprLattice.setIntrospectability(false);
101 exprLattice.setDynamics(0, meta::id<typename DYNAMICS::template exchange_value_type<Expr>>{});
102 exprLattice.collide();
103 std::size_t size = 0;
104 for (int iPop=0; iPop < DESCRIPTOR::q; ++iPop) {
105 size += exprLattice.get(0)[iPop].size();
106 }
107 return size;
108 }
109 catch (std::domain_error& error) {
110 return std::nullopt;
111 }
112 } else {
113 return std::nullopt;
114 }
115}

References olb::ConcreteBlockLattice< T, DESCRIPTOR, PLATFORM >::collide(), olb::BlockLattice< T, DESCRIPTOR >::get(), olb::ConcreteBlockLattice< T, DESCRIPTOR, PLATFORM >::setDynamics(), olb::BlockLattice< T, DESCRIPTOR >::setIntrospectability(), and olb::BlockLattice< T, DESCRIPTOR >::setStatisticsEnabled().

+ Here is the call graph for this function:

◆ getFieldsAccessedByCollision()

template<typename T , typename DESCRIPTOR , typename DYNAMICS >
std::set< FieldTypePromise< T, DESCRIPTOR > > olb::introspection::getFieldsAccessedByCollision ( )

Definition at line 195 of file introspection.h.

195 {
197 lattice.setStatisticsEnabled(false);
198 lattice.setIntrospectability(false);
199
200 lattice.defineDynamics(0, meta::id<DYNAMICS>());
201
202 std::set<FieldTypePromise<T,DESCRIPTOR>> preCollide;
203 lattice.getData().forEach([&](auto& anyFieldType) {
204 preCollide.emplace(anyFieldType.getPromise());
205 });
206
207 lattice.collide();
208
209 std::set<FieldTypePromise<T,DESCRIPTOR>> postCollide;
210 lattice.getData().forEach([&](auto& anyFieldType) {
211 postCollide.emplace(anyFieldType.getPromise());
212 });
213
214 std::set<FieldTypePromise<T,DESCRIPTOR>> accessed;
215 std::set_difference(postCollide.begin(), postCollide.end(),
216 preCollide.begin(), preCollide.end(),
217 std::inserter(accessed, accessed.end()));
218 return accessed;
219}

References olb::ConcreteBlockLattice< T, DESCRIPTOR, PLATFORM >::collide(), olb::BlockLattice< T, DESCRIPTOR >::defineDynamics(), olb::ConcreteBlockLattice< T, DESCRIPTOR, PLATFORM >::getData(), olb::BlockLattice< T, DESCRIPTOR >::setIntrospectability(), and olb::BlockLattice< T, DESCRIPTOR >::setStatisticsEnabled().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getFieldsAccessedByDynamics()

template<typename T , typename DESCRIPTOR , typename DYNAMICS >
std::set< FieldTypePromise< T, DESCRIPTOR > > olb::introspection::getFieldsAccessedByDynamics ( )

Definition at line 168 of file introspection.h.

168 {
170 lattice.setStatisticsEnabled(false);
171 lattice.setIntrospectability(false);
172
173 std::set<FieldTypePromise<T,DESCRIPTOR>> preCollide;
174 lattice.getData().forEach([&](auto& anyFieldType) {
175 preCollide.emplace(anyFieldType.getPromise());
176 });
177
178 lattice.defineDynamics(0, meta::id<DYNAMICS>());
179 lattice.collide();
180
181 std::set<FieldTypePromise<T,DESCRIPTOR>> postCollide;
182 lattice.getData().forEach([&](auto& anyFieldType) {
183 postCollide.emplace(anyFieldType.getPromise());
184 });
185
186 std::set<FieldTypePromise<T,DESCRIPTOR>> accessed;
187 std::set_difference(postCollide.begin(), postCollide.end(),
188 preCollide.begin(), preCollide.end(),
189 std::inserter(accessed, accessed.end()));
190 return accessed;
191}

References olb::ConcreteBlockLattice< T, DESCRIPTOR, PLATFORM >::collide(), olb::BlockLattice< T, DESCRIPTOR >::defineDynamics(), olb::ConcreteBlockLattice< T, DESCRIPTOR, PLATFORM >::getData(), olb::BlockLattice< T, DESCRIPTOR >::setIntrospectability(), and olb::BlockLattice< T, DESCRIPTOR >::setStatisticsEnabled().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getFieldsAccessedByOperator()

template<typename T , typename DESCRIPTOR , typename OPERATOR >
std::set< FieldTypePromise< T, DESCRIPTOR > > olb::introspection::getFieldsAccessedByOperator ( )

Definition at line 223 of file introspection.h.

223 {
225 lattice.setStatisticsEnabled(false);
226 lattice.setIntrospectability(false);
227
228 std::set<FieldTypePromise<T,DESCRIPTOR>> prePostProcess;
229 lattice.getData().forEach([&](auto& anyFieldType) {
230 prePostProcess.emplace(anyFieldType.getPromise());
231 });
232
233 if (OPERATOR::scope == OperatorScope::PerBlock) {
234 lattice.addPostProcessor(typeid(stage::CSE),
236 } else {
237 lattice.addPostProcessor(typeid(stage::CSE),
238 0,
239 meta::id<OPERATOR>{});
240 }
241 lattice.postProcess(typeid(stage::CSE));
242
243 std::set<FieldTypePromise<T,DESCRIPTOR>> postPostProcess;
244 lattice.getData().forEach([&](auto& anyFieldType) {
245 postPostProcess.emplace(anyFieldType.getPromise());
246 });
247
248 std::set<FieldTypePromise<T,DESCRIPTOR>> accessed;
249 std::set_difference(postPostProcess.begin(), postPostProcess.end(),
250 prePostProcess.begin(), prePostProcess.end(),
251 std::inserter(accessed, accessed.end()));
252 return accessed;
253}

References olb::ConcreteBlockLattice< T, DESCRIPTOR, PLATFORM >::addPostProcessor(), olb::ConcreteBlockLattice< T, DESCRIPTOR, PLATFORM >::getData(), olb::PerBlock, olb::ConcreteBlockLattice< T, DESCRIPTOR, PLATFORM >::postProcess(), olb::BlockLattice< T, DESCRIPTOR >::setIntrospectability(), and olb::BlockLattice< T, DESCRIPTOR >::setStatisticsEnabled().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getMemoryBandwidthOfCollision()

template<typename DYNAMICS >
std::optional< std::size_t > olb::introspection::getMemoryBandwidthOfCollision ( )

Returns estimate of number of scalar reads and writes for DYNAMICS::collide.

Definition at line 258 of file introspection.h.

258 {
259 using T = Expr;
260 using DESCRIPTOR = DYNAMICS::descriptor_t;
261
262 try {
265 exprLattice.setIntrospectability(false);
266 exprLattice.setStatisticsEnabled(false);
267
268 exprLattice.setDynamics(0, meta::id<typename DYNAMICS::template exchange_value_type<T>>{});
269
270 std::size_t bandwidth = 0;
271
273 auto cell = exprLattice.get(pos);
274 for (int iPop=0; iPop < DESCRIPTOR::q; ++iPop) {
275 cell[iPop] = "cell[" + std::to_string(iPop) + "]";
276 }
277 // Assume that all populations are read
278 bandwidth += DESCRIPTOR::q;
279
280 auto accessedFields = getFieldsAccessedByCollision<typename DYNAMICS::value_t,DESCRIPTOR,DYNAMICS>();
281
282 // Initialize expressions for the accessed fields
283 for (auto field : accessedFields) {
284 if (auto dim = field.dimension()) {
285 // Assume that all touched fields are read
286 bandwidth += *dim;
287 std::vector<T> initExpr;
288 for (unsigned iD=0; iD < dim; ++iD) {
289 initExpr.emplace_back("cell[" + cse::remove_array_from_name(field.name()) + "][" + std::to_string(iD) + "]");
290 }
291 field.setPlaceholderExpression(cell, initExpr);
292 }
293 }
294
295 // Execute one colliding step to obtain post-collision expressions
296 exprLattice.collide();
297
298 for (int iPop=0; iPop < DESCRIPTOR::q; ++iPop) {
299 if (!cell[iPop].isSymbol("cell[" + std::to_string(iPop) + "]")) {
300 // Count number of population updates
301 bandwidth += 1;
302 }
303 }
304
305 // Obtain fields which were updated and overwritten by the operator
306 for (auto field : accessedFields) {
307 if (auto dim = field.dimension()) {
308 auto postExpr = field.getPlaceholderExpression(cell);
309 for (unsigned iD=0; iD < dim; ++iD) {
310 if (!postExpr[iD].isSymbol("cell["
311 + cse::remove_array_from_name(field.name())
312 + "][" + std::to_string(iD) + "]")) {
313 // Count number of field component updates
314 bandwidth += 1;
315 }
316 }
317 }
318 }
319
320 return bandwidth;
321 }
322 catch (std::domain_error& error) {
323 return std::nullopt;
324 }
325}
Basic value-substitute enabling extraction of expression trees for code generation.
Definition expr.h:39
std::enable_if_t< DESCRIPTOR::d==2, std::shared_ptr< SuperF2D< T > > > field(SuperLattice< T, DESCRIPTOR > &sLattice)
Returns external field functor.

References olb::ConcreteBlockLattice< T, DESCRIPTOR, PLATFORM >::collide(), olb::BlockLattice< T, DESCRIPTOR >::get(), getFieldsAccessedByCollision(), olb::cse::remove_array_from_name(), olb::ConcreteBlockLattice< T, DESCRIPTOR, PLATFORM >::setDynamics(), olb::BlockLattice< T, DESCRIPTOR >::setIntrospectability(), and olb::BlockLattice< T, DESCRIPTOR >::setStatisticsEnabled().

+ Here is the call graph for this function:

◆ getSimplifiedDynamicsName()

std::string olb::introspection::getSimplifiedDynamicsName ( std::string name)

Return reduced and reasonable newline-separated version of given full dynamics name.

Definition at line 329 of file introspection.h.

329 {
330 std::regex removeBaseTypeAndDescriptorRe("(float|double|Expr),\\s?descriptors::D[23]Q[0-9]+<([^<>]*|<([^<>]*|<[^<>]*>)*>)*>,?\\s?");
331 std::regex lineBreakRe("((dynamics|collision|forcing|equilibria)::[a-zA-Z]+|momenta::Tuple<)");
332
333 std::string stage0;
334 std::string stage1;
335 std::regex_replace(std::back_inserter(stage0),
336 name.begin(), name.end(), removeBaseTypeAndDescriptorRe,
337 "");
338 std::regex_replace(std::back_inserter(stage1),
339 stage0.begin(), stage0.end(), lineBreakRe,
340 "\n$&");
341 return stage1;
342}
+ Here is the caller graph for this function:

◆ isOptimizable() [1/3]

template<concepts::IntrospectableDynamics DYNAMICS>
bool olb::introspection::isOptimizable ( )

Definition at line 119 of file introspection.h.

119 {
120 try {
121 using DESCRIPTOR = typename DYNAMICS::descriptor_t;
123 exprLattice.setStatisticsEnabled(false);
124 exprLattice.setIntrospectability(false);
125 exprLattice.setDynamics(0, meta::id<typename DYNAMICS::template exchange_value_type<Expr>>{});
126 exprLattice.collide();
127 }
128 catch (std::domain_error& error) {
129 return false;
130 }
131 return true;
132}

References olb::ConcreteBlockLattice< T, DESCRIPTOR, PLATFORM >::collide(), olb::ConcreteBlockLattice< T, DESCRIPTOR, PLATFORM >::setDynamics(), olb::BlockLattice< T, DESCRIPTOR >::setIntrospectability(), and olb::BlockLattice< T, DESCRIPTOR >::setStatisticsEnabled().

+ Here is the call graph for this function:

◆ isOptimizable() [2/3]

template<typename OPERATOR , typename DESCRIPTOR >
bool olb::introspection::isOptimizable ( )

Definition at line 136 of file introspection.h.

136 {
137 try {
138 const int r = 3;
139 Vector<int,DESCRIPTOR::d> extend(r*2+1);
142 exprLattice.setStatisticsEnabled(false);
143 exprLattice.setIntrospectability(false);
144 if (OPERATOR::scope == OperatorScope::PerBlock) {
145 exprLattice.addPostProcessor(typeid(stage::CSE),
147 } else {
148 exprLattice.addPostProcessor(typeid(stage::CSE),
149 center,
150 meta::id<OPERATOR>{});
151 }
152 exprLattice.postProcess(typeid(stage::CSE));
153 }
154 catch (std::domain_error& error) {
155 return false;
156 }
157 return true;
158}

References olb::ConcreteBlockLattice< T, DESCRIPTOR, PLATFORM >::addPostProcessor(), olb::PerBlock, olb::ConcreteBlockLattice< T, DESCRIPTOR, PLATFORM >::postProcess(), olb::BlockLattice< T, DESCRIPTOR >::setIntrospectability(), and olb::BlockLattice< T, DESCRIPTOR >::setStatisticsEnabled().

+ Here is the call graph for this function:

◆ isOptimizable() [3/3]

template<typename DYNAMICS >
requires (!concepts::IntrospectableDynamics<DYNAMICS>)
bool olb::introspection::isOptimizable ( )

Definition at line 162 of file introspection.h.

162 {
163 return false;
164}