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
43, m_execution_policy(queue->runner()->executionPolicy())
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);
106 if (
auto v = Convert::Type<Int32>::tryParseFromEnvironment(
"ARCANE_ACCELERATOR_NB_GRID_STRIDE",
true)) {
110 m_default_nb_stride = n;
117RunCommandImpl* RunCommandImpl::
118create(RunQueueImpl* r)
120 RunCommandImpl* c = r->_internalCreateOrGetRunCommandImpl();
132notifyBeginLaunchKernel()
136 ARCCORE_FATAL(
"Command has already been launched. You can not re-use the same command.\n"
137 " You can temporarily allow it if you set environment variable\n"
138 " ARCANE_ACCELERATOR_ALLOW_REUSE_COMMAND to 1\n");
147 m_loop_one_exec_stat_ptr = &m_loop_one_exec_stat;
161notifyEndLaunchKernel()
168 m_queue->_addRunningCommand(
this);
182notifyLaunchKernelSyclEvent(
void* sycl_event_ptr)
203notifyEndExecuteKernel()
209 Int64 diff_time_ns = 0;
212 runner()->addTime((
double)diff_time_ns / 1.0e9);
232 m_nb_thread_per_block = 0;
236 m_loop_one_exec_stat.reset();
237 m_loop_one_exec_stat_ptr =
nullptr;
238 m_has_been_launched =
false;
239 m_has_living_run_command =
false;
240 m_may_be_put_in_pool =
false;
241 m_shared_memory_size = 0;
242 m_nb_stride = m_default_nb_stride;
248IReduceMemoryImpl* RunCommandImpl::
249getOrCreateReduceMemoryImpl()
251 ReduceMemoryImpl* p = _getOrCreateReduceMemoryImpl();
253 m_active_reduce_memory_list.insert(p);
262releaseReduceMemoryImpl(ReduceMemoryImpl* p)
264 auto x = m_active_reduce_memory_list.find(p);
265 if (x == m_active_reduce_memory_list.end())
267 m_active_reduce_memory_list.erase(x);
268 m_reduce_memory_pool.push(p);
274IRunQueueStream* RunCommandImpl::
275internalStream()
const
277 return m_queue->_internalStream();
283RunnerImpl* RunCommandImpl::
286 return m_queue->runner();
292ReduceMemoryImpl* RunCommandImpl::
293_getOrCreateReduceMemoryImpl()
297 if (!m_use_accelerator)
300 auto& pool = m_reduce_memory_pool;
303 ReduceMemoryImpl* p = pool.top();
307 return new ReduceMemoryImpl(
this);
317_notifyDestroyRunCommand()
322 m_queue->_putInCommandPool(
this);
#define ARCCORE_FATAL(...)
Macro throwing a FatalErrorException.
Interface of an execution stream for a RunQueue.
virtual void notifyEndLaunchKernel(RunCommandImpl &command)=0
Notification of command launch completion.
virtual void _setSyclLastCommandEvent(void *sycl_event_ptr)
For SYCL, positions the event associated with the last executed command.
virtual void notifyBeginLaunchKernel(RunCommandImpl &command)=0
Notification before command launch.
bool m_use_profiling
Indicates if profiling is desired.
bool m_may_be_put_in_pool
Indicates if the command can be returned to the pool associated with the RunQueue.
bool m_is_allow_reuse_command
Indicates if we allow the same command to be used multiple times.
bool m_has_been_launched
Indicates if the command has been launched.
IRunQueueEventImpl * m_start_event
Events for the start and end of execution.
Int64 m_begin_time
Time when the command is launched.
IRunQueueEventImpl * m_stop_event
Events for the end of execution.
Execution queue for accelerator.
static const ParallelLoopOptions & defaultParallelLoopOptions()
Default execution values for a parallel loop.
Class to manage the profiling of a single loop execution.
void setEndTime(Int64 v)
Sets the loop end time in nanoseconds.
Trace information for a 'for' loop.
static Impl::ForLoopStatInfoList * _threadLocalForLoopInstance()
static bool hasProfiling()
Indicates if profiling is active.
Unicode character string.
bool isAcceleratorPolicy(eExecutionPolicy exec_policy)
Indicates if exec_policy corresponds to an accelerator.
std::int64_t Int64
Signed integer type of 64 bits.