Arcane  v4.1.0.0
Documentation développeur
Chargement...
Recherche...
Aucune correspondance
core/RunQueue.h
1// -*- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature -*-
2//-----------------------------------------------------------------------------
3// Copyright 2000-2025 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.h (C) 2000-2025 */
9/* */
10/* Gestion d'une file d'exécution sur accélérateur. */
11/*---------------------------------------------------------------------------*/
12#ifndef ARCANE_ACCELERATOR_CORE_RUNQUEUE_H
13#define ARCANE_ACCELERATOR_CORE_RUNQUEUE_H
14/*---------------------------------------------------------------------------*/
15/*---------------------------------------------------------------------------*/
16
17#include "arccore/base/AutoRef2.h"
18
19#include "arcane/accelerator/core/RunCommand.h"
20
21/*---------------------------------------------------------------------------*/
22/*---------------------------------------------------------------------------*/
23
24namespace Arcane::Accelerator
25{
26
27/*---------------------------------------------------------------------------*/
28/*---------------------------------------------------------------------------*/
51class ARCANE_ACCELERATOR_CORE_EXPORT RunQueue
52{
53 friend RunCommand;
54 friend ProfileRegion;
55 friend Runner;
56 friend ViewBuildInfo;
57 friend class Impl::RunCommandLaunchInfo;
58 friend RunCommand makeCommand(const RunQueue& run_queue);
59 friend RunCommand makeCommand(const RunQueue* run_queue);
60 // Pour _internalNativeStream()
61 friend class Impl::CudaUtils;
62 friend class Impl::HipUtils;
63 friend class Impl::SyclUtils;
64
65 public:
66
68 class ScopedAsync
69 {
70 public:
71
72 explicit ScopedAsync(RunQueue* queue)
73 : m_queue(queue)
74 {
75 // Rend la file asynchrone
76 if (m_queue) {
77 m_is_async = m_queue->isAsync();
78 m_queue->setAsync(true);
79 }
80 }
81 ~ScopedAsync() noexcept(false)
82 {
83 // Remet la file dans l'état d'origine lors de l'appel au constructeur
84 if (m_queue)
85 m_queue->setAsync(m_is_async);
86 }
87
88 private:
89
90 RunQueue* m_queue = nullptr;
91 bool m_is_async = false;
92 };
93
94 public:
95
97 RunQueue();
98 ~RunQueue();
99
100 public:
101
103 ARCANE_DEPRECATED_REASON("Y2024: Use makeQueue(runner) instead")
104 explicit RunQueue(const Runner& runner);
106 ARCANE_DEPRECATED_REASON("Y2024: Use makeQueue(runner,bi) instead")
107 RunQueue(const Runner& runner, const RunQueueBuildInfo& bi);
108
109 public:
110
111 RunQueue(const RunQueue&);
112 RunQueue& operator=(const RunQueue&);
113 RunQueue(RunQueue&&) noexcept;
114 RunQueue& operator=(RunQueue&&) noexcept;
115
116 public:
117
119 bool isNull() const { return !m_p; }
120
122 eExecutionPolicy executionPolicy() const;
124 bool isAcceleratorPolicy() const;
125
135 void setAsync(bool v);
137 bool isAsync() const;
138
147 const RunQueue& addAsync(bool is_async) const;
148
150 void barrier() const;
151
153 void copyMemory(const MemoryCopyArgs& args) const;
155 void prefetchMemory(const MemoryPrefetchArgs& args) const;
156
163 void recordEvent(RunQueueEvent& event);
165 void recordEvent(Ref<RunQueueEvent>& event);
167 void waitEvent(RunQueueEvent& event);
169 void waitEvent(Ref<RunQueueEvent>& event);
171
174
180 MemoryAllocationOptions allocationOptions() const;
181
193 void setMemoryRessource(eMemoryRessource mem);
194
196 eMemoryRessource memoryRessource() const;
198
199 public:
200
211 void setConcurrentCommandCreation(bool v);
213 bool isConcurrentCommandCreation() const;
214
215 public:
216
229 ARCANE_DEPRECATED_REASON("Y2024: Use toCudaNativeStream(), toHipNativeStream() or toSyclNativeStream() instead")
230 void* platformStream() const;
231
232 public:
233
234 friend bool operator==(const RunQueue& q1, const RunQueue& q2)
235 {
236 return q1.m_p.get() == q2.m_p.get();
237 }
238 friend bool operator!=(const RunQueue& q1, const RunQueue& q2)
239 {
240 return q1.m_p.get() != q2.m_p.get();
241 }
242
243 public:
244
245 impl::RunQueueImpl* _internalImpl() const;
246
247 private:
248
249 // Les méthodes de création sont réservée à Runner.
250 // On ajoute un argument supplémentaire non utilisé pour ne pas utiliser
251 // le constructeur obsolète.
252 RunQueue(const Runner& runner, bool);
254 RunQueue(const Runner& runner, const RunQueueBuildInfo& bi, bool);
255 explicit RunQueue(impl::RunQueueImpl* p);
256
257 private:
258
259 impl::IRunnerRuntime* _internalRuntime() const;
260 impl::IRunQueueStream* _internalStream() const;
261 impl::RunCommandImpl* _getCommandImpl() const;
262 Impl::NativeStream _internalNativeStream() const;
263 void _checkNotNull() const;
264
265 // Pour VariableViewBase
266 friend class VariableViewBase;
267 friend class NumArrayViewBase;
268
269 private:
270
271 AutoRef2<impl::RunQueueImpl> m_p;
272};
273
274/*---------------------------------------------------------------------------*/
275/*---------------------------------------------------------------------------*/
276
277/*---------------------------------------------------------------------------*/
278/*---------------------------------------------------------------------------*/
282inline RunCommand
283makeCommand(const RunQueue& run_queue)
284{
285 run_queue._checkNotNull();
286 return RunCommand(run_queue);
287}
288
292inline RunCommand
293makeCommand(const RunQueue* run_queue)
294{
295 ARCANE_CHECK_POINTER(run_queue);
296 run_queue->_checkNotNull();
297 return RunCommand(*run_queue);
298}
299
300/*---------------------------------------------------------------------------*/
301/*---------------------------------------------------------------------------*/
302
303} // End namespace Arcane::Accelerator
304
305/*---------------------------------------------------------------------------*/
306/*---------------------------------------------------------------------------*/
307
308#endif
#define ARCANE_CHECK_POINTER(ptr)
Macro retournant le pointeur ptr s'il est non nul ou lancant une exception s'il est nul.
Object temporaire pour conserver les informations d'exécution d'une commande et regrouper les tests.
Arguments pour la copie mémoire.
Definition Memory.h:61
Arguments pour le préfetching mémoire.
Definition Memory.h:123
Gestion d'une commande sur accélérateur.
Informations pour créer une RunQueue.
Évènement pour une file d'exécution.
File d'exécution pour un accélérateur.
friend RunCommand makeCommand(const RunQueue &run_queue)
Créé une commande associée à la file run_queue.
RunQueue()
Créé une file nulle.
Definition RunQueue.cc:46
bool isNull() const
Indique si la RunQueue est nulle.
Référence à une instance.
Espace de nom pour l'utilisation des accélérateurs.
RunCommand makeCommand(const RunQueue &run_queue)
Créé une commande associée à la file run_queue.
eExecutionPolicy
Politique d'exécution pour un Runner.
bool isAcceleratorPolicy(eExecutionPolicy exec_policy)
Indique si exec_policy correspond à un accélérateur.
Arcane::eMemoryResource eMemoryRessource
Typedef pour la version Arcane historique (avec 2's')