Arcane  v4.1.4.0
Documentation développeur
Chargement...
Recherche...
Aucune correspondance
CooperativeWorkGroupLoopRange.h
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/* CooperativeWorkGroupLoopRange.h (C) 2000-2026 */
9/* */
10/* Boucle pour le parallélisme hiérarchique coopératif. */
11/*---------------------------------------------------------------------------*/
12#ifndef ARCCORE_ACCELERATOR_COOPERATIVEWORKGROUPLOOPRANGE_H
13#define ARCCORE_ACCELERATOR_COOPERATIVEWORKGROUPLOOPRANGE_H
14/*---------------------------------------------------------------------------*/
15/*---------------------------------------------------------------------------*/
16
17#include "arccore/accelerator/WorkGroupLoopRange.h"
18
19/*---------------------------------------------------------------------------*/
20/*---------------------------------------------------------------------------*/
21
22namespace Arcane::Accelerator
23{
24
25/*---------------------------------------------------------------------------*/
26/*---------------------------------------------------------------------------*/
35{
36 template<typename T> friend class CooperativeWorkGroupLoopContext;
37
38 private:
39
43
44 public:
45
47 Int32 nbBlock() const { return 1; }
48
50 void barrier()
51 {
52 // TODO: A implementer pour le multi-threading via std::barrier()
53 }
54};
55
56/*---------------------------------------------------------------------------*/
57/*---------------------------------------------------------------------------*/
58
59#if defined(ARCCORE_COMPILING_CUDA_OR_HIP)
60
61/*---------------------------------------------------------------------------*/
62/*---------------------------------------------------------------------------*/
67class CooperativeDeviceWorkItemGrid
68{
69 template <typename T> friend class CooperativeWorkGroupLoopContext;
70
71 private:
72
79 __device__ CooperativeDeviceWorkItemGrid()
80 : m_grid_group(cooperative_groups::this_grid())
81 {}
82
83 public:
84
86 __device__ Int32 nbBlock() const { return m_grid_group.group_dim().x; }
87
89 __device__ void barrier() { m_grid_group.sync(); }
90
91 private:
92
93 cooperative_groups::grid_group m_grid_group;
94};
95
96/*---------------------------------------------------------------------------*/
97/*---------------------------------------------------------------------------*/
98
99#endif
100
101/*---------------------------------------------------------------------------*/
102/*---------------------------------------------------------------------------*/
111template <typename IndexType_>
113: public WorkGroupLoopContextBase<IndexType_>
114{
115 // Pour accéder aux constructeurs
116 friend class CooperativeWorkGroupLoopRange<IndexType_>;
119 using BaseClass = WorkGroupLoopContextBase<IndexType_>;
120
121 public:
122
123 using IndexType = IndexType_;
124
125 private:
126
128 constexpr CooperativeWorkGroupLoopContext(IndexType loop_index, Int32 group_index,
129 Int32 group_size, Int32 nb_active_item, IndexType total_size)
130 : BaseClass(loop_index, group_index, group_size, nb_active_item, total_size)
131 {
132 }
133
134 // Ce constructeur n'est utilisé que sur le device
135 // Il ne fait rien car les valeurs utiles sont récupérées via cooperative_groups::this_thread_block()
136 explicit constexpr ARCCORE_DEVICE CooperativeWorkGroupLoopContext(IndexType total_size)
137 : BaseClass(total_size)
138 {}
139
140 public:
141
142#if defined(ARCCORE_DEVICE_CODE) && !defined(ARCCORE_COMPILING_SYCL)
144 __device__ CooperativeDeviceWorkItemGrid grid() const { return CooperativeDeviceWorkItemGrid{}; }
145#else
148#endif
149};
150
151/*---------------------------------------------------------------------------*/
152/*---------------------------------------------------------------------------*/
153/*
154 * Implémentation pour SYCL.
155 */
156#if defined(ARCCORE_COMPILING_SYCL)
157
161class SyclCooperativeDeviceWorkItemGrid
162{
163 template <typename T> friend class SyclCooperativeWorkGroupLoopContext;
164
165 private:
166
167 explicit SyclCooperativeDeviceWorkItemGrid(sycl::nd_item<1> n)
168 : m_nd_item(n)
169 {
170 }
171
172 public:
173
175 Int32 nbBlock() const { return static_cast<Int32>(m_nd_item.get_group_range(0)); }
176
178 void barrier() { /* Not Yet Implemented */ }
179
180 private:
181
182 sycl::nd_item<1> m_nd_item;
183};
184
185/*---------------------------------------------------------------------------*/
186/*---------------------------------------------------------------------------*/
193template <typename IndexType_>
195: public SyclWorkGroupLoopContextBase<IndexType_>
196{
197 friend CooperativeWorkGroupLoopRange<IndexType_>;
198 friend Impl::WorkGroupLoopContextBuilder;
199
200 public:
201
202 using IndexType = IndexType_;
203
204 private:
205
206 // Ce constructeur n'est utilisé que sur le device
207 explicit SyclCooperativeWorkGroupLoopContext(sycl::nd_item<1> nd_item, IndexType total_size)
208 : SyclWorkGroupLoopContextBase<IndexType_>(nd_item, total_size)
209 {
210 }
211
212 public:
213
215 SyclCooperativeDeviceWorkItemGrid grid() const
216 {
217 return SyclCooperativeDeviceWorkItemGrid(this->m_nd_item);
218 }
219};
220
221/*---------------------------------------------------------------------------*/
222/*---------------------------------------------------------------------------*/
223
224#endif // ARCCORE_COMPILING_SYCL
225
226/*---------------------------------------------------------------------------*/
227/*---------------------------------------------------------------------------*/
234template <typename IndexType_>
235class CooperativeWorkGroupLoopRange
236: public WorkGroupLoopRangeBase<IndexType_>
237{
238 public:
239
241 using IndexType = IndexType_;
242
243 // Pour indiquer au KernelLauncher qu'on souhaite un lancement coopératif.
244 static constexpr bool isCooperativeLaunch() { return true; }
245
246 public:
247
248 CooperativeWorkGroupLoopRange() = default;
249 explicit CooperativeWorkGroupLoopRange(IndexType total_nb_element)
250 : WorkGroupLoopRangeBase<IndexType_>(total_nb_element)
251 {}
252
253 public:
254};
255
256/*---------------------------------------------------------------------------*/
257/*---------------------------------------------------------------------------*/
258
259} // namespace Arcane::Accelerator
260
261/*---------------------------------------------------------------------------*/
262/*---------------------------------------------------------------------------*/
263
264#endif
265
266/*---------------------------------------------------------------------------*/
267/*---------------------------------------------------------------------------*/
Gère une grille de WorkItem dans un CooperativeWorkGroupLoopRange pour l'hôte.
Int32 nbBlock() const
Nombre de blocs dans la grille.
void barrier()
Bloque tant que tous les WorkItem de la grille ne sont pas arrivés ici.
Contexte d'exécution d'une commande sur un ensemble de blocs.
constexpr CooperativeWorkGroupLoopContext(IndexType loop_index, Int32 group_index, Int32 group_size, Int32 nb_active_item, IndexType total_size)
Ce constructeur est utilisé dans l'implémentation hôte.
CooperativeHostWorkItemGrid grid() const
Groupe courant.
Intervalle d'itération d'une boucle utilisant le parallélisme hiérarchique collaboratif.
Classe pour exécuter en séquentiel sur l'hôte une partie de la boucle.
constexpr WorkGroupLoopContextBase(IndexType loop_index, Int32 group_index, Int32 group_size, Int32 nb_active_item, IndexType total_size)
Ce constructeur est utilisé dans l'implémentation hôte.
Espace de nom pour l'utilisation des accélérateurs.
std::int32_t Int32
Type entier signé sur 32 bits.