Line data Source code
1 : //* This file is part of the MOOSE framework
2 : //* https://www.mooseframework.org
3 : //*
4 : //* All rights reserved, see COPYRIGHT for full restrictions
5 : //* https://github.com/idaholab/moose/blob/master/COPYRIGHT
6 : //*
7 : //* Licensed under LGPL 2.1, please see LICENSE for details
8 : //* https://www.gnu.org/licenses/lgpl-2.1.html
9 :
10 : #include "KokkosTypes.h"
11 : #include "KokkosFunction.h"
12 : #include "KokkosUserObject.h"
13 : #include "KokkosPostprocessor.h"
14 : #include "KokkosVectorPostprocessor.h"
15 : #include "KokkosReporter.h"
16 :
17 : #include "FEProblemBase.h"
18 : #include "DisplacedProblem.h"
19 : #include "LinearSystem.h"
20 : #include "NonlinearSystemBase.h"
21 : #include "AuxiliarySystem.h"
22 : #include "MaterialBase.h"
23 : #include "MooseVariableDependencyInterface.h"
24 : #include "MaterialPropertyInterface.h"
25 : #include "Coupleable.h"
26 :
27 : Moose::Kokkos::System &
28 292 : FEProblemBase::getKokkosSystem(const unsigned int sys_num)
29 : {
30 292 : return _kokkos_systems[sys_num];
31 : }
32 :
33 : const Moose::Kokkos::System &
34 0 : FEProblemBase::getKokkosSystem(const unsigned int sys_num) const
35 : {
36 0 : return _kokkos_systems[sys_num];
37 : }
38 :
39 : Moose::Kokkos::FESystem &
40 0 : FEProblemBase::getKokkosFESystem(const unsigned int sys_num)
41 : {
42 0 : return _kokkos_fe_systems[sys_num];
43 : }
44 :
45 : const Moose::Kokkos::FESystem &
46 0 : FEProblemBase::getKokkosFESystem(const unsigned int sys_num) const
47 : {
48 0 : return _kokkos_fe_systems[sys_num];
49 : }
50 :
51 : void
52 3138 : FEProblemBase::addKokkosKernel(const std::string & kernel_name,
53 : const std::string & name,
54 : InputParameters & parameters)
55 : {
56 : parallel_object_only();
57 :
58 6276 : const auto nl_sys_num = determineSolverSystem(parameters.varName("variable", name), true).second;
59 3138 : if (!isSolverSystemNonlinear(nl_sys_num))
60 0 : mooseError("You are trying to add a Kernel to a linear variable/system, which is not "
61 : "supported at the moment!");
62 :
63 4561 : setResidualObjectParamsAndLog(
64 1715 : kernel_name, name, parameters, nl_sys_num, "KokkosKernel", _reinit_displaced_elem);
65 :
66 3138 : _nl[nl_sys_num]->addKokkosKernel(kernel_name, name, parameters);
67 :
68 3136 : _has_kokkos_objects = true;
69 3136 : _has_kokkos_residual_objects = true;
70 3136 : }
71 :
72 : void
73 407 : FEProblemBase::addKokkosNodalKernel(const std::string & kernel_name,
74 : const std::string & name,
75 : InputParameters & parameters)
76 : {
77 : parallel_object_only();
78 :
79 814 : const auto nl_sys_num = determineSolverSystem(parameters.varName("variable", name), true).second;
80 :
81 599 : setResidualObjectParamsAndLog(
82 215 : kernel_name, name, parameters, nl_sys_num, "KokkosNodalKernel", _reinit_displaced_elem);
83 :
84 407 : _nl[nl_sys_num]->addKokkosNodalKernel(kernel_name, name, parameters);
85 :
86 407 : _has_kokkos_objects = true;
87 407 : _has_kokkos_residual_objects = true;
88 407 : }
89 :
90 : void
91 4008 : FEProblemBase::addKokkosBoundaryCondition(const std::string & bc_name,
92 : const std::string & name,
93 : InputParameters & parameters)
94 : {
95 : parallel_object_only();
96 :
97 8016 : const auto nl_sys_num = determineSolverSystem(parameters.varName("variable", name), true).second;
98 4008 : if (!isSolverSystemNonlinear(nl_sys_num))
99 0 : mooseError(
100 : "You are trying to add a BoundaryCondition to a linear variable/system, which is not "
101 : "supported at the moment!");
102 :
103 5850 : setResidualObjectParamsAndLog(
104 2166 : bc_name, name, parameters, nl_sys_num, "KokkosBoundaryCondition", _reinit_displaced_face);
105 :
106 4008 : _nl[nl_sys_num]->addKokkosBoundaryCondition(bc_name, name, parameters);
107 :
108 4008 : _has_kokkos_objects = true;
109 4008 : _has_kokkos_residual_objects = true;
110 4008 : }
111 :
112 : void
113 400 : FEProblemBase::addKokkosLinearFVKernel(const std::string & kernel_name,
114 : const std::string & name,
115 : InputParameters & parameters)
116 : {
117 : parallel_object_only();
118 :
119 800 : const auto sys_num = determineSolverSystem(parameters.varName("variable", name), true).second;
120 400 : if (isSolverSystemNonlinear(sys_num))
121 0 : mooseError("You are trying to add a LinearFVKernel to a nonlinear variable/system, which is "
122 : "not supported.");
123 :
124 800 : parameters.set<SubProblem *>("_subproblem") = this;
125 1200 : parameters.set<SystemBase *>("_sys") = _linear_systems[sys_num - _num_nl_sys].get();
126 :
127 400 : logAdd("KokkosLinearFVKernel", name, kernel_name, parameters);
128 400 : _linear_systems[sys_num - _num_nl_sys]->addKokkosKernel(kernel_name, name, parameters);
129 :
130 400 : _mesh.getKokkosMesh()->setNeedsElementSideGeometry();
131 :
132 400 : _has_kokkos_objects = true;
133 400 : _has_kokkos_residual_objects = true;
134 400 : }
135 :
136 : void
137 339 : FEProblemBase::addKokkosLinearFVBC(const std::string & bc_name,
138 : const std::string & name,
139 : InputParameters & parameters)
140 : {
141 : parallel_object_only();
142 :
143 678 : const auto sys_num = determineSolverSystem(parameters.varName("variable", name), true).second;
144 339 : if (isSolverSystemNonlinear(sys_num))
145 0 : mooseError("You are trying to add a LinearFVBoundaryCondition to a nonlinear variable/system, "
146 : "which is not supported.");
147 :
148 678 : parameters.set<SubProblem *>("_subproblem") = this;
149 1017 : parameters.set<SystemBase *>("_sys") = _linear_systems[sys_num - _num_nl_sys].get();
150 :
151 339 : logAdd("KokkosLinearFVBoundaryCondition", name, bc_name, parameters);
152 339 : _linear_systems[sys_num - _num_nl_sys]->addKokkosBoundaryCondition(bc_name, name, parameters);
153 :
154 339 : _mesh.getKokkosMesh()->setNeedsElementSideGeometry();
155 :
156 339 : _has_kokkos_objects = true;
157 339 : _has_kokkos_residual_objects = true;
158 339 : }
159 :
160 : void
161 636 : FEProblemBase::addKokkosAuxKernel(const std::string & kernel_name,
162 : const std::string & name,
163 : InputParameters & parameters)
164 : {
165 : parallel_object_only();
166 :
167 636 : setAuxKernelParamsAndLog(kernel_name, name, parameters, "KokkosAuxKernel");
168 :
169 636 : _aux->addKokkosKernel(kernel_name, name, parameters);
170 :
171 636 : _has_kokkos_objects = true;
172 636 : }
173 :
174 : void
175 922 : FEProblemBase::addKokkosFunction(const std::string & type,
176 : const std::string & name,
177 : InputParameters & parameters)
178 : {
179 : parallel_object_only();
180 :
181 1844 : parameters.set<SubProblem *>("_subproblem") = this;
182 :
183 368 : std::shared_ptr<Moose::FunctionBase> func =
184 554 : _factory.create<Moose::FunctionBase>(type, name, parameters);
185 922 : logAdd("KokkosFunction", name, type, parameters);
186 922 : _kokkos_functions.addObject(func);
187 :
188 922 : _has_kokkos_objects = true;
189 922 : }
190 :
191 : bool
192 1061 : FEProblemBase::hasKokkosFunction(const std::string & name) const
193 : {
194 1061 : return _kokkos_functions.hasActiveObject(name);
195 : }
196 :
197 : Moose::Kokkos::Function
198 117 : FEProblemBase::getKokkosFunction(const std::string & name)
199 : {
200 : #ifdef MOOSE_ENABLE_KOKKOS_GPU
201 0 : mooseError("Retrieving a Kokkos function as abstract type is currently not supported for GPU.");
202 : #endif
203 :
204 117 : const auto & function = getKokkosFunction<Moose::FunctionBase>(name);
205 :
206 : std::shared_ptr<Moose::Kokkos::FunctionWrapperHostBase> wrapper =
207 117 : Moose::Kokkos::FunctorRegistry::buildFunction(&function, function.type());
208 :
209 234 : return Moose::Kokkos::Function(wrapper);
210 117 : }
211 :
212 : void
213 1037 : FEProblemBase::addKokkosPostprocessor(const std::string & pp_name,
214 : const std::string & name,
215 : InputParameters & parameters)
216 : {
217 1037 : checkUserObjectNameCollision(name, "KokkosPostprocessor");
218 :
219 1037 : addKokkosUserObject(pp_name, name, parameters);
220 1037 : }
221 :
222 : void
223 169 : FEProblemBase::addKokkosVectorPostprocessor(const std::string & pp_name,
224 : const std::string & name,
225 : InputParameters & parameters)
226 : {
227 169 : checkUserObjectNameCollision(name, "KokkosVectorPostprocessor");
228 :
229 169 : addKokkosUserObject(pp_name, name, parameters);
230 169 : }
231 :
232 : void
233 34 : FEProblemBase::addKokkosReporter(const std::string & pp_name,
234 : const std::string & name,
235 : InputParameters & parameters)
236 : {
237 34 : checkUserObjectNameCollision(name, "KokkosReporter");
238 :
239 34 : addKokkosUserObject(pp_name, name, parameters);
240 34 : }
241 :
242 : void
243 1240 : FEProblemBase::addKokkosUserObject(const std::string & user_object_name,
244 : const std::string & name,
245 : InputParameters & parameters)
246 : {
247 : parallel_object_only();
248 :
249 : // Add the _subproblem and _sys parameters depending on use_displaced_mesh
250 1240 : addObjectParamsHelper(parameters, name);
251 :
252 : // Create the UserObject
253 559 : std::shared_ptr<UserObjectBase> user_object =
254 681 : _factory.create<UserObjectBase>(user_object_name, name, parameters);
255 1240 : logAdd("KokkosUserObject", name, user_object_name, parameters);
256 :
257 1240 : theWarehouse().add(user_object);
258 :
259 1240 : _has_kokkos_objects = true;
260 1240 : }
261 :
262 : bool
263 57885 : FEProblemBase::hasKokkosUserObject(const std::string & name) const
264 : {
265 57885 : std::vector<UserObjectBase *> objs;
266 57885 : theWarehouse()
267 112246 : .query()
268 56123 : .condition<AttribSystem>("KokkosUserObject")
269 56123 : .condition<AttribName>(name)
270 56123 : .queryInto(objs);
271 115770 : return !objs.empty();
272 57885 : }
273 :
274 : void
275 942 : FEProblemBase::addKokkosMaterial(const std::string & mat_name,
276 : const std::string & name,
277 : InputParameters & parameters)
278 : {
279 1884 : addMaterialHelper({&_kokkos_materials}, mat_name, name, parameters);
280 :
281 934 : _has_kokkos_objects = true;
282 934 : }
283 :
284 : MaterialData &
285 25045 : FEProblemBase::getKokkosMaterialData(Moose::MaterialDataType type, const MooseObject * object) const
286 : {
287 25045 : switch (type)
288 : {
289 13755 : case Moose::BLOCK_MATERIAL_DATA:
290 13755 : if (object)
291 5438 : _kokkos_material_props.addConsumer(type, object);
292 13755 : return _kokkos_material_props.getMaterialData(0);
293 913 : case Moose::NEIGHBOR_MATERIAL_DATA:
294 913 : if (object)
295 913 : _kokkos_neighbor_material_props.addConsumer(type, object);
296 913 : return _kokkos_neighbor_material_props.getMaterialData(0);
297 10377 : case Moose::BOUNDARY_MATERIAL_DATA:
298 : case Moose::FACE_MATERIAL_DATA:
299 : case Moose::INTERFACE_MATERIAL_DATA:
300 10377 : if (object)
301 1743 : _kokkos_bnd_material_props.addConsumer(type, object);
302 10377 : return _kokkos_bnd_material_props.getMaterialData(0);
303 : }
304 :
305 0 : mooseError("FEProblemBase::getKokkosMaterialData(): Invalid MaterialDataType ", type);
306 : }
307 :
308 : const std::set<const MooseObject *> &
309 2460 : FEProblemBase::getKokkosMaterialPropertyStorageConsumers(Moose::MaterialDataType type) const
310 : {
311 2460 : switch (type)
312 : {
313 0 : case Moose::BLOCK_MATERIAL_DATA:
314 0 : return _kokkos_material_props.getConsumers(type);
315 0 : case Moose::NEIGHBOR_MATERIAL_DATA:
316 0 : return _kokkos_neighbor_material_props.getConsumers(type);
317 2460 : case Moose::BOUNDARY_MATERIAL_DATA:
318 : case Moose::FACE_MATERIAL_DATA:
319 : case Moose::INTERFACE_MATERIAL_DATA:
320 2460 : return _kokkos_bnd_material_props.getConsumers(type);
321 : }
322 :
323 0 : mooseError(
324 : "FEProblemBase::getKokkosMaterialPropertyStorageConsumers(): Invalid MaterialDataType ",
325 : type);
326 : }
327 :
328 : void
329 2460 : FEProblemBase::initKokkos()
330 : {
331 12300 : TIME_SECTION("InitializeKokkos", 1, "Initializing Kokkos");
332 :
333 : // Error on unsupported options
334 :
335 2460 : if (haveDisplaced())
336 0 : mooseError("Kokkos does not support displaced mesh yet.");
337 :
338 2460 : if (adaptivity().isOn())
339 0 : mooseError("Kokkos does not support adaptivity yet.");
340 :
341 : // Initialize Kokkos mesh
342 2460 : _mesh.getKokkosMesh()->update();
343 :
344 : // Initialize Kokkos assembly
345 2460 : _kokkos_assembly.init();
346 :
347 : // Call functions that require Kokkos mesh to be initialized first
348 22101 : for (auto hook : _kokkos_mesh_initialization_hooks)
349 19641 : hook();
350 :
351 : // Initialize Kokkos systems
352 :
353 2460 : unsigned int max_system_number = 0;
354 :
355 4754 : for (unsigned int s = 0; s < numNonlinearSystems(); ++s)
356 2294 : max_system_number = std::max(max_system_number, getNonlinearSystemBase(s).number());
357 :
358 2655 : for (unsigned int s = 0; s < numLinearSystems(); ++s)
359 195 : max_system_number = std::max(max_system_number, getLinearSystem(s).number());
360 :
361 2460 : max_system_number = std::max(max_system_number, getAuxiliarySystem().number());
362 :
363 : // Allocate Kokkos system infrastructure per-system based on what each system needs.
364 : // Both arrays are pre-created; placement-new fills only the slots each system requires.
365 :
366 2460 : _kokkos_systems.create<false>(max_system_number + 1);
367 2460 : _kokkos_fe_systems.create<false>(max_system_number + 1);
368 :
369 4949 : auto allocate_system = [&](::SystemBase & sys)
370 : {
371 4949 : if (!sys.nVariables())
372 1755 : return;
373 :
374 3194 : const auto sys_num = sys.number();
375 :
376 : // Scan variables to determine what Kokkos infrastructure this system needs.
377 : // needs_fe: at least one variable precomputes QP-indexed solution arrays
378 : // -> system needs a Kokkos::FESystem.
379 : // needs_fv: at least one variable assembles via the FV path (ElemInfo/FaceInfo,
380 : // no QP reinit) -> system needs a standalone Kokkos::System.
381 : // Both false (scalar-only): FESystem is absent, so FESystem's inherited
382 : // Kokkos::System cannot serve as the system entry; a standalone Kokkos::System
383 : // is still required.
384 3194 : bool needs_fv = false;
385 3194 : bool needs_fe = false;
386 :
387 7355 : for (const auto v : make_range(sys.nFieldVariables()))
388 : {
389 4210 : const auto & var = sys.getVariable(0, v);
390 4210 : if (var.supportsQpBasedLoops())
391 4035 : needs_fe = true;
392 4210 : if (var.supportsGeometricInfoBasedLoops())
393 224 : needs_fv = true;
394 4210 : if (needs_fv && needs_fe)
395 49 : break;
396 : }
397 :
398 3194 : if (!needs_fe)
399 : // No FE/QP-based variables: allocate a plain Kokkos::System. Covers FV-only and
400 : // scalar-only.
401 157 : _kokkos_systems.emplace({sys_num}, sys);
402 3037 : else if (needs_fv)
403 : {
404 : // Mixed FV + FE/QP: construct Kokkos::System first, then FESystem via the
405 : // sharing constructor so both objects operate on the same device memory.
406 : // FV kernels write through Kokkos::System; FE/QP kernels read and write
407 : // through FESystem; shared device pointers keep them consistent.
408 49 : _kokkos_systems.emplace({sys_num}, sys);
409 49 : _kokkos_fe_systems.emplace({sys_num}, _kokkos_systems[sys_num], sys);
410 : }
411 : else
412 : // Pure FE/QP (or FE/QP + scalar): FESystem inherits Kokkos::System, so a standalone
413 : // FESystem is self-contained. No separate Kokkos::System entry is needed;
414 : // scalar variable data is accessible through the inherited base.
415 2988 : _kokkos_fe_systems.emplace({sys_num}, sys);
416 2460 : };
417 :
418 4754 : for (unsigned int s = 0; s < numNonlinearSystems(); ++s)
419 2294 : allocate_system(getNonlinearSystemBase(s));
420 2655 : for (unsigned int s = 0; s < numLinearSystems(); ++s)
421 195 : allocate_system(getLinearSystem(s));
422 2460 : allocate_system(getAuxiliarySystem());
423 :
424 : // Initialize Kokkos material properties
425 :
426 2460 : _kokkos_material_props.allocateKokkosProperties();
427 2460 : _kokkos_bnd_material_props.allocateKokkosProperties();
428 2460 : _kokkos_neighbor_material_props.allocateKokkosProperties();
429 2460 : }
430 :
431 : void
432 781 : FEProblemBase::initKokkosStatefulProps()
433 : {
434 : // Resolve dependencies
435 :
436 781 : std::set<MooseVariableFieldBase *> needed_moose_vars;
437 781 : std::set<TagID> needed_fe_var_vector_tags;
438 :
439 781 : _kokkos_materials.updateVariableDependency(needed_moose_vars);
440 781 : _kokkos_materials.updateFEVariableCoupledVectorTagDependency(needed_fe_var_vector_tags);
441 :
442 : // Copy data and preallocate quadrature point solution vectors
443 :
444 3175 : for (auto & system : _kokkos_fe_systems.constructedEntries())
445 : {
446 1197 : system.setActiveVariables(needed_moose_vars);
447 1197 : system.setActiveSolutionTags(needed_fe_var_vector_tags);
448 :
449 1197 : system.sync(Moose::Kokkos::MemcpyType::HOST_TO_DEVICE);
450 1197 : system.reinit();
451 : }
452 :
453 781 : _kokkos_fe_systems.copyToDevice();
454 :
455 : // Initialize stateful properties
456 :
457 1910 : for (auto & material : _kokkos_materials.getActiveObjects())
458 1129 : if (!material->hasRestoredProperties() && !material->boundaryRestricted())
459 1060 : material->initStatefulProperties(0);
460 :
461 1878 : for (auto & material : _kokkos_materials[Moose::FACE_MATERIAL_DATA].getActiveObjects())
462 1097 : if (!material->hasRestoredProperties())
463 1058 : material->initStatefulProperties(0);
464 :
465 1878 : for (auto & material : _kokkos_materials[Moose::NEIGHBOR_MATERIAL_DATA].getActiveObjects())
466 1097 : if (!material->hasRestoredProperties())
467 1060 : material->initStatefulProperties(0);
468 :
469 1910 : for (auto & material : _kokkos_materials.getActiveObjects())
470 1129 : if (!material->hasRestoredProperties() && material->boundaryRestricted())
471 30 : material->initStatefulProperties(0);
472 :
473 : // Copy to old and older states
474 :
475 781 : _kokkos_material_props.copy();
476 781 : _kokkos_bnd_material_props.copy();
477 781 : _kokkos_neighbor_material_props.copy();
478 :
479 : // Clear
480 :
481 3175 : for (auto & system : _kokkos_fe_systems.constructedEntries())
482 : {
483 1197 : system.sync(Moose::Kokkos::MemcpyType::DEVICE_TO_HOST);
484 :
485 1197 : system.clearActiveVariables();
486 1197 : system.clearActiveSolutionTags();
487 : }
488 781 : }
489 :
490 : void
491 23139 : FEProblemBase::prepareKokkosMaterials(
492 : const std::unordered_set<unsigned int> & consumer_needed_mat_props)
493 : {
494 23139 : auto needed_mat_props = consumer_needed_mat_props;
495 :
496 23139 : _kokkos_materials.updateMatPropDependency(needed_mat_props, 0, true);
497 :
498 23139 : setActiveMaterialProperties(needed_mat_props, 0);
499 23139 : }
500 :
501 : void
502 23139 : FEProblemBase::reinitKokkosMaterials()
503 : {
504 23139 : if (hasActiveMaterialProperties(0))
505 : {
506 52260 : for (auto & material : _kokkos_materials.getActiveObjects())
507 29121 : if (material->hasActiveProperties() && !material->boundaryRestricted())
508 27544 : material->computeProperties();
509 :
510 50908 : for (auto & material : _kokkos_materials[Moose::FACE_MATERIAL_DATA].getActiveObjects())
511 27769 : if (material->hasActiveProperties())
512 27544 : material->computeProperties();
513 :
514 50908 : for (auto & material : _kokkos_materials[Moose::NEIGHBOR_MATERIAL_DATA].getActiveObjects())
515 27769 : if (material->hasActiveProperties())
516 27544 : material->computeProperties();
517 :
518 52260 : for (auto & material : _kokkos_materials.getActiveObjects())
519 29121 : if (material->hasActiveProperties() && material->boundaryRestricted())
520 1352 : material->computeProperties();
521 : }
522 23139 : }
523 :
524 : void
525 214033 : FEProblemBase::computeKokkosUserObjectsInternal(const ExecFlagType & type,
526 : TheWarehouse::Query & query)
527 : {
528 : try
529 : {
530 1070165 : TIME_SECTION("computeKokkosUserObjects", 1, "Computing Kokkos User Objects");
531 :
532 : // Query everything first to obtain a list of execution groups
533 :
534 214033 : std::vector<Moose::Kokkos::UserObject *> uos;
535 214033 : query.clone().queryIntoUnsorted(uos);
536 :
537 214033 : if (!uos.size())
538 212220 : return;
539 :
540 : // Resolve dependencies
541 :
542 1813 : std::set<MooseVariableFEBase *> needed_moose_vars;
543 1813 : std::unordered_set<unsigned int> needed_mat_props;
544 1813 : std::set<TagID> needed_fe_var_vector_tags;
545 :
546 4275 : for (const auto uo : uos)
547 : {
548 2462 : auto v_uo = dynamic_cast<MooseVariableDependencyInterface *>(uo);
549 2462 : if (v_uo)
550 : {
551 2462 : const auto & v_deps = v_uo->getMooseVariableDependencies();
552 2462 : needed_moose_vars.insert(v_deps.begin(), v_deps.end());
553 : }
554 :
555 2462 : auto m_uo = dynamic_cast<MaterialPropertyInterface *>(uo);
556 2462 : if (m_uo)
557 : {
558 1663 : auto & m_deps = m_uo->getMatPropDependencies();
559 1663 : needed_mat_props.insert(m_deps.begin(), m_deps.end());
560 : }
561 :
562 2462 : auto c_uo = dynamic_cast<Coupleable *>(uo);
563 2462 : if (c_uo)
564 : {
565 2462 : const auto & tag_deps = c_uo->getFEVariableCoupleableVectorTags();
566 2462 : needed_fe_var_vector_tags.insert(tag_deps.begin(), tag_deps.end());
567 : }
568 : }
569 :
570 1813 : if (needed_mat_props.size())
571 : {
572 147 : _kokkos_materials.updateVariableDependency(needed_moose_vars);
573 147 : _kokkos_materials.updateFEVariableCoupledVectorTagDependency(needed_fe_var_vector_tags);
574 : }
575 :
576 : // Copy vectors and cache variable values at element quadrature points
577 :
578 4327 : for (auto & system : _kokkos_fe_systems.constructedEntries())
579 : {
580 2514 : system.setActiveVariables(needed_moose_vars);
581 2514 : system.setActiveSolutionTags(needed_fe_var_vector_tags);
582 :
583 : {
584 7542 : TIME_SECTION("KokkosCopy", 1);
585 2514 : system.sync(Moose::Kokkos::MemcpyType::HOST_TO_DEVICE);
586 2514 : }
587 : {
588 7542 : TIME_SECTION("KokkosReinit", 1);
589 2514 : system.reinit();
590 2514 : }
591 : }
592 :
593 1813 : _kokkos_fe_systems.copyToDevice();
594 :
595 : {
596 5439 : TIME_SECTION("KokkosMaterial", 1);
597 :
598 : // Compute material properties
599 :
600 1813 : if (needed_mat_props.size())
601 : {
602 147 : prepareKokkosMaterials(needed_mat_props);
603 147 : reinitKokkosMaterials();
604 : }
605 1813 : }
606 :
607 : {
608 5439 : TIME_SECTION("KokkosUserObject", 1);
609 :
610 : // Compute user objects
611 :
612 1813 : if (type == EXEC_LINEAR)
613 0 : for (auto obj : uos)
614 0 : obj->residualSetup();
615 1813 : else if (type == EXEC_NONLINEAR)
616 0 : for (auto obj : uos)
617 0 : obj->jacobianSetup();
618 :
619 4275 : for (auto obj : uos)
620 2462 : obj->initialize();
621 :
622 4275 : for (auto obj : uos)
623 2462 : obj->compute();
624 :
625 1813 : kokkosJoinAndFinalize(uos);
626 1813 : }
627 :
628 : // Close and restore vectors
629 :
630 : {
631 5439 : TIME_SECTION("KokkosCopy", 1);
632 :
633 4327 : for (auto & system : _kokkos_fe_systems.constructedEntries())
634 2514 : system.sync(Moose::Kokkos::MemcpyType::DEVICE_TO_HOST);
635 1813 : }
636 :
637 : // Clear
638 :
639 4327 : for (auto & system : _kokkos_fe_systems.constructedEntries())
640 : {
641 2514 : system.clearActiveVariables();
642 2514 : system.clearActiveSolutionTags();
643 : }
644 426253 : }
645 0 : catch (...)
646 : {
647 0 : handleException("computeKokkosUserObjectsInternal");
648 0 : }
649 : }
650 :
651 : void
652 1813 : FEProblemBase::kokkosJoinAndFinalize(const std::vector<Moose::Kokkos::UserObject *> & userobjs)
653 : {
654 4275 : for (auto obj : userobjs)
655 : {
656 2462 : obj->finalize();
657 :
658 2462 : auto pp = dynamic_cast<const Moose::Kokkos::Postprocessor *>(obj);
659 2462 : if (pp)
660 : {
661 2269 : _reporter_data.finalize(obj->name());
662 2269 : setPostprocessorValueByName(obj->name(), pp->getValue());
663 : }
664 :
665 2462 : auto vpp = dynamic_cast<Moose::Kokkos::VectorPostprocessor *>(obj);
666 2462 : if (vpp)
667 163 : _reporter_data.finalize(obj->name());
668 :
669 2462 : auto reporter = dynamic_cast<Moose::Kokkos::Reporter *>(obj);
670 2462 : if (reporter)
671 30 : _reporter_data.finalize(obj->name());
672 : }
673 1813 : }
|