Arcane  4.1.12.0
Developer documentation
Loading...
Searching...
No Matches
TestCooperativeLaunch1.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/trace/ITraceMng.h"
13
14#include "arccore/common/accelerator/Runner.h"
15#include "arccore/common/accelerator/RunQueue.h"
16#include "arccore/common/NumArray.h"
17#include "arccore/common/accelerator/Memory.h"
18
22#include "arccore/accelerator/AcceleratorInitializer.h"
23
24#include "./TestCommon.h"
25
26/*---------------------------------------------------------------------------*/
27/*---------------------------------------------------------------------------*/
28
29using namespace Arcane;
30using namespace Arcane::Accelerator;
31
32/*---------------------------------------------------------------------------*/
33/*---------------------------------------------------------------------------*/
34
35extern "C++" void
36_testCooperativeLaunch_GridSync(RunQueue queue, Int32 nb_value,
37 Int32 nb_loop1, Int32 nb_loop2);
38
39extern "C++" Int64
40_testCooperativeLaunch(RunQueue queue, SmallSpan<const Int64> c,
41 Int32 nb_value, Int32 nb_loop);
42extern "C++" Int64
43_testCooperativeLaunch2(RunQueue queue, SmallSpan<const Int64> c,
44 Int32 nb_value, Int32 nb_loop);
45
46void _doTestCooperativeLaunch(bool use_accelerator, Int32 max_allowed_thread)
47{
48 Accelerator::AcceleratorInitializer x(use_accelerator, max_allowed_thread);
49 Runner runner(x.executionPolicy());
50 RunQueue queue(makeQueue(runner));
51 if (queue.isAcceleratorPolicy())
52 queue.setMemoryRessource(eMemoryResource::Device);
53 Int32 nb_loop = 1000;
54 Int32 nb_value = 1000000;
55 Int64 expected_value = 1000004000000;
56
57 nb_value = 10000000;
58 expected_value = 100000040000000;
59 nb_loop = 25;
60
61 //nb_value = 50000000;
62 //expected_value = 2500000200000000;
63 //nb_loop = 20;
64
65 if (!queue.isAcceleratorPolicy()) {
66 if (arccoreIsDebug())
67 nb_loop /= 20;
68 else
69 nb_loop /= 4;
70 if (nb_loop == 0)
71 nb_loop = 1;
72 }
73 //nb_loop = 1;
74
75 ITraceMng* tm = x.traceMng();
76 tm->info() << "Using accelerator policy name=" << queue.executionPolicy() << " nb_loop=" << nb_loop;
77
78 eMemoryResource mem = queue.memoryResource();
80 host_c.resize(nb_value);
81 {
82 for (Int32 i = 0; i < nb_value; ++i) {
83 host_c(i) = (i + 2) + (i + 3);
84 };
85 }
86
88 c.copy(host_c);
89
90 for (Int32 k = 1; k < 5; ++k) {
91 Int32 nb_loop1 = 10000;
92 Int32 nb_loop2 = 0; //
93 _testCooperativeLaunch_GridSync(queue, nb_value, nb_loop1, nb_loop2);
94 }
95 for (Int32 k = 1; k < 5; ++k) {
96 Int32 nb_loop1 = 1000;
97 Int32 nb_loop2 = 9;
98 _testCooperativeLaunch_GridSync(queue, nb_value, nb_loop1, nb_loop2);
99 }
100 for (Int32 k = 1; k < 5; ++k) {
101 Int32 nb_loop1 = 100;
102 Int32 nb_loop2 = 99;
103 _testCooperativeLaunch_GridSync(queue, nb_value, nb_loop1, nb_loop2);
104 }
105 for (Int32 k = 1; k < 5; ++k) {
106 Int32 nb_loop1 = 10;
107 Int32 nb_loop2 = 999;
108 _testCooperativeLaunch_GridSync(queue, nb_value, nb_loop1, nb_loop2);
109 }
110
111 for (Int32 k = 1; k < 5; ++k) {
112 {
113 Int64 v = _testCooperativeLaunch(queue, c, nb_value, nb_loop);
114 Int64 v2 = v / nb_loop;
115 ASSERT_EQ(v2, expected_value);
116 }
117 }
118
119 for (Int32 k = 1; k < 5; ++k) {
120 {
121 Int64 v = _testCooperativeLaunch2(queue, c, nb_value, nb_loop);
122 Int64 v2 = v / nb_loop;
123 ASSERT_EQ(v2, expected_value);
124 }
125 }
126}
127
128ARCCORE_TEST_DO_TEST_ACCELERATOR(ArccoreAccelerator, TestCooperativeLaunch, _doTestCooperativeLaunch);
129
130/*---------------------------------------------------------------------------*/
131/*---------------------------------------------------------------------------*/
Types and functions for managing synchronizations on accelerators.
Types and macros for managing loops on accelerators.
Class to initialize a runtime for the accelerator API.
virtual TraceMessage info()=0
Stream for an information message.
Multi-dimensional arrays for numerical types accessible on accelerators.
View of an array of elements of type T.
Definition Span.h:805
RunQueue makeQueue(const Runner &runner)
Creates a queue associated with runner.
-- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature --
bool arccoreIsDebug()
True if the ARCCORE_DEBUG macro is defined.
eMemoryResource
List of available memory resources.
@ Host
Allocates on the host.
@ Device
Allocates on the device.