Skip to content

Commit

Permalink
Improved the checks for reduction reset methods.
Browse files Browse the repository at this point in the history
  • Loading branch information
rhornung67 committed May 14, 2020
1 parent 22f5f0b commit 4f554c2
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -59,18 +59,24 @@ void ForallReduceMaxSanityTest(RAJA::Index_type first, RAJA::Index_type last)
ASSERT_EQ(static_cast<DATA_TYPE>(max.get()), ref_max);

#if !defined(RAJA_ENABLE_TARGET_OPENMP)
//
// Note: RAJA OpenMP target reductions do not currently support reset
//
max.reset(max_init);
ASSERT_EQ(static_cast<DATA_TYPE>(max.get()), max_init);
#endif

const int nloops = 2;

for (int j = nloops; j > 0; --j) {
RAJA::forall<EXEC_POLICY>(r1, [=] RAJA_HOST_DEVICE(RAJA::Index_type idx) {
max.max( working_array[idx] / j);
});
}

ASSERT_EQ(static_cast<DATA_TYPE>(max.get()), ref_max);
DATA_TYPE factor = 2;
RAJA::forall<EXEC_POLICY>(r1, [=] RAJA_HOST_DEVICE(RAJA::Index_type idx) {
max.max( working_array[idx] * factor);
});
ASSERT_EQ(static_cast<DATA_TYPE>(max.get()), ref_max * factor);

factor = 3;
RAJA::forall<EXEC_POLICY>(r1, [=] RAJA_HOST_DEVICE(RAJA::Index_type idx) {
max.max( working_array[idx] * factor);
});
ASSERT_EQ(static_cast<DATA_TYPE>(max.get()), ref_max * factor);


deallocateForallTestData<DATA_TYPE>(working_res,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,20 +72,28 @@ void ForallReduceMaxLocSanityTest(RAJA::Index_type first, RAJA::Index_type last)
ASSERT_EQ(static_cast<RAJA::Index_type>(max.getLoc()), ref_maxloc);

#if !defined(RAJA_ENABLE_TARGET_OPENMP)
//
// Note: RAJA OpenMP target reductions do not currently support reset
//
max.reset(max_init, maxloc_init);
ASSERT_EQ(static_cast<DATA_TYPE>(max.get()), max_init);
ASSERT_EQ(static_cast<RAJA::Index_type>(max.getLoc()), maxloc_init);
#endif

const int nloops = 2;

for (int j = nloops; j > 0; --j) {
RAJA::forall<EXEC_POLICY>(r1, [=] RAJA_HOST_DEVICE(RAJA::Index_type idx) {
max.maxloc( working_array[idx] * j, idx);
});
}

ASSERT_EQ(static_cast<DATA_TYPE>(max.get()), ref_max * nloops);
DATA_TYPE factor = 2;
RAJA::forall<EXEC_POLICY>(r1, [=] RAJA_HOST_DEVICE(RAJA::Index_type idx) {
max.maxloc( working_array[idx] * factor, idx);
});
ASSERT_EQ(static_cast<DATA_TYPE>(max.get()), ref_max * factor);
ASSERT_EQ(static_cast<RAJA::Index_type>(max.getLoc()), ref_maxloc);

factor = 3;
RAJA::forall<EXEC_POLICY>(r1, [=] RAJA_HOST_DEVICE(RAJA::Index_type idx) {
max.maxloc( working_array[idx] * factor, idx);
});
ASSERT_EQ(static_cast<DATA_TYPE>(max.get()), ref_max * factor);
ASSERT_EQ(static_cast<RAJA::Index_type>(max.getLoc()), ref_maxloc);


deallocateForallTestData<DATA_TYPE>(working_res,
working_array,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,18 +60,24 @@ void ForallReduceMinSanityTest(RAJA::Index_type first, RAJA::Index_type last)
ASSERT_EQ(static_cast<DATA_TYPE>(min.get()), ref_min);

#if !defined(RAJA_ENABLE_TARGET_OPENMP)
//
// Note: RAJA OpenMP target reductions do not currently support reset
//
min.reset(min_init);
ASSERT_EQ(static_cast<DATA_TYPE>(min.get()), min_init);
#endif

const int nloops = 2;

for (int j = nloops; j > 0; --j) {
RAJA::forall<EXEC_POLICY>(r1, [=] RAJA_HOST_DEVICE(RAJA::Index_type idx) {
min.min( working_array[idx] * j);
});
}
DATA_TYPE factor = 3;
RAJA::forall<EXEC_POLICY>(r1, [=] RAJA_HOST_DEVICE(RAJA::Index_type idx) {
min.min( working_array[idx] * factor);
});
ASSERT_EQ(static_cast<DATA_TYPE>(min.get()), ref_min * factor);

ASSERT_EQ(static_cast<DATA_TYPE>(min.get()), ref_min);
factor = 2;
RAJA::forall<EXEC_POLICY>(r1, [=] RAJA_HOST_DEVICE(RAJA::Index_type idx) {
min.min( working_array[idx] * factor);
});
ASSERT_EQ(static_cast<DATA_TYPE>(min.get()), ref_min * factor);


deallocateForallTestData<DATA_TYPE>(working_res,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,18 +72,26 @@ void ForallReduceMinLocSanityTest(RAJA::Index_type first, RAJA::Index_type last)
ASSERT_EQ(static_cast<RAJA::Index_type>(min.getLoc()), ref_minloc);

#if !defined(RAJA_ENABLE_TARGET_OPENMP)
//
// Note: RAJA OpenMP target reductions do not currently support reset
//
min.reset(min_init, minloc_init);
ASSERT_EQ(static_cast<DATA_TYPE>(min.get()), min_init);
ASSERT_EQ(static_cast<RAJA::Index_type>(min.getLoc()), minloc_init);
#endif

const int nloops = 2;

for (int j = nloops; j > 0; --j) {
RAJA::forall<EXEC_POLICY>(r1, [=] RAJA_HOST_DEVICE(RAJA::Index_type idx) {
min.minloc( working_array[idx] * j, idx);
});
}
DATA_TYPE factor = 2;
RAJA::forall<EXEC_POLICY>(r1, [=] RAJA_HOST_DEVICE(RAJA::Index_type idx) {
min.minloc( working_array[idx] * factor, idx);
});
ASSERT_EQ(static_cast<DATA_TYPE>(min.get()), ref_min * factor);
ASSERT_EQ(static_cast<RAJA::Index_type>(min.getLoc()), ref_minloc);

ASSERT_EQ(static_cast<DATA_TYPE>(min.get()), ref_min * nloops);
factor = 3;
RAJA::forall<EXEC_POLICY>(r1, [=] RAJA_HOST_DEVICE(RAJA::Index_type idx) {
min.minloc( working_array[idx] * factor, idx);
});
ASSERT_EQ(static_cast<DATA_TYPE>(min.get()), ref_min * factor);
ASSERT_EQ(static_cast<RAJA::Index_type>(min.getLoc()), ref_minloc);


Expand Down

0 comments on commit 4f554c2

Please sign in to comment.