Arcane  v3.16.7.0
Documentation utilisateur
Chargement...
Recherche...
Aucune correspondance
RunQueueRuntime.cc
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/* RunQueueRuntime.cc (C) 2000-2025 */
9/* */
10/* Implémentation d'un RunQueue pour une cible donnée. */
11/*---------------------------------------------------------------------------*/
12/*---------------------------------------------------------------------------*/
13
14#include "arcane/utils/NotImplementedException.h"
15#include "arcane/utils/MemoryView.h"
17#include "arcane/utils/PlatformUtils.h"
18#include "arcane/utils/FatalErrorException.h"
19
20#include "arcane/accelerator/core/internal/IRunnerRuntime.h"
21#include "arcane/accelerator/core/internal/IRunQueueStream.h"
22#include "arcane/accelerator/core/internal/IRunQueueEventImpl.h"
23#include "arcane/accelerator/core/Memory.h"
24#include "arcane/accelerator/core/DeviceInfoList.h"
25#include "arcane/accelerator/core/DeviceMemoryInfo.h"
26#include "arcane/accelerator/core/NativeStream.h"
27
28#include <cstring>
29
30/*---------------------------------------------------------------------------*/
31/*---------------------------------------------------------------------------*/
32
33namespace Arcane::Accelerator::impl
34{
35
36/*---------------------------------------------------------------------------*/
37/*---------------------------------------------------------------------------*/
38
39class ARCANE_ACCELERATOR_CORE_EXPORT HostRunQueueStream
40: public IRunQueueStream
41{
42 public:
43
44 HostRunQueueStream(IRunnerRuntime* runtime)
45 : m_runtime(runtime)
46 {}
47
48 public:
49
50 void notifyBeginLaunchKernel(RunCommandImpl&) override { return m_runtime->notifyBeginLaunchKernel(); }
51 void notifyEndLaunchKernel(RunCommandImpl&) override { return m_runtime->notifyEndLaunchKernel(); }
52 void barrier() override { return m_runtime->barrier(); }
53 void copyMemory(const MemoryCopyArgs& args) override
54 {
55 MemoryUtils::copyHost(args.destination(), args.source());
56 }
57 void prefetchMemory(const MemoryPrefetchArgs&) override {}
58 NativeStream nativeStream() override { return {}; }
59 bool _barrierNoException() override { return false; }
60
61 private:
62
63 IRunnerRuntime* m_runtime;
64};
65
66/*---------------------------------------------------------------------------*/
67/*---------------------------------------------------------------------------*/
68
69class ARCANE_ACCELERATOR_CORE_EXPORT HostRunQueueEvent
70: public IRunQueueEventImpl
71{
72 public:
73
74 explicit HostRunQueueEvent(bool has_timer)
75 : m_has_timer(has_timer)
76 {}
77
78 public:
79
80 void recordQueue(IRunQueueStream*) final
81 {
82 if (m_has_timer)
83 m_recorded_time = platform::getRealTime();
84 }
85 void wait() final {}
86 void waitForEvent(IRunQueueStream*) final {}
87 bool hasPendingWork() final { return false; }
88 Int64 elapsedTime(IRunQueueEventImpl* start_event) final
89 {
90 ARCANE_CHECK_POINTER(start_event);
91 auto* true_start_event = static_cast<HostRunQueueEvent*>(start_event);
92 if (!m_has_timer || !true_start_event->m_has_timer)
93 ARCANE_FATAL("Event has no timer support");
94 double diff_time = m_recorded_time - true_start_event->m_recorded_time;
95 Int64 diff_as_int64 = static_cast<Int64>(diff_time * 1.0e9);
96 return diff_as_int64;
97 }
98
99 private:
100
101 bool m_has_timer = false;
102 double m_recorded_time = 0.0;
103};
104
105/*---------------------------------------------------------------------------*/
106/*---------------------------------------------------------------------------*/
107
108class ARCANE_ACCELERATOR_CORE_EXPORT CommonRunnerRuntime
109: public IRunnerRuntime
110{
111 public:
112
113 CommonRunnerRuntime()
114 {
115 DeviceInfo d;
116 d.setDeviceId(DeviceId());
117 d.setName("HostDevice");
118 m_device_info_list.addDevice(d);
119 }
120
121 public:
122
123 void notifyBeginLaunchKernel() final {}
124 void notifyEndLaunchKernel() final {}
125 void barrier() final {}
126 IRunQueueStream* createStream(const RunQueueBuildInfo&) final { return new HostRunQueueStream(this); }
127 IRunQueueEventImpl* createEventImpl() final { return new HostRunQueueEvent(false); }
128 IRunQueueEventImpl* createEventImplWithTimer() final { return new HostRunQueueEvent(true); }
129 void setMemoryAdvice(ConstMemoryView, eMemoryAdvice, DeviceId) final {}
130 void unsetMemoryAdvice(ConstMemoryView, eMemoryAdvice, DeviceId) final {}
131 void setCurrentDevice(DeviceId) final {}
132 const IDeviceInfoList* deviceInfoList() final { return &m_device_info_list; }
133 void getPointerAttribute(PointerAttribute& attribute, const void* ptr) final
134 {
135 _fillPointerAttribute(attribute, ptr);
136 }
137 DeviceMemoryInfo getDeviceMemoryInfo(DeviceId) override
138 {
139 // TODO: à implémenter
140 return {};
141 }
142
143 private:
144
145 DeviceInfoList m_device_info_list;
146};
147
148/*---------------------------------------------------------------------------*/
149/*---------------------------------------------------------------------------*/
150
151class ARCANE_ACCELERATOR_CORE_EXPORT SequentialRunnerRuntime
152: public CommonRunnerRuntime
153{
154 eExecutionPolicy executionPolicy() const final { return eExecutionPolicy::Sequential; }
155};
156
157/*---------------------------------------------------------------------------*/
158/*---------------------------------------------------------------------------*/
159
160class ARCANE_ACCELERATOR_CORE_EXPORT ThreadRunnerRuntime
161: public CommonRunnerRuntime
162{
163 public:
164
165 eExecutionPolicy executionPolicy() const final { return eExecutionPolicy::Thread; }
166};
167
168namespace
169{
170 SequentialRunnerRuntime global_sequential_runqueue_runtime;
171 ThreadRunnerRuntime global_thread_runqueue_runtime;
172} // namespace
173
174/*---------------------------------------------------------------------------*/
175/*---------------------------------------------------------------------------*/
176
177//! Récupère l'implémentation séquentielle de RunQueue
178extern "C++" ARCANE_ACCELERATOR_CORE_EXPORT IRunnerRuntime*
179getSequentialRunQueueRuntime()
180{
181 return &global_sequential_runqueue_runtime;
182}
183
184//! Récupère l'implémentation séquentielle de RunQueue
185extern "C++" ARCANE_ACCELERATOR_CORE_EXPORT IRunnerRuntime*
186getThreadRunQueueRuntime()
187{
188 return &global_thread_runqueue_runtime;
189}
190
191/*---------------------------------------------------------------------------*/
192/*---------------------------------------------------------------------------*/
193
194} // End namespace Arcane::Accelerator::impl
195
196/*---------------------------------------------------------------------------*/
197/*---------------------------------------------------------------------------*/
#define ARCANE_CHECK_POINTER(ptr)
Macro retournant le pointeur ptr s'il est non nul ou lancant une exception s'il est nul.
#define ARCANE_FATAL(...)
Macro envoyant une exception FatalErrorException.
Fonctions de gestion mémoire et des allocateurs.
Identifiant d'un composant du système.
Definition DeviceId.h:33
Information sur un device.
Definition DeviceInfo.h:32
Information mémoire d'un accélérateur.
Interface d'une liste de devices.
Arguments pour la copie mémoire.
Definition Memory.h:63
Arguments pour le préfetching mémoire.
Definition Memory.h:125
Informations sur une adresse mémoire.
Informations pour créer une RunQueue.
Interface d'une liste de devices.
Type opaque pour encapsuler une 'stream' native.
Vue constante sur une zone mémoire contigue contenant des éléments de taille fixe.
Definition MemoryView.h:38
eMemoryAdvice
Conseils pour la gestion mémoire.
Definition Memory.h:36
eExecutionPolicy
Politique d'exécution pour un Runner.
@ Sequential
Politique d'exécution séquentielle.
@ Thread
Politique d'exécution multi-thread.
void copyHost(MutableMemoryView destination, ConstMemoryView source)
Copie dans destination les données de source.
Definition MemoryView.cc:90
ARCCORE_BASE_EXPORT Real getRealTime()
Temps Real utilisé en secondes.
std::int64_t Int64
Type entier signé sur 64 bits.