diff --git a/test/functional/kernel/region/CMakeLists.txt b/test/functional/kernel/region/CMakeLists.txt index 11c453054d..33f55234ed 100644 --- a/test/functional/kernel/region/CMakeLists.txt +++ b/test/functional/kernel/region/CMakeLists.txt @@ -13,4 +13,7 @@ if(RAJA_ENABLE_OPENMP) raja_add_test( NAME test-kernel-region-openmp SOURCES test-kernel-region-openmp.cpp) + raja_add_test( + NAME test-kernel-region-sync-openmp + SOURCES test-kernel-region-sync-openmp.cpp) endif() diff --git a/test/functional/kernel/region/test-kernel-region-openmp.cpp b/test/functional/kernel/region/test-kernel-region-openmp.cpp index 855d1fb200..ea1d402051 100644 --- a/test/functional/kernel/region/test-kernel-region-openmp.cpp +++ b/test/functional/kernel/region/test-kernel-region-openmp.cpp @@ -9,7 +9,7 @@ #include "../../forall/test-forall-utils.hpp" -using SequentialKernelRegionExecPols = +using OpenMPKernelRegionExecPols = camp::list< RAJA::KernelPolicy< @@ -43,12 +43,12 @@ using SequentialKernelRegionExecPols = >; -// Cartesian product of types for Sequential tests -using SequentialKernelRegionTypes = +// Cartesian product of types for OpenMP tests +using OpenMPKernelRegionTypes = Test< camp::cartesian_product >::Types; + OpenMPKernelRegionExecPols> >::Types; -INSTANTIATE_TYPED_TEST_SUITE_P(Sequential, - KernelRegionTest, - SequentialKernelRegionTypes); +INSTANTIATE_TYPED_TEST_SUITE_P(OpenMP, + KernelRegionFunctionalTest, + OpenMPKernelRegionTypes); diff --git a/test/functional/kernel/region/test-kernel-region-seq.cpp b/test/functional/kernel/region/test-kernel-region-seq.cpp index 518566dd07..15a1c1644f 100644 --- a/test/functional/kernel/region/test-kernel-region-seq.cpp +++ b/test/functional/kernel/region/test-kernel-region-seq.cpp @@ -50,5 +50,5 @@ using SequentialKernelRegionTypes = SequentialKernelRegionExecPols> >::Types; INSTANTIATE_TYPED_TEST_SUITE_P(Sequential, - KernelRegionTest, + KernelRegionFunctionalTest, SequentialKernelRegionTypes); diff --git a/test/functional/kernel/region/test-kernel-region-sync-openmp.cpp b/test/functional/kernel/region/test-kernel-region-sync-openmp.cpp new file mode 100644 index 0000000000..49e72adf74 --- /dev/null +++ b/test/functional/kernel/region/test-kernel-region-sync-openmp.cpp @@ -0,0 +1,70 @@ +//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// +// 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-kernel-region-sync.hpp" + +#include "../../forall/test-forall-utils.hpp" + +using OpenMPKernelRegionSyncExecPols = + camp::list< + + RAJA::KernelPolicy< + RAJA::statement::Region> + >, + + RAJA::statement::OmpSyncThreads, + + RAJA::statement::For<1, RAJA::omp_for_nowait_exec, + RAJA::statement::Lambda<1, RAJA::Segs<1>> + >, + + RAJA::statement::OmpSyncThreads, + + RAJA::statement::For<0, RAJA::omp_for_nowait_exec, + RAJA::statement::Lambda<2, RAJA::Segs<0>> + > + + > + >, + + RAJA::KernelPolicy< + RAJA::statement::Region> + >, + + RAJA::statement::OmpSyncThreads, + + RAJA::statement::For<1, RAJA::omp_for_exec, + RAJA::statement::Lambda<1, RAJA::Segs<1>> + >, + + RAJA::statement::OmpSyncThreads, + + RAJA::statement::For<0, RAJA::omp_for_exec, + RAJA::statement::Lambda<2, RAJA::Segs<0>> + > + + > + > + + >; + + +// Cartesian product of types for OpenMP tests +using OpenMPKernelRegionSyncTypes = + Test< camp::cartesian_product >::Types; + +INSTANTIATE_TYPED_TEST_SUITE_P(OpenMP, + KernelRegionFunctionalTest, + OpenMPKernelRegionSyncTypes); diff --git a/test/functional/kernel/region/tests/test-kernel-region-sync.hpp b/test/functional/kernel/region/tests/test-kernel-region-sync.hpp new file mode 100644 index 0000000000..34bc8226fb --- /dev/null +++ b/test/functional/kernel/region/tests/test-kernel-region-sync.hpp @@ -0,0 +1,96 @@ +//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// +// 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_KERNEL_REGION_SYNC_HPP__ +#define __TEST_KERNEL_REGION_SYNC_HPP__ + +#include "test-kernel-region-utils.hpp" + +#include +#include +#include + +template +void KernelRegionSyncFunctionalTest(INDEX_TYPE first, INDEX_TYPE last) +{ + camp::resources::Resource host_res{camp::resources::Host()}; + camp::resources::Resource work_res{WORKING_RES()}; + + const INDEX_TYPE N = last - first; + + INDEX_TYPE* work_array1; + INDEX_TYPE* work_array2; + INDEX_TYPE* work_array3; + + INDEX_TYPE* check_array; + + allocRegionTestData(N, + work_res, + &work_array1, &work_array2, &work_array3, + host_res, + &check_array); + + work_res.memset( work_array1, 0, sizeof(INDEX_TYPE) * N ); + work_res.memset( work_array2, 0, sizeof(INDEX_TYPE) * N ); + work_res.memset( work_array3, 0, sizeof(INDEX_TYPE) * N ); + + host_res.memset( check_array, 0, sizeof(INDEX_TYPE) * N ); + + std::vector idx_array(N); + std::iota(idx_array.begin(), idx_array.end(), first); + std::reverse(idx_array.begin(), idx_array.end()); + RAJA::TypedListSegment lseg(&idx_array[0], N, + work_res); + + RAJA::TypedRangeSegment rseg(first, last); + + RAJA::kernel( + + RAJA::make_tuple(rseg, lseg), + + [=] (INDEX_TYPE i) { + work_array1[i - first] = 50; + }, + + [=] (INDEX_TYPE i) { + work_array2[i - first] = 100; + }, + + [=] (INDEX_TYPE i) { + work_array3[i - first] = work_array1[i - first] + + work_array2[i - first] + 1; + } + + ); + + work_res.memcpy(check_array, work_array3, sizeof(INDEX_TYPE) * N); + + for (INDEX_TYPE i = 0; i < N; i++) { + ASSERT_EQ(check_array[i], 151); + } + + deallocRegionTestData(work_res, + work_array1, work_array2, work_array3, + host_res, + check_array); +} + +TYPED_TEST_P(KernelRegionFunctionalTest, RegionSyncKernel) +{ + using INDEX_TYPE = typename camp::at>::type; + using WORKING_RES = typename camp::at>::type; + using EXEC_POLICY = typename camp::at>::type; + + KernelRegionSyncFunctionalTest(0, 25); + KernelRegionSyncFunctionalTest(1, 153); + KernelRegionSyncFunctionalTest(3, 2556); +} + +REGISTER_TYPED_TEST_SUITE_P(KernelRegionFunctionalTest, + RegionSyncKernel); + +#endif // __TEST_KERNEL_REGION_SYNC_HPP__ diff --git a/test/functional/kernel/region/tests/test-kernel-region-utils.hpp b/test/functional/kernel/region/tests/test-kernel-region-utils.hpp new file mode 100644 index 0000000000..fee547ac59 --- /dev/null +++ b/test/functional/kernel/region/tests/test-kernel-region-utils.hpp @@ -0,0 +1,51 @@ +//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// +// 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_KERNEL_REGION_UTILS_HPP__ +#define __TEST_KERNEL_REGION_UTILS_HPP__ + +#include "RAJA/RAJA.hpp" + +#include "camp/resource.hpp" + +#include "gtest/gtest.h" + +template +class KernelRegionFunctionalTest : public ::testing::Test +{ +}; + +template +void allocRegionTestData(int N, + camp::resources::Resource& work_res, + T** work1, T** work2, T** work3, + camp::resources::Resource& host_res, + T** check) +{ + *work1 = work_res.allocate(N); + *work2 = work_res.allocate(N); + *work3 = work_res.allocate(N); + + *check = host_res.allocate(N); +} + +template +void deallocRegionTestData(camp::resources::Resource& work_res, + T* work1, T* work2, T* work3, + camp::resources::Resource& host_res, + T* check) +{ + work_res.deallocate(work1); + work_res.deallocate(work2); + work_res.deallocate(work3); + + host_res.deallocate(check); +} + +TYPED_TEST_SUITE_P(KernelRegionFunctionalTest); + +#endif // __TEST_KERNEL_REGION_UTILS_HPP__ diff --git a/test/functional/kernel/region/tests/test-kernel-region.hpp b/test/functional/kernel/region/tests/test-kernel-region.hpp index f3c8f91b2c..751abc6dc4 100644 --- a/test/functional/kernel/region/tests/test-kernel-region.hpp +++ b/test/functional/kernel/region/tests/test-kernel-region.hpp @@ -8,43 +8,37 @@ #ifndef __TEST_KERNEL_REGION_HPP__ #define __TEST_KERNEL_REGION_HPP__ -#include "RAJA/RAJA.hpp" +#include "test-kernel-region-utils.hpp" -#include "camp/resource.hpp" - -#include "gtest/gtest.h" - -TYPED_TEST_SUITE_P(KernelRegionTest); -template -class KernelRegionTest : public ::testing::Test -{ -}; template -void KernelBasicRegionTest(INDEX_TYPE first, INDEX_TYPE last) +void KernelRegionBasicFunctionalTest(INDEX_TYPE first, INDEX_TYPE last) { + camp::resources::Resource host_res{camp::resources::Host()}; camp::resources::Resource work_res{WORKING_RES()}; - // - // Set some local variables and create some segments for using in tests - // const INDEX_TYPE N = last - first; - RAJA::TypedRangeSegment rseg(first, last); + INDEX_TYPE* work_array1; + INDEX_TYPE* work_array2; + INDEX_TYPE* work_array3; + + INDEX_TYPE* check_array; - INDEX_TYPE* work_array1 = work_res.allocate(N); - INDEX_TYPE* work_array2 = work_res.allocate(N); - INDEX_TYPE* work_array3 = work_res.allocate(N); + allocRegionTestData(N, + work_res, + &work_array1, &work_array2, &work_array3, + host_res, + &check_array); work_res.memset( work_array1, 0, sizeof(INDEX_TYPE) * N ); work_res.memset( work_array2, 0, sizeof(INDEX_TYPE) * N ); work_res.memset( work_array3, 0, sizeof(INDEX_TYPE) * N ); - camp::resources::Resource host_res{camp::resources::Host()}; + host_res.memset( check_array, 0, sizeof(INDEX_TYPE) * N ); - INDEX_TYPE* check_array = host_res.allocate(N); - host_res.memset( check_array, 0, sizeof(INDEX_TYPE) * N ); + RAJA::TypedRangeSegment rseg(first, last); RAJA::kernel( @@ -71,25 +65,24 @@ void KernelBasicRegionTest(INDEX_TYPE first, INDEX_TYPE last) ASSERT_EQ(check_array[i], 151); } - work_res.deallocate(work_array1); - work_res.deallocate(work_array2); - work_res.deallocate(work_array3); - - host_res.deallocate(check_array); + deallocRegionTestData(work_res, + work_array1, work_array2, work_array3, + host_res, + check_array); } -TYPED_TEST_P(KernelRegionTest, RegionSegmentKernel) +TYPED_TEST_P(KernelRegionFunctionalTest, RegionBasicKernel) { using INDEX_TYPE = typename camp::at>::type; using WORKING_RES = typename camp::at>::type; using EXEC_POLICY = typename camp::at>::type; - KernelBasicRegionTest(0, 25); - KernelBasicRegionTest(1, 153); - KernelBasicRegionTest(3, 2556); + KernelRegionBasicFunctionalTest(0, 25); + KernelRegionBasicFunctionalTest(1, 153); + KernelRegionBasicFunctionalTest(3, 2556); } -REGISTER_TYPED_TEST_SUITE_P(KernelRegionTest, - RegionSegmentKernel); +REGISTER_TYPED_TEST_SUITE_P(KernelRegionFunctionalTest, + RegionBasicKernel); #endif // __TEST_KERNEL_REGION_HPP__ diff --git a/test/functional/scan/tests/test-scan-utils.hpp b/test/functional/scan/tests/test-scan-utils.hpp index de5ee9ea25..956544e38b 100644 --- a/test/functional/scan/tests/test-scan-utils.hpp +++ b/test/functional/scan/tests/test-scan-utils.hpp @@ -5,8 +5,8 @@ // SPDX-License-Identifier: (BSD-3-Clause) //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// -#ifndef __TEST_SCAN_HPP__ -#define __TEST_SCAN_HPP__ +#ifndef __TEST_SCAN_UTILS_HPP__ +#define __TEST_SCAN_UTILS_HPP__ #include "RAJA/RAJA.hpp" #include "gtest/gtest.h" @@ -68,4 +68,4 @@ void deallocScanTestData(camp::resources::Resource& work_res, TYPED_TEST_SUITE_P(ScanFunctionalTest); -#endif //__TEST_SCAN_HPP__ +#endif //__TEST_SCAN_UTILS_HPP__