Skip to content

Commit bb82c82

Browse files
[arcane,accelerator] Ajoute support des 'RUNCOMMAND_MAT_ENUMERATE' sur les 'MatCell'.
1 parent 0724167 commit bb82c82

File tree

2 files changed

+272
-6
lines changed

2 files changed

+272
-6
lines changed

arcane/src/arcane/accelerator/RunCommandMaterialEnumerate.h

Lines changed: 269 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
// -*- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature -*-
22
//-----------------------------------------------------------------------------
3-
// Copyright 2000-2023 CEA (www.cea.fr) IFPEN (www.ifpenergiesnouvelles.com)
3+
// Copyright 2000-2024 CEA (www.cea.fr) IFPEN (www.ifpenergiesnouvelles.com)
44
// See the top-level COPYRIGHT file for details.
55
// SPDX-License-Identifier: Apache-2.0
66
//-----------------------------------------------------------------------------
77
/*---------------------------------------------------------------------------*/
8-
/* RunCommandMaterialEnumerate.h (C) 2000-2023 */
8+
/* RunCommandMaterialEnumerate.h (C) 2000-2024 */
99
/* */
1010
/* Helpers et macros pour exécuter une boucle sur une liste d'envcell */
1111
/*---------------------------------------------------------------------------*/
@@ -150,6 +150,71 @@ class EnvCellRunCommand
150150
Container m_items;
151151
};
152152

153+
/*---------------------------------------------------------------------------*/
154+
/*---------------------------------------------------------------------------*/
155+
/*!
156+
* \brief Commande pour itérer sur les MatCell.
157+
*/
158+
class MatCellRunCommand
159+
{
160+
public:
161+
162+
using MatCellVectorView = Arcane::Materials::MatCellVectorView;
163+
using ComponentItemVectorView = Arcane::Materials::ComponentItemVectorView;
164+
using IMeshMaterial = Arcane::Materials::IMeshMaterial;
165+
using ComponentItemLocalId = Arcane::Materials::ComponentItemLocalId;
166+
using MatVarIndex = Arcane::Materials::MatVarIndex;
167+
168+
public:
169+
170+
/*!
171+
* \brief Conteneur contenant les informations nécessaires pour la commande.
172+
*/
173+
class Container
174+
: public impl::MatCommandContainerBase
175+
{
176+
public:
177+
178+
explicit Container(IMeshMaterial* mat)
179+
: impl::MatCommandContainerBase(mat->matView())
180+
{
181+
}
182+
explicit Container(MatCellVectorView view)
183+
: impl::MatCommandContainerBase(view)
184+
{
185+
}
186+
187+
public:
188+
189+
MatCellRunCommand createCommand(RunCommand& run_command) const
190+
{
191+
return MatCellRunCommand(run_command, *this);
192+
}
193+
194+
public:
195+
196+
//! Accesseur pour le i-ème élément de la liste
197+
constexpr ARCCORE_HOST_DEVICE ComponentItemLocalId operator[](Int32 i) const
198+
{
199+
return { ComponentItemLocalId(m_matvar_indexes[i]) };
200+
}
201+
};
202+
203+
private:
204+
205+
// Uniquement appelable depuis 'Container'
206+
explicit MatCellRunCommand(RunCommand& command, const Container& items)
207+
: m_command(command)
208+
, m_items(items)
209+
{
210+
}
211+
212+
public:
213+
214+
RunCommand& m_command;
215+
Container m_items;
216+
};
217+
153218
/*---------------------------------------------------------------------------*/
154219
/*---------------------------------------------------------------------------*/
155220
/*!
@@ -268,6 +333,124 @@ class EnvAndGlobalCellRunCommand
268333
Container m_items;
269334
};
270335

336+
/*---------------------------------------------------------------------------*/
337+
/*---------------------------------------------------------------------------*/
338+
/*!
339+
* \brief Commande pour itérer sur les MatCell et récupérer aussi l'information
340+
* sur la maille globale associée.
341+
*/
342+
class MatAndGlobalCellRunCommand
343+
{
344+
public:
345+
346+
using MatCellVectorView = Arcane::Materials::MatCellVectorView;
347+
using ComponentItemVectorView = Arcane::Materials::ComponentItemVectorView;
348+
using IMeshMaterial = Arcane::Materials::IMeshMaterial;
349+
using ComponentItemLocalId = Arcane::Materials::ComponentItemLocalId;
350+
using MatVarIndex = Arcane::Materials::MatVarIndex;
351+
352+
public:
353+
354+
/*!
355+
* \brief Classe helper pour l'accès au MatVarIndex et au CellLocalId à travers les
356+
* RUNCOMMAND_MAT_ENUMERATE(EnvAndGlobalCell...
357+
*/
358+
class Accessor
359+
{
360+
361+
public:
362+
363+
//! Struct interne simple pour éviter l'usage d'un std::tuple pour l'opérateur()
364+
struct Data
365+
{
366+
ComponentItemLocalId m_mvi;
367+
CellLocalId m_cid;
368+
};
369+
370+
public:
371+
372+
constexpr ARCCORE_HOST_DEVICE Accessor(ComponentItemLocalId mvi, CellLocalId cid)
373+
: m_internal_data{ mvi, cid }
374+
{
375+
}
376+
377+
/*!
378+
* \brief Cet opérateur permet de renvoyer le couple [MatVarIndex, LocalCellId].
379+
*
380+
* L'utilisation classique est :
381+
*
382+
* \code
383+
* cmd << RUNCOMMAND_MAT_ENUMERATE(EnvAndGlobalCell, evi, envcellsv) {
384+
* auto [mvi, cid] = evi();
385+
* }
386+
* \endcode
387+
*
388+
* où evi est le type de cette classe
389+
*/
390+
ARCCORE_HOST_DEVICE Data operator()()
391+
{
392+
return { m_internal_data.m_mvi, m_internal_data.m_cid };
393+
}
394+
395+
///! Accesseur sur la partie MatVarIndex
396+
ARCCORE_HOST_DEVICE ComponentItemLocalId varIndex() { return m_internal_data.m_mvi; };
397+
398+
///! Accesseur sur la partie cell local id
399+
ARCCORE_HOST_DEVICE CellLocalId globalCellId() { return m_internal_data.m_cid; }
400+
401+
private:
402+
403+
Data m_internal_data;
404+
};
405+
406+
/*!
407+
* \brief Conteneur contenant les informations nécessaires pour la commande.
408+
*/
409+
class Container
410+
: public impl::MatCommandContainerBase
411+
{
412+
public:
413+
414+
explicit Container(IMeshMaterial* env)
415+
: impl::MatCommandContainerBase(env->matView())
416+
{
417+
}
418+
explicit Container(MatCellVectorView view)
419+
: impl::MatCommandContainerBase(view)
420+
{
421+
}
422+
423+
public:
424+
425+
MatAndGlobalCellRunCommand createCommand(RunCommand& run_command) const
426+
{
427+
return MatAndGlobalCellRunCommand(run_command, *this);
428+
}
429+
430+
public:
431+
432+
//! Accesseur pour le i-ème élément de la liste
433+
constexpr ARCCORE_HOST_DEVICE Accessor operator[](Int32 i) const
434+
{
435+
return { ComponentItemLocalId(m_matvar_indexes[i]), CellLocalId(m_global_cells_local_id[i]) };
436+
}
437+
};
438+
439+
private:
440+
441+
// Uniquement appelable depuis 'Container'
442+
explicit MatAndGlobalCellRunCommand(RunCommand& command, const Container& items)
443+
: m_command(command)
444+
, m_items(items)
445+
{
446+
}
447+
448+
public:
449+
450+
RunCommand& m_command;
451+
Container m_items;
452+
};
453+
271454
/*---------------------------------------------------------------------------*/
272455
/*---------------------------------------------------------------------------*/
273456

@@ -295,6 +478,30 @@ class RunCommandMatItemEnumeratorTraitsT<Arcane::Materials::EnvAndGlobalCell>
295478
/*---------------------------------------------------------------------------*/
296479
/*---------------------------------------------------------------------------*/
297480

481+
//! Spécialisation pour une vue sur un matériau et la maille globale associée
482+
template <>
483+
class RunCommandMatItemEnumeratorTraitsT<Arcane::Materials::MatAndGlobalCell>
484+
{
485+
public:
486+
487+
using EnumeratorType = MatAndGlobalCellRunCommand::Accessor;
488+
using ContainerType = MatAndGlobalCellRunCommand::Container;
489+
490+
public:
491+
492+
static ContainerType createContainer(const Arcane::Materials::MatCellVectorView& items)
493+
{
494+
return ContainerType{ items };
495+
}
496+
static ContainerType createContainer(Arcane::Materials::IMeshMaterial* env)
497+
{
498+
return ContainerType{ env };
499+
}
500+
};
501+
502+
/*---------------------------------------------------------------------------*/
503+
/*---------------------------------------------------------------------------*/
504+
298505
//! Spécialisation pour une vue sur un milieu.
299506
template <>
300507
class RunCommandMatItemEnumeratorTraitsT<Arcane::Materials::EnvCell>
@@ -319,6 +526,30 @@ class RunCommandMatItemEnumeratorTraitsT<Arcane::Materials::EnvCell>
319526
/*---------------------------------------------------------------------------*/
320527
/*---------------------------------------------------------------------------*/
321528

529+
//! Spécialisation pour une vue sur un matériau
530+
template <>
531+
class RunCommandMatItemEnumeratorTraitsT<Arcane::Materials::MatCell>
532+
{
533+
public:
534+
535+
using EnumeratorType = Arcane::Materials::ComponentItemLocalId;
536+
using ContainerType = MatCellRunCommand::Container;
537+
538+
public:
539+
540+
static ContainerType createContainer(const Arcane::Materials::MatCellVectorView& items)
541+
{
542+
return ContainerType{ items };
543+
}
544+
static ContainerType createContainer(Arcane::Materials::IMeshMaterial* mat)
545+
{
546+
return ContainerType{ mat };
547+
}
548+
};
549+
550+
/*---------------------------------------------------------------------------*/
551+
/*---------------------------------------------------------------------------*/
552+
322553
} // namespace Arcane::Accelerator
323554

324555
/*---------------------------------------------------------------------------*/
@@ -351,9 +582,13 @@ doMatContainerGPULambda(ContainerType items, Lambda func)
351582
/*---------------------------------------------------------------------------*/
352583
/*---------------------------------------------------------------------------*/
353584
/*!
354-
* \brief Applique l'enumération \a func sur la liste d'entité \a items.
585+
* \brief Applique l'énumération \a func sur la liste d'entité \a items.
355586
*
356-
* Le container peut être issu de EnvAndGlobalCellRunCommand ou 'EnvCellRunCommand.
587+
* Le conteneur peut être issu de:
588+
* - EnvAndGlobalCellRunCommand
589+
* - EnvCellRunCommand
590+
* - MatAndGlobalCellRunCommand
591+
* - MatCellRunCommand
357592
*/
358593
template <typename ContainerType, typename Lambda> void
359594
_applyEnvCells(RunCommand& command, ContainerType items, const Lambda& func)
@@ -406,6 +641,21 @@ namespace Arcane::Accelerator
406641
/*---------------------------------------------------------------------------*/
407642
/*---------------------------------------------------------------------------*/
408643

644+
inline MatAndGlobalCellRunCommand
645+
operator<<(RunCommand& command, const MatAndGlobalCellRunCommand::Container& view)
646+
{
647+
return view.createCommand(command);
648+
}
649+
650+
template <typename Lambda>
651+
void operator<<(MatAndGlobalCellRunCommand&& nr, const Lambda& func)
652+
{
653+
impl::_applyEnvCells(nr.m_command, nr.m_items, func);
654+
}
655+
656+
/*---------------------------------------------------------------------------*/
657+
/*---------------------------------------------------------------------------*/
658+
409659
inline EnvAndGlobalCellRunCommand
410660
operator<<(RunCommand& command, const EnvAndGlobalCellRunCommand::Container& view)
411661
{
@@ -436,6 +686,21 @@ void operator<<(EnvCellRunCommand&& nr, const Lambda& func)
436686
/*---------------------------------------------------------------------------*/
437687
/*---------------------------------------------------------------------------*/
438688

689+
inline MatCellRunCommand
690+
operator<<(RunCommand& command, const MatCellRunCommand::Container& view)
691+
{
692+
return view.createCommand(command);
693+
}
694+
695+
template <typename Lambda>
696+
void operator<<(MatCellRunCommand&& nr, const Lambda& func)
697+
{
698+
impl::_applyEnvCells(nr.m_command, nr.m_items, func);
699+
}
700+
701+
/*---------------------------------------------------------------------------*/
702+
/*---------------------------------------------------------------------------*/
703+
439704
} // End namespace Arcane::Accelerator
440705

441706
/*---------------------------------------------------------------------------*/

arcane/src/arcane/core/materials/MaterialsCoreGlobal.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
// -*- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature -*-
22
//-----------------------------------------------------------------------------
3-
// Copyright 2000-2023 CEA (www.cea.fr) IFPEN (www.ifpenergiesnouvelles.com)
3+
// Copyright 2000-2024 CEA (www.cea.fr) IFPEN (www.ifpenergiesnouvelles.com)
44
// See the top-level COPYRIGHT file for details.
55
// SPDX-License-Identifier: Apache-2.0
66
//-----------------------------------------------------------------------------
77
/*---------------------------------------------------------------------------*/
8-
/* MaterialsCoreGlobal.h (C) 2000-2023 */
8+
/* MaterialsCoreGlobal.h (C) 2000-2024 */
99
/* */
1010
/* Déclarations générales des matériaux de Arcane. */
1111
/*---------------------------------------------------------------------------*/
@@ -80,6 +80,7 @@ class MaterialVariableBuildInfo;
8080
class MaterialVariableTypeInfo;
8181
class MeshMaterialVariableRef;
8282
class EnvAndGlobalCell {};
83+
class MatAndGlobalCell {};
8384
class IMeshMaterialMngInternal;
8485
class MeshEnvironmentBuildInfo;
8586
class MeshBlockBuildInfo;

0 commit comments

Comments
 (0)