Arcane  v4.1.3.0
Documentation développeur
Chargement...
Recherche...
Aucune correspondance
TestLoop_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
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++" void
32 SmallSpan<Int64> c, Int32 nb_thread,
33 Int32 nb_value, Int32 nb_part, Int32 nb_loop)
34{
35 if ((nb_value % nb_part) != 0)
36 ARCCORE_FATAL("{0} is not a multiple of {1}", nb_value, nb_part);
37 Int32 nb_true_value = nb_value / nb_part;
38 Int32 offset = nb_true_value;
39 double x = Platform::getRealTime();
40 {
41 SmallSpan<const Int64> c_view(c);
42 for (int j = 0; j < nb_loop; ++j) {
43 auto command = makeCommand(queue);
44 command.addNbThreadPerBlock(nb_thread);
45 command << RUNCOMMAND_LOOP1(iter, nb_true_value)
46 {
47 Int32 i = iter;
48 for (Int32 k = 0; k < nb_part; ++k) {
49 Int32 z = i + (offset * k);
50 c(z) = a(z) + b(z);
51 }
52 };
53 }
54 }
55 double y = Platform::getRealTime();
56 // Nombre d´octets transférés
57 Int64 nb_byte = c.size() * sizeof(Int64) * nb_loop * 3;
58 Real diff = y - x;
59 Real nb_giga_byte_second = (static_cast<Real>(nb_byte) / 1.0e9) / diff;
60 std::cout << "** TotalLoopDirect "
61 << " nb_part=" << nb_part << " nb_value=" << nb_value
62 << " nb_thread=" << nb_thread
63 << " GB/s=" << nb_giga_byte_second << " time=" << diff << "\n";
64}
65
66/*---------------------------------------------------------------------------*/
67/*---------------------------------------------------------------------------*/
#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.
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 -*-