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 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675
|
//@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 <sstream>
#include <iostream>
#include <limits>
#include <Kokkos_Core.hpp>
namespace Test {
struct ReducerTag {};
template <typename ScalarType, class DeviceType>
class ReduceFunctor {
public:
using execution_space = DeviceType;
using size_type = typename execution_space::size_type;
struct value_type {
ScalarType value[3];
};
const size_type nwork;
KOKKOS_INLINE_FUNCTION
ReduceFunctor(const size_type& arg_nwork) : nwork(arg_nwork) {}
KOKKOS_INLINE_FUNCTION
ReduceFunctor(const ReduceFunctor& rhs) : nwork(rhs.nwork) {}
/*
KOKKOS_INLINE_FUNCTION
void init( value_type & dst ) const
{
dst.value[0] = 0;
dst.value[1] = 0;
dst.value[2] = 0;
}
*/
KOKKOS_INLINE_FUNCTION
void join(value_type& dst, const value_type& src) const {
dst.value[0] += src.value[0];
dst.value[1] += src.value[1];
dst.value[2] += src.value[2];
}
KOKKOS_INLINE_FUNCTION
void operator()(size_type iwork, value_type& dst) const {
dst.value[0] += 1;
dst.value[1] += iwork + 1;
dst.value[2] += nwork - iwork;
}
};
template <class DeviceType>
class ReduceFunctorFinal : public ReduceFunctor<int64_t, DeviceType> {
public:
using value_type = typename ReduceFunctor<int64_t, DeviceType>::value_type;
KOKKOS_INLINE_FUNCTION
ReduceFunctorFinal(const size_t n) : ReduceFunctor<int64_t, DeviceType>(n) {}
KOKKOS_INLINE_FUNCTION
void final(value_type& dst) const {
dst.value[0] = -dst.value[0];
dst.value[1] = -dst.value[1];
dst.value[2] = -dst.value[2];
}
};
template <class DeviceType>
class ReduceFunctorFinalTag {
public:
using execution_space = DeviceType;
using size_type = typename execution_space::size_type;
using ScalarType = int64_t;
struct value_type {
ScalarType value[3];
};
const size_type nwork;
KOKKOS_INLINE_FUNCTION
ReduceFunctorFinalTag(const size_type arg_nwork) : nwork(arg_nwork) {}
KOKKOS_INLINE_FUNCTION
void join(const ReducerTag, value_type& dst, const value_type& src) const {
dst.value[0] += src.value[0];
dst.value[1] += src.value[1];
dst.value[2] += src.value[2];
}
KOKKOS_INLINE_FUNCTION
void operator()(const ReducerTag, size_type iwork, value_type& dst) const {
dst.value[0] -= 1;
dst.value[1] -= iwork + 1;
dst.value[2] -= nwork - iwork;
}
KOKKOS_INLINE_FUNCTION
void final(const ReducerTag, value_type& dst) const {
++dst.value[0];
++dst.value[1];
++dst.value[2];
}
};
template <typename ScalarType, class DeviceType>
class RuntimeReduceFunctor {
public:
// Required for functor:
using execution_space = DeviceType;
using value_type = ScalarType[];
const unsigned value_count;
// Unit test details:
using size_type = typename execution_space::size_type;
const size_type nwork;
RuntimeReduceFunctor(const size_type arg_nwork, const size_type arg_count)
: value_count(arg_count), nwork(arg_nwork) {}
KOKKOS_INLINE_FUNCTION
void init(ScalarType dst[]) const {
for (unsigned i = 0; i < value_count; ++i) dst[i] = 0;
}
KOKKOS_INLINE_FUNCTION
void join(ScalarType dst[], const ScalarType src[]) const {
for (unsigned i = 0; i < value_count; ++i) dst[i] += src[i];
}
KOKKOS_INLINE_FUNCTION
void operator()(size_type iwork, ScalarType dst[]) const {
const size_type tmp[3] = {1, iwork + 1, nwork - iwork};
for (size_type i = 0; i < static_cast<size_type>(value_count); ++i) {
dst[i] += tmp[i % 3];
}
}
};
template <typename ScalarType, class DeviceType>
class RuntimeReduceMinMax {
public:
// Required for functor:
using execution_space = DeviceType;
using value_type = ScalarType[];
const unsigned value_count;
// Unit test details:
using size_type = typename execution_space::size_type;
const size_type nwork;
const ScalarType amin;
const ScalarType amax;
RuntimeReduceMinMax(const size_type arg_nwork, const size_type arg_count)
: value_count(arg_count),
nwork(arg_nwork),
amin(std::numeric_limits<ScalarType>::min()),
amax(std::numeric_limits<ScalarType>::max()) {}
KOKKOS_INLINE_FUNCTION
void init(ScalarType dst[]) const {
for (unsigned i = 0; i < value_count; ++i) {
dst[i] = i % 2 ? amax : amin;
}
}
KOKKOS_INLINE_FUNCTION
void join(ScalarType dst[], const ScalarType src[]) const {
for (unsigned i = 0; i < value_count; ++i) {
dst[i] = i % 2 ? (dst[i] < src[i] ? dst[i] : src[i]) // min
: (dst[i] > src[i] ? dst[i] : src[i]); // max
}
}
KOKKOS_INLINE_FUNCTION
void operator()(size_type iwork, ScalarType dst[]) const {
const ScalarType tmp[2] = {ScalarType(iwork + 1),
ScalarType(nwork - iwork)};
for (size_type i = 0; i < static_cast<size_type>(value_count); ++i) {
dst[i] = i % 2 ? (dst[i] < tmp[i % 2] ? dst[i] : tmp[i % 2])
: (dst[i] > tmp[i % 2] ? dst[i] : tmp[i % 2]);
}
}
};
template <class DeviceType>
class RuntimeReduceFunctorFinal
: public RuntimeReduceFunctor<int64_t, DeviceType> {
public:
using base_type = RuntimeReduceFunctor<int64_t, DeviceType>;
using value_type = typename base_type::value_type;
using scalar_type = int64_t;
RuntimeReduceFunctorFinal(const size_t theNwork, const size_t count)
: base_type(theNwork, count) {}
KOKKOS_INLINE_FUNCTION
void final(value_type dst) const {
for (unsigned i = 0; i < base_type::value_count; ++i) {
dst[i] = -dst[i];
}
}
};
template <class ValueType, class DeviceType>
class CombinedReduceFunctorSameType {
public:
using execution_space = typename DeviceType::execution_space;
using size_type = typename execution_space::size_type;
const size_type nwork;
KOKKOS_INLINE_FUNCTION
constexpr explicit CombinedReduceFunctorSameType(const size_type& arg_nwork)
: nwork(arg_nwork) {}
KOKKOS_DEFAULTED_FUNCTION
constexpr CombinedReduceFunctorSameType(
const CombinedReduceFunctorSameType& rhs) = default;
KOKKOS_INLINE_FUNCTION
void operator()(size_type iwork, ValueType& dst1, ValueType& dst2,
ValueType& dst3) const {
dst1 += 1;
dst2 += iwork + 1;
dst3 += nwork - iwork;
}
KOKKOS_INLINE_FUNCTION
void operator()(size_type iwork, size_type always_zero_1,
size_type always_zero_2, ValueType& dst1, ValueType& dst2,
ValueType& dst3) const {
dst1 += 1 + always_zero_1;
dst2 += iwork + 1 + always_zero_2;
dst3 += nwork - iwork;
}
};
namespace {
template <typename ScalarType, class DeviceType>
class TestReduce {
public:
using execution_space = DeviceType;
using size_type = typename execution_space::size_type;
TestReduce(const size_type& nwork) {
run_test(nwork);
run_test_final(nwork);
run_test_final_tag(nwork);
}
void run_test(const size_type& nwork) {
using functor_type = Test::ReduceFunctor<ScalarType, execution_space>;
using value_type = typename functor_type::value_type;
enum { Count = 3 };
enum { Repeat = 100 };
value_type result[Repeat];
const uint64_t nw = nwork;
const uint64_t nsum = nw % 2 ? nw * ((nw + 1) / 2) : (nw / 2) * (nw + 1);
for (unsigned i = 0; i < Repeat; ++i) {
Kokkos::parallel_reduce(nwork, functor_type(nwork), result[i]);
}
for (unsigned i = 0; i < Repeat; ++i) {
for (unsigned j = 0; j < Count; ++j) {
const uint64_t correct = 0 == j % 3 ? nw : nsum;
ASSERT_EQ((ScalarType)correct, result[i].value[j]);
}
}
}
void run_test_final(const size_type& nwork) {
using functor_type = Test::ReduceFunctorFinal<execution_space>;
using value_type = typename functor_type::value_type;
enum { Count = 3 };
enum { Repeat = 100 };
value_type result[Repeat];
const uint64_t nw = nwork;
const uint64_t nsum = nw % 2 ? nw * ((nw + 1) / 2) : (nw / 2) * (nw + 1);
for (unsigned i = 0; i < Repeat; ++i) {
if (i % 2 == 0) {
Kokkos::parallel_reduce(nwork, functor_type(nwork), result[i]);
} else {
Kokkos::parallel_reduce("Reduce", nwork, functor_type(nwork),
result[i]);
}
}
for (unsigned i = 0; i < Repeat; ++i) {
for (unsigned j = 0; j < Count; ++j) {
const uint64_t correct = 0 == j % 3 ? nw : nsum;
ASSERT_EQ((ScalarType)correct, -result[i].value[j]);
}
}
}
void run_test_final_tag(const size_type& nwork) {
using functor_type = Test::ReduceFunctorFinalTag<execution_space>;
using value_type = typename functor_type::value_type;
enum { Count = 3 };
enum { Repeat = 100 };
value_type result[Repeat];
const uint64_t nw = nwork;
const uint64_t nsum = nw % 2 ? nw * ((nw + 1) / 2) : (nw / 2) * (nw + 1);
for (unsigned i = 0; i < Repeat; ++i) {
if (i % 2 == 0) {
Kokkos::parallel_reduce(
Kokkos::RangePolicy<execution_space, ReducerTag>(0, nwork),
functor_type(nwork), result[i]);
} else {
Kokkos::parallel_reduce(
"Reduce",
Kokkos::RangePolicy<execution_space, ReducerTag>(0, nwork),
functor_type(nwork), result[i]);
}
}
for (unsigned i = 0; i < Repeat; ++i) {
for (unsigned j = 0; j < Count; ++j) {
const uint64_t correct = 0 == j % 3 ? nw : nsum;
ASSERT_EQ((ScalarType)correct, 1 - result[i].value[j]);
}
}
}
};
template <typename ScalarType, class DeviceType>
class TestReduceDynamic {
public:
using execution_space = DeviceType;
using size_type = typename execution_space::size_type;
TestReduceDynamic(const size_type nwork) {
run_test_dynamic(nwork);
#ifndef KOKKOS_ENABLE_OPENACC
// FIXME_OPENACC - OpenACC (V3.3) does not support custom reductions.
run_test_dynamic_minmax(nwork);
#endif
run_test_dynamic_final(nwork);
}
void run_test_dynamic(const size_type nwork) {
using functor_type =
Test::RuntimeReduceFunctor<ScalarType, execution_space>;
enum { Count = 3 };
enum { Repeat = 100 };
ScalarType result[Repeat][Count];
const uint64_t nw = nwork;
const uint64_t nsum = nw % 2 ? nw * ((nw + 1) / 2) : (nw / 2) * (nw + 1);
for (unsigned i = 0; i < Repeat; ++i) {
if (i % 2 == 0) {
Kokkos::parallel_reduce(nwork, functor_type(nwork, Count), result[i]);
} else {
Kokkos::parallel_reduce("Reduce", nwork, functor_type(nwork, Count),
result[i]);
}
}
for (unsigned i = 0; i < Repeat; ++i) {
for (unsigned j = 0; j < Count; ++j) {
const uint64_t correct = 0 == j % 3 ? nw : nsum;
ASSERT_EQ((ScalarType)correct, result[i][j]);
}
}
}
void run_test_dynamic_minmax(const size_type nwork) {
using functor_type = Test::RuntimeReduceMinMax<ScalarType, execution_space>;
enum { Count = 2 };
enum { Repeat = 100 };
ScalarType result[Repeat][Count];
for (unsigned i = 0; i < Repeat; ++i) {
if (i % 2 == 0) {
Kokkos::parallel_reduce(nwork, functor_type(nwork, Count), result[i]);
} else {
Kokkos::parallel_reduce("Reduce", nwork, functor_type(nwork, Count),
result[i]);
}
}
for (unsigned i = 0; i < Repeat; ++i) {
for (unsigned j = 0; j < Count; ++j) {
if (nwork == 0) {
ScalarType amin(std::numeric_limits<ScalarType>::min());
ScalarType amax(std::numeric_limits<ScalarType>::max());
const ScalarType correct = (j % 2) ? amax : amin;
ASSERT_EQ((ScalarType)correct, result[i][j]);
} else {
const uint64_t correct = j % 2 ? 1 : nwork;
ASSERT_EQ((ScalarType)correct, result[i][j]);
}
}
}
}
void run_test_dynamic_final(const size_type nwork) {
using functor_type = Test::RuntimeReduceFunctorFinal<execution_space>;
enum { Count = 3 };
enum { Repeat = 100 };
typename functor_type::scalar_type result[Repeat][Count];
const uint64_t nw = nwork;
const uint64_t nsum = nw % 2 ? nw * ((nw + 1) / 2) : (nw / 2) * (nw + 1);
for (unsigned i = 0; i < Repeat; ++i) {
if (i % 2 == 0) {
Kokkos::parallel_reduce(nwork, functor_type(nwork, Count), result[i]);
} else {
Kokkos::parallel_reduce("TestKernelReduce", nwork,
functor_type(nwork, Count), result[i]);
}
}
for (unsigned i = 0; i < Repeat; ++i) {
for (unsigned j = 0; j < Count; ++j) {
const uint64_t correct = 0 == j % 3 ? nw : nsum;
ASSERT_EQ((ScalarType)correct, -result[i][j]);
}
}
}
};
template <typename ScalarType, class DeviceType>
class TestReduceDynamicView {
public:
using execution_space = DeviceType;
using size_type = typename execution_space::size_type;
TestReduceDynamicView(const size_type nwork) { run_test_dynamic_view(nwork); }
void run_test_dynamic_view(const size_type nwork) {
using functor_type =
Test::RuntimeReduceFunctor<ScalarType, execution_space>;
using result_type = Kokkos::View<ScalarType*, DeviceType>;
using result_host_type = typename result_type::HostMirror;
const unsigned CountLimit = 23;
const uint64_t nw = nwork;
const uint64_t nsum = nw % 2 ? nw * ((nw + 1) / 2) : (nw / 2) * (nw + 1);
for (unsigned count = 0; count < CountLimit; ++count) {
result_type result("result", count);
result_host_type host_result = Kokkos::create_mirror(result);
// Test result to host pointer:
std::string str("TestKernelReduce");
if (count % 2 == 0) {
Kokkos::parallel_reduce(nw, functor_type(nw, count), host_result);
} else {
Kokkos::parallel_reduce(str, nw, functor_type(nw, count), host_result);
}
Kokkos::fence("Fence before accessing result on the host");
for (unsigned j = 0; j < count; ++j) {
const uint64_t correct = 0 == j % 3 ? nw : nsum;
ASSERT_EQ(host_result(j), (ScalarType)correct);
host_result(j) = 0;
}
}
}
};
} // namespace
// FIXME_SYCL
// FIXME_OPENMPTARGET : The feature works with LLVM/13 on NVIDIA
// architectures. The jenkins currently tests with LLVM/12.
#if !defined(KOKKOS_ENABLE_SYCL) && \
(!defined(KOKKOS_ENABLE_OPENMPTARGET) || \
defined(KOKKOS_COMPILER_CLANG) && (KOKKOS_COMPILER_CLANG >= 1300))
TEST(TEST_CATEGORY, int64_t_reduce) {
TestReduce<int64_t, TEST_EXECSPACE>(0);
TestReduce<int64_t, TEST_EXECSPACE>(1000000);
}
TEST(TEST_CATEGORY, double_reduce) {
TestReduce<double, TEST_EXECSPACE>(0);
TestReduce<double, TEST_EXECSPACE>(1000000);
}
TEST(TEST_CATEGORY, int64_t_reduce_dynamic) {
TestReduceDynamic<int64_t, TEST_EXECSPACE>(0);
TestReduceDynamic<int64_t, TEST_EXECSPACE>(1000000);
}
TEST(TEST_CATEGORY, double_reduce_dynamic) {
TestReduceDynamic<double, TEST_EXECSPACE>(0);
TestReduceDynamic<double, TEST_EXECSPACE>(1000000);
}
TEST(TEST_CATEGORY, int64_t_reduce_dynamic_view) {
TestReduceDynamicView<int64_t, TEST_EXECSPACE>(0);
TestReduceDynamicView<int64_t, TEST_EXECSPACE>(1000000);
}
#endif
// FIXME_OPENMPTARGET: Not yet implemented.
#ifndef KOKKOS_ENABLE_OPENMPTARGET
// FIXME_OPENACC: Not yet implemented.
#ifndef KOKKOS_ENABLE_OPENACC
TEST(TEST_CATEGORY, int_combined_reduce) {
using functor_type = CombinedReduceFunctorSameType<int64_t, TEST_EXECSPACE>;
constexpr uint64_t nw = 1000;
uint64_t nsum = (nw / 2) * (nw + 1);
int64_t result1 = 0;
int64_t result2 = 0;
int64_t result3 = 0;
Kokkos::parallel_reduce("int_combined_reduce",
Kokkos::RangePolicy<TEST_EXECSPACE>(0, nw),
functor_type(nw), result1, result2, result3);
ASSERT_EQ(nw, uint64_t(result1));
ASSERT_EQ(nsum, uint64_t(result2));
ASSERT_EQ(nsum, uint64_t(result3));
}
TEST(TEST_CATEGORY, mdrange_combined_reduce) {
using functor_type = CombinedReduceFunctorSameType<int64_t, TEST_EXECSPACE>;
constexpr uint64_t nw = 1000;
uint64_t nsum = (nw / 2) * (nw + 1);
{
int64_t result1 = 0;
int64_t result2 = 0;
int64_t result3 = 0;
Kokkos::parallel_reduce(
"int_combined_reduce_mdrange",
Kokkos::MDRangePolicy<TEST_EXECSPACE, Kokkos::Rank<3>>({{0, 0, 0}},
{{nw, 1, 1}}),
functor_type(nw), result1, result2, result3);
ASSERT_EQ(nw, uint64_t(result1));
ASSERT_EQ(nsum, uint64_t(result2));
ASSERT_EQ(nsum, uint64_t(result3));
}
{
int64_t result1 = 0;
int64_t result2 = 0;
int64_t result3 = 0;
Kokkos::parallel_reduce(
"int_combined_reduce_mdrange",
Kokkos::MDRangePolicy<TEST_EXECSPACE, Kokkos::Rank<3>,
Kokkos::Schedule<Kokkos::Dynamic>>({{0, 0, 0}},
{{nw, 1, 1}}),
functor_type(nw), result1, result2, result3);
ASSERT_EQ(nw, uint64_t(result1));
ASSERT_EQ(nsum, uint64_t(result2));
ASSERT_EQ(nsum, uint64_t(result3));
}
}
TEST(TEST_CATEGORY, int_combined_reduce_mixed) {
using functor_type = CombinedReduceFunctorSameType<int64_t, TEST_EXECSPACE>;
constexpr uint64_t nw = 1000;
uint64_t nsum = (nw / 2) * (nw + 1);
{
auto result1_v = Kokkos::View<int64_t, Kokkos::HostSpace>{"result1_v"};
int64_t result2 = 0;
auto result3_v = Kokkos::View<int64_t, Kokkos::HostSpace>{"result3_v"};
Kokkos::parallel_reduce("int_combined-reduce_mixed",
Kokkos::RangePolicy<TEST_EXECSPACE>(0, nw),
functor_type(nw), result1_v, result2,
Kokkos::Sum<int64_t, Kokkos::HostSpace>{result3_v});
ASSERT_EQ(int64_t(nw), result1_v());
ASSERT_EQ(int64_t(nsum), result2);
ASSERT_EQ(int64_t(nsum), result3_v());
}
{
using MemorySpace = typename TEST_EXECSPACE::memory_space;
auto result1_v = Kokkos::View<int64_t, MemorySpace>{"result1_v"};
int64_t result2 = 0;
auto result3_v = Kokkos::View<int64_t, MemorySpace>{"result3_v"};
Kokkos::parallel_reduce("int_combined-reduce_mixed",
Kokkos::RangePolicy<TEST_EXECSPACE>(0, nw),
functor_type(nw), result1_v, result2,
Kokkos::Sum<int64_t, MemorySpace>{result3_v});
int64_t result1;
Kokkos::deep_copy(result1, result1_v);
ASSERT_EQ(int64_t(nw), result1);
ASSERT_EQ(int64_t(nsum), result2);
int64_t result3;
Kokkos::deep_copy(result3, result3_v);
ASSERT_EQ(int64_t(nsum), result3);
}
}
#endif
#endif
#if defined(NDEBUG)
// the following test was made for:
// https://github.com/kokkos/kokkos/issues/6517
struct FunctorReductionWithLargeIterationCount {
KOKKOS_FUNCTION void operator()(const int64_t /*i*/, double& update) const {
update += 1.0;
}
};
TEST(TEST_CATEGORY, reduction_with_large_iteration_count) {
// FIXME_OPENMPTARGET - causes runtime failure with CrayClang compiler
#if defined(KOKKOS_COMPILER_CRAY_LLVM) && defined(KOKKOS_ENABLE_OPENMPTARGET)
GTEST_SKIP() << "known to fail with OpenMPTarget+Cray LLVM";
#endif
if constexpr (std::is_same_v<typename TEST_EXECSPACE::memory_space,
Kokkos::HostSpace>) {
GTEST_SKIP() << "Disabling for host backends";
}
const int64_t N = pow(2LL, 39LL) - pow(2LL, 8LL) + 1;
Kokkos::RangePolicy<TEST_EXECSPACE, Kokkos::IndexType<int64_t>> p(0, N);
double nu = 0;
Kokkos::parallel_reduce("sample reduction", p,
FunctorReductionWithLargeIterationCount(), nu);
ASSERT_DOUBLE_EQ(nu, double(N));
}
#endif
} // namespace Test
|