14#include "arccore/common/accelerator/internal/RunQueueImpl.h"
17#include "arccore/common/SmallArray.h"
19#include "arccore/common/accelerator/internal/IRunnerRuntime.h"
20#include "arccore/common/accelerator/internal/IRunQueueStream.h"
21#include "arccore/common/accelerator/internal/RunCommandImpl.h"
22#include "arccore/common/accelerator/internal/RunnerImpl.h"
23#include "arccore/common/accelerator/internal/IRunQueueEventImpl.h"
25#include "arccore/common/accelerator/Runner.h"
26#include "arccore/common/accelerator/DeviceId.h"
27#include "arccore/common/accelerator/RunQueueEvent.h"
28#include "arccore/common/accelerator/KernelLaunchArgs.h"
30#include <unordered_set>
35namespace Arcane::Accelerator::Impl
46 explicit Lock(RunQueueImpl* p)
48 if (p->m_use_pool_mutex) {
49 m_mutex = p->m_pool_mutex.get();
60 Lock(
const Lock&) =
delete;
61 Lock& operator=(
const Lock&) =
delete;
65 std::mutex* m_mutex =
nullptr;
73: m_runner_impl(runner_impl)
74, m_execution_policy(runner_impl->executionPolicy())
75, m_runtime(runner_impl->runtime())
76, m_queue_stream(m_runtime->createStream(bi))
87 delete m_queue_stream;
100 std::unordered_set<RunCommandImpl*> command_set;
104 if (command_set.find(c) != command_set.end())
105 std::cerr <<
"Command is present several times in the command pool\n";
106 command_set.insert(c);
108 RunCommand::_internalDestroyImpl(c);
117_destroy(RunQueueImpl* q)
119 q->_freeCommandsInPool();
138 if (!_internalStream()->_barrierNoException()) {
142 std::cerr <<
"WARNING: Error in internal accelerator barrier\n";
145 m_runner_impl->_internalPutRunQueueImplInPool(
this);
147 RunQueueImpl::_destroy(
this);
155_setDefaultMemoryRessource()
165MemoryAllocationOptions RunQueueImpl::
166allocationOptions()
const
169 Int16 device_id =
static_cast<Int16>(m_runner_impl->deviceId().asInt32());
170 opt.setDevice(device_id);
178isAutoPrefetchCommand()
const
180 return m_runner_impl->isAutoPrefetchCommand();
187copyMemory(
const MemoryCopyArgs& args)
const
189 _internalStream()->copyMemory(args);
196prefetchMemory(
const MemoryPrefetchArgs& args)
const
198 _internalStream()->prefetchMemory(args);
205recordEvent(RunQueueEvent& event)
207 auto* p =
event._internalEventImpl();
208 return p->recordQueue(_internalStream());
215waitEvent(RunQueueEvent& event)
217 auto* p =
event._internalEventImpl();
218 return p->waitForEvent(_internalStream());
224RunQueueImpl* RunQueueImpl::
227 return _reset(r->_internalCreateOrGetRunQueueImpl());
233RunQueueImpl* RunQueueImpl::
234create(RunnerImpl* r,
const RunQueueBuildInfo& bi)
236 return _reset(r->_internalCreateOrGetRunQueueImpl(bi));
242RunCommandImpl* RunQueueImpl::
243_internalCreateOrGetRunCommandImpl()
245 RunCommandImpl* p =
nullptr;
256 p = RunCommand::_internalCreateImpl(
this);
273 if (m_use_pool_mutex) {
284 for (RunCommandImpl* p : command_list) {
285 p->notifyEndExecuteKernel();
289 for (RunCommandImpl* p : command_list) {
296 p->notifyEndExecuteKernel();
339_putInCommandPool(RunCommandImpl* p)
354 _internalStream()->barrier();
372 p->_setDefaultMemoryRessource();
380setConcurrentCommandCreation(
bool v)
382 m_use_pool_mutex = v;
383 if (!m_pool_mutex.get())
384 m_pool_mutex = std::make_unique<std::mutex>();
391dumpStats(std::ostream& ostr)
const
Memory management utility functions.
Implementation of a command for accelerator.
bool m_may_be_put_in_pool
Indicates if the command can be returned to the pool associated with the RunQueue.
bool m_has_living_run_command
Indicates if a RunCommand has a reference to this instance.
Lock for the RunCommand pool in multi-thread.
eMemoryResource m_memory_ressource
Default memory resource.
void _checkPutCommandInPoolNoLock(RunCommandImpl *p)
Returns the command to the pool if possible.
UniqueArray< RunCommandImpl * > m_active_run_command_list
List of running commands.
void _internalFreeRunningCommands()
Frees running commands.
bool m_is_async
Indicates if the queue is asynchronous.
static RunQueueImpl * _reset(RunQueueImpl *p)
Resets the implementation.
std::stack< RunCommandImpl * > m_run_command_pool
Command pool.
void _internalBarrier()
Blocks until all commands are finished.
Information to create a RunQueue.
void add(ConstReferenceType val)
Adds element val to the end of the array.
1D data array with pre-allocated stack buffer.
bool isAcceleratorPolicy(eExecutionPolicy exec_policy)
Indicates if exec_policy corresponds to an accelerator.
MemoryAllocationOptions getAllocationOptions(eMemoryResource mem_resource)
Default allocation for the resource mem_resource.
eMemoryResource getDefaultDataMemoryResource()
Memory resource used by the default allocator for data.
std::int16_t Int16
Signed integer type of 16 bits.
bool arccoreIsCheck()
True if in check mode.
@ Host
Allocates on the host.
std::int32_t Int32
Signed integer type of 32 bits.