14#include "arcane/accelerator/core/internal/RunCommandImpl.h"
15#include "arcane/accelerator/core/internal/AcceleratorCoreGlobalInternal.h"
17#include "arcane/utils/ForLoopTraceInfo.h"
19#include "arcane/utils/PlatformUtils.h"
20#include "arcane/utils/ValueConvert.h"
22#include "arcane/accelerator/core/Runner.h"
23#include "arcane/accelerator/core/internal/IRunQueueEventImpl.h"
24#include "arcane/accelerator/core/internal/IRunQueueStream.h"
25#include "arcane/accelerator/core/internal/IRunnerRuntime.h"
26#include "arcane/accelerator/core/internal/RunQueueImpl.h"
27#include "arcane/accelerator/core/internal/ReduceMemoryImpl.h"
28#include "arcane/accelerator/core/internal/RunnerImpl.h"
33namespace Arcane::Accelerator::impl
43RunCommandImpl(RunQueueImpl* queue)
67 while (!m_reduce_memory_pool.empty()) {
68 delete m_reduce_memory_pool.top();
69 m_reduce_memory_pool.pop();
76IRunQueueEventImpl* RunCommandImpl::
79 if (m_use_sequential_timer_event)
80 return getSequentialRunQueueRuntime()->createEventImplWithTimer();
81 return runner()->_createEventWithTimer();
98 if (m_use_accelerator && !ProfilingRegistry::hasProfiling())
99 m_use_sequential_timer_event =
true;
101 m_start_event = _createEvent();
102 m_stop_event = _createEvent();
104 if (
auto v = Convert::Type<Int32>::tryParseFromEnvironment(
"ARCANE_ACCELERATOR_ALLOW_REUSE_COMMAND",
true))
105 m_is_allow_reuse_command = (v.value() != 0);
111RunCommandImpl* RunCommandImpl::
112create(RunQueueImpl* r)
114 RunCommandImpl* c = r->_internalCreateOrGetRunCommandImpl();
125notifyBeginLaunchKernel()
127 if (m_has_been_launched) {
128 if (!m_is_allow_reuse_command)
129 ARCANE_FATAL(
"Command has already been launched. You can not re-use the same command.\n"
130 " You can temporarily allow it if you set environment variable\n"
131 " ARCANE_ACCELERATOR_ALLOW_REUSE_COMMAND to 1\n");
136 m_has_been_launched =
true;
137 if (m_use_profiling) {
138 m_start_event->recordQueue(stream);
139 m_begin_time = platform::getRealTimeNS();
140 m_loop_one_exec_stat_ptr = &m_loop_one_exec_stat;
141 m_loop_one_exec_stat.setBeginTime(m_begin_time);
153notifyEndLaunchKernel()
158 m_stop_event->recordQueue(stream);
160 m_queue->_addRunningCommand(
this);
180 m_start_event->recordQueue(stream);
193notifyEndExecuteKernel()
196 if (!m_has_been_launched)
200 if (m_use_profiling){
201 diff_time_ns = m_stop_event->elapsedTime(m_start_event);
210 ProfilingRegistry::_threadLocalForLoopInstance()->merge(*
exec_info,
flti);
222 m_nb_thread_per_block = 0;
223 m_use_profiling = ProfilingRegistry::hasProfiling();
224 m_parallel_loop_options = TaskFactory::defaultParallelLoopOptions();
226 m_loop_one_exec_stat.reset();
227 m_loop_one_exec_stat_ptr =
nullptr;
228 m_has_been_launched =
false;
229 m_has_living_run_command =
false;
230 m_may_be_put_in_pool =
false;
236IReduceMemoryImpl* RunCommandImpl::
237getOrCreateReduceMemoryImpl()
239 ReduceMemoryImpl*
p = _getOrCreateReduceMemoryImpl();
241 m_active_reduce_memory_list.insert(
p);
250releaseReduceMemoryImpl(ReduceMemoryImpl* p)
252 auto x = m_active_reduce_memory_list.find(p);
253 if (x == m_active_reduce_memory_list.end())
255 m_active_reduce_memory_list.erase(x);
256 m_reduce_memory_pool.push(p);
262IRunQueueStream* RunCommandImpl::
263internalStream()
const
265 return m_queue->_internalStream();
271RunnerImpl* RunCommandImpl::
274 return m_queue->runner();
280ReduceMemoryImpl* RunCommandImpl::
281_getOrCreateReduceMemoryImpl()
285 if (!m_use_accelerator)
288 auto& pool = m_reduce_memory_pool;
291 ReduceMemoryImpl* p = pool.top();
295 return new ReduceMemoryImpl(
this);
304_notifyDestroyRunCommand()
308 if (!m_has_been_launched || m_may_be_put_in_pool)
309 m_queue->_putInCommandPool(
this);
#define ARCANE_FATAL(...)
Macro envoyant une exception FatalErrorException.
Classes, Types et macros pour gérer la concurrence.
Interface d'un flux d'exécution pour une RunQueue.
virtual void notifyBeginLaunchKernel(impl::RunCommandImpl &command)=0
Notification avant le lancement de la commande.
virtual void _setSyclLastCommandEvent(void *sycl_event_ptr)
Pour SYCL, positionne l'évènement associé à la dernière commande exécutée.
virtual void notifyEndLaunchKernel(impl::RunCommandImpl &command)=0
Notification de fin de lancement de la commande.
Classe pour gérer le profiling d'une seule exécution d'une boucle.
Informations de trace pour une boucle 'for'.
Lecteur des fichiers de maillage via la bibliothèque LIMA.
Chaîne de caractères unicode.
bool isAcceleratorPolicy(eExecutionPolicy exec_policy)
Indique si exec_policy correspond à un accélérateur.
std::int64_t Int64
Type entier signé sur 64 bits.