Skip to content

Commit 53947ef

Browse files
Merge pull request #1169 from arcaneframework/dev/gg-add-typedef-for-numarray-views
Add typedef for NumArray views
2 parents 8a34744 + 3b2927c commit 53947ef

File tree

2 files changed

+64
-49
lines changed

2 files changed

+64
-49
lines changed

arcane/src/arcane/accelerator/NumArrayViews.h

Lines changed: 17 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-2022 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-
/* NumArrayViews.h (C) 2000-2022 */
8+
/* NumArrayViews.h (C) 2000-2024 */
99
/* */
1010
/* Gestion des vues pour les 'NumArray' pour les accélérateurs. */
1111
/*---------------------------------------------------------------------------*/
@@ -196,6 +196,21 @@ viewIn(RunCommand& command, const NumArray<DataType, Extents, LayoutType>& v)
196196
/*---------------------------------------------------------------------------*/
197197
/*---------------------------------------------------------------------------*/
198198

199+
//! Vue en entrée sur un NumArray
200+
template <typename DataType, typename Extents, typename LayoutType = DefaultLayout>
201+
using NumArrayInView = NumArrayView<DataViewGetter<DataType>, Extents, LayoutType>;
202+
203+
//! Vue en sortie sur un NumArray
204+
template <typename DataType, typename Extents, typename LayoutType = DefaultLayout>
205+
using NumArrayOutView = NumArrayView<DataViewSetter<DataType>, Extents, LayoutType>;
206+
207+
//! Vue en entrée/sortie sur un NumArray
208+
template <typename DataType, typename Extents, typename LayoutType = DefaultLayout>
209+
using NumArrayInOutView = NumArrayView<DataViewGetterSetter<DataType>, Extents, LayoutType>;
210+
211+
/*---------------------------------------------------------------------------*/
212+
/*---------------------------------------------------------------------------*/
213+
199214
} // End namespace Arcane::Accelerator
200215

201216
/*---------------------------------------------------------------------------*/

arcane/src/arcane/tests/accelerator/NumArrayUnitTest.cc

Lines changed: 47 additions & 47 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-
/* NumArrayUnitTest.cc (C) 2000-2023 */
8+
/* NumArrayUnitTest.cc (C) 2000-2024 */
99
/* */
1010
/* Service de test des 'NumArray'. */
1111
/*---------------------------------------------------------------------------*/
@@ -31,11 +31,11 @@
3131

3232
namespace Arcane
3333
{
34-
extern "C++" ARCANE_CORE_EXPORT
35-
void _arcaneTestRealArrayVariant();
34+
extern "C++" ARCANE_CORE_EXPORT void
35+
_arcaneTestRealArrayVariant();
3636
extern "C++" ARCANE_CORE_EXPORT void
3737
_arcaneTestRealArray2Variant();
38-
}
38+
} // namespace Arcane
3939

4040
namespace ArcaneTest
4141
{
@@ -299,7 +299,7 @@ _executeTest1(eMemoryRessource mem_kind)
299299
{
300300
NumArray<double, MDDim1> t1(mem_kind);
301301
t1.resize(n1);
302-
_checkPointerAttribute(mem_kind,t1.bytes().data());
302+
_checkPointerAttribute(mem_kind, t1.bytes().data());
303303

304304
NumArray<double, MDDim1> t2(mem_kind);
305305
t2.resize(n1);
@@ -309,30 +309,30 @@ _executeTest1(eMemoryRessource mem_kind)
309309

310310
{
311311
[[maybe_unused]] auto span_value = t1.span();
312-
using ValueType1 = NumArray<double,MDDim1>::value_type;
312+
using ValueType1 = NumArray<double, MDDim1>::value_type;
313313
using ValueType2 = decltype(span_value)::value_type;
314-
bool is_same_type = std::is_same_v<ValueType1,ValueType2>;
314+
bool is_same_type = std::is_same_v<ValueType1, ValueType2>;
315315
std::cout << "IS_SAME: " << is_same_type << "\n";
316316
if (!is_same_type)
317317
ARCANE_FATAL("Not same value type");
318318

319-
using LayoutType1 = NumArray<double,MDDim1>::LayoutPolicyType;
319+
using LayoutType1 = NumArray<double, MDDim1>::LayoutPolicyType;
320320
using LayoutType2 = decltype(span_value)::LayoutPolicyType;
321-
bool is_same_policy = std::is_same_v<LayoutType1,LayoutType2>;
321+
bool is_same_policy = std::is_same_v<LayoutType1, LayoutType2>;
322322
if (!is_same_policy)
323323
ARCANE_FATAL("Not same policy");
324324
}
325325
{
326326
auto command = makeCommand(queue);
327327
auto out_t1 = viewOut(command, t1);
328328
command.addNbThreadPerBlock(128);
329-
if (command.nbThreadPerBlock()!=128)
330-
ARCANE_FATAL("Bad number of thread per block (v={0} expected=128)",command.nbThreadPerBlock());
329+
if (command.nbThreadPerBlock() != 128)
330+
ARCANE_FATAL("Bad number of thread per block (v={0} expected=128)", command.nbThreadPerBlock());
331331

332332
command << RUNCOMMAND_LOOP1(iter, n1)
333333
{
334334
auto [i] = iter();
335-
if ((i%2)==0)
335+
if ((i % 2) == 0)
336336
out_t1(i) = _getValue(i);
337337
else
338338
out_t1[i] = _getValue(i);
@@ -346,7 +346,7 @@ _executeTest1(eMemoryRessource mem_kind)
346346
{
347347
auto command = makeCommand(queue);
348348
auto in_t1 = t1.constSpan();
349-
MDSpan<double,MDDim1> out_t2 = t2.span();
349+
MDSpan<double, MDDim1> out_t2 = t2.span();
350350

351351
command << RUNCOMMAND_LOOP1(iter, n1)
352352
{
@@ -364,8 +364,8 @@ _executeTest1(eMemoryRessource mem_kind)
364364
}
365365
{
366366
auto command = makeCommand(queue);
367-
auto in_t1 = viewIn(command,t1);
368-
auto out_t3 = viewOut(command,t3);
367+
ax::NumArrayInView<double, MDDim1> in_t1 = viewIn(command, t1);
368+
ax::NumArrayOutView<double, MDDim1> out_t3 = viewOut(command, t3);
369369

370370
command << RUNCOMMAND_LOOP1(iter, n1)
371371
{
@@ -385,68 +385,68 @@ _executeTest1(eMemoryRessource mem_kind)
385385
{
386386
NumArray<double, MDDim2> t1(mem_kind);
387387
t1.resize(n1, n2);
388-
_doRank2(queue,t1,expected_sum2);
388+
_doRank2(queue, t1, expected_sum2);
389389
}
390390
{
391-
NumArray<double, ExtentsV<n1,n2>> t1(mem_kind);
392-
_doRank2(queue,t1,expected_sum2);
391+
NumArray<double, ExtentsV<n1, n2>> t1(mem_kind);
392+
_doRank2(queue, t1, expected_sum2);
393393
}
394394
{
395-
NumArray<double, ExtentsV<DynExtent,n2>> t1(mem_kind);
395+
NumArray<double, ExtentsV<DynExtent, n2>> t1(mem_kind);
396396
t1.resize(n1);
397-
_doRank2(queue,t1,expected_sum2);
397+
_doRank2(queue, t1, expected_sum2);
398398
}
399399
{
400-
NumArray<double, ExtentsV<n1,DynExtent>> t1(mem_kind);
400+
NumArray<double, ExtentsV<n1, DynExtent>> t1(mem_kind);
401401
t1.resize(n2);
402-
_doRank2(queue,t1,expected_sum2);
402+
_doRank2(queue, t1, expected_sum2);
403403
}
404404

405405
// Tableaux 3D
406406
{
407407
NumArray<double, MDDim3, LeftLayout> t1(mem_kind);
408408
t1.resize(n1, n2, n3);
409-
_doRank3(queue,t1,expected_sum3);
409+
_doRank3(queue, t1, expected_sum3);
410410
}
411411
{
412412
NumArray<double, MDDim3, RightLayout> t1(mem_kind);
413413
t1.resize(n1, n2, n3);
414-
_doRank3(queue,t1,expected_sum3);
414+
_doRank3(queue, t1, expected_sum3);
415415
}
416416
{
417-
NumArray<double, ExtentsV<DynExtent,n2,n3>, LeftLayout> t1(mem_kind);
417+
NumArray<double, ExtentsV<DynExtent, n2, n3>, LeftLayout> t1(mem_kind);
418418
t1.resize(n1);
419-
_doRank3(queue,t1,expected_sum3);
419+
_doRank3(queue, t1, expected_sum3);
420420
}
421421
{
422-
NumArray<double, ExtentsV<n1,n2,n3>, LeftLayout> t1(mem_kind);
423-
_doRank3(queue,t1,expected_sum3);
422+
NumArray<double, ExtentsV<n1, n2, n3>, LeftLayout> t1(mem_kind);
423+
_doRank3(queue, t1, expected_sum3);
424424
}
425425
{
426-
NumArray<double, ExtentsV<DynExtent,n2,DynExtent>, LeftLayout> t1(mem_kind);
427-
t1.resize(n1,n3);
428-
_doRank3(queue,t1,expected_sum3);
426+
NumArray<double, ExtentsV<DynExtent, n2, DynExtent>, LeftLayout> t1(mem_kind);
427+
t1.resize(n1, n3);
428+
_doRank3(queue, t1, expected_sum3);
429429
}
430430

431431
// Tableaux 4D
432432
{
433433
NumArray<double, MDDim4> t1(mem_kind);
434434
t1.resize(n1, n2, n3, n4);
435-
_doRank4(queue,t1,expected_sum4);
435+
_doRank4(queue, t1, expected_sum4);
436436
}
437437
{
438-
NumArray<double, ExtentsV<n1,DynExtent,DynExtent,n4>> t1(mem_kind);
439-
t1.resize(n2,n3);
440-
_doRank4(queue,t1,expected_sum4);
438+
NumArray<double, ExtentsV<n1, DynExtent, DynExtent, n4>> t1(mem_kind);
439+
t1.resize(n2, n3);
440+
_doRank4(queue, t1, expected_sum4);
441441
}
442442
{
443-
NumArray<double, ExtentsV<DynExtent,DynExtent,n3,n4>, LeftLayout> t1(mem_kind);
443+
NumArray<double, ExtentsV<DynExtent, DynExtent, n3, n4>, LeftLayout> t1(mem_kind);
444444
t1.resize(n1, n2);
445-
_doRank4(queue,t1,expected_sum4);
445+
_doRank4(queue, t1, expected_sum4);
446446
}
447447
{
448-
NumArray<double, ExtentsV<n1,n2,n3,n4>> t1(mem_kind);
449-
_doRank4(queue,t1,expected_sum4);
448+
NumArray<double, ExtentsV<n1, n2, n3, n4>> t1(mem_kind);
449+
_doRank4(queue, t1, expected_sum4);
450450
}
451451

452452
{
@@ -456,7 +456,7 @@ _executeTest1(eMemoryRessource mem_kind)
456456
t1.resize(n1);
457457
{
458458
auto command = makeCommand(queue);
459-
auto out_t1 = viewOut(command,t1);
459+
ax::NumArrayInOutView<double, MDDim1> out_t1 = viewInOut(command, t1);
460460

461461
command << RUNCOMMAND_LOOP1(iter, n1)
462462
{
@@ -466,9 +466,9 @@ _executeTest1(eMemoryRessource mem_kind)
466466
}
467467
info() << "CHECK ALLOCATOR";
468468
NumArray<double, MDDim1> t2(t1);
469-
if (t1.memoryRessource()!=t2.memoryRessource())
469+
if (t1.memoryRessource() != t2.memoryRessource())
470470
ARCANE_FATAL("Bad memory ressource 1");
471-
if (t1.memoryAllocator()!=t2.memoryAllocator())
471+
if (t1.memoryAllocator() != t2.memoryAllocator())
472472
ARCANE_FATAL("Bad allocator 1");
473473

474474
NumArray<double, MDDim1> host_t1(eMemoryRessource::Host);
@@ -480,9 +480,9 @@ _executeTest1(eMemoryRessource mem_kind)
480480
NumArray<double, MDDim1> t3;
481481
t3.resize(25);
482482
t3 = t1;
483-
if (t1.memoryRessource()!=t3.memoryRessource())
484-
ARCANE_FATAL("Bad memory ressource 2 t1={0} t3={1}",t1.memoryRessource(),t3.memoryRessource());
485-
if (t1.memoryAllocator()!=t3.memoryAllocator())
483+
if (t1.memoryRessource() != t3.memoryRessource())
484+
ARCANE_FATAL("Bad memory ressource 2 t1={0} t3={1}", t1.memoryRessource(), t3.memoryRessource());
485+
if (t1.memoryAllocator() != t3.memoryAllocator())
486486
ARCANE_FATAL("Bad allocator 2");
487487
NumArray<double, MDDim1> host_t3(eMemoryRessource::Host);
488488
host_t3.copy(t3);
@@ -656,7 +656,7 @@ _executeTest4(eMemoryRessource mem_kind)
656656
{
657657
auto command = makeCommand(queue);
658658
auto in_t1 = viewIn(command, t1);
659-
auto out_t3 = viewOut(command, t3);
659+
auto out_t3 = viewInOut(command, t3);
660660

661661
command << RUNCOMMAND_LOOP1(iter, n1)
662662
{

0 commit comments

Comments
 (0)