-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added min/max sanity tests and some cleanup.
- Loading branch information
1 parent
246bfe6
commit d03013b
Showing
4 changed files
with
205 additions
and
11 deletions.
There are no files selected for viewing
94 changes: 94 additions & 0 deletions
94
test/functional/forall/reduce-sanity/tests/test-forall-reduce-sanity-max.hpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// | ||
// Copyright (c) 2016-20, Lawrence Livermore National Security, LLC | ||
// and RAJA project contributors. See the RAJA/COPYRIGHT file for details. | ||
// | ||
// SPDX-License-Identifier: (BSD-3-Clause) | ||
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// | ||
|
||
#ifndef __TEST_FORALL_REDUCEMAX_SANITY_HPP__ | ||
#define __TEST_FORALL_REDUCEMAX_SANITY_HPP__ | ||
|
||
#include "RAJA/RAJA.hpp" | ||
|
||
#include "test-forall-reduce-sanity.hpp" | ||
|
||
#include <cstdlib> | ||
#include <numeric> | ||
|
||
template <typename DATA_TYPE, typename WORKING_RES, | ||
typename EXEC_POLICY, typename REDUCE_POLICY> | ||
void ForallReduceMaxSanityTest(RAJA::Index_type first, RAJA::Index_type last) | ||
{ | ||
RAJA::TypedRangeSegment<RAJA::Index_type> r1(first, last); | ||
|
||
camp::resources::Resource working_res{WORKING_RES()}; | ||
DATA_TYPE* working_array; | ||
DATA_TYPE* check_array; | ||
DATA_TYPE* test_array; | ||
|
||
allocateForallTestData<DATA_TYPE>(last, | ||
working_res, | ||
&working_array, | ||
&check_array, | ||
&test_array); | ||
|
||
const int modval = 100; | ||
const DATA_TYPE max_init = -1; | ||
const DATA_TYPE big_max = modval + 1; | ||
|
||
for (RAJA::Index_type i = 0; i < last; ++i) { | ||
test_array[i] = static_cast<DATA_TYPE>( rand() % modval ); | ||
} | ||
|
||
DATA_TYPE ref_max = max_init; | ||
for (RAJA::Index_type i = first; i < last; ++i) { | ||
ref_max = RAJA_MAX(test_array[i], ref_max); | ||
} | ||
|
||
working_res.memcpy(working_array, test_array, sizeof(DATA_TYPE) * last); | ||
|
||
RAJA::ReduceMax<REDUCE_POLICY, DATA_TYPE> maxinit(big_max); | ||
RAJA::ReduceMax<REDUCE_POLICY, DATA_TYPE> max(max_init); | ||
|
||
RAJA::forall<EXEC_POLICY>(r1, [=] RAJA_HOST_DEVICE(RAJA::Index_type idx) { | ||
maxinit.max( working_array[idx] ); | ||
max.max( working_array[idx] ); | ||
}); | ||
|
||
ASSERT_EQ(static_cast<DATA_TYPE>(maxinit.get()), big_max); | ||
ASSERT_EQ(static_cast<DATA_TYPE>(max.get()), ref_max); | ||
|
||
max.reset(max_init); | ||
|
||
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); | ||
|
||
|
||
deallocateForallTestData<DATA_TYPE>(working_res, | ||
working_array, | ||
check_array, | ||
test_array); | ||
} | ||
|
||
|
||
TYPED_TEST_P(ForallReduceSanityTest, ReduceMaxSanityForall) | ||
{ | ||
using DATA_TYPE = typename camp::at<TypeParam, camp::num<0>>::type; | ||
using WORKING_RES = typename camp::at<TypeParam, camp::num<1>>::type; | ||
using EXEC_POLICY = typename camp::at<TypeParam, camp::num<2>>::type; | ||
using REDUCE_POLICY = typename camp::at<TypeParam, camp::num<3>>::type; | ||
|
||
ForallReduceMaxSanityTest<DATA_TYPE, WORKING_RES, | ||
EXEC_POLICY, REDUCE_POLICY>(0, 587); | ||
ForallReduceMaxSanityTest<DATA_TYPE, WORKING_RES, | ||
EXEC_POLICY, REDUCE_POLICY>(3, 642); | ||
} | ||
|
||
#endif // __TEST_FORALL_REDUCEMAX_SANITY_HPP__ |
95 changes: 95 additions & 0 deletions
95
test/functional/forall/reduce-sanity/tests/test-forall-reduce-sanity-min.hpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// | ||
// Copyright (c) 2016-20, Lawrence Livermore National Security, LLC | ||
// and RAJA project contributors. See the RAJA/COPYRIGHT file for details. | ||
// | ||
// SPDX-License-Identifier: (BSD-3-Clause) | ||
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// | ||
|
||
#ifndef __TEST_FORALL_REDUCEMIN_SANITY_HPP__ | ||
#define __TEST_FORALL_REDUCEMIN_SANITY_HPP__ | ||
|
||
#include "RAJA/RAJA.hpp" | ||
|
||
#include "test-forall-reduce-sanity.hpp" | ||
|
||
#include <cstdlib> | ||
#include <numeric> | ||
|
||
template <typename DATA_TYPE, typename WORKING_RES, | ||
typename EXEC_POLICY, typename REDUCE_POLICY> | ||
void ForallReduceMinSanityTest(RAJA::Index_type first, RAJA::Index_type last) | ||
{ | ||
RAJA::TypedRangeSegment<RAJA::Index_type> r1(first, last); | ||
|
||
camp::resources::Resource working_res{WORKING_RES()}; | ||
DATA_TYPE* working_array; | ||
DATA_TYPE* check_array; | ||
DATA_TYPE* test_array; | ||
|
||
allocateForallTestData<DATA_TYPE>(last, | ||
working_res, | ||
&working_array, | ||
&check_array, | ||
&test_array); | ||
|
||
const int modval = 100; | ||
const DATA_TYPE min_init = modval+1; | ||
const DATA_TYPE small_min = -modval; | ||
|
||
for (RAJA::Index_type i = 0; i < last; ++i) { | ||
test_array[i] = static_cast<DATA_TYPE>( rand() % modval ); | ||
} | ||
|
||
DATA_TYPE ref_min = min_init; | ||
for (RAJA::Index_type i = first; i < last; ++i) { | ||
ref_min = RAJA_MIN(test_array[i], ref_min); | ||
} | ||
|
||
working_res.memcpy(working_array, test_array, sizeof(DATA_TYPE) * last); | ||
|
||
|
||
RAJA::ReduceMin<REDUCE_POLICY, DATA_TYPE> mininit(small_min); | ||
RAJA::ReduceMin<REDUCE_POLICY, DATA_TYPE> min(min_init); | ||
|
||
RAJA::forall<EXEC_POLICY>(r1, [=] RAJA_HOST_DEVICE(RAJA::Index_type idx) { | ||
mininit.min( working_array[idx] ); | ||
min.min( working_array[idx] ); | ||
}); | ||
|
||
ASSERT_EQ(static_cast<DATA_TYPE>(mininit.get()), small_min); | ||
ASSERT_EQ(static_cast<DATA_TYPE>(min.get()), ref_min); | ||
|
||
min.reset(min_init); | ||
|
||
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); | ||
}); | ||
} | ||
|
||
ASSERT_EQ(static_cast<DATA_TYPE>(min.get()), ref_min); | ||
|
||
|
||
deallocateForallTestData<DATA_TYPE>(working_res, | ||
working_array, | ||
check_array, | ||
test_array); | ||
} | ||
|
||
|
||
TYPED_TEST_P(ForallReduceSanityTest, ReduceMinSanityForall) | ||
{ | ||
using DATA_TYPE = typename camp::at<TypeParam, camp::num<0>>::type; | ||
using WORKING_RES = typename camp::at<TypeParam, camp::num<1>>::type; | ||
using EXEC_POLICY = typename camp::at<TypeParam, camp::num<2>>::type; | ||
using REDUCE_POLICY = typename camp::at<TypeParam, camp::num<3>>::type; | ||
|
||
ForallReduceMinSanityTest<DATA_TYPE, WORKING_RES, | ||
EXEC_POLICY, REDUCE_POLICY>(0, 587); | ||
ForallReduceMinSanityTest<DATA_TYPE, WORKING_RES, | ||
EXEC_POLICY, REDUCE_POLICY>(3, 642); | ||
} | ||
|
||
#endif // __TEST_FORALL_REDUCEMIN_SANITY_HPP__ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters