Arcane  v3.15.0.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-2024 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-2024 */
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"
16#include "arcane/utils/PlatformUtils.h"
17#include "arcane/utils/FatalErrorException.h"
18
19#include "arcane/accelerator/core/internal/IRunnerRuntime.h"
20#include "arcane/accelerator/core/internal/IRunQueueStream.h"
21#include "arcane/accelerator/core/internal/IRunQueueEventImpl.h"
22#include "arcane/accelerator/core/Memory.h"
23#include "arcane/accelerator/core/DeviceInfoList.h"
24#include "arcane/accelerator/core/DeviceMemoryInfo.h"
25#include "arcane/accelerator/core/NativeStream.h"
26
27#include <cstring>
28
29/*---------------------------------------------------------------------------*/
30/*---------------------------------------------------------------------------*/
31
32namespace Arcane::Accelerator::impl
33{
34
35/*---------------------------------------------------------------------------*/
36/*---------------------------------------------------------------------------*/
37
38class ARCANE_ACCELERATOR_CORE_EXPORT HostRunQueueStream
39: public IRunQueueStream
40{
41 public:
42
43 HostRunQueueStream(IRunnerRuntime* runtime)
44 : m_runtime(runtime)
45 {}
46
47 public:
48
49 void notifyBeginLaunchKernel(RunCommandImpl&) override { return m_runtime->notifyBeginLaunchKernel(); }
50 void notifyEndLaunchKernel(RunCommandImpl&) override { return m_runtime->notifyEndLaunchKernel(); }
51 void barrier() override { return m_runtime->barrier(); }
52 void copyMemory(const MemoryCopyArgs& args) override
53 {
54 args.destination().copyHost(args.source());
55 }
56 void prefetchMemory(const MemoryPrefetchArgs&) override {}
57 NativeStream nativeStream() override { return {}; }
58 bool _barrierNoException() override { return false; }
59
60 private:
61
62 IRunnerRuntime* m_runtime;
63};
64
65/*---------------------------------------------------------------------------*/
66/*---------------------------------------------------------------------------*/
67
68class ARCANE_ACCELERATOR_CORE_EXPORT HostRunQueueEvent
69: public IRunQueueEventImpl
70{
71 public:
72
73 explicit HostRunQueueEvent(bool has_timer)
74 : m_has_timer(has_timer)
75 {}
76
77 public:
78
79 void recordQueue(IRunQueueStream*) final
80 {
81 if (m_has_timer)
82 m_recorded_time = platform::getRealTime();
83 }
84 void wait() final {}
85 void waitForEvent(IRunQueueStream*) final {}
86 Int64 elapsedTime(IRunQueueEventImpl* start_event) final
87 {
88 ARCANE_CHECK_POINTER(start_event);
89 auto* true_start_event = static_cast<HostRunQueueEvent*>(start_event);
90 if (!m_has_timer || !true_start_event->m_has_timer)
91 ARCANE_FATAL("Event has no timer support");
92 double diff_time = m_recorded_time - true_start_event->m_recorded_time;
93 Int64 diff_as_int64 = static_cast<Int64>(diff_time * 1.0e9);
94 return diff_as_int64;
95 }
96
97 private:
98
99 bool m_has_timer = false;
100 double m_recorded_time = 0.0;
101};
102
103/*---------------------------------------------------------------------------*/
104/*---------------------------------------------------------------------------*/
105
106class ARCANE_ACCELERATOR_CORE_EXPORT CommonRunnerRuntime
107: public IRunnerRuntime
108{
109 public:
110
112 {
113 DeviceInfo d;
114 d.setDeviceId(DeviceId());
115 d.setName("HostDevice");
116 m_device_info_list.addDevice(d);
117 }
118
119 public:
120
121 void notifyBeginLaunchKernel() final {}
122 void notifyEndLaunchKernel() final {}
123 void barrier() final {}
124 IRunQueueStream* createStream(const RunQueueBuildInfo&) final { return new HostRunQueueStream(this); }
125 IRunQueueEventImpl* createEventImpl() final { return new HostRunQueueEvent(false); }
126 IRunQueueEventImpl* createEventImplWithTimer() final { return new HostRunQueueEvent(true); }
127 void setMemoryAdvice(ConstMemoryView, eMemoryAdvice, DeviceId) final {}
128 void unsetMemoryAdvice(ConstMemoryView, eMemoryAdvice, DeviceId) final {}
129 void setCurrentDevice(DeviceId) final {}
130 const IDeviceInfoList* deviceInfoList() final { return &m_device_info_list; }
131 void getPointerAttribute(PointerAttribute& attribute, const void* ptr) final
132 {
133 _fillPointerAttribute(attribute, ptr);
134 }
135 DeviceMemoryInfo getDeviceMemoryInfo(DeviceId) override
136 {
137 // TODO: à implémenter
138 return {};
139 }
140
141 private:
142
143 DeviceInfoList m_device_info_list;
144};
145
146/*---------------------------------------------------------------------------*/
147/*---------------------------------------------------------------------------*/
148
149class ARCANE_ACCELERATOR_CORE_EXPORT SequentialRunnerRuntime
150: public CommonRunnerRuntime
151{
152 eExecutionPolicy executionPolicy() const final { return eExecutionPolicy::Sequential; }
153};
154
155/*---------------------------------------------------------------------------*/
156/*---------------------------------------------------------------------------*/
157
158class ARCANE_ACCELERATOR_CORE_EXPORT ThreadRunnerRuntime
159: public CommonRunnerRuntime
160{
161 public:
162
163 eExecutionPolicy executionPolicy() const final { return eExecutionPolicy::Thread; }
164};
165
166namespace
167{
168 SequentialRunnerRuntime global_sequential_runqueue_runtime;
169 ThreadRunnerRuntime global_thread_runqueue_runtime;
170} // namespace
171
172/*---------------------------------------------------------------------------*/
173/*---------------------------------------------------------------------------*/
174
175//! Récupère l'implémentation séquentielle de RunQueue
176extern "C++" ARCANE_ACCELERATOR_CORE_EXPORT IRunnerRuntime*
177getSequentialRunQueueRuntime()
178{
179 return &global_sequential_runqueue_runtime;
180}
181
182//! Récupère l'implémentation séquentielle de RunQueue
183extern "C++" ARCANE_ACCELERATOR_CORE_EXPORT IRunnerRuntime*
184getThreadRunQueueRuntime()
185{
186 return &global_thread_runqueue_runtime;
187}
188
189/*---------------------------------------------------------------------------*/
190/*---------------------------------------------------------------------------*/
191
192} // End namespace Arcane::Accelerator::impl
193
194/*---------------------------------------------------------------------------*/
195/*---------------------------------------------------------------------------*/
#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.
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.
eMemoryAdvice
Conseils pour la gestion mémoire.
Definition Memory.h:36
eExecutionPolicy
Politique d'exécution pour un Runner.
std::int64_t Int64
Type entier signé sur 64 bits.