12#ifndef ARCANE_ACCELERATOR_RUNCOMMANDMATERIALENUMERATE_H
13#define ARCANE_ACCELERATOR_RUNCOMMANDMATERIALENUMERATE_H
18#include "arcane/core/materials/ComponentItemVectorView.h"
19#include "arcane/core/materials/MaterialsCoreGlobal.h"
20#include "arcane/core/materials/MatItem.h"
22#include "arcane/core/materials/ConstituentItemIndexedSelectionView.h"
24#include "arcane/accelerator/KernelLauncher.h"
25#include "arcane/accelerator/RunCommand.h"
26#include "arcane/accelerator/RunCommandLaunchInfo.h"
28#include "arccore/common/HostKernelRemainingArgsHelper.h"
45template <
typename ConstituentItemLocalIdType_>
46class ConstituentAndGlobalCellIteratorValue
50 using ConstituentItemLocalIdType = ConstituentItemLocalIdType_;
51 using ComponentItemLocalId = Arcane::Materials::ComponentItemLocalId;
61 constexpr ARCCORE_HOST_DEVICE Data(ConstituentItemLocalIdType mvi, CellLocalId cid)
68 ConstituentItemLocalIdType m_mvi;
74 constexpr ARCCORE_HOST_DEVICE ConstituentAndGlobalCellIteratorValue(ConstituentItemLocalIdType mvi, CellLocalId cid,
Int32 index)
75 : m_internal_data{ mvi, cid }
100 return m_internal_data;
104 constexpr ARCCORE_HOST_DEVICE ConstituentItemLocalIdType
varIndex()
const {
return m_internal_data.m_mvi; };
107 constexpr ARCCORE_HOST_DEVICE CellLocalId
globalCellId()
const {
return m_internal_data.m_cid; }
110 constexpr ARCCORE_HOST_DEVICE
Int32 index()
const {
return m_index; }
114 Data m_internal_data;
132namespace Arcane::Accelerator::Impl
140template <
typename ContainerType_>
141class ConstituentRunCommandBase2
145 using ContainerType = ContainerType_;
146 using ThatClass = ConstituentRunCommandBase2<ContainerType_>;
147 using CommandType = ThatClass;
151 static CommandType create(
RunCommand& run_command,
const ContainerType& items)
153 return CommandType(run_command, items);
159 explicit ConstituentRunCommandBase2(
RunCommand& command,
const ContainerType& items)
168 ContainerType m_items;
176class AllEnvCellRunCommandContainer
180 using ThatClass = AllEnvCellRunCommandContainer;
182 using ContainerCreateViewType = AllEnvCellVectorView;
188 explicit AllEnvCellRunCommandContainer(ContainerCreateViewType view)
195 constexpr ARCCORE_HOST_DEVICE
Int32 size()
const {
return m_view.size(); }
214class ConstituentCommandContainerBase
219 using ComponentItemLocalId = Arcane::Materials::ComponentItemLocalId;
224 explicit ConstituentCommandContainerBase(ComponentItemVectorView view)
227 m_nb_item = m_items.nbItem();
228 m_matvar_indexes = m_items._matvarIndexes();
229 m_global_cells_local_id = m_items._internalLocalIds();
234 constexpr ARCCORE_HOST_DEVICE
Int32 size()
const {
return m_nb_item; }
238 ComponentItemVectorView m_items;
250template <
typename ConstituentItemLocalIdType_,
typename ContainerCreateViewType_>
251class ConstituentRunCommandContainer
252:
public ConstituentCommandContainerBase
256 using ThatClass = ConstituentRunCommandContainer;
257 using IteratorValueType = ConstituentItemLocalIdType_;
259 using ContainerCreateViewType = ContainerCreateViewType_;
263 explicit ConstituentRunCommandContainer(ContainerCreateViewType view)
273 return { ComponentItemLocalId(m_matvar_indexes[i]) };
277using EnvCellRunCommandContainer = ConstituentRunCommandContainer<Arcane::Materials::EnvItemLocalId, Arcane::Materials::EnvCellVectorView>;
278using MatCellRunCommandContainer = ConstituentRunCommandContainer<Arcane::Materials::MatItemLocalId, Arcane::Materials::MatCellVectorView>;
286template <
typename ConstituentItemLocalIdType_,
typename ContainerCreateViewType_>
287class ConstituentAndGlobalCellRunCommandContainer
288:
public ConstituentCommandContainerBase
292 using ThatClass = ConstituentAndGlobalCellRunCommandContainer;
295 using ContainerCreateViewType = ContainerCreateViewType_;
299 explicit ConstituentAndGlobalCellRunCommandContainer(ContainerCreateViewType_ view)
300 : ConstituentCommandContainerBase(view)
309 return { ComponentItemLocalId(m_matvar_indexes[i]), CellLocalId(m_global_cells_local_id[i]), i };
316using EnvAndGlobalCellRunCommandContainer = ConstituentAndGlobalCellRunCommandContainer<Arcane::Materials::EnvItemLocalId, Arcane::Materials::EnvCellVectorView>;
317using MatAndGlobalCellRunCommandContainer = ConstituentAndGlobalCellRunCommandContainer<Arcane::Materials::MatItemLocalId, Arcane::Materials::MatCellVectorView>;
325template <
typename ConstituentItemLocalIdType_,
typename ContainerCreateViewType_>
326class ConstituentIndexedSelectionRunCommandContainer
330 using ThatClass = ConstituentIndexedSelectionRunCommandContainer;
331 using IteratorValueType = ConstituentItemLocalIdType_;
333 using ContainerCreateViewType = ContainerCreateViewType_;
337 explicit ConstituentIndexedSelectionRunCommandContainer(ContainerCreateViewType view)
347 return { ComponentItemLocalId(m_view[i]) };
350 ARCCORE_HOST_DEVICE
Int32 size() {
return m_view.size(); }
354 ContainerCreateViewType m_view;
360using EnvIndexedSelectionRunCommandContainer = ConstituentIndexedSelectionRunCommandContainer<Arcane::Materials::EnvItemLocalId, Arcane::Materials::EnvCellVectorSelectionView>;
365#if defined(ARCANE_COMPILING_CUDA_OR_HIP)
369template <
typename ContainerType,
typename Lambda,
typename... RemainingArgs> __global__
void
370doMatContainerGPULambda(
ContainerType items, Lambda func, RemainingArgs... remaining_args)
372 auto privatizer = Impl::privatize(func);
373 auto& body = privatizer.privateCopy();
374 Int32 i = blockDim.x * blockIdx.x + threadIdx.x;
376 if (i < items.size()) {
377 body(items[i], remaining_args...);
387#if defined(ARCANE_COMPILING_SYCL)
389template <
typename ContainerType,
typename Lambda,
typename... RemainingArgs>
390class DoMatContainerSYCLLambda
394 void operator()(sycl::nd_item<1> x, SmallSpan<std::byte> shm_view,
395 ContainerType items, Lambda func,
396 RemainingArgs... remaining_args)
const
398 auto privatizer = Impl::privatize(func);
399 auto& body = privatizer.privateCopy();
401 Int32 i =
static_cast<Int32
>(x.get_global_id(0));
402 Impl::SyclKernelRemainingArgsHelper::applyAtBegin(x, shm_view, remaining_args...);
403 if (i < items.size()) {
404 body(items[i], remaining_args...);
406 Impl::SyclKernelRemainingArgsHelper::applyAtEnd(x, shm_view, remaining_args...);
409 void operator()(sycl::id<1> x, ContainerType items, Lambda func)
const
411 auto privatizer = Impl::privatize(func);
412 auto& body = privatizer.privateCopy();
414 Int32 i =
static_cast<Int32
>(x);
415 if (i < items.size()) {
426template <
typename ContainerType,
typename Lambda,
typename... RemainingArgs>
427void _doConstituentItemsLambda(
Int32 base_index,
Int32 size, ContainerType items,
428 const Lambda& func, RemainingArgs... remaining_args)
430 auto privatizer = Impl::privatize(func);
431 auto& body = privatizer.privateCopy();
434 Int32 last_value = base_index + size;
435 for (
Int32 i = base_index; i < last_value; ++i) {
436 body(items[i], remaining_args...);
444template <
typename ContainerType_,
typename... RemainingArgs>
445class GenericConstituentCommandArgs
449 using ContainerType = ContainerType_;
450 using IteratorValueType = ContainerType::IteratorValueType;
454 explicit GenericConstituentCommandArgs(
const ContainerType& container,
const RemainingArgs&... remaining_args)
455 : m_container(container)
456 , m_remaining_args(remaining_args...)
461 ContainerType m_container;
462 std::tuple<RemainingArgs...> m_remaining_args;
468template <
typename ContainerType_,
typename... RemainingArgs>
469class GenericConstituentCommand
473 using ContainerType = ContainerType_;
474 using ConstituentCommandType = ContainerType::CommandType;
478 explicit GenericConstituentCommand(
const ConstituentCommandType& command)
481 explicit GenericConstituentCommand(
const ConstituentCommandType& command,
482 const std::tuple<RemainingArgs...>& remaining_args)
484 , m_remaining_args(remaining_args)
489 ConstituentCommandType m_command;
490 std::tuple<RemainingArgs...> m_remaining_args;
504template <
typename ContainerType,
typename Lambda,
typename... RemainingArgs>
void
509 Int32 vsize = items.size();
516 switch (exec_policy) {
518 ARCCORE_KERNEL_CUDA_FUNC((doMatContainerGPULambda<ContainerType, Lambda, RemainingArgs...>),
519 launch_info, func, items, remaining_args...);
522 ARCCORE_KERNEL_HIP_FUNC((doMatContainerGPULambda<ContainerType, Lambda, RemainingArgs...>),
523 launch_info, func, items, remaining_args...);
526 ARCCORE_KERNEL_SYCL_FUNC((impl::DoMatContainerSYCLLambda<ContainerType, Lambda, RemainingArgs...>{}),
527 launch_info, func, items, remaining_args...);
530 _doConstituentItemsLambda(0, vsize, items, func, remaining_args...);
535 _doConstituentItemsLambda(begin, size, items, func, remaining_args...);
539 ARCCORE_FATAL(
"Invalid execution policy '{0}'", exec_policy);
546template <
typename ConstituentCommandType,
typename... RemainingArgs,
typename Lambda>
547void operator<<(
const GenericConstituentCommand<ConstituentCommandType, RemainingArgs...>& c,
const Lambda& func)
549 if constexpr (
sizeof...(RemainingArgs) > 0) {
550 std::apply([&](
auto... vs) {
556 Impl::_applyConstituentCells(c.m_command.m_command, c.m_command.m_items, func);
562template <
typename ConstituentItemType,
typename ConstituentItemContainerType,
typename... RemainingArgs>
auto
563makeExtendedConstituentItemEnumeratorLoop(ConstituentItemType x,
564 const ConstituentItemContainerType& container,
565 const RemainingArgs&... remaining_args)
568 using TraitsType =
decltype(container_instance);
587inline Accelerator::Impl::EnvAndGlobalCellRunCommandContainer
590 return Accelerator::Impl::EnvAndGlobalCellRunCommandContainer{ env->
envView() };
592inline Accelerator::Impl::EnvAndGlobalCellRunCommandContainer
595 return Accelerator::Impl::EnvAndGlobalCellRunCommandContainer{ view };
602inline Accelerator::Impl::MatAndGlobalCellRunCommandContainer
605 return Accelerator::Impl::MatAndGlobalCellRunCommandContainer{ mat->
matView() };
607inline Accelerator::Impl::MatAndGlobalCellRunCommandContainer
610 return Accelerator::Impl::MatAndGlobalCellRunCommandContainer{ mat };
617inline Accelerator::Impl::AllEnvCellRunCommandContainer
627inline Accelerator::Impl::EnvCellRunCommandContainer
630 return Accelerator::Impl::EnvCellRunCommandContainer(env->
envView());
632inline Accelerator::Impl::EnvCellRunCommandContainer
635 return Accelerator::Impl::EnvCellRunCommandContainer(view);
642inline Accelerator::Impl::MatCellRunCommandContainer
645 return Accelerator::Impl::MatCellRunCommandContainer(mat->
matView());
647inline Accelerator::Impl::MatCellRunCommandContainer
650 return Accelerator::Impl::MatCellRunCommandContainer(view);
656inline Accelerator::Impl::EnvIndexedSelectionRunCommandContainer
659 return Accelerator::Impl::EnvIndexedSelectionRunCommandContainer{ view };
676template <
typename TraitsType,
typename... RemainingArgs>
auto
680 using CommandType =
typename ContainerType::CommandType;
682 return GenericCommandType(CommandType::create(command, args.m_container), args.m_remaining_args);
690operator<<(
RunCommand& command,
const Impl::MatAndGlobalCellRunCommandContainer& view)
692 using CommandType = Impl::MatAndGlobalCellRunCommandContainer::CommandType;
701operator<<(
RunCommand& command,
const Impl::EnvAndGlobalCellRunCommandContainer& view)
703 using CommandType = Impl::EnvAndGlobalCellRunCommandContainer::CommandType;
712operator<<(
RunCommand& command,
const Impl::EnvCellRunCommandContainer& view)
714 using CommandType = Impl::EnvCellRunCommandContainer::CommandType;
723operator<<(
RunCommand& command,
const Impl::MatCellRunCommandContainer& view)
725 using CommandType = Impl::MatCellRunCommandContainer::CommandType;
737#define A_RUNCOMMAND_MAT_ENUMERATE_BUILDER_HELPER(ConstituentItemNameType, env_or_mat_container, ...) \
738 ::Arcane::Accelerator::Impl::makeExtendedConstituentItemEnumeratorLoop(ConstituentItemNameType{}, env_or_mat_container __VA_OPT__(, __VA_ARGS__))
760#define RUNCOMMAND_MAT_ENUMERATE(ConstituentItemNameType, iter_name, env_or_mat_container, ...) \
761 A_FUNCINFO << A_RUNCOMMAND_MAT_ENUMERATE_BUILDER_HELPER(ConstituentItemNameType, env_or_mat_container __VA_OPT__(, __VA_ARGS__)) \
762 << [=] ARCCORE_HOST_DEVICE(typename decltype(A_RUNCOMMAND_MAT_ENUMERATE_BUILDER_HELPER(ConstituentItemNameType, env_or_mat_container __VA_OPT__(, __VA_ARGS__)))::IteratorValueType iter_name \
763 __VA_OPT__(ARCCORE_RUNCOMMAND_REMAINING_FOR_EACH(__VA_ARGS__)))
#define ARCCORE_FATAL(...)
Macro envoyant une exception FatalErrorException.
Classes, Types et macros pour gérer la concurrence.
void _applyConstituentCells(RunCommand &command, ContainerType items, const Lambda &func, const RemainingArgs &... remaining_args)
Applique l'énumération func sur la liste d'entité items.
Conteneur pour une commande sur les AllEnvCell.
__host__ __device__ IteratorValueType operator[](Int32 i) const
Accesseur pour le i-ème élément de la liste.
constexpr __host__ __device__ IteratorValueType operator[](Int32 i) const
Accesseur pour le i-ème élément de la liste.
Classe de base des conteneurs pour les command sur les constituants (sauf pour les AllEnvCell).
constexpr __host__ __device__ IteratorValueType operator[](Int32 i) const
Accesseur pour le i-ème élément de la liste.
Classe de base pour les commandes sur les constituants.
constexpr __host__ __device__ IteratorValueType operator[](Int32 i) const
Accesseur pour le i-ème élément de la liste.
static ARCCORE_DEVICE void applyAtEnd(Int32 index, RemainingArgs &... remaining_args)
Applique les fonctors des arguments additionnels en fin de kernel.
static ARCCORE_DEVICE void applyAtBegin(Int32 index, RemainingArgs &... remaining_args)
Applique les fonctors des arguments additionnels en début de kernel.
Object temporaire pour conserver les informations d'exécution d'une commande et regrouper les tests.
void beginExecute()
Indique qu'on commence l'exécution de la commande.
void endExecute()
Signale la fin de l'exécution.
Gestion d'une commande sur accélérateur.
static void applyAtEnd(RemainingArgs &... remaining_args)
Applique les functors des arguments additionnels à la fin de l'itération.
static void applyAtBegin(RemainingArgs &... remaining_args)
Applique les functors des arguments additionnels au début de l'itération.
Vue sur une liste de mailles avec infos sur les milieux.
Maille arcane avec info matériaux et milieux.
Vue sur un vecteur sur les entités d'un composant.
Index d'une boucle accélérateur sur les matériaux ou milieux.
constexpr __host__ __device__ Int32 index() const
Index de l'itération courante.
constexpr __host__ __device__ CellLocalId globalCellId() const
Accesseur sur la partie cell local id.
constexpr __host__ __device__ Data operator()()
Cet opérateur permet de renvoyer le couple [ConstituentItemLocalIdType, CellLocalId].
constexpr __host__ __device__ ConstituentItemLocalIdType varIndex() const
Accesseur sur la partie MatVarIndex.
Maille arcane d'un milieu.
Interface d'un milieu d'un maillage.
virtual EnvItemVectorView envView() const =0
Vue associée à ce milieu.
Interface d'un matériau d'un maillage.
virtual MatItemVectorView matView() const =0
Vue associée à ce matériau.
Représente un matériau d'une maille multi-matériau.
Représente un index sur les variables matériaux et milieux.
Vue d'un tableau d'éléments de type T.
void arcaneParallelFor(Integer i0, Integer size, InstanceType *itype, void(InstanceType::*lambda_function)(Integer i0, Integer size))
Applique en concurrence la fonction lambda lambda_function sur l'intervalle d'itération [i0,...
Espace de nom pour l'utilisation des accélérateurs.
eExecutionPolicy
Politique d'exécution pour un Runner.
@ SYCL
Politique d'exécution utilisant l'environnement SYCL.
@ HIP
Politique d'exécution utilisant l'environnement HIP.
@ CUDA
Politique d'exécution utilisant l'environnement CUDA.
@ Sequential
Politique d'exécution séquentielle.
@ Thread
Politique d'exécution multi-thread.
Active toujours les traces dans les parties Arcane concernant les matériaux.
EnvItemVectorView EnvCellVectorView
Type de la vue sur un EnvCellVector.
ConstituentAndGlobalCellIteratorValue< EnvItemLocalId > EnvAndGlobalCellIteratorValue
Type de la valeur de l'itérateur pour RUNCOMMAND_MAT_ENUMERATE(EnvAndGlobalCell,.....
ConstituentAndGlobalCellIteratorValue< MatItemLocalId > MatAndGlobalCellIteratorValue
Type de la valeur de l'itérateur pour RUNCOMMAND_MAT_ENUMERATE(MatAndGlobalCell,.....
MatItemVectorView MatCellVectorView
Type de la vue sur un MatCellVector.
Accelerator::Impl::EnvAndGlobalCellRunCommandContainer arcaneCreateRunCommandMaterialContainer(Arcane::Materials::EnvAndGlobalCell, Arcane::Materials::IMeshEnvironment *env)
Spécialisation pour une vue sur un milieu et la maille globale associée.
ConstituentItemIndexedSelectionView< EnvCellVectorView > EnvCellVectorSelectionView
Selection sur un 'EvnCellVectorView'.
std::int32_t Int32
Type entier signé sur 32 bits.