File: TestStdAlgorithmsNumerics.cpp

package info (click to toggle)
kokkos 4.7.01-2
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 16,636 kB
  • sloc: cpp: 223,676; sh: 2,446; makefile: 2,437; python: 91; fortran: 4; ansic: 2
file content (602 lines) | stat: -rw-r--r-- 23,872 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
//@HEADER
// ************************************************************************
//
//                        Kokkos v. 4.0
//       Copyright (2022) National Technology & Engineering
//               Solutions of Sandia, LLC (NTESS).
//
// Under the terms of Contract DE-NA0003525 with NTESS,
// the U.S. Government retains certain rights in this software.
//
// Part of Kokkos, under the Apache License v2.0 with LLVM Exceptions.
// See https://kokkos.org/LICENSE for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//@HEADER

#include <TestStdAlgorithmsCommon.hpp>

namespace KE = Kokkos::Experimental;

namespace Test {
namespace stdalgos {

template <class ValueType>
struct TimesTwoUnaryTransformFunctor {
  KOKKOS_INLINE_FUNCTION
  ValueType operator()(const ValueType& a) const { return (a * 2.); }
};

template <class ValueType>
struct MultiplyAndHalveBinaryTransformFunctor {
  KOKKOS_INLINE_FUNCTION
  ValueType operator()(const ValueType& a, const ValueType& b) const {
    return (a * b) * 0.5;
  }
};

template <class ValueType>
struct SumJoinFunctor {
  KOKKOS_INLINE_FUNCTION
  ValueType operator()(const ValueType& a, const ValueType& b) const {
    return a + b;
  }
};

struct std_algorithms_numerics_test : public ::testing::Test {
  Kokkos::LayoutStride layout{20, 2};

  // value_type
  using static_view_t  = Kokkos::View<value_type[20]>;
  using dyn_view_t     = Kokkos::View<value_type*>;
  using strided_view_t = Kokkos::View<value_type*, Kokkos::LayoutStride>;

  static_view_t m_static_view{"std-algo-test-1D-contiguous-view-static"};
  dyn_view_t m_dynamic_view{"std-algo-test-1D-contiguous-view-dyn", 20};
  strided_view_t m_strided_view{"std-algo-test-1D-strided-view", layout};

  // custom scalar (cs)
  using static_view_cs_t = Kokkos::View<CustomValueType[20]>;
  using dyn_view_cs_t    = Kokkos::View<CustomValueType*>;
  using strided_view_cs_t =
      Kokkos::View<CustomValueType*, Kokkos::LayoutStride>;

  static_view_cs_t m_static_view_cs{
      "std-algo-test-1D-contiguous-view-static-custom-scalar"};
  dyn_view_cs_t m_dynamic_view_cs{
      "std-algo-test-1D-contiguous-view-dyn-custom_scalar", 20};
  strided_view_cs_t m_strided_view_cs{
      "std-algo-test-1D-strided-view-custom-scalar", layout};

  template <class ViewFromType, class ViewToType>
  void copyPodViewToCustom(ViewFromType v_from, ViewToType v_to) {
    for (std::size_t i = 0; i < v_from.extent(0); ++i) {
      v_to(i)() = v_from(i);
    }
  }

  void fillFixtureViews() {
    static_view_t tmpView("tmpView");
    static_view_cs_t tmpViewCs("tmpViewCs");
    auto tmp_view_h = Kokkos::create_mirror_view(Kokkos::HostSpace(), tmpView);
    auto tmp_view_cs_h =
        Kokkos::create_mirror_view(Kokkos::HostSpace(), tmpViewCs);
    tmp_view_h(0)  = 0.;
    tmp_view_h(1)  = 0.;
    tmp_view_h(2)  = 0.;
    tmp_view_h(3)  = 2.;
    tmp_view_h(4)  = 2.;
    tmp_view_h(5)  = 1.;
    tmp_view_h(6)  = 1.;
    tmp_view_h(7)  = 1.;
    tmp_view_h(8)  = 1.;
    tmp_view_h(9)  = 0.;
    tmp_view_h(10) = -2.;
    tmp_view_h(11) = -2.;
    tmp_view_h(12) = 0.;
    tmp_view_h(13) = 2.;
    tmp_view_h(14) = 2.;
    tmp_view_h(15) = 1.;
    tmp_view_h(16) = 1.;
    tmp_view_h(17) = 1.;
    tmp_view_h(18) = 1.;
    tmp_view_h(19) = 0.;

    copyPodViewToCustom(tmp_view_h, tmp_view_cs_h);

    Kokkos::deep_copy(tmpView, tmp_view_h);
    Kokkos::deep_copy(tmpViewCs, tmp_view_cs_h);

    CopyFunctor<static_view_t, static_view_t> F1(tmpView, m_static_view);
    Kokkos::parallel_for("_std_algo_copy1", 20, F1);

    CopyFunctor<static_view_t, dyn_view_t> F2(tmpView, m_dynamic_view);
    Kokkos::parallel_for("_std_algo_copy2", 20, F2);

    CopyFunctor<static_view_t, strided_view_t> F3(tmpView, m_strided_view);
    Kokkos::parallel_for("_std_algo_copy3", 20, F3);

    CopyFunctor<static_view_cs_t, static_view_cs_t> F4(tmpViewCs,
                                                       m_static_view_cs);
    Kokkos::parallel_for("_std_algo_copy4", 20, F4);

    CopyFunctor<static_view_cs_t, dyn_view_cs_t> F5(tmpViewCs,
                                                    m_dynamic_view_cs);
    Kokkos::parallel_for("_std_algo_copy5", 20, F5);

    CopyFunctor<static_view_cs_t, strided_view_cs_t> F6(tmpViewCs,
                                                        m_strided_view_cs);
    Kokkos::parallel_for("_std_algo_copy6", 20, F6);
  }
};

#if !defined KOKKOS_ENABLE_OPENMPTARGET

// -------------------------------------------------------------------
// test default case of transform_reduce
//
// test for both POD types and custom scalar types
// -------------------------------------------------------------------
template <class ExecutionSpace, class ViewType1, class ViewType2,
          class ValueType>
void run_and_check_transform_reduce_default(ViewType1 first_view,
                                            ViewType2 second_view,
                                            ValueType init_value,
                                            ValueType result_value) {
  // trivial cases
  const auto r1 = KE::transform_reduce(ExecutionSpace(), KE::cbegin(first_view),
                                       KE::cbegin(first_view),
                                       KE::cbegin(second_view), init_value);

  const auto r2 = KE::transform_reduce(
      "MYLABEL", ExecutionSpace(), KE::cbegin(first_view),
      KE::cbegin(first_view), KE::cbegin(second_view), init_value);
  ASSERT_EQ(r1, init_value);
  ASSERT_EQ(r2, init_value);

  // non-trivial cases
  const auto r3 = KE::transform_reduce(ExecutionSpace(), KE::cbegin(first_view),
                                       KE::cend(first_view),
                                       KE::cbegin(second_view), init_value);

  const auto r4 = KE::transform_reduce(
      "MYLABEL", ExecutionSpace(), KE::cbegin(first_view), KE::cend(first_view),
      KE::cbegin(second_view), init_value);

  const auto r5 = KE::transform_reduce(ExecutionSpace(), first_view,
                                       second_view, init_value);
  const auto r6 = KE::transform_reduce("MYLABEL", ExecutionSpace(), first_view,
                                       second_view, init_value);

  ASSERT_EQ(r3, result_value);
  ASSERT_EQ(r4, result_value);
  ASSERT_EQ(r5, result_value);
  ASSERT_EQ(r6, result_value);
}

TEST_F(std_algorithms_numerics_test,
       transform_reduce_default_functors_using_pod_value_type) {
  fillFixtureViews();
  const value_type init0 = 0.;
  const value_type init5 = 5.;
  const value_type gold0 = 32.;
  const value_type gold5 = 37.;

  run_and_check_transform_reduce_default<exespace>(
      m_static_view, m_dynamic_view, init0, gold0);
  run_and_check_transform_reduce_default<exespace>(
      m_static_view, m_dynamic_view, init5, gold5);

  run_and_check_transform_reduce_default<exespace>(
      m_static_view, m_strided_view, init0, gold0);
  run_and_check_transform_reduce_default<exespace>(
      m_static_view, m_strided_view, init5, gold5);

  run_and_check_transform_reduce_default<exespace>(
      m_dynamic_view, m_strided_view, init0, gold0);
  run_and_check_transform_reduce_default<exespace>(
      m_dynamic_view, m_strided_view, init5, gold5);
}

TEST_F(std_algorithms_numerics_test,
       transform_reduce_default_functors_using_custom_value_type) {
  fillFixtureViews();
  const CustomValueType init0{0.};
  const CustomValueType init5{5.};
  const CustomValueType gold0{32.};
  const CustomValueType gold5{37.};

  run_and_check_transform_reduce_default<exespace>(
      m_static_view_cs, m_dynamic_view_cs, init0, gold0);
  run_and_check_transform_reduce_default<exespace>(
      m_static_view_cs, m_dynamic_view_cs, init5, gold5);

  run_and_check_transform_reduce_default<exespace>(
      m_static_view_cs, m_strided_view_cs, init0, gold0);
  run_and_check_transform_reduce_default<exespace>(
      m_static_view_cs, m_strided_view_cs, init5, gold5);

  run_and_check_transform_reduce_default<exespace>(
      m_dynamic_view_cs, m_strided_view_cs, init0, gold0);
  run_and_check_transform_reduce_default<exespace>(
      m_dynamic_view_cs, m_strided_view_cs, init5, gold5);
}

// -------------------------------------------------------------------
// transform_reduce for custom joiner and custom transform op
// test for both POD types and custom scalar types
//
// test overload1 accepting two intervals
//
// Note that in the std, the reducer is called BinaryReductionOp
// but in the Kokkos naming convention, it corresponds to a "joiner"
// that knows how to join two values.
// the "joiner" is assumed to be commutative:
//
// https://en.cppreference.com/w/cpp/algorithm/transform_reduce
//
// -------------------------------------------------------------------

template <class ExecutionSpace, class ViewType1, class ViewType2,
          class ValueType, class... Args>
void run_and_check_transform_reduce_overloadA(ViewType1 first_view,
                                              ViewType2 second_view,
                                              ValueType init_value,
                                              ValueType result_value,
                                              Args const&... args) {
  // trivial cases
  const auto r1 = KE::transform_reduce(
      ExecutionSpace(), KE::cbegin(first_view), KE::cbegin(first_view),
      KE::cbegin(second_view), init_value, args...);

  const auto r2 = KE::transform_reduce(
      "MYLABEL", ExecutionSpace(), KE::cbegin(first_view),
      KE::cbegin(first_view), KE::cbegin(second_view), init_value, args...);

  ASSERT_EQ(r1, init_value);
  ASSERT_EQ(r2, init_value);

  // non trivial cases
  const auto r3 = KE::transform_reduce(
      ExecutionSpace(), KE::cbegin(first_view), KE::cend(first_view),
      KE::cbegin(second_view), init_value, args...);

  const auto r4 = KE::transform_reduce(
      "MYLABEL", ExecutionSpace(), KE::cbegin(first_view), KE::cend(first_view),
      KE::cbegin(second_view), init_value, args...);

  const auto r5 = KE::transform_reduce(ExecutionSpace(), first_view,
                                       second_view, init_value, args...);
  const auto r6 = KE::transform_reduce("MYLABEL", ExecutionSpace(), first_view,
                                       second_view, init_value, args...);

  ASSERT_EQ(r3, result_value);
  ASSERT_EQ(r4, result_value);
  ASSERT_EQ(r5, result_value);
  ASSERT_EQ(r6, result_value);
}

TEST_F(std_algorithms_numerics_test,
       transform_reduce_custom_functors_overloadA_using_pod_value_type) {
  using joiner_type = SumJoinFunctor<value_type>;
  using transf_type = MultiplyAndHalveBinaryTransformFunctor<value_type>;

  const value_type init0 = 0.;
  const value_type init5 = 5.;
  const value_type gold0 = 16.;
  const value_type gold5 = 21.;

  fillFixtureViews();
  run_and_check_transform_reduce_overloadA<exespace>(
      m_static_view, m_dynamic_view, init0, gold0, joiner_type(),
      transf_type());
  run_and_check_transform_reduce_overloadA<exespace>(
      m_static_view, m_dynamic_view, init5, gold5, joiner_type(),
      transf_type());

  run_and_check_transform_reduce_overloadA<exespace>(
      m_static_view, m_strided_view, init0, gold0, joiner_type(),
      transf_type());
  run_and_check_transform_reduce_overloadA<exespace>(
      m_static_view, m_strided_view, init5, gold5, joiner_type(),
      transf_type());
  run_and_check_transform_reduce_overloadA<exespace>(
      m_dynamic_view, m_strided_view, init0, gold0, joiner_type(),
      transf_type());
  run_and_check_transform_reduce_overloadA<exespace>(
      m_dynamic_view, m_strided_view, init5, gold5, joiner_type(),
      transf_type());
}

TEST_F(std_algorithms_numerics_test,
       transform_reduce_custom_functors_overloadA_using_custom_value_type) {
  using joiner_type = SumJoinFunctor<CustomValueType>;
  using transf_type = MultiplyAndHalveBinaryTransformFunctor<CustomValueType>;

  const CustomValueType init0{0.};
  const CustomValueType init5{5.};
  const CustomValueType gold0{16.};
  const CustomValueType gold5{21.};

  fillFixtureViews();
  run_and_check_transform_reduce_overloadA<exespace>(
      m_static_view_cs, m_dynamic_view_cs, init0, gold0, joiner_type(),
      transf_type());
  run_and_check_transform_reduce_overloadA<exespace>(
      m_static_view_cs, m_dynamic_view_cs, init5, gold5, joiner_type(),
      transf_type());

  run_and_check_transform_reduce_overloadA<exespace>(
      m_static_view_cs, m_strided_view_cs, init0, gold0, joiner_type(),
      transf_type());
  run_and_check_transform_reduce_overloadA<exespace>(
      m_static_view_cs, m_strided_view_cs, init5, gold5, joiner_type(),
      transf_type());

  run_and_check_transform_reduce_overloadA<exespace>(
      m_dynamic_view_cs, m_strided_view_cs, init0, gold0, joiner_type(),
      transf_type());
  run_and_check_transform_reduce_overloadA<exespace>(
      m_dynamic_view_cs, m_strided_view_cs, init5, gold5, joiner_type(),
      transf_type());
}

// -------------------------------------------------------------------
// transform_reduce for custom joiner and custom transform op
// test for both POD types and custom scalar types
//
// test overload1 accepting single interval/view
//
// Note that in the std, the reducer is called BinaryReductionOp
// but in the Kokkos naming convention, it corresponds to a "joiner"
// that knows how to join two values.
// the "joiner" is assumed to be commutative:
//
// https://en.cppreference.com/w/cpp/algorithm/transform_reduce
//
// -------------------------------------------------------------------

template <class ExecutionSpace, class ViewType, class ValueType, class... Args>
void run_and_check_transform_reduce_overloadB(ViewType view,
                                              ValueType init_value,
                                              ValueType result_value,
                                              Args const&... args) {
  // trivial
  const auto r1 = KE::transform_reduce(ExecutionSpace(), KE::cbegin(view),
                                       KE::cbegin(view), init_value, args...);

  const auto r2 =
      KE::transform_reduce("MYLABEL", ExecutionSpace(), KE::cbegin(view),
                           KE::cbegin(view), init_value, args...);

  ASSERT_EQ(r1, init_value);
  ASSERT_EQ(r2, init_value);

  // non trivial
  const auto r3 = KE::transform_reduce(ExecutionSpace(), KE::cbegin(view),
                                       KE::cend(view), init_value, args...);

  const auto r4 =
      KE::transform_reduce("MYLABEL", ExecutionSpace(), KE::cbegin(view),
                           KE::cend(view), init_value, args...);
  const auto r5 =
      KE::transform_reduce(ExecutionSpace(), view, init_value, args...);

  const auto r6 = KE::transform_reduce("MYLABEL", ExecutionSpace(), view,
                                       init_value, args...);

  ASSERT_EQ(r3, result_value);
  ASSERT_EQ(r4, result_value);
  ASSERT_EQ(r5, result_value);
  ASSERT_EQ(r6, result_value);
}

TEST_F(std_algorithms_numerics_test,
       transform_reduce_custom_functors_overloadB_using_pod_value_type) {
  using joiner_type = SumJoinFunctor<value_type>;
  using transf_type = TimesTwoUnaryTransformFunctor<value_type>;

  const value_type init0 = 0.;
  const value_type init5 = 5.;
  const value_type gold0 = 24.;
  const value_type gold5 = 29.;

  fillFixtureViews();
  run_and_check_transform_reduce_overloadB<exespace>(
      m_static_view, init0, gold0, joiner_type(), transf_type());
  run_and_check_transform_reduce_overloadB<exespace>(
      m_dynamic_view, init5, gold5, joiner_type(), transf_type());
  run_and_check_transform_reduce_overloadB<exespace>(
      m_strided_view, init0, gold0, joiner_type(), transf_type());
}

TEST_F(std_algorithms_numerics_test,
       transform_reduce_custom_functors_overloadB_using_custom_value_type) {
  using joiner_type = SumJoinFunctor<CustomValueType>;
  using transf_type = TimesTwoUnaryTransformFunctor<CustomValueType>;

  const CustomValueType init0{0.};
  const CustomValueType init5{5.};
  const CustomValueType gold0{24.};
  const CustomValueType gold5{29.};

  fillFixtureViews();
  run_and_check_transform_reduce_overloadB<exespace>(
      m_static_view_cs, init0, gold0, joiner_type(), transf_type());
  run_and_check_transform_reduce_overloadB<exespace>(
      m_dynamic_view_cs, init5, gold5, joiner_type(), transf_type());
  run_and_check_transform_reduce_overloadB<exespace>(
      m_strided_view_cs, init0, gold0, joiner_type(), transf_type());
}

// -------------------------------------------------------------------
// test reduce overload1
//
// test for both POD types and custom scalar types
// -------------------------------------------------------------------
template <class ExecutionSpace, class ViewType, class ValueType>
void run_and_check_reduce_overloadA(ViewType view, ValueType non_trivial_result,
                                    ValueType trivial_result) {
  // trivial cases
  const auto r1 =
      KE::reduce(ExecutionSpace(), KE::cbegin(view), KE::cbegin(view));
  const auto r2 = KE::reduce("MYLABEL", ExecutionSpace(), KE::cbegin(view),
                             KE::cbegin(view));
  ASSERT_EQ(r1, trivial_result);
  ASSERT_EQ(r2, trivial_result);

  // non trivial cases
  const auto r3 =
      KE::reduce(ExecutionSpace(), KE::cbegin(view), KE::cend(view));
  const auto r4 =
      KE::reduce("MYLABEL", ExecutionSpace(), KE::cbegin(view), KE::cend(view));
  const auto r5 = KE::reduce(ExecutionSpace(), view);
  const auto r6 = KE::reduce("MYLABEL", ExecutionSpace(), view);

  ASSERT_EQ(r3, non_trivial_result);
  ASSERT_EQ(r4, non_trivial_result);
  ASSERT_EQ(r5, non_trivial_result);
  ASSERT_EQ(r6, non_trivial_result);
}

TEST_F(std_algorithms_numerics_test,
       reduce_default_functors_overloadA_using_pod_value_type) {
  fillFixtureViews();
  const value_type trivial_gold     = 0.;
  const value_type non_trivial_gold = 12.;
  run_and_check_reduce_overloadA<exespace>(m_static_view, non_trivial_gold,
                                           trivial_gold);
  run_and_check_reduce_overloadA<exespace>(m_dynamic_view, non_trivial_gold,
                                           trivial_gold);
  run_and_check_reduce_overloadA<exespace>(m_strided_view, non_trivial_gold,
                                           trivial_gold);
}

TEST_F(std_algorithms_numerics_test,
       reduce_default_functors_overloadA_using_custom_value_type) {
  fillFixtureViews();
  const CustomValueType trivial_gold{0.};
  const CustomValueType non_trivial_gold{12.};
  run_and_check_reduce_overloadA<exespace>(m_static_view_cs, non_trivial_gold,
                                           trivial_gold);
  run_and_check_reduce_overloadA<exespace>(m_dynamic_view_cs, non_trivial_gold,
                                           trivial_gold);
  run_and_check_reduce_overloadA<exespace>(m_strided_view_cs, non_trivial_gold,
                                           trivial_gold);
}

// -------------------------------------------------------------------
// test reduce overload2 with init value
//
// test for both POD types and custom scalar types
// -------------------------------------------------------------------
template <class ExecutionSpace, class ViewType, class ValueType>
void run_and_check_reduce_overloadB(ViewType view, ValueType result_value,
                                    ValueType init_value) {
  // trivial cases
  const auto r1 = KE::reduce(ExecutionSpace(), KE::cbegin(view),
                             KE::cbegin(view), init_value);
  const auto r2 = KE::reduce("MYLABEL", ExecutionSpace(), KE::cbegin(view),
                             KE::cbegin(view), init_value);
  ASSERT_EQ(r1, init_value);
  ASSERT_EQ(r2, init_value);

  // non trivial cases
  const auto r3 = KE::reduce(ExecutionSpace(), KE::cbegin(view), KE::cend(view),
                             init_value);
  const auto r4 = KE::reduce("MYLABEL", ExecutionSpace(), KE::cbegin(view),
                             KE::cend(view), init_value);
  const auto r5 = KE::reduce(ExecutionSpace(), view, init_value);
  const auto r6 = KE::reduce("MYLABEL", ExecutionSpace(), view, init_value);

  ASSERT_EQ(r3, result_value);
  ASSERT_EQ(r4, result_value);
  ASSERT_EQ(r5, result_value);
  ASSERT_EQ(r6, result_value);
}

TEST_F(std_algorithms_numerics_test,
       reduce_default_functors_overloadB_using_pod_value_type) {
  fillFixtureViews();
  const value_type init = 5.;
  const value_type gold = 17.;
  run_and_check_reduce_overloadB<exespace>(m_static_view, gold, init);
  run_and_check_reduce_overloadB<exespace>(m_dynamic_view, gold, init);
  run_and_check_reduce_overloadB<exespace>(m_strided_view, gold, init);
}

TEST_F(std_algorithms_numerics_test,
       reduce_default_functors_overloadB_using_custom_value_type) {
  fillFixtureViews();
  const CustomValueType init{5.};
  const CustomValueType gold{17.};
  run_and_check_reduce_overloadB<exespace>(m_static_view_cs, gold, init);
  run_and_check_reduce_overloadB<exespace>(m_dynamic_view_cs, gold, init);
  run_and_check_reduce_overloadB<exespace>(m_strided_view_cs, gold, init);
}

// -------------------------------------------------------------------
// test reduce overload3 with init value
//
// test for both POD types and custom scalar types
// -------------------------------------------------------------------
template <class ExecutionSpace, class ViewType, class ValueType, class BinaryOp>
void run_and_check_reduce_overloadC(ViewType view, ValueType result_value,
                                    ValueType init_value, BinaryOp joiner) {
  // trivial cases
  const auto r1 = KE::reduce(ExecutionSpace(), KE::cbegin(view),
                             KE::cbegin(view), init_value, joiner);
  const auto r2 = KE::reduce("MYLABEL", ExecutionSpace(), KE::cbegin(view),
                             KE::cbegin(view), init_value, joiner);
  ASSERT_EQ(r1, init_value);
  ASSERT_EQ(r2, init_value);

  // non trivial cases
  const auto r3 = KE::reduce(ExecutionSpace(), KE::cbegin(view), KE::cend(view),
                             init_value, joiner);
  const auto r4 = KE::reduce("MYLABEL", ExecutionSpace(), KE::cbegin(view),
                             KE::cend(view), init_value, joiner);
  const auto r5 = KE::reduce(ExecutionSpace(), view, init_value, joiner);
  const auto r6 =
      KE::reduce("MYLABEL", ExecutionSpace(), view, init_value, joiner);

  ASSERT_EQ(r3, result_value);
  ASSERT_EQ(r4, result_value);
  ASSERT_EQ(r5, result_value);
  ASSERT_EQ(r6, result_value);
}

TEST_F(std_algorithms_numerics_test,
       reduce_custom_functors_using_pod_value_type) {
  using joiner_type = SumJoinFunctor<value_type>;

  fillFixtureViews();
  const value_type init = 5.;
  const value_type gold = 17.;
  run_and_check_reduce_overloadC<exespace>(m_static_view, gold, init,
                                           joiner_type());
  run_and_check_reduce_overloadC<exespace>(m_dynamic_view, gold, init,
                                           joiner_type());
  run_and_check_reduce_overloadC<exespace>(m_strided_view, gold, init,
                                           joiner_type());
}

TEST_F(std_algorithms_numerics_test,
       reduce_custom_functors_using_custom_value_type) {
  using joiner_type = SumJoinFunctor<CustomValueType>;

  fillFixtureViews();
  const CustomValueType init{5.};
  const CustomValueType gold{17.};
  run_and_check_reduce_overloadC<exespace>(m_static_view_cs, gold, init,
                                           joiner_type());
  run_and_check_reduce_overloadC<exespace>(m_dynamic_view_cs, gold, init,
                                           joiner_type());
  run_and_check_reduce_overloadC<exespace>(m_strided_view_cs, gold, init,
                                           joiner_type());
}

#endif  // not defined KOKKOS_ENABLE_OPENMPTARGET

}  // namespace stdalgos
}  // namespace Test