Arcane  4.1.12.0
Developer documentation
Loading...
Searching...
No Matches
RunQueue.cc
1// -*- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature -*-
2//-----------------------------------------------------------------------------
3// Copyright 2000-2026 CEA (www.cea.fr) IFPEN (www.ifpenergiesnouvelles.com)
4// See the top-level COPYRIGHT file for details.
5// SPDX-License-Identifier: Apache-2.0
6//-----------------------------------------------------------------------------
7/*---------------------------------------------------------------------------*/
8/* RunQueue.cc (C) 2000-2026 */
9/* */
10/* Management of an execution queue on an accelerator. */
11/*---------------------------------------------------------------------------*/
12/*---------------------------------------------------------------------------*/
13
14#include "arccore/common/accelerator/internal/AcceleratorCoreGlobalInternal.h"
15#include "arccore/common/accelerator/RunQueue.h"
16
17#include "arccore/base/FatalErrorException.h"
18
19#include "arccore/common/accelerator/internal/IRunnerRuntime.h"
20#include "arccore/common/accelerator/internal/IRunQueueStream.h"
21#include "arccore/common/accelerator/internal/IRunQueueEventImpl.h"
22#include "arccore/common/accelerator/internal/RunQueueImpl.h"
23#include "arccore/common/accelerator/internal/RunnerImpl.h"
24#include "arccore/common/accelerator/Runner.h"
25#include "arccore/common/accelerator/RunQueueEvent.h"
26#include "arccore/common/accelerator/Memory.h"
27#include "arccore/common/accelerator/NativeStream.h"
28
29/*---------------------------------------------------------------------------*/
30/*---------------------------------------------------------------------------*/
31
32namespace Arcane::Accelerator
33{
34
35/*---------------------------------------------------------------------------*/
36/*---------------------------------------------------------------------------*/
37
38// NOTE: Constructors and destructors must be in the source file,
39// because the type \a m_p is opaque and its usage is not known in
40// the class definition.
41
42/*---------------------------------------------------------------------------*/
43/*---------------------------------------------------------------------------*/
44
47{
48}
49
50/*---------------------------------------------------------------------------*/
51/*---------------------------------------------------------------------------*/
52
54RunQueue(const Runner& runner)
55: m_p(Impl::RunQueueImpl::create(runner._impl()))
56{
57}
58
59/*---------------------------------------------------------------------------*/
60/*---------------------------------------------------------------------------*/
61
63RunQueue(const Runner& runner, const RunQueueBuildInfo& bi)
64: m_p(Impl::RunQueueImpl::create(runner._impl(), bi))
65{
66}
67
68/*---------------------------------------------------------------------------*/
69/*---------------------------------------------------------------------------*/
70
72RunQueue(const Runner& runner, bool)
73: m_p(Impl::RunQueueImpl::create(runner._impl()))
74{
75}
76
77/*---------------------------------------------------------------------------*/
78/*---------------------------------------------------------------------------*/
79
81RunQueue(const Runner& runner, const RunQueueBuildInfo& bi, bool)
82: m_p(Impl::RunQueueImpl::create(runner._impl(), bi))
83{
84}
85
86/*---------------------------------------------------------------------------*/
87/*---------------------------------------------------------------------------*/
88
90RunQueue(const RunQueue& x)
91: m_p(x.m_p)
92{
93}
94
95/*---------------------------------------------------------------------------*/
96/*---------------------------------------------------------------------------*/
97
99RunQueue(RunQueue&& x) noexcept
100: m_p(std::move(x.m_p))
101{
102}
103
104/*---------------------------------------------------------------------------*/
105/*---------------------------------------------------------------------------*/
106
108RunQueue(Impl::RunQueueImpl* p)
109: m_p(p)
110{
111}
112
113/*---------------------------------------------------------------------------*/
114/*---------------------------------------------------------------------------*/
115
116RunQueue& RunQueue::
117operator=(const RunQueue& x)
118{
119 if (&x != this)
120 m_p = x.m_p;
121 return (*this);
122}
123
124/*---------------------------------------------------------------------------*/
125/*---------------------------------------------------------------------------*/
126
127RunQueue& RunQueue::
128operator=(RunQueue&& x) noexcept
129{
130 m_p = std::move(x.m_p);
131 return (*this);
132}
133
134/*---------------------------------------------------------------------------*/
135/*---------------------------------------------------------------------------*/
136
137RunQueue::
138~RunQueue()
139{
140}
141
142/*---------------------------------------------------------------------------*/
143/*---------------------------------------------------------------------------*/
144
145/*---------------------------------------------------------------------------*/
146/*---------------------------------------------------------------------------*/
147
148void RunQueue::
149_checkNotNull() const
150{
151 if (!m_p)
152 ARCCORE_FATAL("Invalid operation on null RunQueue");
153}
154
155/*---------------------------------------------------------------------------*/
156/*---------------------------------------------------------------------------*/
157
159barrier() const
160{
161 if (m_p)
162 m_p->_internalBarrier();
163}
164
165/*---------------------------------------------------------------------------*/
166/*---------------------------------------------------------------------------*/
167
169executionPolicy() const
170{
171 if (m_p)
172 return m_p->executionPolicy();
174}
175
176/*---------------------------------------------------------------------------*/
177/*---------------------------------------------------------------------------*/
178
179Impl::IRunnerRuntime* RunQueue::
180_internalRuntime() const
181{
182 return m_p->_internalRuntime();
183}
184
185/*---------------------------------------------------------------------------*/
186/*---------------------------------------------------------------------------*/
187
188Impl::IRunQueueStream* RunQueue::
189_internalStream() const
190{
191 return m_p->_internalStream();
192}
193
194/*---------------------------------------------------------------------------*/
195/*---------------------------------------------------------------------------*/
196
197Impl::RunCommandImpl* RunQueue::
198_getCommandImpl() const
199{
200 return m_p->_internalCreateOrGetRunCommandImpl();
201}
202
203/*---------------------------------------------------------------------------*/
204/*---------------------------------------------------------------------------*/
205
206Impl::RunQueueImpl* RunQueue::
207_internalImpl() const
208{
209 _checkNotNull();
210 return m_p.get();
211}
212
213/*---------------------------------------------------------------------------*/
214/*---------------------------------------------------------------------------*/
215
216Impl::NativeStream RunQueue::
217_internalNativeStream() const
218{
219 if (m_p)
220 return m_p->_internalStream()->nativeStream();
221 return {};
222}
223
224/*---------------------------------------------------------------------------*/
225/*---------------------------------------------------------------------------*/
226
228platformStream() const
229{
230 return _internalNativeStream().m_native_pointer;
231}
232
233/*---------------------------------------------------------------------------*/
234/*---------------------------------------------------------------------------*/
235
237copyMemory(const MemoryCopyArgs& args) const
238{
239 _checkNotNull();
240 m_p->copyMemory(args);
241}
242
243/*---------------------------------------------------------------------------*/
244/*---------------------------------------------------------------------------*/
245
247prefetchMemory(const MemoryPrefetchArgs& args) const
248{
249 _checkNotNull();
250 m_p->prefetchMemory(args);
251}
252
253/*---------------------------------------------------------------------------*/
254/*---------------------------------------------------------------------------*/
255
258{
259 _checkNotNull();
260 m_p->waitEvent(event);
261}
262
263/*---------------------------------------------------------------------------*/
264/*---------------------------------------------------------------------------*/
265
268{
269 RunQueueEvent* e = event.get();
271 waitEvent(*e);
272}
273
274/*---------------------------------------------------------------------------*/
275/*---------------------------------------------------------------------------*/
276
279{
280 _checkNotNull();
281 m_p->recordEvent(event);
282}
283
284/*---------------------------------------------------------------------------*/
285/*---------------------------------------------------------------------------*/
286
289{
290 RunQueueEvent* e = event.get();
292 recordEvent(*e);
293}
294
295/*---------------------------------------------------------------------------*/
296/*---------------------------------------------------------------------------*/
297
299setAsync(bool v)
300{
301 _checkNotNull();
302 m_p->m_is_async = v;
303}
304
305/*---------------------------------------------------------------------------*/
306/*---------------------------------------------------------------------------*/
307
309addAsync(bool is_async) const
310{
311 _checkNotNull();
312 m_p->m_is_async = is_async;
313 return (*this);
314}
315
316/*---------------------------------------------------------------------------*/
317/*---------------------------------------------------------------------------*/
318
320isAsync() const
321{
322 if (m_p)
323 return m_p->m_is_async;
324 return false;
325}
326
327/*---------------------------------------------------------------------------*/
328/*---------------------------------------------------------------------------*/
329
335
336/*---------------------------------------------------------------------------*/
337/*---------------------------------------------------------------------------*/
338
340allocationOptions() const
341{
342 if (m_p)
343 return m_p->allocationOptions();
344 return {};
345}
346
347/*---------------------------------------------------------------------------*/
348/*---------------------------------------------------------------------------*/
349
352{
353 _checkNotNull();
354 m_p->m_memory_ressource = mem;
355}
356
357/*---------------------------------------------------------------------------*/
358/*---------------------------------------------------------------------------*/
359
361memoryRessource() const
362{
363 if (m_p)
364 return m_p->m_memory_ressource;
366}
367
368/*---------------------------------------------------------------------------*/
369/*---------------------------------------------------------------------------*/
370
372memoryResource() const
373{
374 if (m_p)
375 return m_p->m_memory_ressource;
377}
378
379/*---------------------------------------------------------------------------*/
380/*---------------------------------------------------------------------------*/
381
384{
385 _checkNotNull();
387 ARCCORE_FATAL("setting concurrent command creation is not supported for RunQueue running on accelerator");
388 m_p->setConcurrentCommandCreation(v);
389}
390
391/*---------------------------------------------------------------------------*/
392/*---------------------------------------------------------------------------*/
393
396{
397 if (m_p)
398 return m_p->isConcurrentCommandCreation();
399 return false;
400}
401
402/*---------------------------------------------------------------------------*/
403/*---------------------------------------------------------------------------*/
404
405extern "C++" ePointerAccessibility
406getPointerAccessibility(RunQueue* queue, const void* ptr, PointerAttribute* ptr_attr)
407{
408 if (!queue || queue->isNull())
410 return Impl::RuntimeStaticInfo::getPointerAccessibility(queue->executionPolicy(), ptr, ptr_attr);
411}
412
413extern "C++" void Impl::
414arcaneCheckPointerIsAccessible(const RunQueue* queue, const void* ptr,
415 const char* name, const TraceInfo& ti)
416{
417 if (!queue || queue->isNull())
418 return;
419 return Impl::RuntimeStaticInfo::checkPointerIsAcccessible(queue->executionPolicy(), ptr, name, ti);
420}
421
422/*---------------------------------------------------------------------------*/
423/*---------------------------------------------------------------------------*/
424
425} // namespace Arcane::Accelerator
426
427/*---------------------------------------------------------------------------*/
428/*---------------------------------------------------------------------------*/
#define ARCCORE_FATAL(...)
Macro throwing a FatalErrorException.
#define ARCCORE_CHECK_POINTER(ptr)
Macro that returns the pointer ptr if it is not null or throws an exception if it is null.
Interface of the runtime associated with an accelerator.
bool isAsync() const
Indicates if the execution queue is asynchronous.
Definition RunQueue.cc:320
void waitEvent(RunQueueEvent &event)
Blocks execution on the instance until the jobs recorded in event are finished.
Definition RunQueue.cc:257
void copyMemory(const MemoryCopyArgs &args) const
Copies information between two memory regions.
Definition RunQueue.cc:237
eMemoryResource memoryRessource() const
Memory resource used for allocations with this instance.
Definition RunQueue.cc:361
RunQueue()
Creates a null queue.
Definition RunQueue.cc:46
void setAsync(bool v)
Sets the instance's asynchronous state.
Definition RunQueue.cc:299
void * platformStream() const
Pointer to the internal structure dependent on the implementation.
Definition RunQueue.cc:228
void recordEvent(RunQueueEvent &event)
Definition RunQueue.cc:278
void prefetchMemory(const MemoryPrefetchArgs &args) const
Performs a memory prefetch.
Definition RunQueue.cc:247
MemoryAllocationOptions allocationOptions() const
Allocation options associated with this queue.
Definition RunQueue.cc:340
void barrier() const
Blocks until all commands associated with the queue are finished.
Definition RunQueue.cc:159
const RunQueue & addAsync(bool is_async) const
Sets the instance's asynchronous state.
Definition RunQueue.cc:309
eExecutionPolicy executionPolicy() const
Execution policy of the queue.
Definition RunQueue.cc:169
eMemoryResource memoryResource() const
Memory resource used for allocations with this instance.
Definition RunQueue.cc:372
void setMemoryRessource(eMemoryResource mem)
Sets the memory resource used for allocations with this instance.
Definition RunQueue.cc:351
bool isAcceleratorPolicy() const
Indicates if the instance is associated with an accelerator.
Definition RunQueue.cc:331
bool isConcurrentCommandCreation() const
Indicates if concurrent creation of multiple RunCommands is allowed.
Definition RunQueue.cc:395
void setConcurrentCommandCreation(bool v)
Indicates if the creation of RunCommand for this instance is allowed from multiple threads.
Definition RunQueue.cc:383
Reference to an instance.
ePointerAccessibility getPointerAccessibility(eExecutionPolicy policy, const void *ptr, PointerAttribute *ptr_attr)
Accessibility of address ptr for execution policypolicy.
ePointerAccessibility
Accessibility information of a memory address.
eExecutionPolicy
Execution policy for a Runner.
bool isAcceleratorPolicy(eExecutionPolicy exec_policy)
Indicates if exec_policy corresponds to an accelerator.
eMemoryResource
List of available memory resources.
@ Unknown
Unknown or uninitialized value.