Skip to content

Commit dc78d8a

Browse files
Merge pull request #1180 from arcaneframework/dev/gg-add-prefetch-for-variableview
Add support for automatic prefetching before running a command
2 parents 6a533b8 + 78a8396 commit dc78d8a

File tree

9 files changed

+106
-27
lines changed

9 files changed

+106
-27
lines changed
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
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+
/* VariableViews.cc (C) 2000-2024 */
9+
/* */
10+
/* Gestion des vues sur les variables pour les accélérateurs. */
11+
/*---------------------------------------------------------------------------*/
12+
/*---------------------------------------------------------------------------*/
13+
14+
#include "arcane/accelerator/VariableViews.h"
15+
16+
#include "arcane/accelerator/core/RunCommand.h"
17+
#include "arcane/accelerator/core/RunQueue.h"
18+
19+
#include "arcane/core/VariableUtils.h"
20+
21+
/*---------------------------------------------------------------------------*/
22+
/*---------------------------------------------------------------------------*/
23+
/*!
24+
* \file VariableViews.h
25+
*
26+
* Ce fichier contient les déclarations des types pour gérer
27+
* les vues pour les accélérateurs des variables du maillage.
28+
*/
29+
/*---------------------------------------------------------------------------*/
30+
/*---------------------------------------------------------------------------*/
31+
32+
namespace Arcane::Accelerator
33+
{
34+
35+
/*---------------------------------------------------------------------------*/
36+
/*---------------------------------------------------------------------------*/
37+
38+
VariableViewBase::
39+
VariableViewBase(RunCommand& command, IVariable* var)
40+
{
41+
RunQueue& q = command.m_run_queue;
42+
if (q._isAutoPrefetchCommand())
43+
VariableUtils::prefetchVariableAsync(var, &q);
44+
}
45+
46+
/*---------------------------------------------------------------------------*/
47+
/*---------------------------------------------------------------------------*/
48+
49+
} // namespace Arcane::Accelerator
50+
51+
/*---------------------------------------------------------------------------*/
52+
/*---------------------------------------------------------------------------*/

arcane/src/arcane/accelerator/VariableViews.h

Lines changed: 6 additions & 15 deletions
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-2023 CEA (www.cea.fr) IFPEN (www.ifpenergiesnouvelles.com)
3+
// Copyright 2000-2024 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-
/* VariableViews.h (C) 2000-2023 */
8+
/* VariableViews.h (C) 2000-2024 */
99
/* */
1010
/* Gestion des vues sur les variables pour les accélérateurs. */
1111
/*---------------------------------------------------------------------------*/
@@ -25,12 +25,7 @@
2525

2626
/*---------------------------------------------------------------------------*/
2727
/*---------------------------------------------------------------------------*/
28-
/*!
29-
* \file Views.h
30-
*
31-
* Ce fichier contient les déclarations des types pour gérer
32-
* les vues pour les accélérateurs des variables du maillage.
33-
*/
28+
3429
/*---------------------------------------------------------------------------*/
3530
/*---------------------------------------------------------------------------*/
3631

@@ -45,15 +40,11 @@ template<typename DataType> class View1DGetterSetter;
4540
/*!
4641
* \brief Classe de base des vues sur les variables.
4742
*/
48-
class VariableViewBase
43+
class ARCANE_ACCELERATOR_EXPORT VariableViewBase
4944
{
5045
public:
51-
// Pour l'instant n'utilise pas encore \a command et \a var
52-
// mais il ne faut pas les supprimer
53-
VariableViewBase(RunCommand&,IVariable*)
54-
{
55-
}
56-
private:
46+
47+
VariableViewBase(RunCommand& command,IVariable* var);
5748
};
5849

5950
/*---------------------------------------------------------------------------*/

arcane/src/arcane/accelerator/core/RunCommand.h

Lines changed: 3 additions & 2 deletions
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-2023 CEA (www.cea.fr) IFPEN (www.ifpenergiesnouvelles.com)
3+
// Copyright 2000-2024 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-
/* RunCommand.h (C) 2000-2023 */
8+
/* RunCommand.h (C) 2000-2024 */
99
/* */
1010
/* Gestion d'une commande sur accélérateur. */
1111
/*---------------------------------------------------------------------------*/
@@ -42,6 +42,7 @@ class ARCANE_ACCELERATOR_CORE_EXPORT RunCommand
4242
friend impl::IReduceMemoryImpl* impl::internalGetOrCreateReduceMemoryImpl(RunCommand* command);
4343
friend impl::RunCommandLaunchInfo;
4444
friend impl::RunQueueImpl;
45+
friend class VariableViewBase;
4546
friend RunCommand makeCommand(RunQueue& run_queue);
4647
friend RunCommand makeCommand(RunQueue* run_queue);
4748

arcane/src/arcane/accelerator/core/RunQueue.cc

Lines changed: 11 additions & 2 deletions
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-2023 CEA (www.cea.fr) IFPEN (www.ifpenergiesnouvelles.com)
3+
// Copyright 2000-2024 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-
/* RunQueue.cc (C) 2000-2023 */
8+
/* RunQueue.cc (C) 2000-2024 */
99
/* */
1010
/* Gestion d'une file d'exécution sur accélérateur. */
1111
/*---------------------------------------------------------------------------*/
@@ -188,6 +188,15 @@ isAsync() const
188188
/*---------------------------------------------------------------------------*/
189189
/*---------------------------------------------------------------------------*/
190190

191+
bool RunQueue::
192+
_isAutoPrefetchCommand() const
193+
{
194+
return m_p->m_runner->_isAutoPrefetchCommand();
195+
}
196+
197+
/*---------------------------------------------------------------------------*/
198+
/*---------------------------------------------------------------------------*/
199+
191200
extern "C++" ePointerAccessibility
192201
getPointerAccessibility(RunQueue* queue, const void* ptr, PointerAttribute* ptr_attr)
193202
{

arcane/src/arcane/accelerator/core/RunQueue.h

Lines changed: 7 additions & 3 deletions
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-2023 CEA (www.cea.fr) IFPEN (www.ifpenergiesnouvelles.com)
3+
// Copyright 2000-2024 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-
/* RunQueue.h (C) 2000-2023 */
8+
/* RunQueue.h (C) 2000-2024 */
99
/* */
1010
/* Gestion d'une file d'exécution sur accélérateur. */
1111
/*---------------------------------------------------------------------------*/
@@ -92,7 +92,7 @@ class ARCANE_ACCELERATOR_CORE_EXPORT RunQueue
9292
void setAsync(bool v);
9393
//! Indique si la file d'exécution est asynchrone.
9494
bool isAsync() const;
95-
//! Bloque tant que toutes les commandes associées à la file ne sont pas terminées.
95+
//! Bloque tant que toutes les commandes associées à la file ne sont pas terminées.
9696
void barrier();
9797

9898
//! Copie des informations entre deux zones mémoires
@@ -128,6 +128,10 @@ class ARCANE_ACCELERATOR_CORE_EXPORT RunQueue
128128
impl::IRunQueueStream* _internalStream() const;
129129
impl::RunCommandImpl* _getCommandImpl();
130130

131+
// Pour VariableViewBase
132+
friend class VariableViewBase;
133+
bool _isAutoPrefetchCommand() const;
134+
131135
private:
132136

133137
impl::RunQueueImpl* m_p;

arcane/src/arcane/accelerator/core/Runner.cc

Lines changed: 21 additions & 2 deletions
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-2023 CEA (www.cea.fr) IFPEN (www.ifpenergiesnouvelles.com)
3+
// Copyright 2000-2024 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-
/* Runner.cc (C) 2000-2023 */
8+
/* Runner.cc (C) 2000-2024 */
99
/* */
1010
/* Gestion d'une file d'exécution sur accélérateur. */
1111
/*---------------------------------------------------------------------------*/
@@ -18,6 +18,7 @@
1818
#include "arcane/utils/NotImplementedException.h"
1919
#include "arcane/utils/ArgumentException.h"
2020
#include "arcane/utils/MemoryView.h"
21+
#include "arcane/utils/ValueConvert.h"
2122

2223
#include "arcane/accelerator/core/RunQueueBuildInfo.h"
2324
#include "arcane/accelerator/core/DeviceId.h"
@@ -165,6 +166,11 @@ class Runner::Impl
165166
m_device_id = device;
166167
m_runtime = _getRuntime(v);
167168
m_is_init = true;
169+
m_is_auto_prefetch_command = false;
170+
171+
// Pour test
172+
if (auto v = Convert::Type<Int32>::tryParseFromEnvironment("ARCANE_ACCELERATOR_PREFETCH_COMMAND", true))
173+
m_is_auto_prefetch_command = (v.value() != 0);
168174

169175
// Il faut initialiser le pool à la fin car il a besoin d'accéder à \a m_runtime
170176
m_run_queue_pool = new RunQueueImplStack(runner);
@@ -199,6 +205,7 @@ class Runner::Impl
199205
}
200206

201207
impl::IRunnerRuntime* runtime() const { return m_runtime; }
208+
bool isAutoPrefetchCommand() const { return m_is_auto_prefetch_command; }
202209

203210
public:
204211

@@ -220,6 +227,9 @@ class Runner::Impl
220227
*/
221228
std::atomic<Int64> m_cumulative_command_time = 0;
222229

230+
//! Indique si on pré-copie les données avant une commande de cette RunQueue
231+
bool m_is_auto_prefetch_command = false;
232+
223233
private:
224234

225235
void _freePool(RunQueueImplStack* s)
@@ -543,6 +553,15 @@ stopAllProfiling()
543553
/*---------------------------------------------------------------------------*/
544554
/*---------------------------------------------------------------------------*/
545555

556+
bool Runner::
557+
_isAutoPrefetchCommand() const
558+
{
559+
return m_p->isAutoPrefetchCommand();
560+
}
561+
562+
/*---------------------------------------------------------------------------*/
563+
/*---------------------------------------------------------------------------*/
564+
546565
extern "C++" ePointerAccessibility
547566
getPointerAccessibility(Runner* runner, const void* ptr, PointerAttribute* ptr_attr)
548567
{

arcane/src/arcane/accelerator/core/Runner.h

Lines changed: 3 additions & 3 deletions
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-2023 CEA (www.cea.fr) IFPEN (www.ifpenergiesnouvelles.com)
3+
// Copyright 2000-2024 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-
/* Runner.h (C) 2000-2023 */
8+
/* Runner.h (C) 2000-2024 */
99
/* */
1010
/* Gestion de l'exécution sur accélérateur. */
1111
/*---------------------------------------------------------------------------*/
@@ -155,14 +155,14 @@ class ARCANE_ACCELERATOR_CORE_EXPORT Runner
155155
void _addCommandTime(double v);
156156
impl::IRunnerRuntime* _internalRuntime() const;
157157

158-
159158
private:
160159

161160
std::shared_ptr<Impl> m_p;
162161

163162
private:
164163

165164
void _checkIsInit() const;
165+
bool _isAutoPrefetchCommand() const;
166166
};
167167

168168
/*---------------------------------------------------------------------------*/

arcane/src/arcane/accelerator/srcs.cmake

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ set( ARCANE_SOURCES
3333
Scan.cc
3434
SpanViews.h
3535
VariableViews.h
36+
VariableViews.cc
3637
Views.h
3738
ViewsCommon.h
3839
)

arcane/src/arcane/tests/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -601,10 +601,12 @@ endif()
601601

602602
if (ARCANE_HAS_ACCELERATOR_API)
603603
arcane_add_accelerator_test_sequential(hydro_accelerator5 testHydroAccelerator-5.arc -m 50)
604+
arcane_add_accelerator_test_sequential(hydro_accelerator5_prefetch testHydroAccelerator-5.arc -m 50 "-We,ARCANE_ACCELERATOR_PREFETCH_COMMAND,1")
604605
arcane_add_accelerator_test_parallel(hydro_accelerator5 testHydroAccelerator-5.arc 4 -m 50)
605606
arcane_add_accelerator_test_parallel_thread(hydro_accelerator5 testHydroAccelerator-5.arc 4 -m 50)
606607
arcane_add_accelerator_test_message_passing_hybrid(hydro_accelerator5 CASE_FILE testHydroAccelerator-5.arc NB_SHM 2 NB_MPI 2 ARGS -m 50)
607608
arcane_add_test(hydro_accelerator5 testHydroAccelerator-5.arc -m 50)
609+
arcane_add_test_sequential(hydro_accelerator5_prefetch testHydroAccelerator-5.arc -m 50 "-We,ARCANE_ACCELERATOR_PREFETCH_COMMAND,1")
608610
arcane_add_test_sequential_task(hydro_accelerator5 testHydroAccelerator-5.arc 4 -m 50)
609611
arcane_add_test_parallel_thread(hydro_accelerator5 testHydroAccelerator-5.arc 4 -m 50)
610612
arcane_add_test_message_passing_hybrid(hydro_accelerator5 CASE_FILE testHydroAccelerator-5.arc NB_SHM 2 NB_MPI 2 ARGS -m 50)

0 commit comments

Comments
 (0)