Arcane  v4.1.4.0
Documentation développeur
Chargement...
Recherche...
Aucune correspondance
RunCommand.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/* RunCommand.cc (C) 2000-2026 */
9/* */
10/* Gestion d'une commande sur accélérateur. */
11/*---------------------------------------------------------------------------*/
12/*---------------------------------------------------------------------------*/
13
14#include "arccore/common/accelerator/RunCommand.h"
15
16#include "arccore/common/ArraySimdPadder.h"
17
18#include "arccore/common/accelerator/RunQueue.h"
19#include "arccore/common/accelerator/NativeStream.h"
20#include "arccore/common/accelerator/internal/RunQueueImpl.h"
21#include "arccore/common/accelerator/internal/ReduceMemoryImpl.h"
22#include "arccore/common/accelerator/internal/RunCommandImpl.h"
23#include "arccore/common/accelerator/internal/IRunQueueStream.h"
24
25/*---------------------------------------------------------------------------*/
26/*---------------------------------------------------------------------------*/
27
28namespace Arcane::Accelerator
29{
30
31/*---------------------------------------------------------------------------*/
32/*---------------------------------------------------------------------------*/
33
34RunCommand::
35RunCommand(const RunQueue& run_queue)
36: m_p(run_queue._getCommandImpl())
37{
38 m_p->m_has_living_run_command = true;
39}
40
41/*---------------------------------------------------------------------------*/
42/*---------------------------------------------------------------------------*/
43
44RunCommand::
45~RunCommand()
46{
47 m_p->m_has_living_run_command = false;
48 m_p->_notifyDestroyRunCommand();
49}
50
51/*---------------------------------------------------------------------------*/
52/*---------------------------------------------------------------------------*/
53
54/*---------------------------------------------------------------------------*/
55/*---------------------------------------------------------------------------*/
56
58eExecutionPolicy RunCommand::
59executionPolicy() const
60{
61 return m_p->m_execution_policy;
62}
63
64/*---------------------------------------------------------------------------*/
65/*---------------------------------------------------------------------------*/
66
67const TraceInfo& RunCommand::
68traceInfo() const
69{
70 return m_p->traceInfo();
71}
72
73/*---------------------------------------------------------------------------*/
74/*---------------------------------------------------------------------------*/
75
76const String& RunCommand::
77kernelName() const
78{
79 return m_p->kernelName();
80}
81
82/*---------------------------------------------------------------------------*/
83/*---------------------------------------------------------------------------*/
84
85Int32 RunCommand::
86nbThreadPerBlock() const
87{
88 return m_p->m_nb_thread_per_block;
89}
90
91/*---------------------------------------------------------------------------*/
92/*---------------------------------------------------------------------------*/
93
94RunCommand& RunCommand::
95addTraceInfo(const TraceInfo& ti)
96{
97 m_p->m_trace_info = ti;
98 return *this;
99}
100
101/*---------------------------------------------------------------------------*/
102/*---------------------------------------------------------------------------*/
103
104RunCommand& RunCommand::
105addKernelName(const String& v)
106{
107 m_p->m_kernel_name = v;
108 return *this;
109}
110
111/*---------------------------------------------------------------------------*/
112/*---------------------------------------------------------------------------*/
113
114RunCommand& RunCommand::
115addNbThreadPerBlock(Int32 v)
116{
117 if (v < 0)
118 v = 0;
119 if (v > 0 && v < 32)
120 v = 32;
121 m_p->m_nb_thread_per_block = v;
122 return *this;
123}
124
125/*---------------------------------------------------------------------------*/
126/*---------------------------------------------------------------------------*/
127
128RunCommand& RunCommand::
129addNbStride(Int32 v)
130{
131 // On ne gère le pas de grille que sur accélérateur.
132 if (m_p->m_use_accelerator){
133 if (v < 0)
134 v = 1;
135 m_p->m_nb_stride = v;
136 }
137 return *this;
138}
139
140/*---------------------------------------------------------------------------*/
141/*---------------------------------------------------------------------------*/
142
143void RunCommand::
144setParallelLoopOptions(const ParallelLoopOptions& opt)
145{
146 m_p->m_parallel_loop_options = opt;
147}
148
149/*---------------------------------------------------------------------------*/
150/*---------------------------------------------------------------------------*/
151
152const ParallelLoopOptions& RunCommand::
153parallelLoopOptions() const
154{
155 return m_p->m_parallel_loop_options;
156}
157
158/*---------------------------------------------------------------------------*/
159/*---------------------------------------------------------------------------*/
160
161extern "C++" ARCCORE_COMMON_EXPORT
162RunCommand&
163operator<<(RunCommand& command, const TraceInfo& trace_info)
164{
165 return command.addTraceInfo(trace_info);
166}
167
168/*---------------------------------------------------------------------------*/
169/*---------------------------------------------------------------------------*/
170
171Impl::NativeStream RunCommand::
172_internalNativeStream() const
173{
174 return m_p->internalStream()->nativeStream();
175}
176
177/*---------------------------------------------------------------------------*/
178/*---------------------------------------------------------------------------*/
179
181_internalQueueImpl() const
182{
183 return m_p->m_queue;
184}
185
186/*---------------------------------------------------------------------------*/
187/*---------------------------------------------------------------------------*/
188
189Impl::RunCommandImpl* RunCommand::
190_internalCreateImpl(Impl::RunQueueImpl* queue)
191{
192 return new Impl::RunCommandImpl(queue);
193}
194
195/*---------------------------------------------------------------------------*/
196/*---------------------------------------------------------------------------*/
197
198void RunCommand::
199_internalDestroyImpl(Impl::RunCommandImpl* p)
200{
201 delete p;
202}
203
204/*---------------------------------------------------------------------------*/
205/*---------------------------------------------------------------------------*/
206
207void RunCommand::
208_allocateReduceMemory(Int32 nb_grid)
209{
210 auto& mem_list = m_p->m_active_reduce_memory_list;
211 if (!mem_list.empty()) {
212 for (auto& x : mem_list)
213 x->setGridSizeAndAllocate(nb_grid);
214 }
215}
216
217/*---------------------------------------------------------------------------*/
218/*---------------------------------------------------------------------------*/
219
220void RunCommand::
221_internalNotifyBeginLaunchKernel()
222{
223 m_p->notifyBeginLaunchKernel();
224}
225
226/*---------------------------------------------------------------------------*/
227/*---------------------------------------------------------------------------*/
228
229void RunCommand::
230_internalNotifyEndLaunchKernel()
231{
232 m_p->notifyEndLaunchKernel();
233}
234
235/*---------------------------------------------------------------------------*/
236/*---------------------------------------------------------------------------*/
237
238void RunCommand::
239_internalNotifyBeginLaunchKernelSyclEvent(void* sycl_event_ptr)
240{
241 m_p->notifyLaunchKernelSyclEvent(sycl_event_ptr);
242}
243
244/*---------------------------------------------------------------------------*/
245/*---------------------------------------------------------------------------*/
246
247ForLoopOneExecStat* RunCommand::
248_internalCommandExecStat()
249{
250 return m_p->m_loop_one_exec_stat_ptr;
251}
252
253/*---------------------------------------------------------------------------*/
254/*---------------------------------------------------------------------------*/
255
256Int32 RunCommand::
257_addSharedMemory(Int32 size)
258{
259 Int32 current_size = m_p->m_shared_memory_size;
260 m_p->m_shared_memory_size += ArraySimdPadder::getSizeWithSpecificPadding<16>(size);
261 return current_size;
262}
263
264/*---------------------------------------------------------------------------*/
265/*---------------------------------------------------------------------------*/
266
267Int32 RunCommand::
268_sharedMemory() const
269{
270 return m_p->m_shared_memory_size;
271}
272
273/*---------------------------------------------------------------------------*/
274/*---------------------------------------------------------------------------*/
275
276Int32 RunCommand::
277nbStride() const
278{
279 return m_p->m_nb_stride;
280}
281
282/*---------------------------------------------------------------------------*/
283/*---------------------------------------------------------------------------*/
284
285} // namespace Arcane::Accelerator
286
287/*---------------------------------------------------------------------------*/
288/*---------------------------------------------------------------------------*/
friend ARCCORE_COMMON_EXPORT RunCommand & operator<<(RunCommand &command, const TraceInfo &trace_info)
Affichage des informations de la commande.
RunCommand & addTraceInfo(const TraceInfo &ti)
Positionne le informations de trace.
Definition RunCommand.cc:95
Options d'exécution d'une boucle parallèle en multi-thread.
Chaîne de caractères unicode.
Espace de nom pour l'utilisation des accélérateurs.
eExecutionPolicy
Politique d'exécution pour un Runner.
std::int32_t Int32
Type entier signé sur 32 bits.