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"
23#include "arcane/accelerator/KernelLauncher.h"
24#include "arcane/accelerator/RunCommand.h"
25#include "arcane/accelerator/RunCommandLaunchInfo.h"
42template <
typename ConstituentItemLocalIdType_>
43class ConstituentAndGlobalCellIteratorValue
47 using ConstituentItemLocalIdType = ConstituentItemLocalIdType_;
48 using ComponentItemLocalId = Arcane::Materials::ComponentItemLocalId;
58 constexpr ARCCORE_HOST_DEVICE Data(ConstituentItemLocalIdType mvi, CellLocalId cid)
65 ConstituentItemLocalIdType m_mvi;
71 constexpr ARCCORE_HOST_DEVICE ConstituentAndGlobalCellIteratorValue(ConstituentItemLocalIdType mvi, CellLocalId cid,
Int32 index)
72 : m_internal_data{ mvi, cid }
97 return m_internal_data;
101 constexpr ARCCORE_HOST_DEVICE ConstituentItemLocalIdType
varIndex()
const {
return m_internal_data.m_mvi; };
104 constexpr ARCCORE_HOST_DEVICE CellLocalId
globalCellId()
const {
return m_internal_data.m_cid; }
107 constexpr ARCCORE_HOST_DEVICE
Int32 index()
const {
return m_index; }
111 Data m_internal_data;
129namespace Arcane::Accelerator::impl
137class AllEnvCellRunCommand
144 using ContainerCreateViewType = AllEnvCellVectorView;
155 explicit Container(ContainerCreateViewType view)
163 constexpr ARCCORE_HOST_DEVICE
Int32 size()
const {
return m_view.size(); }
173 AllEnvCellVectorView m_view;
186 explicit AllEnvCellRunCommand(
RunCommand& command,
const Container& items)
201class ConstituentCommandContainerBase
206 using ComponentItemLocalId = Arcane::Materials::ComponentItemLocalId;
211 explicit ConstituentCommandContainerBase(ComponentItemVectorView view)
214 m_nb_item = m_items.nbItem();
215 m_matvar_indexes = m_items._matvarIndexes();
216 m_global_cells_local_id = m_items._internalLocalIds();
221 constexpr ARCCORE_HOST_DEVICE
Int32 size()
const {
return m_nb_item; }
225 ComponentItemVectorView m_items;
236template <
typename ConstituentItemLocalIdType_,
typename ContainerCreateViewType_>
237class ConstituentRunCommandBase
241 using ThatClass = ConstituentRunCommandBase<ConstituentItemLocalIdType_, ContainerCreateViewType_>;
242 using CommandType = ThatClass;
243 using IteratorValueType = ConstituentItemLocalIdType_;
244 using ContainerCreateViewType = ContainerCreateViewType_;
256 explicit Container(ContainerCreateViewType view)
266 return { ComponentItemLocalId(m_matvar_indexes[i]) };
272 static CommandType create(
RunCommand& run_command,
const Container& items)
274 return CommandType(run_command, items);
280 explicit ConstituentRunCommandBase(
RunCommand& command,
const Container& items)
292using EnvCellRunCommand = ConstituentRunCommandBase<Arcane::Materials::EnvItemLocalId, Arcane::Materials::EnvCellVectorView>;
293using MatCellRunCommand = ConstituentRunCommandBase<Arcane::Materials::MatItemLocalId, Arcane::Materials::MatCellVectorView>;
300template <
typename ConstituentItemLocalIdType_,
typename ContainerCreateViewType_>
301class ConstituentAndGlobalCellRunCommandBase
305 using ThatClass = ConstituentAndGlobalCellRunCommandBase<ConstituentItemLocalIdType_, ContainerCreateViewType_>;
306 using CommandType = ThatClass;
308 using ContainerCreateViewType = ContainerCreateViewType_;
320 explicit Container(ContainerCreateViewType view)
330 return { ComponentItemLocalId(m_matvar_indexes[i]), CellLocalId(m_global_cells_local_id[i]), i };
336 static CommandType create(
RunCommand& run_command,
const Container& items)
338 return CommandType(run_command, items);
344 explicit ConstituentAndGlobalCellRunCommandBase(
RunCommand& command,
const Container& items)
359using EnvAndGlobalCellRunCommand = ConstituentAndGlobalCellRunCommandBase<Arcane::Materials::EnvItemLocalId, Arcane::Materials::EnvCellVectorView>;
360using MatAndGlobalCellRunCommand = ConstituentAndGlobalCellRunCommandBase<Arcane::Materials::MatItemLocalId, Arcane::Materials::MatCellVectorView>;
376template <
typename MatItemType>
384template <
typename CommandType_>
389 using CommandType = CommandType_;
390 using IteratorValueType = CommandType::IteratorValueType;
391 using ContainerType = CommandType::Container;
392 using ContainerCreateViewType = CommandType::ContainerCreateViewType;
396 static ContainerType createContainer(
const ContainerCreateViewType& items)
398 return ContainerType{ items };
413 using BaseClass::createContainer;
417 return ContainerType{ env->
envView() };
432 using BaseClass::createContainer;
436 return ContainerType{ mat->
matView() };
461 using BaseClass::createContainer;
467 return ContainerType(env->
envView());
482 using BaseClass::createContainer;
486 return ContainerType(mat->
matView());
493#if defined(ARCANE_COMPILING_CUDA) || defined(ARCANE_COMPILING_HIP)
497template <
typename ContainerType,
typename Lambda,
typename... RemainingArgs> __global__
void
498doMatContainerGPULambda(
ContainerType items, Lambda func, RemainingArgs... remaining_args)
500 auto privatizer = Impl::privatize(func);
501 auto& body = privatizer.privateCopy();
502 Int32 i = blockDim.x * blockIdx.x + threadIdx.x;
504 if (i < items.size()) {
505 body(items[i], remaining_args...);
515#if defined(ARCANE_COMPILING_SYCL)
517template <
typename ContainerType,
typename Lambda,
typename... RemainingArgs>
518class DoMatContainerSYCLLambda
524 RemainingArgs... remaining_args)
const
526 auto privatizer = Impl::privatize(func);
527 auto& body = privatizer.privateCopy();
529 Int32 i =
static_cast<Int32>(x.get_global_id(0));
531 if (i < items.size()) {
532 body(items[i], remaining_args...);
534 Impl::KernelRemainingArgsHelper::applyRemainingArgsAtEnd(x, shm_view, remaining_args...);
537 void operator()(sycl::id<1> x, ContainerType items, Lambda func)
const
539 auto privatizer = Impl::privatize(func);
540 auto& body = privatizer.privateCopy();
542 Int32 i =
static_cast<Int32
>(x);
543 if (i < items.size()) {
554template <
typename ContainerType,
typename Lambda,
typename... RemainingArgs>
555void _doConstituentItemsLambda(
Int32 base_index,
Int32 size, ContainerType items,
556 const Lambda& func, RemainingArgs... remaining_args)
558 auto privatizer = Impl::privatize(func);
559 auto& body = privatizer.privateCopy();
562 Int32 last_value = base_index + size;
563 for (
Int32 i = base_index; i < last_value; ++i) {
564 body(items[i], remaining_args...);
572template <
typename TraitsType,
typename... RemainingArgs>
573class GenericConstituentCommandArgs
577 using ContainerType =
typename TraitsType::ContainerType;
581 explicit GenericConstituentCommandArgs(
const ContainerType& container,
const RemainingArgs&... remaining_args)
582 : m_container(container)
583 , m_remaining_args(remaining_args...)
588 ContainerType m_container;
589 std::tuple<RemainingArgs...> m_remaining_args;
595template <
typename ConstituentCommandType,
typename... RemainingArgs>
596class GenericConstituentCommand
600 using ContainerType =
typename ConstituentCommandType::Container;
604 explicit GenericConstituentCommand(
const ConstituentCommandType& command)
607 explicit GenericConstituentCommand(
const ConstituentCommandType& command,
const std::tuple<RemainingArgs...>& remaining_args)
609 , m_remaining_args(remaining_args)
614 ConstituentCommandType m_command;
615 std::tuple<RemainingArgs...> m_remaining_args;
629template <
typename ContainerType,
typename Lambda,
typename... RemainingArgs>
void
634 Int32 vsize = items.size();
641 switch (exec_policy) {
643 _applyKernelCUDA(launch_info, ARCANE_KERNEL_CUDA_FUNC(doMatContainerGPULambda) <
ContainerType, Lambda, RemainingArgs... >,
644 func, items, remaining_args...);
647 _applyKernelHIP(launch_info, ARCANE_KERNEL_HIP_FUNC(doMatContainerGPULambda) <
ContainerType, Lambda, RemainingArgs... >,
648 func, items, remaining_args...);
651 _applyKernelSYCL(launch_info, ARCANE_KERNEL_SYCL_FUNC(impl::DoMatContainerSYCLLambda) <
ContainerType, Lambda, RemainingArgs... > {},
652 func, items, remaining_args...);
655 _doConstituentItemsLambda(0, vsize, items, func, remaining_args...);
660 _doConstituentItemsLambda(begin, size, items, func, remaining_args...);
664 ARCANE_FATAL(
"Invalid execution policy '{0}'", exec_policy);
672template <
typename ConstituentCommandType,
typename... RemainingArgs,
typename Lambda>
673void operator<<(
const GenericConstituentCommand<ConstituentCommandType, RemainingArgs...>& c,
const Lambda& func)
675 if constexpr (
sizeof...(RemainingArgs) > 0) {
676 std::apply([&](
auto... vs) {
682 impl::_applyConstituentCells(c.m_command.m_command, c.m_command.m_items, func);
688template <
typename ConstituentItemType,
typename ConstituentItemContainerType,
typename... RemainingArgs>
auto
689makeExtendedConstituentItemEnumeratorLoop(
const ConstituentItemContainerType& container,
690 const RemainingArgs&... remaining_args)
710template <
typename TraitsType,
typename... RemainingArgs>
auto
713 using CommandType =
typename TraitsType::CommandType;
715 return GenericCommandType(CommandType::create(command, args.m_container), args.m_remaining_args);
725 using CommandType = impl::MatAndGlobalCellRunCommand;
736 using CommandType = impl::EnvAndGlobalCellRunCommand;
747 using CommandType = impl::EnvCellRunCommand;
758 using CommandType = impl::MatCellRunCommand;
790#define RUNCOMMAND_MAT_ENUMERATE(ConstituentItemNameType, iter_name, env_or_mat_container, ...) \
791 A_FUNCINFO << ::Arcane::Accelerator::impl::makeExtendedConstituentItemEnumeratorLoop<ConstituentItemNameType>(env_or_mat_container __VA_OPT__(, __VA_ARGS__)) \
792 << [=] ARCCORE_HOST_DEVICE(::Arcane::Accelerator::impl::RunCommandConstituentItemEnumeratorTraitsT<ConstituentItemNameType>::IteratorValueType iter_name \
793 __VA_OPT__(ARCANE_RUNCOMMAND_REDUCER_FOR_EACH(__VA_ARGS__)))
#define ARCANE_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.
static ARCCORE_DEVICE void applyRemainingArgsAtBegin(Int32 index, RemainingArgs &... remaining_args)
Applique les fonctors des arguments additionnels en début de kernel.
static ARCCORE_DEVICE void applyRemainingArgsAtEnd(Int32 index, RemainingArgs &... remaining_args)
Applique les fonctors des arguments additionnels en fin 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.
const ForLoopRunInfo & loopRunInfo() const
Informations d'exécution de la boucle.
Gestion d'une commande sur accélérateur.
__host__ __device__ IteratorValueType operator[](Int32 i) const
Accesseur pour le i-ème élément de la liste.
Commande pour itérer sur les AllEnvCell.
constexpr __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.
Caractéristiques d'un énumérateur d'une commande sur les matériaux/milieux.
Classe de base des caractéristiques des commandes sur les constituants.
static void applyRemainingArgsAtEnd(RemainingArgs &... remaining_args)
Applique les functors des arguments additionnels à la fin de l'itération.
static void applyRemainingArgsAtBegin(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.
std::ostream & operator<<(std::ostream &o, eExecutionPolicy exec_policy)
Affiche le nom de la politique d'exécution.
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.
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,.....
-*- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature -*-
std::int32_t Int32
Type entier signé sur 32 bits.