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"
27#include "arccore/common/HostKernelRemainingArgsHelper.h"
44template <
typename ConstituentItemLocalIdType_>
45class ConstituentAndGlobalCellIteratorValue
49 using ConstituentItemLocalIdType = ConstituentItemLocalIdType_;
50 using ComponentItemLocalId = Arcane::Materials::ComponentItemLocalId;
60 constexpr ARCCORE_HOST_DEVICE Data(ConstituentItemLocalIdType mvi, CellLocalId cid)
67 ConstituentItemLocalIdType m_mvi;
73 constexpr ARCCORE_HOST_DEVICE ConstituentAndGlobalCellIteratorValue(ConstituentItemLocalIdType mvi, CellLocalId cid,
Int32 index)
74 : m_internal_data{ mvi, cid }
99 return m_internal_data;
103 constexpr ARCCORE_HOST_DEVICE ConstituentItemLocalIdType
varIndex()
const {
return m_internal_data.m_mvi; };
106 constexpr ARCCORE_HOST_DEVICE CellLocalId
globalCellId()
const {
return m_internal_data.m_cid; }
109 constexpr ARCCORE_HOST_DEVICE
Int32 index()
const {
return m_index; }
113 Data m_internal_data;
131namespace Arcane::Accelerator::impl
139class AllEnvCellRunCommand
146 using ContainerCreateViewType = AllEnvCellVectorView;
157 explicit Container(ContainerCreateViewType view)
165 constexpr ARCCORE_HOST_DEVICE
Int32 size()
const {
return m_view.size(); }
175 AllEnvCellVectorView m_view;
188 explicit AllEnvCellRunCommand(
RunCommand& command,
const Container& items)
203class ConstituentCommandContainerBase
208 using ComponentItemLocalId = Arcane::Materials::ComponentItemLocalId;
213 explicit ConstituentCommandContainerBase(ComponentItemVectorView view)
216 m_nb_item = m_items.nbItem();
217 m_matvar_indexes = m_items._matvarIndexes();
218 m_global_cells_local_id = m_items._internalLocalIds();
223 constexpr ARCCORE_HOST_DEVICE
Int32 size()
const {
return m_nb_item; }
227 ComponentItemVectorView m_items;
238template <
typename ConstituentItemLocalIdType_,
typename ContainerCreateViewType_>
239class ConstituentRunCommandBase
243 using ThatClass = ConstituentRunCommandBase<ConstituentItemLocalIdType_, ContainerCreateViewType_>;
244 using CommandType = ThatClass;
245 using IteratorValueType = ConstituentItemLocalIdType_;
246 using ContainerCreateViewType = ContainerCreateViewType_;
258 explicit Container(ContainerCreateViewType view)
268 return { ComponentItemLocalId(m_matvar_indexes[i]) };
274 static CommandType create(
RunCommand& run_command,
const Container& items)
276 return CommandType(run_command, items);
282 explicit ConstituentRunCommandBase(
RunCommand& command,
const Container& items)
294using EnvCellRunCommand = ConstituentRunCommandBase<Arcane::Materials::EnvItemLocalId, Arcane::Materials::EnvCellVectorView>;
295using MatCellRunCommand = ConstituentRunCommandBase<Arcane::Materials::MatItemLocalId, Arcane::Materials::MatCellVectorView>;
302template <
typename ConstituentItemLocalIdType_,
typename ContainerCreateViewType_>
303class ConstituentAndGlobalCellRunCommandBase
307 using ThatClass = ConstituentAndGlobalCellRunCommandBase<ConstituentItemLocalIdType_, ContainerCreateViewType_>;
308 using CommandType = ThatClass;
310 using ContainerCreateViewType = ContainerCreateViewType_;
322 explicit Container(ContainerCreateViewType view)
332 return { ComponentItemLocalId(m_matvar_indexes[i]), CellLocalId(m_global_cells_local_id[i]), i };
338 static CommandType create(
RunCommand& run_command,
const Container& items)
340 return CommandType(run_command, items);
346 explicit ConstituentAndGlobalCellRunCommandBase(
RunCommand& command,
const Container& items)
361using EnvAndGlobalCellRunCommand = ConstituentAndGlobalCellRunCommandBase<Arcane::Materials::EnvItemLocalId, Arcane::Materials::EnvCellVectorView>;
362using MatAndGlobalCellRunCommand = ConstituentAndGlobalCellRunCommandBase<Arcane::Materials::MatItemLocalId, Arcane::Materials::MatCellVectorView>;
378template <
typename MatItemType>
386template <
typename CommandType_>
391 using CommandType = CommandType_;
392 using IteratorValueType = CommandType::IteratorValueType;
393 using ContainerType = CommandType::Container;
394 using ContainerCreateViewType = CommandType::ContainerCreateViewType;
398 static ContainerType createContainer(
const ContainerCreateViewType& items)
400 return ContainerType{ items };
415 using BaseClass::createContainer;
419 return ContainerType{ env->
envView() };
434 using BaseClass::createContainer;
438 return ContainerType{ mat->
matView() };
463 using BaseClass::createContainer;
469 return ContainerType(env->
envView());
484 using BaseClass::createContainer;
488 return ContainerType(mat->
matView());
495#if defined(ARCANE_COMPILING_CUDA_OR_HIP)
499template <
typename ContainerType,
typename Lambda,
typename... RemainingArgs> __global__
void
500doMatContainerGPULambda(
ContainerType items, Lambda func, RemainingArgs... remaining_args)
502 auto privatizer = Impl::privatize(func);
503 auto& body = privatizer.privateCopy();
504 Int32 i = blockDim.x * blockIdx.x + threadIdx.x;
506 if (i < items.size()) {
507 body(items[i], remaining_args...);
517#if defined(ARCANE_COMPILING_SYCL)
519template <
typename ContainerType,
typename Lambda,
typename... RemainingArgs>
520class DoMatContainerSYCLLambda
526 RemainingArgs... remaining_args)
const
528 auto privatizer = Impl::privatize(func);
529 auto& body = privatizer.privateCopy();
531 Int32 i =
static_cast<Int32>(x.get_global_id(0));
532 Impl::SyclKernelRemainingArgsHelper::applyAtBegin(x, shm_view, remaining_args...);
533 if (i < items.size()) {
534 body(items[i], remaining_args...);
536 Impl::SyclKernelRemainingArgsHelper::applyAtEnd(x, shm_view, remaining_args...);
539 void operator()(sycl::id<1> x, ContainerType items, Lambda func)
const
541 auto privatizer = Impl::privatize(func);
542 auto& body = privatizer.privateCopy();
544 Int32 i =
static_cast<Int32
>(x);
545 if (i < items.size()) {
556template <
typename ContainerType,
typename Lambda,
typename... RemainingArgs>
557void _doConstituentItemsLambda(
Int32 base_index,
Int32 size, ContainerType items,
558 const Lambda& func, RemainingArgs... remaining_args)
560 auto privatizer = Impl::privatize(func);
561 auto& body = privatizer.privateCopy();
564 Int32 last_value = base_index + size;
565 for (
Int32 i = base_index; i < last_value; ++i) {
566 body(items[i], remaining_args...);
574template <
typename TraitsType,
typename... RemainingArgs>
575class GenericConstituentCommandArgs
579 using ContainerType =
typename TraitsType::ContainerType;
583 explicit GenericConstituentCommandArgs(
const ContainerType& container,
const RemainingArgs&... remaining_args)
584 : m_container(container)
585 , m_remaining_args(remaining_args...)
590 ContainerType m_container;
591 std::tuple<RemainingArgs...> m_remaining_args;
597template <
typename ConstituentCommandType,
typename... RemainingArgs>
598class GenericConstituentCommand
602 using ContainerType =
typename ConstituentCommandType::Container;
606 explicit GenericConstituentCommand(
const ConstituentCommandType& command)
609 explicit GenericConstituentCommand(
const ConstituentCommandType& command,
const std::tuple<RemainingArgs...>& remaining_args)
611 , m_remaining_args(remaining_args)
616 ConstituentCommandType m_command;
617 std::tuple<RemainingArgs...> m_remaining_args;
631template <
typename ContainerType,
typename Lambda,
typename... RemainingArgs>
void
636 Int32 vsize = items.size();
643 switch (exec_policy) {
645 ARCCORE_KERNEL_CUDA_FUNC((doMatContainerGPULambda < ContainerType, Lambda, RemainingArgs... >),
646 launch_info, func, items, remaining_args...);
649 ARCCORE_KERNEL_HIP_FUNC((doMatContainerGPULambda < ContainerType, Lambda, RemainingArgs... >),
650 launch_info, func, items, remaining_args...);
653 ARCCORE_KERNEL_SYCL_FUNC((impl::DoMatContainerSYCLLambda < ContainerType, Lambda, RemainingArgs... > {}),
654 launch_info, func, items, remaining_args...);
657 _doConstituentItemsLambda(0, vsize, items, func, remaining_args...);
662 _doConstituentItemsLambda(begin, size, items, func, remaining_args...);
666 ARCCORE_FATAL(
"Invalid execution policy '{0}'", exec_policy);
673template <
typename ConstituentCommandType,
typename... RemainingArgs,
typename Lambda>
674void operator<<(
const GenericConstituentCommand<ConstituentCommandType, RemainingArgs...>& c,
const Lambda& func)
676 if constexpr (
sizeof...(RemainingArgs) > 0) {
677 std::apply([&](
auto... vs) {
683 impl::_applyConstituentCells(c.m_command.m_command, c.m_command.m_items, func);
689template <
typename ConstituentItemType,
typename ConstituentItemContainerType,
typename... RemainingArgs>
auto
690makeExtendedConstituentItemEnumeratorLoop(
const ConstituentItemContainerType& container,
691 const RemainingArgs&... remaining_args)
711template <
typename TraitsType,
typename... RemainingArgs>
auto
714 using CommandType =
typename TraitsType::CommandType;
716 return GenericCommandType(CommandType::create(command, args.m_container), args.m_remaining_args);
724operator<<(
RunCommand& command,
const impl::MatAndGlobalCellRunCommand::Container& view)
726 using CommandType = impl::MatAndGlobalCellRunCommand;
735operator<<(
RunCommand& command,
const impl::EnvAndGlobalCellRunCommand::Container& view)
737 using CommandType = impl::EnvAndGlobalCellRunCommand;
746operator<<(
RunCommand& command,
const impl::EnvCellRunCommand::Container& view)
748 using CommandType = impl::EnvCellRunCommand;
757operator<<(
RunCommand& command,
const impl::MatCellRunCommand::Container& view)
759 using CommandType = impl::MatCellRunCommand;
791#define RUNCOMMAND_MAT_ENUMERATE(ConstituentItemNameType, iter_name, env_or_mat_container, ...) \
792 A_FUNCINFO << ::Arcane::Accelerator::impl::makeExtendedConstituentItemEnumeratorLoop<ConstituentItemNameType>(env_or_mat_container __VA_OPT__(, __VA_ARGS__)) \
793 << [=] ARCCORE_HOST_DEVICE(::Arcane::Accelerator::impl::RunCommandConstituentItemEnumeratorTraitsT<ConstituentItemNameType>::IteratorValueType iter_name \
794 __VA_OPT__(ARCCORE_RUNCOMMAND_REMAINING_FOR_EACH(__VA_ARGS__)))
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 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.
__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 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.
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.