Arcane  v4.1.1.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-2025 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-2025 */
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
57const TraceInfo& RunCommand::
58traceInfo() const
59{
60 return m_p->traceInfo();
61}
62
63/*---------------------------------------------------------------------------*/
64/*---------------------------------------------------------------------------*/
65
66const String& RunCommand::
67kernelName() const
68{
69 return m_p->kernelName();
70}
71
72/*---------------------------------------------------------------------------*/
73/*---------------------------------------------------------------------------*/
74
75Int32 RunCommand::
76nbThreadPerBlock() const
77{
78 return m_p->m_nb_thread_per_block;
79}
80
81/*---------------------------------------------------------------------------*/
82/*---------------------------------------------------------------------------*/
83
84RunCommand& RunCommand::
85addTraceInfo(const TraceInfo& ti)
86{
87 m_p->m_trace_info = ti;
88 return *this;
89}
90
91/*---------------------------------------------------------------------------*/
92/*---------------------------------------------------------------------------*/
93
94RunCommand& RunCommand::
95addKernelName(const String& v)
96{
97 m_p->m_kernel_name = v;
98 return *this;
99}
100
101/*---------------------------------------------------------------------------*/
102/*---------------------------------------------------------------------------*/
103
104RunCommand& RunCommand::
105addNbThreadPerBlock(Int32 v)
106{
107 if (v < 0)
108 v = 0;
109 if (v > 0 && v < 32)
110 v = 32;
111 m_p->m_nb_thread_per_block = v;
112 return *this;
113}
114
115/*---------------------------------------------------------------------------*/
116/*---------------------------------------------------------------------------*/
117
118void RunCommand::
119setParallelLoopOptions(const ParallelLoopOptions& opt)
120{
121 m_p->m_parallel_loop_options = opt;
122}
123
124/*---------------------------------------------------------------------------*/
125/*---------------------------------------------------------------------------*/
126
127const ParallelLoopOptions& RunCommand::
128parallelLoopOptions() const
129{
130 return m_p->m_parallel_loop_options;
131}
132
133/*---------------------------------------------------------------------------*/
134/*---------------------------------------------------------------------------*/
135
136extern "C++" ARCCORE_COMMON_EXPORT
137RunCommand&
138operator<<(RunCommand& command, const TraceInfo& trace_info)
139{
140 return command.addTraceInfo(trace_info);
141}
142
143/*---------------------------------------------------------------------------*/
144/*---------------------------------------------------------------------------*/
145
146Impl::NativeStream RunCommand::
147_internalNativeStream() const
148{
149 return m_p->internalStream()->nativeStream();
150}
151
152/*---------------------------------------------------------------------------*/
153/*---------------------------------------------------------------------------*/
154
156_internalQueueImpl() const
157{
158 return m_p->m_queue;
159}
160
161/*---------------------------------------------------------------------------*/
162/*---------------------------------------------------------------------------*/
163
164impl::RunCommandImpl* RunCommand::
165_internalCreateImpl(impl::RunQueueImpl* queue)
166{
167 return new impl::RunCommandImpl(queue);
168}
169
170/*---------------------------------------------------------------------------*/
171/*---------------------------------------------------------------------------*/
172
173void RunCommand::
174_internalDestroyImpl(impl::RunCommandImpl* p)
175{
176 delete p;
177}
178
179/*---------------------------------------------------------------------------*/
180/*---------------------------------------------------------------------------*/
181
182void RunCommand::
183_allocateReduceMemory(Int32 nb_grid)
184{
185 auto& mem_list = m_p->m_active_reduce_memory_list;
186 if (!mem_list.empty()) {
187 for (auto& x : mem_list)
188 x->setGridSizeAndAllocate(nb_grid);
189 }
190}
191
192/*---------------------------------------------------------------------------*/
193/*---------------------------------------------------------------------------*/
194
195void RunCommand::
196_internalNotifyBeginLaunchKernel()
197{
198 m_p->notifyBeginLaunchKernel();
199}
200
201/*---------------------------------------------------------------------------*/
202/*---------------------------------------------------------------------------*/
203
204void RunCommand::
205_internalNotifyEndLaunchKernel()
206{
207 m_p->notifyEndLaunchKernel();
208}
209
210/*---------------------------------------------------------------------------*/
211/*---------------------------------------------------------------------------*/
212
213void RunCommand::
214_internalNotifyBeginLaunchKernelSyclEvent(void* sycl_event_ptr)
215{
216 m_p->notifyLaunchKernelSyclEvent(sycl_event_ptr);
217}
218
219/*---------------------------------------------------------------------------*/
220/*---------------------------------------------------------------------------*/
221
222ForLoopOneExecStat* RunCommand::
223_internalCommandExecStat()
224{
225 return m_p->m_loop_one_exec_stat_ptr;
226}
227
228/*---------------------------------------------------------------------------*/
229/*---------------------------------------------------------------------------*/
230
231Int32 RunCommand::
232_addSharedMemory(Int32 size)
233{
234 Int32 current_size = m_p->m_shared_memory_size;
235 m_p->m_shared_memory_size += ArraySimdPadder::getSizeWithSpecificPadding<16>(size);
236 return current_size;
237}
238
239/*---------------------------------------------------------------------------*/
240/*---------------------------------------------------------------------------*/
241
242Int32 RunCommand::
243_sharedMemory() const
244{
245 return m_p->m_shared_memory_size;
246}
247
248/*---------------------------------------------------------------------------*/
249/*---------------------------------------------------------------------------*/
250
251} // namespace Arcane::Accelerator
252
253/*---------------------------------------------------------------------------*/
254/*---------------------------------------------------------------------------*/
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:85
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.
std::int32_t Int32
Type entier signé sur 32 bits.