14#include "arccore/common/accelerator/internal/RunCommandImpl.h"
15#include "arccore/common/accelerator/internal/AcceleratorCoreGlobalInternal.h"
17#include "arccore/base/FatalErrorException.h"
18#include "arccore/base/ForLoopTraceInfo.h"
19#include "arccore/base/PlatformUtils.h"
20#include "arccore/base/Convert.h"
21#include "arccore/base/ConcurrencyBase.h"
23#include "arccore/common/accelerator/Runner.h"
24#include "arccore/common/accelerator/internal/IRunQueueEventImpl.h"
25#include "arccore/common/accelerator/internal/IRunQueueStream.h"
26#include "arccore/common/accelerator/internal/IRunnerRuntime.h"
27#include "arccore/common/accelerator/internal/RunQueueImpl.h"
28#include "arccore/common/accelerator/internal/ReduceMemoryImpl.h"
29#include "arccore/common/accelerator/internal/RunnerImpl.h"
34namespace Arcane::Accelerator::Impl
41RunCommandImpl(RunQueueImpl* queue)
43, m_execution_policy(queue->runner()->executionPolicy())
44, m_use_accelerator(isAcceleratorPolicy(m_execution_policy))
66 while (!m_reduce_memory_pool.empty()) {
67 delete m_reduce_memory_pool.top();
68 m_reduce_memory_pool.pop();
75IRunQueueEventImpl* RunCommandImpl::
78 if (m_use_sequential_timer_event)
79 return getSequentialRunQueueRuntime()->createEventImplWithTimer();
80 return runner()->_createEventWithTimer();
97 if (m_use_accelerator && !ProfilingRegistry::hasProfiling())
98 m_use_sequential_timer_event =
true;
100 m_start_event = _createEvent();
101 m_stop_event = _createEvent();
103 if (
auto v = Convert::Type<Int32>::tryParseFromEnvironment(
"ARCANE_ACCELERATOR_ALLOW_REUSE_COMMAND",
true))
104 m_is_allow_reuse_command = (v.value() != 0);
110RunCommandImpl* RunCommandImpl::
111create(RunQueueImpl* r)
113 RunCommandImpl* c = r->_internalCreateOrGetRunCommandImpl();
124notifyBeginLaunchKernel()
126 if (m_has_been_launched) {
127 if (!m_is_allow_reuse_command)
128 ARCCORE_FATAL(
"Command has already been launched. You can not re-use the same command.\n"
129 " You can temporarily allow it if you set environment variable\n"
130 " ARCANE_ACCELERATOR_ALLOW_REUSE_COMMAND to 1\n");
132 IRunQueueStream* stream = internalStream();
133 stream->notifyBeginLaunchKernel(*
this);
135 m_has_been_launched =
true;
136 if (m_use_profiling) {
137 m_start_event->recordQueue(stream);
138 m_begin_time = platform::getRealTimeNS();
139 m_loop_one_exec_stat_ptr = &m_loop_one_exec_stat;
140 m_loop_one_exec_stat.setBeginTime(m_begin_time);
152notifyEndLaunchKernel()
154 IRunQueueStream* stream = internalStream();
157 m_stop_event->recordQueue(stream);
158 stream->notifyEndLaunchKernel(*
this);
159 m_queue->_addRunningCommand(
this);
172notifyLaunchKernelSyclEvent(
void* sycl_event_ptr)
174 IRunQueueStream* stream = internalStream();
175 stream->_setSyclLastCommandEvent(sycl_event_ptr);
179 m_start_event->recordQueue(stream);
192notifyEndExecuteKernel()
195 if (!m_has_been_launched)
198 Int64 diff_time_ns = 0;
199 if (m_use_profiling){
200 diff_time_ns = m_stop_event->elapsedTime(m_start_event);
201 runner()->addTime((
double)diff_time_ns / 1.0e9);
204 ForLoopOneExecStat* exec_info = m_loop_one_exec_stat_ptr;
206 exec_info->setEndTime(m_begin_time + diff_time_ns);
208 ForLoopTraceInfo flti(traceInfo(), kernelName());
209 ProfilingRegistry::_threadLocalForLoopInstance()->merge(*exec_info, flti);
219 m_kernel_name = String();
220 m_trace_info = TraceInfo();
221 m_nb_thread_per_block = 0;
222 m_use_profiling = ProfilingRegistry::hasProfiling();
223 m_parallel_loop_options = ConcurrencyBase::defaultParallelLoopOptions();
225 m_loop_one_exec_stat.reset();
226 m_loop_one_exec_stat_ptr =
nullptr;
227 m_has_been_launched =
false;
228 m_has_living_run_command =
false;
229 m_may_be_put_in_pool =
false;
230 m_shared_memory_size = 0;
237IReduceMemoryImpl* RunCommandImpl::
238getOrCreateReduceMemoryImpl()
240 ReduceMemoryImpl* p = _getOrCreateReduceMemoryImpl();
242 m_active_reduce_memory_list.insert(p);
251releaseReduceMemoryImpl(ReduceMemoryImpl* p)
253 auto x = m_active_reduce_memory_list.find(p);
254 if (x == m_active_reduce_memory_list.end())
256 m_active_reduce_memory_list.erase(x);
257 m_reduce_memory_pool.push(p);
263IRunQueueStream* RunCommandImpl::
264internalStream()
const
266 return m_queue->_internalStream();
272RunnerImpl* RunCommandImpl::
275 return m_queue->runner();
281ReduceMemoryImpl* RunCommandImpl::
282_getOrCreateReduceMemoryImpl()
286 if (!m_use_accelerator)
289 auto& pool = m_reduce_memory_pool;
292 ReduceMemoryImpl* p = pool.top();
296 return new ReduceMemoryImpl(
this);
305_notifyDestroyRunCommand()
309 if (!m_has_been_launched || m_may_be_put_in_pool)
310 m_queue->_putInCommandPool(
this);
#define ARCCORE_FATAL(...)
Macro envoyant une exception FatalErrorException.