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");
133 IRunQueueStream* stream = internalStream();
134 stream->notifyBeginLaunchKernel(*
this);
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()
155 IRunQueueStream* stream = internalStream();
158 m_stop_event->recordQueue(stream);
159 stream->notifyEndLaunchKernel(*
this);
160 m_queue->_addRunningCommand(
this);
173notifyLaunchKernelSyclEvent(
void* sycl_event_ptr)
175 IRunQueueStream* stream = internalStream();
176 stream->_setSyclLastCommandEvent(sycl_event_ptr);
180 m_start_event->recordQueue(stream);
193notifyEndExecuteKernel()
196 if (!m_has_been_launched)
199 Int64 diff_time_ns = 0;
200 if (m_use_profiling){
201 diff_time_ns = m_stop_event->elapsedTime(m_start_event);
202 runner()->addTime((
double)diff_time_ns / 1.0e9);
205 ForLoopOneExecStat* exec_info = m_loop_one_exec_stat_ptr;
207 exec_info->setEndTime(m_begin_time + diff_time_ns);
209 ForLoopTraceInfo flti(traceInfo(), kernelName());
210 ProfilingRegistry::_threadLocalForLoopInstance()->merge(*exec_info, flti);
220 m_kernel_name = String();
221 m_trace_info = TraceInfo();
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.
bool isAcceleratorPolicy(eExecutionPolicy exec_policy)
Indique si exec_policy correspond à un accélérateur.