Arcane  v4.1.0.0
Documentation développeur
Chargement...
Recherche...
Aucune correspondance
core/internal/RunQueueImpl.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/* RunQueueImpl.h (C) 2000-2025 */
9/* */
10/* Implémentation d'une 'RunQueue'. */
11/*---------------------------------------------------------------------------*/
12#ifndef ARCANE_ACCELERATOR_CORE_INTERNAL_RUNQUEUEIMPL_H
13#define ARCANE_ACCELERATOR_CORE_INTERNAL_RUNQUEUEIMPL_H
14/*---------------------------------------------------------------------------*/
15/*---------------------------------------------------------------------------*/
16
18
19#include "arccore/common/Array.h"
20
21#include <stack>
22#include <atomic>
23#include <mutex>
24
25/*---------------------------------------------------------------------------*/
26/*---------------------------------------------------------------------------*/
27
28namespace Arcane::Accelerator::impl
29{
30
31/*---------------------------------------------------------------------------*/
32/*---------------------------------------------------------------------------*/
40class ARCANE_ACCELERATOR_CORE_EXPORT RunQueueImpl
41{
42 friend class Arcane::Accelerator::Runner;
44 friend class RunCommandImpl;
45 friend class RunQueueImplStack;
46 friend class RunnerImpl;
47
48 class Lock;
49
50 private:
51
52 RunQueueImpl(RunnerImpl* runner_impl, Int32 id, const RunQueueBuildInfo& bi);
53
54 private:
55
56 // Il faut utiliser _destroy() pour détruire l'instance.
57 ~RunQueueImpl();
58
59 public:
60
61 RunQueueImpl(const RunQueueImpl&) = delete;
62 RunQueueImpl(RunQueueImpl&&) = delete;
63 RunQueueImpl& operator=(const RunQueueImpl&) = delete;
64 RunQueueImpl& operator=(RunQueueImpl&&) = delete;
65
66 public:
67
68 static RunQueueImpl* create(RunnerImpl* r, const RunQueueBuildInfo& bi);
69 static RunQueueImpl* create(RunnerImpl* r);
70
71 public:
72
73 eExecutionPolicy executionPolicy() const { return m_execution_policy; }
74 RunnerImpl* runner() const { return m_runner_impl; }
75 MemoryAllocationOptions allocationOptions() const;
76 bool isAutoPrefetchCommand() const;
77
78 void copyMemory(const MemoryCopyArgs& args) const;
79 void prefetchMemory(const MemoryPrefetchArgs& args) const;
80
81 void recordEvent(RunQueueEvent& event);
82 void waitEvent(RunQueueEvent& event);
83
84 void setConcurrentCommandCreation(bool v);
85 bool isConcurrentCommandCreation() const { return m_use_pool_mutex; }
86
87 void dumpStats(std::ostream& ostr) const;
88 bool isAsync() const { return m_is_async; }
89
90 void _internalBarrier();
91 IRunnerRuntime* _internalRuntime() const { return m_runtime; }
92 IRunQueueStream* _internalStream() const { return m_queue_stream; }
93
94 public:
95
96 void addRef()
97 {
98 ++m_nb_ref;
99 }
100 void removeRef()
101 {
102 Int32 v = std::atomic_fetch_add(&m_nb_ref, -1);
103 if (v == 1)
104 _release();
105 }
106
107 private:
108
109 RunCommandImpl* _internalCreateOrGetRunCommandImpl();
111 bool _isInPool() const { return m_is_in_pool; }
112 void _release();
113 void _setDefaultMemoryRessource();
114 void _addRunningCommand(RunCommandImpl* p);
115 void _putInCommandPool(RunCommandImpl* p);
116 void _freeCommandsInPool();
117 void _checkPutCommandInPoolNoLock(RunCommandImpl* p);
118 static RunQueueImpl* _reset(RunQueueImpl* p);
119 static void _destroy(RunQueueImpl* q);
120
121 private:
122
123 RunnerImpl* m_runner_impl = nullptr;
124 eExecutionPolicy m_execution_policy = eExecutionPolicy::None;
125 IRunnerRuntime* m_runtime = nullptr;
126 IRunQueueStream* m_queue_stream = nullptr;
128 std::stack<RunCommandImpl*> m_run_command_pool;
134 bool m_is_in_pool = false;
136 std::atomic<Int32> m_nb_ref = 0;
138 bool m_is_async = false;
140 eMemoryRessource m_memory_ressource = eMemoryRessource::Unknown;
141
142 // Mutex pour les commandes (actif si \a m_use_pool_mutex est vrai)
143 std::unique_ptr<std::mutex> m_pool_mutex;
144 bool m_use_pool_mutex = false;
145};
146
147/*---------------------------------------------------------------------------*/
148/*---------------------------------------------------------------------------*/
149
150} // namespace Arcane::Accelerator::impl
151
152/*---------------------------------------------------------------------------*/
153/*---------------------------------------------------------------------------*/
154
155#endif
Arguments pour la copie mémoire.
Definition Memory.h:61
Arguments pour le préfetching mémoire.
Definition Memory.h:123
Informations pour créer une RunQueue.
Évènement pour une file d'exécution.
File d'exécution pour un accélérateur.
Gestionnaire d'exécution pour accélérateur.
Definition core/Runner.h:67
Interface d'un flux d'exécution pour une RunQueue.
Interface du runtime associé à un accélérateur.
Verrou pour le pool de RunCommand en multi-thread.
void _checkPutCommandInPoolNoLock(RunCommandImpl *p)
Remet la commande dans le pool si possible.
static RunQueueImpl * _reset(RunQueueImpl *p)
Réinitialise l'implémentation.
bool m_is_async
Indique si la file est asynchrone.
eMemoryRessource m_memory_ressource
Ressource mémoire par défaut.
bool m_is_in_pool
Indique si l'instance est dans un pool d'instance.
void _internalBarrier()
Bloque jusqu'à ce que toutes les commandes soient terminées.
std::stack< RunCommandImpl * > m_run_command_pool
Pool de commandes.
std::atomic< Int32 > m_nb_ref
Nombre de références sur l'instance.
UniqueArray< RunCommandImpl * > m_active_run_command_list
Liste des commandes en cours d'exécution.
void _internalFreeRunningCommands()
Libère les commandes en cours d'exécution.
Vecteur 1D de données avec sémantique par valeur (style STL).
eExecutionPolicy
Politique d'exécution pour un Runner.
@ None
Aucune politique d'exécution.
Arcane::eMemoryResource eMemoryRessource
Typedef pour la version Arcane historique (avec 2's')
std::int32_t Int32
Type entier signé sur 32 bits.