Skip to content

Commit

Permalink
Add basic region tests for forall methods.
Browse files Browse the repository at this point in the history
  • Loading branch information
rhornung67 committed May 4, 2020
1 parent 2f2f18d commit 6f8291e
Show file tree
Hide file tree
Showing 5 changed files with 167 additions and 0 deletions.
2 changes: 2 additions & 0 deletions test/functional/forall/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,5 @@ add_subdirectory(segment-view)
add_subdirectory(atomic)
add_subdirectory(atomic-view)
add_subdirectory(atomic-ref)

add_subdirectory(region)
16 changes: 16 additions & 0 deletions test/functional/forall/region/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
###############################################################################
# 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)
###############################################################################

raja_add_test(
NAME test-forall-region-seq
SOURCES test-forall-region-seq.cpp)

if(RAJA_ENABLE_OPENMP)
raja_add_test(
NAME test-forall-region-openmp
SOURCES test-forall-region-openmp.cpp)
endif()
31 changes: 31 additions & 0 deletions test/functional/forall/region/test-forall-region-openmp.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~//
// 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)
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~//

#include "tests/test-forall-region.hpp"

#if defined(RAJA_ENABLE_OPENMP)

#include "../test-forall-utils.hpp"

using OpenMPRegionPols = camp::list< RAJA::omp_parallel_region >;

using OpenMPForallExecPols =
camp::list< RAJA::omp_for_nowait_exec,
RAJA::omp_for_exec >;

// Cartesian product of types for OpenMP tests
using OpenMPForallRegionTypes =
Test< camp::cartesian_product<IdxTypeList,
HostResourceList,
OpenMPRegionPols,
OpenMPForallExecPols>>::Types;

INSTANTIATE_TYPED_TEST_SUITE_P(OpenMP,
ForallRegionTest,
OpenMPForallRegionTypes);

#endif
23 changes: 23 additions & 0 deletions test/functional/forall/region/test-forall-region-seq.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~//
// 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)
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~//

#include "tests/test-forall-region.hpp"

#include "../test-forall-execpol.hpp"

using SequentialRegionPols = camp::list< RAJA::seq_region >;

// Cartesian product of types for Sequential tests
using SequentialForallRegionTypes =
Test< camp::cartesian_product<IdxTypeList,
HostResourceList,
SequentialRegionPols,
SequentialForallExecPols>>::Types;

INSTANTIATE_TYPED_TEST_SUITE_P(Sequential,
ForallRegionTest,
SequentialForallRegionTypes);
95 changes: 95 additions & 0 deletions test/functional/forall/region/tests/test-forall-region.hpp
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_REGION_HPP__
#define __TEST_FORALL_REGION_HPP__

#include "RAJA/RAJA.hpp"

#include "../../test-forall-utils.hpp"

#include <numeric>
#include <numeric>

TYPED_TEST_SUITE_P(ForallRegionTest);
template <typename T>
class ForallRegionTest : public ::testing::Test
{
};

template <typename INDEX_TYPE, typename WORKING_RES,
typename REG_POLICY, typename EXEC_POLICY>
void ForallBasicRegionTest(INDEX_TYPE first, INDEX_TYPE last)
{
camp::resources::Resource working_res{WORKING_RES()};

//
// Set some local variables and create some segments for using in tests
//
const INDEX_TYPE N = last - first;

RAJA::TypedRangeSegment<INDEX_TYPE> rseg(first, last);

std::vector<INDEX_TYPE> idx_array(N);
std::iota(&idx_array[0], &idx_array[0] + N, first);

RAJA::TypedListSegment<INDEX_TYPE> lseg(&idx_array[0], N,
working_res);

INDEX_TYPE* working_array;
INDEX_TYPE* check_array;
INDEX_TYPE* test_array;

allocateForallTestData<INDEX_TYPE>(N,
working_res,
&working_array,
&check_array,
&test_array);

working_res.memset( working_array, 0, sizeof(INDEX_TYPE) * N );

RAJA::region<REG_POLICY>([=]() {

RAJA::forall<EXEC_POLICY>(rseg, [=] RAJA_HOST_DEVICE(INDEX_TYPE idx) {
working_array[idx - first] += 1;
});

RAJA::forall<EXEC_POLICY>(lseg, [=] RAJA_HOST_DEVICE(INDEX_TYPE idx) {
working_array[idx - first] += 2;
});

});


working_res.memcpy(check_array, working_array, sizeof(INDEX_TYPE) * N);

for (INDEX_TYPE i = 0; i < N; i++) {
ASSERT_EQ(check_array[i], 3);
}

deallocateForallTestData<INDEX_TYPE>(working_res,
working_array,
check_array,
test_array);
}

TYPED_TEST_P(ForallRegionTest, RegionSegmentForall)
{
using INDEX_TYPE = typename camp::at<TypeParam, camp::num<0>>::type;
using WORKING_RES = typename camp::at<TypeParam, camp::num<1>>::type;
using REG_POLICY = typename camp::at<TypeParam, camp::num<2>>::type;
using EXEC_POLICY = typename camp::at<TypeParam, camp::num<3>>::type;

ForallBasicRegionTest<INDEX_TYPE, WORKING_RES, REG_POLICY, EXEC_POLICY>(0, 25);
ForallBasicRegionTest<INDEX_TYPE, WORKING_RES, REG_POLICY, EXEC_POLICY>(1, 53);
ForallBasicRegionTest<INDEX_TYPE, WORKING_RES, REG_POLICY, EXEC_POLICY>(3, 2556);
}

REGISTER_TYPED_TEST_SUITE_P(ForallRegionTest,
RegionSegmentForall);

#endif // __TEST_FORALL_REGION_HPP__

0 comments on commit 6f8291e

Please sign in to comment.