12#ifndef ARCANE_ACCELERATOR_RUNCOMMANDENUMERATE_H
13#define ARCANE_ACCELERATOR_RUNCOMMANDENUMERATE_H
17#include "arccore/common/accelerator/RunCommand.h"
18#include "arcane/accelerator/KernelLauncher.h"
21#include "arcane/core/ItemGroup.h"
24#include "arccore/common/HostKernelRemainingArgsHelper.h"
42class IteratorWithIndex
47 constexpr ARCCORE_HOST_DEVICE IteratorWithIndex(
Int32 i, T v)
54 constexpr ARCCORE_HOST_DEVICE
Int32 index()
const {
return m_index; }
55 constexpr ARCCORE_HOST_DEVICE T value()
const {
return m_value; }
95 constexpr ARCCORE_HOST_DEVICE
static T create(
Int32, T value)
106namespace Arcane::Accelerator::impl
119 || std::derived_from<T, ItemLocalId>
120 || std::derived_from<T, IteratorWithIndexBase>;
139 using ItemType =
typename ItemLocalIdT<T>::ItemType;
150 using ItemType =
typename T::ItemType;
167template <
typename ItemType>
168class RunCommandItemContainer
173 : m_item_group(group)
177 : m_item_vector_view(item_vector_view)
178 , m_unpadded_vector_view(item_vector_view)
184 Int32 size()
const {
return m_unpadded_vector_view.size(); }
188 if (!m_item_group.null())
189 return m_item_group._paddedView();
190 return m_item_vector_view;
211template <RunCommandEnumerateIteratorConcept IteratorValueType_>
212class RunCommandItemEnumeratorTraitsT
217 using ItemType =
typename SubTraitsType::ItemType;
219 using ValueType =
typename SubTraitsType::ValueType;
221 using BuilderType =
typename SubTraitsType::BuilderType;
226 : m_item_container(group)
229 : m_item_container(vector_view)
241template <
typename TraitsType,
typename ContainerType,
typename Lambda,
typename... RemainingArgs>
242void _doItemsLambda(
Int32 base_index,
ContainerType sub_items,
const Lambda& func, RemainingArgs... remaining_args)
244 using ItemType = TraitsType::ItemType;
245 using BuilderType = TraitsType::BuilderType;
247 auto privatizer = Impl::privatize(func);
248 auto& body = privatizer.privateCopy();
252 body(BuilderType::create(iitem.index() + base_index,
LocalIdType(iitem.itemLocalId())), remaining_args...);
262template <
typename TraitsType,
typename Lambda,
typename... RemainingArgs>
void
264 const Lambda& func,
const RemainingArgs&... remaining_args)
270 using ItemType =
typename TraitsType::ItemType;
275 switch (exec_policy) {
277 ARCCORE_KERNEL_CUDA_FUNC((Impl::doIndirectGPULambda2 < TraitsType, Lambda, RemainingArgs... >),
278 launch_info, func, ids, remaining_args...);
281 ARCCORE_KERNEL_HIP_FUNC((Impl::doIndirectGPULambda2 < TraitsType, Lambda, RemainingArgs... >),
282 launch_info, func, ids, remaining_args...);
285 ARCCORE_KERNEL_SYCL_FUNC((Impl::DoIndirectSYCLLambda < TraitsType, Lambda, RemainingArgs... > {}),
286 launch_info, func, ids, remaining_args...);
289 impl::_doItemsLambda<TraitsType>(0, items.paddedView(), func, remaining_args...);
294 impl::_doItemsLambda<TraitsType>(base_index, sub_items, func, remaining_args...);
298 ARCCORE_FATAL(
"Invalid execution policy '{0}'", exec_policy);
306template <
typename TraitsType,
typename... RemainingArgs>
307class ItemRunCommandArgs
311 ItemRunCommandArgs(
const TraitsType& traits,
const RemainingArgs&... remaining_args)
313 , m_remaining_args(remaining_args...)
320 std::tuple<RemainingArgs...> m_remaining_args;
334template <
typename TraitsType,
typename Lambda>
void
335run(
RunCommand& command,
const TraitsType& traits,
const Lambda& func)
343template <
typename TraitsType,
typename... RemainingArgs>
348 ItemRunCommand(
RunCommand& command,
const TraitsType& traits)
354 ItemRunCommand(
RunCommand& command,
const TraitsType& traits,
const std::tuple<RemainingArgs...>& remaining_args)
357 , m_remaining_args(remaining_args)
365 std::tuple<RemainingArgs...> m_remaining_args;
371template <
typename ItemType>
auto
382template <
typename ItemType>
auto
385 using TraitsType = impl::RunCommandItemEnumeratorTraitsT<ItemType>;
391template <
typename ItemType>
auto
392operator<<(RunCommand& command,
const ItemGroupT<ItemType>& items)
394 using TraitsType = impl::RunCommandItemEnumeratorTraitsT<ItemType>;
395 return ItemRunCommand<TraitsType>(command, TraitsType(items));
398template <
typename TraitsType,
typename Lambda>
401 run(nr.m_command, nr.m_traits, f);
404template <
typename TraitsType,
typename... RemainingArgs>
auto
407 return ItemRunCommand<TraitsType, RemainingArgs...>(command, args.m_traits, args.m_remaining_args);
410template <
typename TraitsType,
typename Lambda,
typename... RemainingArgs>
413 if constexpr (
sizeof...(RemainingArgs) > 0) {
417 run(nr.m_command, nr.m_traits, f);
425namespace Arcane::Accelerator::impl
431template <
typename ItemTypeName,
typename ItemContainerType,
typename... RemainingArgs>
auto
432makeExtendedItemEnumeratorLoop(
const ItemContainerType& container_type,
433 const RemainingArgs&... remaining_args)
436 return ItemRunCommandArgs<TraitsType, RemainingArgs...>(TraitsType(container_type), remaining_args...);
465#define RUNCOMMAND_ENUMERATE(ItemTypeName, iter_name, item_group, ...) \
466 A_FUNCINFO << ::Arcane::Accelerator::impl::makeExtendedItemEnumeratorLoop<ItemTypeName>(item_group __VA_OPT__(, __VA_ARGS__)) \
467 << [=] ARCCORE_HOST_DEVICE(::Arcane::Accelerator::impl::RunCommandItemEnumeratorTraitsT<ItemTypeName>::ValueType iter_name \
468 __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.
Déclarations de types sur les entités.
void _applyItems(RunCommand &command, typename TraitsType::ContainerType items, const Lambda &func, const RemainingArgs &... remaining_args)
Applique l'enumération func sur la liste d'entité items.
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.
Conteneur pour RunCommandEnumerate.
Template pour connaitre le type d'entité associé à T.
Caractéristiques d'un énumérateur d'une commande sur les entités.
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.
Référence à un groupe d'un genre donné.
ItemVectorView _unpaddedView() const
Vue sur les entités du groupe sans padding pour la vectorisation.
Index d'une entité ItemType dans une variable.
Caractéristiques des éléments du maillage.
Vue sur un tableau typé d'entités.
Vue sur un vecteur d'entités.
Classe de base pour un itérateur permettant de conserver l'index de l'itération.
Vue d'un tableau d'éléments de type T.
Concept pour contraintre les valeurs dans RUNCOMMAND_ENUMERATE.
void arcaneParallelForeach(const ItemVectorView &items_view, const ForLoopRunInfo &run_info, InstanceType *instance, void(InstanceType::*function)(ItemVectorViewT< ItemType > items))
Applique en concurrence la méthode function de l'instance instance sur la vue items_view avec les opt...
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.
-*- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature -*-
Int32 Integer
Type représentant un entier.
std::int32_t Int32
Type entier signé sur 32 bits.