Arcane  v4.1.4.0
Documentation développeur
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/common/accelerator/RunCommand.h"
18
19/*---------------------------------------------------------------------------*/
20/*---------------------------------------------------------------------------*/
21
22namespace Arcane::Accelerator
23{
24
25/*---------------------------------------------------------------------------*/
26/*---------------------------------------------------------------------------*/
27
28template <bool IsCooperativeLaunch, typename IndexType_> ARCCORE_ACCELERATOR_EXPORT void
30setBlockSize(Int32 block_size)
31{
32 if ((block_size <= 0) || ((block_size % 32) != 0))
33 ARCCORE_FATAL("Invalid value '{0}' for block size: should be a multiple of 32", block_size);
34 m_block_size = block_size;
35 _setNbBlock();
36}
37
38/*---------------------------------------------------------------------------*/
39/*---------------------------------------------------------------------------*/
40
41template <bool IsCooperativeLaunch, typename IndexType_> ARCCORE_ACCELERATOR_EXPORT void
43setBlockSize(const RunCommand& command)
44{
45 // TODO: en multi-threading, à calculer en fonction du nombre de threads
46 // disponibles et du nombre total d'éléments
47 Int32 block_size = 1024;
48 eExecutionPolicy policy = command.executionPolicy();
49 if (isAcceleratorPolicy(policy))
50 block_size = 256;
51 else if (IsCooperativeLaunch) {
52 // TODO: gérer le multi-threading.
53 // En séquentiel, il n'y a qu'un seul bloc dont la taille est le nombre
54 // d'éléments.
55 m_block_size = m_nb_element;
56 m_nb_block = 1;
57 return;
58 }
59 setBlockSize(block_size);
60}
61
62/*---------------------------------------------------------------------------*/
63/*---------------------------------------------------------------------------*/
64
65template <bool IsCooperativeLaunch, typename IndexType_> void
68{
69 m_nb_block = static_cast<Int32>((m_nb_element + (m_block_size - 1)) / m_block_size);
70}
71
72/*---------------------------------------------------------------------------*/
73/*---------------------------------------------------------------------------*/
74
79
80/*---------------------------------------------------------------------------*/
81/*---------------------------------------------------------------------------*/
82
83} // namespace Arcane::Accelerator
84
85/*---------------------------------------------------------------------------*/
86/*---------------------------------------------------------------------------*/
#define ARCCORE_FATAL(...)
Macro envoyant une exception FatalErrorException.
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.
ARCCORE_ACCELERATOR_EXPORT void setBlockSize(Int32 nb_block)
Positionne la taille d'un bloc.
Espace de nom pour l'utilisation des accélérateurs.
eExecutionPolicy
Politique d'exécution pour un Runner.
bool isAcceleratorPolicy(eExecutionPolicy exec_policy)
Indique si exec_policy correspond à un accélérateur.
std::int32_t Int32
Type entier signé sur 32 bits.