Arcane  v4.1.3.0
Documentation développeur
Chargement...
Recherche...
Aucune correspondance
TestReduceGridStride_Accelerator.cc
1// -*- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature -*-
2//-----------------------------------------------------------------------------
3// Copyright 2000-2026 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#include <gtest/gtest.h>
9
10#include "arccore/base/PlatformUtils.h"
11#include "arccore/base/ForLoopRanges.h"
12
13#include "arccore/common/accelerator/Runner.h"
14#include "arccore/common/accelerator/RunQueue.h"
15#include "arccore/common/NumArray.h"
16
17#define ARCCORE_EXPERIMENTAL_GRID_STRIDE
18
19namespace Arcane
20{
21
22} // namespace Arcane
23
27#include "arccore/accelerator/internal/Initializer.h"
28
29/*---------------------------------------------------------------------------*/
30/*---------------------------------------------------------------------------*/
31
32using namespace Arcane;
33using namespace Arcane::Accelerator;
34
35/*---------------------------------------------------------------------------*/
36/*---------------------------------------------------------------------------*/
37
38extern "C++" Int64
39_testReduceGridStride(RunQueue queue, SmallSpan<const Int64> c, Int32 nb_thread,
40 Int32 nb_value, Int32 nb_part, Int32 nb_loop, bool is_async)
41{
42 queue.setAsync(is_async);
43 Int64 total_x = {};
44 if ((nb_value % nb_part) != 0)
45 ARCCORE_FATAL("{0} is not a multiple of {1}", nb_value, nb_part);
46 if (!queue.isAcceleratorPolicy())
47 nb_part = 1;
48 double x = Platform::getRealTime();
49 {
50 SmallSpan<const Int64> c_view(c);
51 for (int j = 0; j < nb_loop; ++j) {
52 auto command = makeCommand(queue);
53 ReducerSum2<Int64> reducer(command);
54 command.addNbThreadPerBlock(nb_thread);
55 command.addNbStride(nb_part);
56 command << RUNCOMMAND_LOOP1(iter, nb_value, reducer)
57 {
58 reducer.combine(c_view[iter]);
59 };
60 Int64 tx = reducer.reducedValue();
61 total_x += tx;
62 }
63 }
64 double y = Platform::getRealTime();
65 Int64 nb_byte = c.size() * sizeof(Int64) * nb_loop;
66 Real diff = y - x;
67 Real nb_giga_byte_second = (static_cast<Real>(nb_byte) / 1.0e9) / diff;
68 std::cout << "** TotalReduceGridStride=" << total_x << " async?=" << is_async
69 << " nb_part=" << nb_part << " nb_value=" << nb_value
70 << " nb_thread=" << nb_thread
71 << " GB/s=" << nb_giga_byte_second << " time=" << diff << "\n";
72 return total_x;
73}
74
75/*---------------------------------------------------------------------------*/
76/*---------------------------------------------------------------------------*/
#define ARCCORE_FATAL(...)
Macro envoyant une exception FatalErrorException.
Types et fonctions pour gérer les synchronisations sur les accélérateurs.
Types et macros pour gérer les boucles sur les accélérateurs.
#define RUNCOMMAND_LOOP1(iter_name, x1,...)
Boucle 1D sur accélérateur avec arguments supplémentaires.
void setAsync(bool v)
Positionne l'asynchronisme de l'instance.
Definition RunQueue.cc:299
bool isAcceleratorPolicy() const
Indique si l'instance est associée à un accélérateur.
Definition RunQueue.cc:331
Vue d'un tableau d'éléments de type T.
Definition Span.h:801
constexpr __host__ __device__ SizeType size() const noexcept
Retourne la taille du tableau.
Definition Span.h:325
Espace de nom pour l'utilisation des accélérateurs.
RunCommand makeCommand(const RunQueue &run_queue)
Créé une commande associée à la file run_queue.
ARCCORE_BASE_EXPORT Real getRealTime()
Temps Real utilisé en secondes.
-*- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature -*-