Skip to content

Commit 20e0688

Browse files
Merge pull request #2006 from arcaneframework/dev/gg-add-accelerator-query-event
Add support to query work on `RunQueueEvent`
2 parents e001132 + e43e36a commit 20e0688

File tree

8 files changed

+84
-40
lines changed

8 files changed

+84
-40
lines changed

arcane/src/arcane/accelerator/core/RunQueueEvent.cc

+11
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,17 @@ wait()
142142
/*---------------------------------------------------------------------------*/
143143
/*---------------------------------------------------------------------------*/
144144

145+
bool RunQueueEvent::
146+
hasPendingWork() const
147+
{
148+
if (m_p)
149+
return m_p->m_impl->hasPendingWork();
150+
return false;
151+
}
152+
153+
/*---------------------------------------------------------------------------*/
154+
/*---------------------------------------------------------------------------*/
155+
145156
impl::IRunQueueEventImpl* RunQueueEvent::
146157
_internalEventImpl() const
147158
{

arcane/src/arcane/accelerator/core/RunQueueEvent.h

+8
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,14 @@ class ARCANE_ACCELERATOR_CORE_EXPORT RunQueueEvent
7474
//! Bloque tant que les files associées à cet évènement n'ont pas fini leur travail.
7575
void wait();
7676

77+
/*!
78+
* \brief Indique si les RunQueue associées à cet évènement ont fini leur travail.
79+
*
80+
* Retourne \a false si les RunQueue enregistrées via RunQueue::recordEvent() ont
81+
* fini leur travail. Retourn \a true sinon.
82+
*/
83+
bool hasPendingWork() const;
84+
7785
private:
7886

7987
impl::IRunQueueEventImpl* _internalEventImpl() const;

arcane/src/arcane/accelerator/core/RunQueueRuntime.cc

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
// -*- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature -*-
22
//-----------------------------------------------------------------------------
3-
// Copyright 2000-2024 CEA (www.cea.fr) IFPEN (www.ifpenergiesnouvelles.com)
3+
// Copyright 2000-2025 CEA (www.cea.fr) IFPEN (www.ifpenergiesnouvelles.com)
44
// See the top-level COPYRIGHT file for details.
55
// SPDX-License-Identifier: Apache-2.0
66
//-----------------------------------------------------------------------------
77
/*---------------------------------------------------------------------------*/
8-
/* RunQueueRuntime.cc (C) 2000-2024 */
8+
/* RunQueueRuntime.cc (C) 2000-2025 */
99
/* */
1010
/* Implémentation d'un RunQueue pour une cible donnée. */
1111
/*---------------------------------------------------------------------------*/
@@ -83,6 +83,7 @@ class ARCANE_ACCELERATOR_CORE_EXPORT HostRunQueueEvent
8383
}
8484
void wait() final {}
8585
void waitForEvent(IRunQueueStream*) final {}
86+
bool hasPendingWork() final { return false; }
8687
Int64 elapsedTime(IRunQueueEventImpl* start_event) final
8788
{
8889
ARCANE_CHECK_POINTER(start_event);

arcane/src/arcane/accelerator/core/internal/IRunQueueEventImpl.h

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
// -*- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature -*-
22
//-----------------------------------------------------------------------------
3-
// Copyright 2000-2024 CEA (www.cea.fr) IFPEN (www.ifpenergiesnouvelles.com)
3+
// Copyright 2000-2025 CEA (www.cea.fr) IFPEN (www.ifpenergiesnouvelles.com)
44
// See the top-level COPYRIGHT file for details.
55
// SPDX-License-Identifier: Apache-2.0
66
//-----------------------------------------------------------------------------
77
/*---------------------------------------------------------------------------*/
8-
/* IRunQueueEventImpl.h (C) 2000-2024 */
8+
/* IRunQueueEventImpl.h (C) 2000-2025 */
99
/* */
1010
/* Interface de l'implémentation d'un évènement. */
1111
/*---------------------------------------------------------------------------*/
@@ -42,6 +42,8 @@ class ARCANE_ACCELERATOR_CORE_EXPORT IRunQueueEventImpl
4242

4343
//! Temps écoulé (en nanoseconde) entre l'évènement \a from_event et cet évènement.
4444
virtual Int64 elapsedTime(IRunQueueEventImpl* from_event) = 0;
45+
46+
virtual bool hasPendingWork() =0;
4547
};
4648

4749
/*---------------------------------------------------------------------------*/

arcane/src/arcane/accelerator/cuda/runtime/CudaAcceleratorRuntime.cc

+9
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,15 @@ class CudaRunQueueEvent
232232
return nano_time;
233233
}
234234

235+
bool hasPendingWork() final
236+
{
237+
cudaError_t v = cudaEventQuery(m_cuda_event);
238+
if (v == cudaErrorNotReady)
239+
return true;
240+
ARCANE_CHECK_CUDA(v);
241+
return false;
242+
}
243+
235244
private:
236245

237246
cudaEvent_t m_cuda_event;

arcane/src/arcane/accelerator/hip/runtime/HipAcceleratorRuntime.cc

+11-2
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
// -*- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature -*-
22
//-----------------------------------------------------------------------------
3-
// Copyright 2000-2024 CEA (www.cea.fr) IFPEN (www.ifpenergiesnouvelles.com)
3+
// Copyright 2000-2025 CEA (www.cea.fr) IFPEN (www.ifpenergiesnouvelles.com)
44
// See the top-level COPYRIGHT file for details.
55
// SPDX-License-Identifier: Apache-2.0
66
//-----------------------------------------------------------------------------
77
/*---------------------------------------------------------------------------*/
8-
/* HipAcceleratorRuntime.cc (C) 2000-2024 */
8+
/* HipAcceleratorRuntime.cc (C) 2000-2025 */
99
/* */
1010
/* Runtime pour 'HIP'. */
1111
/*---------------------------------------------------------------------------*/
@@ -187,6 +187,15 @@ class HipRunQueueEvent
187187
return nano_time;
188188
}
189189

190+
bool hasPendingWork() final
191+
{
192+
hipError_t v = hipEventQuery(m_hip_event);
193+
if (v == hipErrorNotReady)
194+
return true;
195+
ARCANE_CHECK_HIP(v);
196+
return false;
197+
}
198+
190199
private:
191200

192201
hipEvent_t m_hip_event;

arcane/src/arcane/accelerator/sycl/runtime/SyclAcceleratorRuntime.cc

+8-2
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
// -*- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature -*-
22
//-----------------------------------------------------------------------------
3-
// Copyright 2000-2024 CEA (www.cea.fr) IFPEN (www.ifpenergiesnouvelles.com)
3+
// Copyright 2000-2025 CEA (www.cea.fr) IFPEN (www.ifpenergiesnouvelles.com)
44
// See the top-level COPYRIGHT file for details.
55
// SPDX-License-Identifier: Apache-2.0
66
//-----------------------------------------------------------------------------
77
/*---------------------------------------------------------------------------*/
8-
/* SyclAcceleratorRuntime.cc (C) 2000-2024 */
8+
/* SyclAcceleratorRuntime.cc (C) 2000-2025 */
99
/* */
1010
/* Runtime pour 'SYCL'. */
1111
/*---------------------------------------------------------------------------*/
@@ -16,6 +16,7 @@
1616

1717
#include "arcane/utils/PlatformUtils.h"
1818
#include "arcane/utils/NotSupportedException.h"
19+
#include "arcane/utils/NotImplementedException.h"
1920
#include "arcane/utils/FatalErrorException.h"
2021
#include "arcane/utils/IMemoryRessourceMng.h"
2122
#include "arcane/utils/internal/IMemoryRessourceMngInternal.h"
@@ -216,6 +217,11 @@ class SyclRunQueueEvent
216217
return (end - start);
217218
}
218219

220+
bool hasPendingWork() final
221+
{
222+
ARCANE_THROW(NotImplementedException,"hasPendingWork()");
223+
}
224+
219225
private:
220226

221227
sycl::event m_sycl_event;

arcane/src/arcane/tests/accelerator/RunQueueUnitTest.cc

+30-32
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#include "arcane/utils/NumArray.h"
1515
#include "arcane/utils/ValueChecker.h"
1616
#include "arcane/utils/MemoryUtils.h"
17+
#include "arcane/utils/PlatformUtils.h"
1718

1819
#include "arcane/core/BasicUnitTest.h"
1920
#include "arcane/core/ServiceFactory.h"
@@ -22,6 +23,7 @@
2223
#include "arcane/accelerator/core/Runner.h"
2324
#include "arcane/accelerator/core/RunQueueEvent.h"
2425
#include "arcane/accelerator/core/IAcceleratorMng.h"
26+
#include "arcane/accelerator/core/internal/RunQueueImpl.h"
2527

2628
#include "arcane/accelerator/NumArrayViews.h"
2729
#include "arcane/accelerator/SpanViews.h"
@@ -49,7 +51,6 @@ class RunQueueUnitTest
4951
public:
5052

5153
explicit RunQueueUnitTest(const ServiceBuildInfo& cb);
52-
~RunQueueUnitTest();
5354

5455
public:
5556

@@ -58,14 +59,14 @@ class RunQueueUnitTest
5859

5960
private:
6061

61-
ax::Runner* m_runner = nullptr;
62+
ax::Runner m_runner;
6263

6364
public:
6465

6566
void _executeTestNullQueue();
6667
void _executeTest1(bool use_priority);
6768
void _executeTest2();
68-
void _executeTest3();
69+
void _executeTest3(bool use_pooling);
6970
void _executeTest4();
7071
void _executeTest5();
7172
};
@@ -87,21 +88,13 @@ RunQueueUnitTest(const ServiceBuildInfo& sb)
8788
/*---------------------------------------------------------------------------*/
8889
/*---------------------------------------------------------------------------*/
8990

90-
RunQueueUnitTest::
91-
~RunQueueUnitTest()
92-
{
93-
}
94-
95-
/*---------------------------------------------------------------------------*/
96-
/*---------------------------------------------------------------------------*/
97-
9891
/*---------------------------------------------------------------------------*/
9992
/*---------------------------------------------------------------------------*/
10093

10194
void RunQueueUnitTest::
10295
initializeTest()
10396
{
104-
m_runner = subDomain()->acceleratorMng()->defaultRunner();
97+
m_runner = subDomain()->acceleratorMng()->runner();
10598
}
10699

107100
/*---------------------------------------------------------------------------*/
@@ -112,14 +105,13 @@ executeTest()
112105
{
113106
_executeTestNullQueue();
114107
_executeTest2();
115-
bool old_v = m_runner->isConcurrentQueueCreation();
116-
m_runner->setConcurrentQueueCreation(true);
117108
_executeTest1(false);
118109
_executeTest1(true);
119-
_executeTest3();
110+
_executeTest3(false);
111+
if (m_runner.executionPolicy() != ax::eExecutionPolicy::SYCL)
112+
_executeTest3(true);
120113
_executeTest4();
121114
_executeTest5();
122-
m_runner->setConcurrentQueueCreation(old_v);
123115
}
124116

125117
/*---------------------------------------------------------------------------*/
@@ -140,13 +132,13 @@ _executeTestNullQueue()
140132
if (queue.allocationOptions() != default_mem_opt)
141133
ARCANE_FATAL("Bad null allocationOptions()");
142134

143-
queue = makeQueue(*m_runner);
135+
queue = makeQueue(m_runner);
144136
vc.areEqual(queue.isNull(), false, "not null");
145137

146138
queue = RunQueue();
147139
vc.areEqual(queue.isNull(), true, "is null (2)");
148140

149-
queue = makeQueue(*m_runner);
141+
queue = makeQueue(m_runner);
150142
if (queue.executionPolicy() == eExecutionPolicy::None)
151143
ARCANE_FATAL("Bad execution policy");
152144
}
@@ -185,14 +177,15 @@ _executeTest1(bool use_priority)
185177
ax::RunQueueBuildInfo bi;
186178
if (use_priority && (i > 3))
187179
bi.setPriority(-8);
188-
auto queue_ref = makeQueueRef(*m_runner, bi);
180+
auto queue_ref = makeQueueRef(m_runner, bi);
189181
queue_ref->setAsync(true);
190182
allthreads.add(new std::thread(task_func, queue_ref, i));
191183
}
192184
for (auto thr : allthreads) {
193185
thr->join();
194186
delete thr;
195187
}
188+
info() << "End of wait";
196189

197190
Int64 true_total = 0;
198191
Int64 expected_true_total = 0;
@@ -217,10 +210,10 @@ _executeTest2()
217210
info() << "Test2: use events";
218211
ValueChecker vc(A_FUNCINFO);
219212

220-
auto event{ makeEvent(*m_runner) };
221-
auto queue1{ makeQueue(*m_runner) };
213+
auto event{ makeEvent(m_runner) };
214+
auto queue1{ makeQueue(m_runner) };
222215
queue1.setAsync(true);
223-
auto queue2{ makeQueue(*m_runner) };
216+
auto queue2{ makeQueue(m_runner) };
224217
queue2.setAsync(true);
225218

226219
Integer nb_value = 100000;
@@ -244,7 +237,7 @@ _executeTest2()
244237
v(iter) = v(iter) * 2;
245238
};
246239
}
247-
queue1.barrier();
240+
248241
queue2.barrier();
249242

250243
// Vérifie les valeurs
@@ -257,19 +250,19 @@ _executeTest2()
257250

258251
/*---------------------------------------------------------------------------*/
259252
/*---------------------------------------------------------------------------*/
260-
// Test la synchronisation de avec un évènement.
253+
// Teste la synchronisation avec un évènement.
261254
void RunQueueUnitTest::
262-
_executeTest3()
255+
_executeTest3(bool use_pooling)
263256
{
264-
info() << "Test3: use events with wait()";
257+
info() << "Test3: use events with wait() or pooling is_pooling?=" << use_pooling;
265258
ValueChecker vc(A_FUNCINFO);
266259

267260
UniqueArray<Ref<ax::RunQueueEvent>> event_array;
268-
event_array.add(makeEventRef(*m_runner));
261+
event_array.add(makeEventRef(m_runner));
269262

270-
auto queue1{ makeQueue(*m_runner) };
263+
auto queue1{ makeQueue(m_runner) };
271264
queue1.setAsync(true);
272-
auto queue2{ makeQueue(*m_runner) };
265+
auto queue2{ makeQueue(m_runner) };
273266
queue2.setAsync(true);
274267

275268
Integer nb_value = 100000;
@@ -284,7 +277,12 @@ _executeTest3()
284277
};
285278
queue1.recordEvent(event_array[0]);
286279
}
287-
event_array[0]->wait();
280+
if (use_pooling)
281+
while (event_array[0]->hasPendingWork()) {
282+
// Do something ...
283+
}
284+
else
285+
event_array[0]->wait();
288286
{
289287
auto command2 = makeCommand(queue2);
290288
auto v = viewInOut(command2, values);
@@ -316,7 +314,7 @@ _executeTest4()
316314
Arcane::Accelerator::RunQueueEvent event0;
317315
if (!event0.isNull())
318316
ARCANE_FATAL("Event is not null");
319-
event0 = makeEvent(*m_runner);
317+
event0 = makeEvent(m_runner);
320318
if (event0.isNull())
321319
ARCANE_FATAL("Event is null");
322320
Arcane::Accelerator::RunQueueEvent event1(event0);
@@ -326,7 +324,7 @@ _executeTest4()
326324

327325
ValueChecker vc(A_FUNCINFO);
328326
//![SampleRunQueueEventSample1]
329-
Arcane::Accelerator::Runner runner = *m_runner;
327+
Arcane::Accelerator::Runner runner = m_runner;
330328

331329
Arcane::Accelerator::RunQueueEvent event(makeEvent(runner));
332330

0 commit comments

Comments
 (0)