Arcane  v4.1.4.0
Documentation utilisateur
Chargement...
Recherche...
Aucune correspondance
WorkGroupLoopRange.cc
1// -*- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature -*-
2//-----------------------------------------------------------------------------
3// Copyright 2000-2026 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/* WorkGroupLoopRange.cc (C) 2000-2026 */
9/* */
10/* Boucle pour le parallélisme hiérarchique. */
11/*---------------------------------------------------------------------------*/
12/*---------------------------------------------------------------------------*/
13
14#include "arccore/accelerator/WorkGroupLoopRange.h"
15
16#include "arccore/base/FatalErrorException.h"
17#include "arccore/base/ParallelLoopOptions.h"
18
19#include "arccore/common/accelerator/RunCommand.h"
20
21/*---------------------------------------------------------------------------*/
22/*---------------------------------------------------------------------------*/
23
24namespace Arcane::Accelerator
25{
26
27/*---------------------------------------------------------------------------*/
28/*---------------------------------------------------------------------------*/
29
30template <bool IsCooperativeLaunch, typename IndexType_> ARCCORE_ACCELERATOR_EXPORT void
32setBlockSize(IndexType block_size)
33{
34 if ((block_size <= 0) || ((block_size % 32) != 0))
35 ARCCORE_FATAL("Invalid value '{0}' for block size: should be a multiple of 32", block_size);
36 m_block_size = block_size;
37 _setNbBlock();
38}
39
40/*---------------------------------------------------------------------------*/
41/*---------------------------------------------------------------------------*/
42
43template <bool IsCooperativeLaunch, typename IndexType_> ARCCORE_ACCELERATOR_EXPORT void
46{
47 // TODO: en multi-threading, à calculer en fonction du nombre de threads
48 // disponibles et du nombre total d'éléments
49 IndexType block_size = 1024;
50 eExecutionPolicy policy = command.executionPolicy();
51 if (isAcceleratorPolicy(policy))
52 block_size = 256;
53 else if (policy == eExecutionPolicy::Thread) {
54 ParallelLoopOptions loop_options = command.parallelLoopOptions();
55 Int32 nb_thread = loop_options.maxThread();
56 if (nb_thread == 0)
57 nb_thread = 1;
58 m_nb_block = nb_thread;
59 m_block_size = (m_nb_element + (nb_thread - 1)) / nb_thread;
60 loop_options.setGrainSize(1);
61 command.setParallelLoopOptions(loop_options);
62 return;
63 }
64 else if (IsCooperativeLaunch) {
65 // TODO: gérer le multi-threading.
66 // En séquentiel, il n'y a qu'un seul bloc dont la taille est le nombre
67 // d'éléments.
68 m_block_size = m_nb_element;
69 m_nb_block = 1;
70 return;
71 }
72 setBlockSize(block_size);
73}
74
75/*---------------------------------------------------------------------------*/
76/*---------------------------------------------------------------------------*/
77
78template <bool IsCooperativeLaunch, typename IndexType_> void
81{
82 m_nb_block = static_cast<Int32>((m_nb_element + (m_block_size - 1)) / m_block_size);
83}
84
85/*---------------------------------------------------------------------------*/
86/*---------------------------------------------------------------------------*/
87
92
93/*---------------------------------------------------------------------------*/
94/*---------------------------------------------------------------------------*/
95
96} // namespace Arcane::Accelerator
97
98/*---------------------------------------------------------------------------*/
99/*---------------------------------------------------------------------------*/
#define ARCCORE_FATAL(...)
Macro envoyant une exception FatalErrorException.
const ParallelLoopOptions & parallelLoopOptions() const
Configuration des boucles multi-thread.
void setParallelLoopOptions(const ParallelLoopOptions &opt)
Positionne la configuration des boucles multi-thread.
eExecutionPolicy executionPolicy() const
Politique d'exécution de la commande.
Definition RunCommand.cc:59
Intervalle d'itération d'une boucle utilisant le parallélisme hiérarchique.
void setBlockSize(IndexType nb_block)
Positionne la taille d'un bloc.
Options d'exécution d'une boucle parallèle en multi-thread.
Int32 maxThread() const
Nombre maximal de threads autorisés.
void setGrainSize(Integer v)
Positionne la taille (approximative) d'un intervalle d'itération.
Espace de nom pour l'utilisation des accélérateurs.
eExecutionPolicy
Politique d'exécution pour un Runner.
@ Thread
Politique d'exécution multi-thread.
bool isAcceleratorPolicy(eExecutionPolicy exec_policy)
Indique si exec_policy correspond à un accélérateur.
std::int32_t Int32
Type entier signé sur 32 bits.