Arcane  v4.1.0.0
Documentation développeur
Chargement...
Recherche...
Aucune correspondance
RunCommandLaunchImpl.h
1// -*- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature -*-
2//-----------------------------------------------------------------------------
3// Copyright 2000-2024 CEA (www.cea.fr) IFPEN (www.ifpenergiesnouvelles.com)
4// See the top-level COPYRIGHT file for details.
5// SPDX-License-Identifier: Apache-2.0
6//-----------------------------------------------------------------------------
7/*---------------------------------------------------------------------------*/
8/* RunCommandLaunchImpl.h (C) 2000-2025 */
9/* */
10/* Implémentation d'une RunCommand pour le parallélisme hiérarchique. */
11/*---------------------------------------------------------------------------*/
12#ifndef ARCANE_ACCELERATOR_RUNCOMMANDLAUNCHIMPL_H
13#define ARCANE_ACCELERATOR_RUNCOMMANDLAUNCHIMPL_H
14/*---------------------------------------------------------------------------*/
15/*---------------------------------------------------------------------------*/
16
17#include "arcane/accelerator/WorkGroupLoopRange.h"
18
20
22
23#include "arccore/common/SequentialFor.h"
24
25/*---------------------------------------------------------------------------*/
26/*---------------------------------------------------------------------------*/
27
28namespace Arcane::Accelerator::Impl
29{
30
36{
37 public:
38
40 template <typename Lambda, typename... RemainingArgs> static void
41 apply(Int32 begin_index, Int32 nb_loop, WorkGroupLoopRange bounds,
42 const Lambda& func, RemainingArgs... remaining_args)
43 {
45 const Int32 group_size = bounds.groupSize();
46 Int32 loop_index = begin_index * group_size;
47 for (Int32 i = begin_index; i < (begin_index + nb_loop); ++i) {
48 // Pour la dernière itération de la boucle, le nombre d'éléments actifs peut-être
49 // inférieur à la taille d'un groupe si \a total_nb_element n'est pas
50 // un multiple de \a group_size.
51 Int32 nb_active = bounds.nbActiveItem(i);
52 func(WorkGroupLoopContext(loop_index, i, group_size, nb_active), remaining_args...);
53 loop_index += group_size;
54 }
55
57 }
58};
59
60/*---------------------------------------------------------------------------*/
61/*---------------------------------------------------------------------------*/
62
63} // namespace Arcane::Accelerator::Impl
64
65/*---------------------------------------------------------------------------*/
66/*---------------------------------------------------------------------------*/
67
68namespace Arcane::Accelerator
69{
70
71/*---------------------------------------------------------------------------*/
72/*---------------------------------------------------------------------------*/
77template <typename Lambda, typename... RemainingArgs> void
78arcaneSequentialFor(WorkGroupLoopRange bounds, const Lambda& func, const RemainingArgs&... remaining_args)
79{
80 Impl::WorkGroupSequentialForHelper::apply(0, bounds.nbGroup(), bounds, func, remaining_args...);
81}
82
83/*---------------------------------------------------------------------------*/
84/*---------------------------------------------------------------------------*/
89template <typename Lambda, typename... RemainingArgs> void
91 const Lambda& func, const RemainingArgs&... remaining_args)
92{
93 auto sub_func = [=](Int32 begin_index, Int32 nb_loop) {
94 Impl::WorkGroupSequentialForHelper::apply(begin_index, nb_loop, bounds, func, remaining_args...);
95 };
96 arcaneParallelFor(0, bounds.nbGroup(), run_info, sub_func);
97}
98
99/*---------------------------------------------------------------------------*/
100/*---------------------------------------------------------------------------*/
101
102} // namespace Arcane::Accelerator
103
104/*---------------------------------------------------------------------------*/
105/*---------------------------------------------------------------------------*/
106
107#endif
108
109/*---------------------------------------------------------------------------*/
110/*---------------------------------------------------------------------------*/
Classes, Types et macros pour gérer la concurrence.
Types et macros pour gérer les boucles sur les accélérateurs.
Classe pour exécuter en séquentiel sur l'hôte une partie de la boucle.
static void apply(Int32 begin_index, Int32 nb_loop, WorkGroupLoopRange bounds, const Lambda &func, RemainingArgs... remaining_args)
Applique le fonctor func sur une boucle séqentielle.
Contexte d'exécution d'une commande sur un ensemble de blocs.
Intervalle d'itération d'une boucle utilisant le parallélisme hiérarchique.
constexpr Int32 nbActiveItem(Int32 i) const
Nombre d'éléments actifs pour le i-ème groupe.
constexpr Int32 nbGroup() const
Nombre de groupes.
constexpr Int32 groupSize() const
Taille d'un groupe.
Informations d'exécution d'une boucle.
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.
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.
void arccoreParallelFor(WorkGroupLoopRange bounds, ForLoopRunInfo run_info, const Lambda &func, const RemainingArgs &... remaining_args)
Applique le fonctor func sur une boucle parallèle.
void arcaneSequentialFor(WorkGroupLoopRange bounds, const Lambda &func, const RemainingArgs &... remaining_args)
Applique le fonctor func sur une boucle séqentielle.
std::int32_t Int32
Type entier signé sur 32 bits.