Arcane  v4.1.2.0
Documentation développeur
Chargement...
Recherche...
Aucune correspondance
TestReduce_Accelerator.cc
1// -*- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature -*-
2//-----------------------------------------------------------------------------
3// Copyright 2000-2025 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
12#include "arccore/common/accelerator/Runner.h"
13#include "arccore/common/accelerator/RunQueue.h"
14#include "arccore/common/NumArray.h"
15
19#include "arccore/accelerator/internal/Initializer.h"
20
21/*---------------------------------------------------------------------------*/
22/*---------------------------------------------------------------------------*/
23
24using namespace Arcane;
25using namespace Arcane::Accelerator;
26
27/*---------------------------------------------------------------------------*/
28/*---------------------------------------------------------------------------*/
29
30extern "C++" Int64
31_testReduceDirect(RunQueue queue, SmallSpan<const Int64> c, Int32 nb_thread,
32 Int32 nb_value, Int32 nb_part, Int32 nb_loop, bool is_async)
33{
34 queue.setAsync(is_async);
35 Int64 total_x = {};
36 if ((nb_value % nb_part) != 0)
37 ARCCORE_FATAL("{0} is not a multiple of {1}", nb_value, nb_part);
38 Int32 nb_true_value = nb_value / nb_part;
39 Int32 offset = nb_true_value;
40 double x = Platform::getRealTime();
41 {
42 SmallSpan<const Int64> c_view(c);
43 for (int j = 0; j < nb_loop; ++j) {
44 auto command = makeCommand(queue);
45 ReducerSum2<Int64> reducer(command);
46 command.addNbThreadPerBlock(nb_thread);
47 command << RUNCOMMAND_LOOP1(iter, nb_true_value, reducer)
48 {
49 Int32 i = iter;
50 for (Int32 k = 0; k < nb_part; ++k)
51 reducer.combine(c_view[i + (offset * k)]);
52 };
53 Int64 tx = reducer.reducedValue();
54 total_x += tx;
55 }
56 }
57 double y = Platform::getRealTime();
58 Int64 nb_byte = c.size() * sizeof(Int64) * nb_loop;
59 Real diff = y - x;
60 Real nb_giga_byte_second = (static_cast<Real>(nb_byte) / 1.0e9) / diff;
61 std::cout << "** TotalReduceDirect=" << total_x << " async?=" << is_async
62 << " nb_part=" << nb_part << " nb_value=" << nb_value
63 << " nb_thread=" << nb_thread
64 << " GB/s=" << nb_giga_byte_second << " time=" << diff << "\n";
65 return total_x;
66}
67
68/*---------------------------------------------------------------------------*/
69/*---------------------------------------------------------------------------*/
#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
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 -*-