Arcane  v4.1.1.0
Documentation utilisateur
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 ARCCORE_ACCELERATOR_RUNCOMMANDLAUNCHIMPL_H
13#define ARCCORE_ACCELERATOR_RUNCOMMANDLAUNCHIMPL_H
14/*---------------------------------------------------------------------------*/
15/*---------------------------------------------------------------------------*/
16
17#include "arccore/accelerator/WorkGroupLoopRange.h"
18
20
21//#include "arcane/core/Concurrency.h"
22
23#include "arccore/common/SequentialFor.h"
24
25/*---------------------------------------------------------------------------*/
26/*---------------------------------------------------------------------------*/
27
28namespace Arcane::Accelerator::Impl
29{
30
31/*!
32 * \internal
33 * \brief Classe pour exécuter en séquentiel sur l'hôte une partie de la boucle.
34 */
36{
37 public:
38
39 //! Applique le fonctor \a func sur une boucle séqentielle.
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/*---------------------------------------------------------------------------*/
73/*!
74 * \internal
75 * \brief Applique le fonctor \a func sur une boucle séqentielle.
76 */
77template <typename Lambda, typename... RemainingArgs> void
78arccoreSequentialFor(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/*---------------------------------------------------------------------------*/
85/*!
86 * \internal
87 * \brief Applique le fonctor \a func sur une boucle parallèle.
88 */
89template <typename Lambda, typename... RemainingArgs> void
90arccoreParallelFor(WorkGroupLoopRange bounds, ForLoopRunInfo run_info,
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 arccoreParallelFor(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/*---------------------------------------------------------------------------*/
Types et macros pour gérer les boucles sur les accélérateurs.
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.
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.
Espace de nom pour l'utilisation des accélérateurs.
void arccoreSequentialFor(LoopBoundType< 1, IndexType > bounds, const Lambda &func, RemainingArgs... remaining_args)
Applique le functor func sur une boucle 1D.
std::int32_t Int32
Type entier signé sur 32 bits.