12#ifndef ARCANE_ACCELERATOR_RUNCOMMANDENUMERATE_H
13#define ARCANE_ACCELERATOR_RUNCOMMANDENUMERATE_H
17#include "arcane/accelerator/RunCommand.h"
18#include "arcane/accelerator/KernelLauncher.h"
20#include "arcane/utils/ArcaneCxx20.h"
23#include "arcane/core/ItemGroup.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 = SubTraitsType::BuilderType;
226 : m_item_container(group)
229 : m_item_container(vector_view)
241template <
typename TraitsType,
typename ContainerType,
typename Lambda,
typename... ReducerArgs>
242void _doItemsLambda(
Int32 base_index,
ContainerType sub_items,
const Lambda& func, ReducerArgs... reducer_args)
244 using ItemType = TraitsType::ItemType;
245 using BuilderType = TraitsType::BuilderType;
247 auto privatizer = privatize(func);
248 auto& body = privatizer.privateCopy();
251 body(BuilderType::create(iitem.index() + base_index,
LocalIdType(iitem.itemLocalId())), reducer_args...);
261template <
typename TraitsType,
typename Lambda,
typename... ReducerArgs>
void
263 const Lambda& func,
const ReducerArgs&... reducer_args)
269 using ItemType = TraitsType::ItemType;
274 switch (exec_policy) {
276 _applyKernelCUDA(launch_info, ARCANE_KERNEL_CUDA_FUNC(doIndirectGPULambda2) < TraitsType, Lambda, ReducerArgs... >, func, ids, reducer_args...);
279 _applyKernelHIP(launch_info, ARCANE_KERNEL_HIP_FUNC(doIndirectGPULambda2) < TraitsType, Lambda, ReducerArgs... >, func, ids, reducer_args...);
282 _applyKernelSYCL(launch_info, ARCANE_KERNEL_SYCL_FUNC(impl::DoIndirectSYCLLambda) < TraitsType, Lambda, ReducerArgs... > {}, func, ids, reducer_args...);
285 impl::_doItemsLambda<TraitsType>(0, items.paddedView(), func, reducer_args...);
290 impl::_doItemsLambda<TraitsType>(base_index, sub_items, func, reducer_args...);
294 ARCANE_FATAL(
"Invalid execution policy '{0}'", exec_policy);
302template <
typename TraitsType,
typename... ReducerArgs>
303class ItemRunCommandArgs
307 ItemRunCommandArgs(
const TraitsType& traits,
const ReducerArgs&... reducer_args)
309 , m_reducer_args(reducer_args...)
316 std::tuple<ReducerArgs...> m_reducer_args;
330template <
typename TraitsType,
typename Lambda>
void
331run(
RunCommand& command,
const TraitsType& traits,
const Lambda& func)
339template <
typename TraitsType,
typename... ReducerArgs>
344 ItemRunCommand(
RunCommand& command,
const TraitsType& traits)
350 ItemRunCommand(
RunCommand& command,
const TraitsType& traits,
const std::tuple<ReducerArgs...>& reducer_args)
353 , m_reducer_args(reducer_args)
361 std::tuple<ReducerArgs...> m_reducer_args;
367template <
typename ItemType>
auto
378template <
typename ItemType>
auto
381 using TraitsType = impl::RunCommandItemEnumeratorTraitsT<ItemType>;
387template <
typename ItemType>
auto
388operator<<(RunCommand& command,
const ItemGroupT<ItemType>& items)
390 using TraitsType = impl::RunCommandItemEnumeratorTraitsT<ItemType>;
391 return ItemRunCommand<TraitsType>(command, TraitsType(items));
394template <
typename TraitsType,
typename Lambda>
397 run(nr.m_command, nr.m_traits, f);
400template <
typename TraitsType,
typename... ReducerArgs>
auto
403 return ItemRunCommand<TraitsType, ReducerArgs...>(command, args.m_traits, args.m_reducer_args);
406template <
typename TraitsType,
typename Lambda,
typename... ReducerArgs>
409 if constexpr (
sizeof...(ReducerArgs) > 0) {
413 run(nr.m_command, nr.m_traits, f);
421namespace Arcane::Accelerator::impl
427template <
typename ItemTypeName,
typename ItemContainerType,
typename... ReducerArgs>
auto
428makeExtendedItemEnumeratorLoop(
const ItemContainerType& container_type,
429 const ReducerArgs&... reducer_args)
432 return ItemRunCommandArgs<TraitsType, ReducerArgs...>(TraitsType(container_type), reducer_args...);
461#define RUNCOMMAND_ENUMERATE(ItemTypeName, iter_name, item_group, ...) \
462 A_FUNCINFO << ::Arcane::Accelerator::impl::makeExtendedItemEnumeratorLoop<ItemTypeName>(item_group __VA_OPT__(, __VA_ARGS__)) \
463 << [=] ARCCORE_HOST_DEVICE(::Arcane::Accelerator::impl::RunCommandItemEnumeratorTraitsT<ItemTypeName>::ValueType iter_name \
464 __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.
Déclarations de types sur les entités.
void _applyItems(RunCommand &command, typename TraitsType::ContainerType items, const Lambda &func, const ReducerArgs &... reducer_args)
Applique l'enumération func sur la liste d'entité items.
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.
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.
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.
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.
static void applyReducerArgs(ReducerArgs &... reducer_args)
Applique les fonctors des arguments additionnels.
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.
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.
-*- 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.