Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support to query work on RunQueueEvent #2006

Merged
merged 2 commits into from
Feb 25, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions arcane/src/arcane/accelerator/core/RunQueueEvent.cc
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,17 @@ wait()
/*---------------------------------------------------------------------------*/
/*---------------------------------------------------------------------------*/

bool RunQueueEvent::
hasPendingWork() const
{
if (m_p)
return m_p->m_impl->hasPendingWork();
return false;
}

/*---------------------------------------------------------------------------*/
/*---------------------------------------------------------------------------*/

impl::IRunQueueEventImpl* RunQueueEvent::
_internalEventImpl() const
{
Expand Down
8 changes: 8 additions & 0 deletions arcane/src/arcane/accelerator/core/RunQueueEvent.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,14 @@ class ARCANE_ACCELERATOR_CORE_EXPORT RunQueueEvent
//! Bloque tant que les files associées à cet évènement n'ont pas fini leur travail.
void wait();

/*!
* \brief Indique si les RunQueue associées à cet évènement ont fini leur travail.
*
* Retourne \a false si les RunQueue enregistrées via RunQueue::recordEvent() ont
* fini leur travail. Retourn \a true sinon.
*/
bool hasPendingWork() const;

private:

impl::IRunQueueEventImpl* _internalEventImpl() const;
Expand Down
5 changes: 3 additions & 2 deletions arcane/src/arcane/accelerator/core/RunQueueRuntime.cc
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
// -*- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature -*-
//-----------------------------------------------------------------------------
// Copyright 2000-2024 CEA (www.cea.fr) IFPEN (www.ifpenergiesnouvelles.com)
// Copyright 2000-2025 CEA (www.cea.fr) IFPEN (www.ifpenergiesnouvelles.com)
// See the top-level COPYRIGHT file for details.
// SPDX-License-Identifier: Apache-2.0
//-----------------------------------------------------------------------------
/*---------------------------------------------------------------------------*/
/* RunQueueRuntime.cc (C) 2000-2024 */
/* RunQueueRuntime.cc (C) 2000-2025 */
/* */
/* Implémentation d'un RunQueue pour une cible donnée. */
/*---------------------------------------------------------------------------*/
Expand Down Expand Up @@ -83,6 +83,7 @@ class ARCANE_ACCELERATOR_CORE_EXPORT HostRunQueueEvent
}
void wait() final {}
void waitForEvent(IRunQueueStream*) final {}
bool hasPendingWork() final { return false; }
Int64 elapsedTime(IRunQueueEventImpl* start_event) final
{
ARCANE_CHECK_POINTER(start_event);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
// -*- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature -*-
//-----------------------------------------------------------------------------
// Copyright 2000-2024 CEA (www.cea.fr) IFPEN (www.ifpenergiesnouvelles.com)
// Copyright 2000-2025 CEA (www.cea.fr) IFPEN (www.ifpenergiesnouvelles.com)
// See the top-level COPYRIGHT file for details.
// SPDX-License-Identifier: Apache-2.0
//-----------------------------------------------------------------------------
/*---------------------------------------------------------------------------*/
/* IRunQueueEventImpl.h (C) 2000-2024 */
/* IRunQueueEventImpl.h (C) 2000-2025 */
/* */
/* Interface de l'implémentation d'un évènement. */
/*---------------------------------------------------------------------------*/
Expand Down Expand Up @@ -42,6 +42,8 @@ class ARCANE_ACCELERATOR_CORE_EXPORT IRunQueueEventImpl

//! Temps écoulé (en nanoseconde) entre l'évènement \a from_event et cet évènement.
virtual Int64 elapsedTime(IRunQueueEventImpl* from_event) = 0;

virtual bool hasPendingWork() =0;
};

/*---------------------------------------------------------------------------*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,15 @@ class CudaRunQueueEvent
return nano_time;
}

bool hasPendingWork() final
{
cudaError_t v = cudaEventQuery(m_cuda_event);
if (v == cudaErrorNotReady)
return true;
ARCANE_CHECK_CUDA(v);
return false;
}

private:

cudaEvent_t m_cuda_event;
Expand Down
13 changes: 11 additions & 2 deletions arcane/src/arcane/accelerator/hip/runtime/HipAcceleratorRuntime.cc
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
// -*- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature -*-
//-----------------------------------------------------------------------------
// Copyright 2000-2024 CEA (www.cea.fr) IFPEN (www.ifpenergiesnouvelles.com)
// Copyright 2000-2025 CEA (www.cea.fr) IFPEN (www.ifpenergiesnouvelles.com)
// See the top-level COPYRIGHT file for details.
// SPDX-License-Identifier: Apache-2.0
//-----------------------------------------------------------------------------
/*---------------------------------------------------------------------------*/
/* HipAcceleratorRuntime.cc (C) 2000-2024 */
/* HipAcceleratorRuntime.cc (C) 2000-2025 */
/* */
/* Runtime pour 'HIP'. */
/*---------------------------------------------------------------------------*/
Expand Down Expand Up @@ -187,6 +187,15 @@ class HipRunQueueEvent
return nano_time;
}

bool hasPendingWork() final
{
hipError_t v = hipEventQuery(m_hip_event);
if (v == hipErrorNotReady)
return true;
ARCANE_CHECK_HIP(v);
return false;
}

private:

hipEvent_t m_hip_event;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
// -*- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature -*-
//-----------------------------------------------------------------------------
// Copyright 2000-2024 CEA (www.cea.fr) IFPEN (www.ifpenergiesnouvelles.com)
// Copyright 2000-2025 CEA (www.cea.fr) IFPEN (www.ifpenergiesnouvelles.com)
// See the top-level COPYRIGHT file for details.
// SPDX-License-Identifier: Apache-2.0
//-----------------------------------------------------------------------------
/*---------------------------------------------------------------------------*/
/* SyclAcceleratorRuntime.cc (C) 2000-2024 */
/* SyclAcceleratorRuntime.cc (C) 2000-2025 */
/* */
/* Runtime pour 'SYCL'. */
/*---------------------------------------------------------------------------*/
Expand All @@ -16,6 +16,7 @@

#include "arcane/utils/PlatformUtils.h"
#include "arcane/utils/NotSupportedException.h"
#include "arcane/utils/NotImplementedException.h"
#include "arcane/utils/FatalErrorException.h"
#include "arcane/utils/IMemoryRessourceMng.h"
#include "arcane/utils/internal/IMemoryRessourceMngInternal.h"
Expand Down Expand Up @@ -216,6 +217,11 @@ class SyclRunQueueEvent
return (end - start);
}

bool hasPendingWork() final
{
ARCANE_THROW(NotImplementedException,"hasPendingWork()");
}

private:

sycl::event m_sycl_event;
Expand Down
62 changes: 30 additions & 32 deletions arcane/src/arcane/tests/accelerator/RunQueueUnitTest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include "arcane/utils/NumArray.h"
#include "arcane/utils/ValueChecker.h"
#include "arcane/utils/MemoryUtils.h"
#include "arcane/utils/PlatformUtils.h"

#include "arcane/core/BasicUnitTest.h"
#include "arcane/core/ServiceFactory.h"
Expand All @@ -22,6 +23,7 @@
#include "arcane/accelerator/core/Runner.h"
#include "arcane/accelerator/core/RunQueueEvent.h"
#include "arcane/accelerator/core/IAcceleratorMng.h"
#include "arcane/accelerator/core/internal/RunQueueImpl.h"

#include "arcane/accelerator/NumArrayViews.h"
#include "arcane/accelerator/SpanViews.h"
Expand Down Expand Up @@ -49,7 +51,6 @@ class RunQueueUnitTest
public:

explicit RunQueueUnitTest(const ServiceBuildInfo& cb);
~RunQueueUnitTest();

public:

Expand All @@ -58,14 +59,14 @@ class RunQueueUnitTest

private:

ax::Runner* m_runner = nullptr;
ax::Runner m_runner;

public:

void _executeTestNullQueue();
void _executeTest1(bool use_priority);
void _executeTest2();
void _executeTest3();
void _executeTest3(bool use_pooling);
void _executeTest4();
void _executeTest5();
};
Expand All @@ -87,21 +88,13 @@ RunQueueUnitTest(const ServiceBuildInfo& sb)
/*---------------------------------------------------------------------------*/
/*---------------------------------------------------------------------------*/

RunQueueUnitTest::
~RunQueueUnitTest()
{
}

/*---------------------------------------------------------------------------*/
/*---------------------------------------------------------------------------*/

/*---------------------------------------------------------------------------*/
/*---------------------------------------------------------------------------*/

void RunQueueUnitTest::
initializeTest()
{
m_runner = subDomain()->acceleratorMng()->defaultRunner();
m_runner = subDomain()->acceleratorMng()->runner();
}

/*---------------------------------------------------------------------------*/
Expand All @@ -112,14 +105,13 @@ executeTest()
{
_executeTestNullQueue();
_executeTest2();
bool old_v = m_runner->isConcurrentQueueCreation();
m_runner->setConcurrentQueueCreation(true);
_executeTest1(false);
_executeTest1(true);
_executeTest3();
_executeTest3(false);
if (m_runner.executionPolicy() != ax::eExecutionPolicy::SYCL)
_executeTest3(true);
_executeTest4();
_executeTest5();
m_runner->setConcurrentQueueCreation(old_v);
}

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

queue = makeQueue(*m_runner);
queue = makeQueue(m_runner);
vc.areEqual(queue.isNull(), false, "not null");

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

queue = makeQueue(*m_runner);
queue = makeQueue(m_runner);
if (queue.executionPolicy() == eExecutionPolicy::None)
ARCANE_FATAL("Bad execution policy");
}
Expand Down Expand Up @@ -185,14 +177,15 @@ _executeTest1(bool use_priority)
ax::RunQueueBuildInfo bi;
if (use_priority && (i > 3))
bi.setPriority(-8);
auto queue_ref = makeQueueRef(*m_runner, bi);
auto queue_ref = makeQueueRef(m_runner, bi);
queue_ref->setAsync(true);
allthreads.add(new std::thread(task_func, queue_ref, i));
}
for (auto thr : allthreads) {
thr->join();
delete thr;
}
info() << "End of wait";

Int64 true_total = 0;
Int64 expected_true_total = 0;
Expand All @@ -217,10 +210,10 @@ _executeTest2()
info() << "Test2: use events";
ValueChecker vc(A_FUNCINFO);

auto event{ makeEvent(*m_runner) };
auto queue1{ makeQueue(*m_runner) };
auto event{ makeEvent(m_runner) };
auto queue1{ makeQueue(m_runner) };
queue1.setAsync(true);
auto queue2{ makeQueue(*m_runner) };
auto queue2{ makeQueue(m_runner) };
queue2.setAsync(true);

Integer nb_value = 100000;
Expand All @@ -244,7 +237,7 @@ _executeTest2()
v(iter) = v(iter) * 2;
};
}
queue1.barrier();

queue2.barrier();

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

/*---------------------------------------------------------------------------*/
/*---------------------------------------------------------------------------*/
// Test la synchronisation de avec un évènement.
// Teste la synchronisation avec un évènement.
void RunQueueUnitTest::
_executeTest3()
_executeTest3(bool use_pooling)
{
info() << "Test3: use events with wait()";
info() << "Test3: use events with wait() or pooling is_pooling?=" << use_pooling;
ValueChecker vc(A_FUNCINFO);

UniqueArray<Ref<ax::RunQueueEvent>> event_array;
event_array.add(makeEventRef(*m_runner));
event_array.add(makeEventRef(m_runner));

auto queue1{ makeQueue(*m_runner) };
auto queue1{ makeQueue(m_runner) };
queue1.setAsync(true);
auto queue2{ makeQueue(*m_runner) };
auto queue2{ makeQueue(m_runner) };
queue2.setAsync(true);

Integer nb_value = 100000;
Expand All @@ -284,7 +277,12 @@ _executeTest3()
};
queue1.recordEvent(event_array[0]);
}
event_array[0]->wait();
if (use_pooling)
while (event_array[0]->hasPendingWork()) {
// Do something ...
}
else
event_array[0]->wait();
{
auto command2 = makeCommand(queue2);
auto v = viewInOut(command2, values);
Expand Down Expand Up @@ -316,7 +314,7 @@ _executeTest4()
Arcane::Accelerator::RunQueueEvent event0;
if (!event0.isNull())
ARCANE_FATAL("Event is not null");
event0 = makeEvent(*m_runner);
event0 = makeEvent(m_runner);
if (event0.isNull())
ARCANE_FATAL("Event is null");
Arcane::Accelerator::RunQueueEvent event1(event0);
Expand All @@ -326,7 +324,7 @@ _executeTest4()

ValueChecker vc(A_FUNCINFO);
//![SampleRunQueueEventSample1]
Arcane::Accelerator::Runner runner = *m_runner;
Arcane::Accelerator::Runner runner = m_runner;

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

Expand Down
Loading