From b4be2ed8bd7597bd6193b51b7785c381bbf7c5fc Mon Sep 17 00:00:00 2001 From: Max Yang Date: Mon, 21 Sep 2020 16:38:15 -0700 Subject: [PATCH 01/18] Fix overwriting of m_elems for copied slice --- src/chai/ManagedArray.inl | 2 +- tests/integration/managed_array_tests.cpp | 26 ++++++++++++++++++++++- 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/src/chai/ManagedArray.inl b/src/chai/ManagedArray.inl index 4eebf458..33db39d0 100644 --- a/src/chai/ManagedArray.inl +++ b/src/chai/ManagedArray.inl @@ -111,7 +111,7 @@ CHAI_HOST_DEVICE ManagedArray::ManagedArray(ManagedArray const& other): #if !defined(CHAI_DEVICE_COMPILE) if (m_active_base_pointer || m_elems > 0 ) { // we only update m_elems if we are not null and we have a pointer record - if (m_pointer_record) { + if (m_pointer_record && !m_is_slice) { m_elems = m_pointer_record->m_size/sizeof(T); } move(m_resource_manager->getExecutionSpace()); diff --git a/tests/integration/managed_array_tests.cpp b/tests/integration/managed_array_tests.cpp index c61320f3..0a08c099 100644 --- a/tests/integration/managed_array_tests.cpp +++ b/tests/integration/managed_array_tests.cpp @@ -85,7 +85,27 @@ TEST(ManagedArray, Slice) { array[i] = i; }); - chai::ManagedArray sl = array.slice(0,5); + const int SLICE_SZ = 5; + chai::ManagedArray sl = array.slice(0,SLICE_SZ); + ASSERT_EQ(SLICE_SZ, sl.size()); + + sl.free(); + array.free(); + assert_empty_map(true); +} + +TEST(ManagedArray, SliceCopyCtor) { + chai::ManagedArray array(10); + + forall(sequential(), 0, 10, [=] (int i) { + array[i] = i; + }); + + const int SLICE_SZ = 5; + chai::ManagedArray sl = array.slice(0,SLICE_SZ); + chai::ManagedArray slcopy = sl; + ASSERT_EQ(SLICE_SZ, slcopy.size()); + sl.free(); array.free(); assert_empty_map(true); @@ -98,8 +118,12 @@ TEST(ManagedArray, SliceOfSlice) { array[i] = i; }); + const int SLICE_SZ_1 = 6; + const int SLICE_SZ_2 = 3; chai::ManagedArray sl1 = array.slice(0,6); chai::ManagedArray sl2 = sl1.slice(3,3); + ASSERT_EQ(sl1.size(), SLICE_SZ_1); + ASSERT_EQ(sl2.size(), SLICE_SZ_2); forall(sequential(), 0, 3, [=] (int i) { sl1[i] = sl2[i]; From 8d58db6cabc9f54a9c20f59b7a6959c6a0c99487 Mon Sep 17 00:00:00 2001 From: Max Yang Date: Tue, 22 Sep 2020 18:09:42 -0700 Subject: [PATCH 02/18] Add fix for ManagedArray::shallowCopy as well --- src/chai/ManagedArray.hpp | 2 +- tests/integration/managed_array_tests.cpp | 49 +++++++++++++++++++++++ 2 files changed, 50 insertions(+), 1 deletion(-) diff --git a/src/chai/ManagedArray.hpp b/src/chai/ManagedArray.hpp index 81503b40..2a9057fe 100644 --- a/src/chai/ManagedArray.hpp +++ b/src/chai/ManagedArray.hpp @@ -399,7 +399,7 @@ class ManagedArray : public CHAICopyable #if !defined(CHAI_DEVICE_COMPILE) // if we can, ensure elems is based off the pointer_record size to protect against // casting leading to incorrect size info in m_elems. - if (m_pointer_record != nullptr) { + if (m_pointer_record != nullptr && !m_is_slice) { m_elems = m_pointer_record->m_size / sizeof(T); } #endif diff --git a/tests/integration/managed_array_tests.cpp b/tests/integration/managed_array_tests.cpp index 0a08c099..dc0fdb23 100644 --- a/tests/integration/managed_array_tests.cpp +++ b/tests/integration/managed_array_tests.cpp @@ -139,6 +139,29 @@ TEST(ManagedArray, SliceOfSlice) { assert_empty_map(true); } +TEST(ManagedArray, ArrayOfSlices) { + chai::ManagedArray array(10); + chai::ManagedArray> arrayOfSlices(5); + + forall(sequential(), 0, 10, [=] (int i) { + array[i] = i; + }); + + forall(sequential(), 0, 5, [=] (int i) { + arrayOfSlices[i] = array.slice(2*i, 2); + arrayOfSlices[i][1] = arrayOfSlices[i][0]; + }); + + forall(sequential(), 0, 5, [=] (int i) { + ASSERT_EQ(arrayOfSlices[i].size(), 2); + ASSERT_EQ(array[2*i], array[2*i+1]); + }); + + arrayOfSlices.free(); + array.free(); + assert_empty_map(true); +} + #if defined(CHAI_ENABLE_PICK) #if (!defined(CHAI_DISABLE_RM)) TEST(ManagedArray, PickHostFromHostConst) { @@ -556,6 +579,32 @@ GPU_TEST(ManagedArray, IncrementDecrementFromHostOnDevice) #endif #endif +GPU_TEST(ManagedArray, ArrayOfSlicesDevice) { + chai::ManagedArray array(10); + chai::ManagedArray> arrayOfSlices(5); + + forall(sequential(), 0, 10, [=] (int i) { + array[i] = i; + }); + + forall(sequential(), 0, 5, [=] (int i) { + arrayOfSlices[i] = array.slice(2*i, 2); + }); + + forall(gpu(), 0, 5, [=] __device__ (int i) { + arrayOfSlices[i][1] = arrayOfSlices[i][0]; + }); + + forall(sequential(), 0, 5, [=] (int i) { + ASSERT_EQ(arrayOfSlices[i].size(), 2); + ASSERT_EQ(array[2*i], array[2*i+1]); + }); + + arrayOfSlices.free(); + array.free(); + assert_empty_map(true); +} + GPU_TEST(ManagedArray, SliceOfSliceDevice) { chai::ManagedArray array(10); From 37b320b971200b2bf2852a990730e307253c6cb6 Mon Sep 17 00:00:00 2001 From: Alan Dayton Date: Wed, 23 Sep 2020 16:17:47 -0700 Subject: [PATCH 03/18] Fixes for when implicit conversions are disabled --- tests/integration/raja-chai-tests.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/integration/raja-chai-tests.cpp b/tests/integration/raja-chai-tests.cpp index c48ce12e..d08703e1 100644 --- a/tests/integration/raja-chai-tests.cpp +++ b/tests/integration/raja-chai-tests.cpp @@ -57,7 +57,7 @@ CUDA_TEST(ChaiTest, Simple) v2[i] *= 2.0f; }); - float* raw_v2 = v2; + float* raw_v2 = v2.data(); for (int i = 0; i < 10; i++) { ASSERT_FLOAT_EQ(raw_v2[i], i * 2.0f * 2.0f); ; @@ -90,7 +90,7 @@ CUDA_TEST(ChaiTest, Views) v2(i) *= 2.0f; }); - float* raw_v2 = v2.data; + float* raw_v2 = v2.data.data(); for (int i = 0; i < 10; i++) { ASSERT_FLOAT_EQ(raw_v2[i], i * 1.0f * 2.0f * 2.0f); ; From 21662a6cd66799a5678635b7171e583e50473f6c Mon Sep 17 00:00:00 2001 From: Alan Dayton Date: Wed, 23 Sep 2020 16:19:06 -0700 Subject: [PATCH 04/18] Build fix for windows --- src/chai/ArrayManager.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/chai/ArrayManager.hpp b/src/chai/ArrayManager.hpp index 41237001..ba4c092f 100644 --- a/src/chai/ArrayManager.hpp +++ b/src/chai/ArrayManager.hpp @@ -414,7 +414,7 @@ class ArrayManager /*! * \brief synchronize the device if there hasn't been a synchronize since the last kernel */ - bool syncIfNeeded(); + CHAISHAREDDLL_API bool syncIfNeeded(); /*! * \brief Evicts the data in the given space. From c3fa75f75fa5f2cfbc5aaa856dad78c08a7f7071 Mon Sep 17 00:00:00 2001 From: "Adrien M. Bernede" Date: Tue, 6 Oct 2020 19:14:27 -0700 Subject: [PATCH 05/18] Move generic documentation to shared location keep specific examples only --- docs/sphinx/developer/ci.rst | 14 ++++ docs/sphinx/developer/uberenv.rst | 105 ++++++++++++++++++++++++++++++ docs/sphinx/developer_guide.rst | 93 ++------------------------ 3 files changed, 125 insertions(+), 87 deletions(-) create mode 100644 docs/sphinx/developer/ci.rst create mode 100644 docs/sphinx/developer/uberenv.rst diff --git a/docs/sphinx/developer/ci.rst b/docs/sphinx/developer/ci.rst new file mode 100644 index 00000000..412f01cb --- /dev/null +++ b/docs/sphinx/developer/ci.rst @@ -0,0 +1,14 @@ +.. _ci: + +=========================== +CHAI Continuous Integration +=========================== + +Gitlab CI +--------- + +CHAI shares its Gitlab CI workflow with other projects. The documentation is +therefore `shared`_. + +.. shared: /.cmake .. + $ cmake --build -j . + $ ctest --output-on-failure -T test + +It is also possible to use this configuration with the CI script outside of CI: + +.. code-block:: bash + + $ HOST_CONFIG=/.cmake scripts/gitlab/build_and_test.sh + +Testing new dependencies versions +--------------------------------- + +CHAI depends on Umpire, and optionally CHAI. Testing with newer versions of both is made straightforward with Uberenv and Spack: + +* ``$ python scripts/uberenv/uberenv.py --spec=%clang@9.0.0 ^umpire@develop`` +* ``$ python scripts/uberenv/uberenv.py --spec=%clang@9.0.0+raja ^raja@develop`` + +Those commands will install respectively `umpire@develop` and `raja@develop` locally, and generate host-config files with the corresponding paths. + +Again, the CI script can be used directly to install, build and test in one command: + +.. code-block:: bash + + $ SPEC="%clang@9.0.0 ^umpire@develop" scripts/gitlab/build_and_test.sh diff --git a/docs/sphinx/developer_guide.rst b/docs/sphinx/developer_guide.rst index cb141b29..81a5648b 100644 --- a/docs/sphinx/developer_guide.rst +++ b/docs/sphinx/developer_guide.rst @@ -4,93 +4,12 @@ Developer Guide =============== -Generating CHAI host-config files -=================================== +This section aims at gathering information useful to the developer. -.. note:: -This mechanism will generate a cmake configuration file that reproduces the configuration `Spack ` would have generated in the same context. It will contain all the information necessary to build CHAI with the described toolchain. +In particular, the local build scenarios as well as CI testing will be discussed here. -In particular, the host config file will setup: -* flags corresponding with the target required (Release, Debug). -* compilers path, and other toolkits (cuda if required), etc. -* paths to installed dependencies. +.. toctree:: + :maxdepth: 1 -This provides an easy way to build CHAI based on `Spack ` itself driven by `Uberenv `_. - -Uberenv role ------------- - -Uberenv helps by doing the following: - -* Pulls a blessed version of Spack locally -* If you are on a known operating system (like TOSS3), we have defined compilers and system packages so you don't have to rebuild the world (CMake typically in CHAI). -* Overrides CHAI Spack packages with the local one if it exists. (see ``scripts/uberenv/packages``). -* Covers both dependencies and project build in one command. - -Uberenv will create a directory ``uberenv_libs`` containing a Spack instance with the required CHAI dependencies installed. It then generates a host-config file (``.cmake``) at the root of CHAI repository. - -Using Uberenv to generate the host-config file ----------------------------------------------- - -.. code-block:: bash - - $ python scripts/uberenv/uberenv.py - -.. note:: - On LC machines, it is good practice to do the build step in parallel on a compute node. Here is an example command: ``srun -ppdebug -N1 --exclusive python scripts/uberenv/uberenv.py`` - -Unless otherwise specified Spack will default to a compiler. It is recommended to specify which compiler to use: add the compiler spec to the ``--spec`` Uberenv command line option. - -On blessed systems, compiler specs can be found in the Spack compiler files in our repository: ``scripts/uberenv/spack_configs//compilers.yaml``. - -Some examples uberenv options: - -* ``--spec=%clang@4.0.0`` -* ``--spec=%clang@4.0.0+cuda`` -* ``--prefix=`` - -It is also possible to use the CI script outside of CI: - -.. code-block:: bash - - $ SPEC="%clang@9.0.0 +cuda" scripts/gitlab/build_and_test.sh --deps-only - -Building dependencies can take a long time. If you already have a Spack instance you would like to reuse (in supplement of the local one managed by Uberenv), you can do so changing the uberenv command as follow: - -.. code-block:: bash - - $ python scripts/uberenv/uberenv.py --upstream=/opt/spack - -Using host-config files to build CHAI -------------------------------------- - -When a host-config file exists for the desired machine and toolchain, it can easily be used in the CMake build process: - -.. code-block:: bash - - $ mkdir build && cd build - $ cmake -C /lassen-blueos_3_ppc64le_ib_p9-clang@9.0.0.cmake .. - $ cmake --build -j . - $ ctest --output-on-failure -T test - -It is also possible to use the CI script outside of CI: - -.. code-block:: bash - - $ HOST_CONFIG=/.cmake scripts/gitlab/build_and_test.sh - -Testing new dependencies versions ---------------------------------- - -CHAI depends on Umpire, and optionally RAJA. Testing with newer versions of both is made straightforward with Uberenv and Spack: - -* ``$ python scripts/uberenv/uberenv.py --spec=%clang@9.0.0 ^umpire@develop`` -* ``$ python scripts/uberenv/uberenv.py --spec=%clang@9.0.0+raja ^raja@develop`` - -Those commands will install respectively `umpire@develop` and `raja@develop` locally, and generate host-config files with the corresponding paths. - -Again, the CI script can be used directly to install, build and test in one command: - -.. code-block:: bash - - $ SPEC="%clang@9.0.0 ^umpire@develop" scripts/gitlab/build_and_test.sh + developer/ci.rst + developer/uberenv.rst From 94e8f6b96a1e052d3b2a6ed20efa61df6084fa9b Mon Sep 17 00:00:00 2001 From: "Adrien M. Bernede" Date: Tue, 6 Oct 2020 19:16:40 -0700 Subject: [PATCH 06/18] Minor change --- docs/sphinx/developer/ci.rst | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/sphinx/developer/ci.rst b/docs/sphinx/developer/ci.rst index 412f01cb..7c3c787b 100644 --- a/docs/sphinx/developer/ci.rst +++ b/docs/sphinx/developer/ci.rst @@ -1,8 +1,8 @@ .. _ci: -=========================== -CHAI Continuous Integration -=========================== +====================== +Continuous Integration +====================== Gitlab CI --------- From 3f256ce66e0dcf7e33bb3505eaa67e3c69848c6b Mon Sep 17 00:00:00 2001 From: "Adrien M. Bernede" Date: Wed, 7 Oct 2020 13:37:44 -0700 Subject: [PATCH 07/18] Minor change --- docs/sphinx/developer/uberenv.rst | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/sphinx/developer/uberenv.rst b/docs/sphinx/developer/uberenv.rst index ef5f55b9..d697cc01 100644 --- a/docs/sphinx/developer/uberenv.rst +++ b/docs/sphinx/developer/uberenv.rst @@ -42,6 +42,7 @@ CI contains jobs for quartz. $ git grep -h "SPEC" .gitlab/quartz-jobs.yml | grep "gcc" SPEC: "%gcc@4.9.3" SPEC: "%gcc@6.1.0" + SPEC: "%gcc@7.1.0" SPEC: "%gcc@7.3.0" SPEC: "%gcc@8.1.0" From 620d714b1fb1b87d12d7db9966d1e740a21873c9 Mon Sep 17 00:00:00 2001 From: Adrien Bernede <51493078+adrienbernede@users.noreply.github.com> Date: Wed, 7 Oct 2020 13:48:51 -0700 Subject: [PATCH 08/18] Update docs/sphinx/developer/uberenv.rst Copy-Paste mistake --- docs/sphinx/developer/uberenv.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/sphinx/developer/uberenv.rst b/docs/sphinx/developer/uberenv.rst index d697cc01..03857e63 100644 --- a/docs/sphinx/developer/uberenv.rst +++ b/docs/sphinx/developer/uberenv.rst @@ -60,7 +60,7 @@ In CHAI, the Spack configuration for MacOS contains the default compilers depend Using Uberenv to generate the host-config file ---------------------------------------------- -We have seen that we can safely use `gcc@8.1.0` on quartz. Let us ask for the default configuration first, and then produce static libs, have OpenMP support and run the benchmarks: +We have seen that we can safely use `gcc@8.1.0` on quartz. Let us ask for the default configuration first, and then ask for RAJA support and link to develop version of RAJA: .. code-block:: bash From 079118e0a8e3e77c825dc1cdefc138f7f0e43b65 Mon Sep 17 00:00:00 2001 From: Robert Chen Date: Wed, 14 Oct 2020 15:39:51 -0700 Subject: [PATCH 09/18] Update interface for MultiView use. --- src/chai/ManagedArrayView.hpp | 8 ++++ tests/integration/raja-chai-nested.cpp | 63 ++++++++++++++++++++++++++ tests/integration/raja-chai-tests.cpp | 37 +++++++++++++++ 3 files changed, 108 insertions(+) diff --git a/src/chai/ManagedArrayView.hpp b/src/chai/ManagedArrayView.hpp index cbab0343..16858f17 100644 --- a/src/chai/ManagedArrayView.hpp +++ b/src/chai/ManagedArrayView.hpp @@ -28,6 +28,14 @@ using TypedManagedArrayView = RAJA::TypedViewBase; +template +using ManagedArrayMultiView = + RAJA::MultiView *, + chai::ManagedArray> *>; + } // end of namespace chai #endif // defined(CHAI_ENABLE_RAJA_PLUGIN) diff --git a/tests/integration/raja-chai-nested.cpp b/tests/integration/raja-chai-nested.cpp index f46cf3fb..e4b89328 100644 --- a/tests/integration/raja-chai-nested.cpp +++ b/tests/integration/raja-chai-nested.cpp @@ -170,6 +170,69 @@ CUDA_TEST(Chai, NestedView) }); } +CUDA_TEST(Chai, NestedMultiView) +{ + using POLICY = + RAJA::KernelPolicy< + RAJA::statement::For<0, RAJA::seq_exec, + RAJA::statement::For<1, RAJA::seq_exec, + RAJA::statement::Lambda<0> + > + > + >; + +#if defined(RAJA_ENABLE_CUDA) + using POLICY_PARALLEL = + RAJA::KernelPolicy< + RAJA::statement::CudaKernel< + RAJA::statement::For<1, RAJA::cuda_block_x_loop, + RAJA::statement::For<0, RAJA::cuda_thread_x_loop, + RAJA::statement::Lambda<0> + > + > + > + >; +#elif defined(RAJA_ENABLE_OPENMP) + using POLICY_PARALLEL = + RAJA::KernelPolicy< + RAJA::statement::For<1, RAJA::omp_parallel_for_exec, + RAJA::statement::For<0, RAJA::seq_exec, + RAJA::statement::Lambda<0> + > + > + >; +#else + using POLICY_PARALLEL = POLICY; +#endif + + const int X = 16; + const int Y = 16; + + chai::ManagedArray v1_array(X * Y); + chai::ManagedArray v2_array(X * Y); + + chai::ManagedArray all_arrays[2]; + all_arrays[0] = v1_array; + all_arrays[1] = v2_array; + + using view = chai::ManagedArrayMultiView>; + + view mview(all_arrays, RAJA::Layout<2>(X*Y)); + + RAJA::kernel(RAJA::make_tuple(RangeSegment(0, Y), RangeSegment(0, X)), + [=](int i, int j) { mview(0, i, j) = (i + (j * X)) * 1.0f; }); + + RAJA::kernel(RAJA::make_tuple(RangeSegment(0, Y), RangeSegment(0, X)), + [=] PARALLEL_RAJA_DEVICE(int i, int j) { + mview(1, i, j) = mview(0, i, j) * 2.0f; + }); + + RAJA::kernel(RAJA::make_tuple(RangeSegment(0, Y), RangeSegment(0, X)), + [=](int i, int j) { + ASSERT_FLOAT_EQ(mview(1, i, j), mview(0, i, j) * 2.0f); + }); +} + /////////////////////////////////////////////////////////////////////////// // // Example LTimes kernel test routines diff --git a/tests/integration/raja-chai-tests.cpp b/tests/integration/raja-chai-tests.cpp index c48ce12e..621aa63b 100644 --- a/tests/integration/raja-chai-tests.cpp +++ b/tests/integration/raja-chai-tests.cpp @@ -96,3 +96,40 @@ CUDA_TEST(ChaiTest, Views) ; } } + +CUDA_TEST(ChaiTest, MultiView) +{ + chai::ManagedArray v1_array(10); + chai::ManagedArray v2_array(10); + + chai::ManagedArray all_arrays[2]; + all_arrays[0] = v1_array; + all_arrays[1] = v2_array; + + using view = chai::ManagedArrayMultiView >; + + view mymultiview(all_arrays, RAJA::Layout<1>(10)); + + RAJA::forall(RAJA::RangeSegment(0, 10), [=](int i) { + mymultiview(0,i) = static_cast(i * 1.0f); + }); + + RAJA::forall(RAJA::RangeSegment(0, 10), [=] PARALLEL_RAJA_DEVICE(int i) { + mymultiview(1,i) = mymultiview(0,i) * 2.0f; + }); + + RAJA::forall(RAJA::RangeSegment(0, 10), [=](int i) { + ASSERT_FLOAT_EQ(mymultiview(1,i), i * 2.0f); + }); + + RAJA::forall(RAJA::RangeSegment(0, 10), [=] PARALLEL_RAJA_DEVICE(int i) { + mymultiview(1,i) *= 2.0f; + }); + + // accessing pointer to v2_array + float* raw_v2 = mymultiview.data[1]; + for (int i = 0; i < 10; i++) { + ASSERT_FLOAT_EQ(raw_v2[i], i * 1.0f * 2.0f * 2.0f); + ; + } +} From d83240eaaf6d9bd10ec41f2df5a8893f9ce88d2b Mon Sep 17 00:00:00 2001 From: Robert Chen Date: Wed, 14 Oct 2020 15:40:18 -0700 Subject: [PATCH 10/18] Bump RAJA to latest develop. --- src/tpl/raja | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/tpl/raja b/src/tpl/raja index 32d92e38..a81a5303 160000 --- a/src/tpl/raja +++ b/src/tpl/raja @@ -1 +1 @@ -Subproject commit 32d92e38da41cc8d4db25ec79b9884a73a0cb3a1 +Subproject commit a81a53034b6209b6c47942f65846f5155e37d46f From 27773fb5b20cb55fd557758a2e5bb3290ba604bd Mon Sep 17 00:00:00 2001 From: Robert Chen Date: Wed, 14 Oct 2020 16:06:08 -0700 Subject: [PATCH 11/18] Add index repositioning in tests and fix constructor call. --- tests/integration/raja-chai-nested.cpp | 9 +++++++-- tests/integration/raja-chai-tests.cpp | 19 ++++++++++++------- 2 files changed, 19 insertions(+), 9 deletions(-) diff --git a/tests/integration/raja-chai-nested.cpp b/tests/integration/raja-chai-nested.cpp index e4b89328..68f26cc6 100644 --- a/tests/integration/raja-chai-nested.cpp +++ b/tests/integration/raja-chai-nested.cpp @@ -215,16 +215,21 @@ CUDA_TEST(Chai, NestedMultiView) all_arrays[0] = v1_array; all_arrays[1] = v2_array; + // default MultiView using view = chai::ManagedArrayMultiView>; + view mview(all_arrays, RAJA::Layout<2>(X, Y)); - view mview(all_arrays, RAJA::Layout<2>(X*Y)); + // MultiView with index in 1st position + using view1p = chai::ManagedArrayMultiView, 1>; + view1p mview1p(all_arrays, RAJA::Layout<2>(X, Y)); RAJA::kernel(RAJA::make_tuple(RangeSegment(0, Y), RangeSegment(0, X)), [=](int i, int j) { mview(0, i, j) = (i + (j * X)) * 1.0f; }); RAJA::kernel(RAJA::make_tuple(RangeSegment(0, Y), RangeSegment(0, X)), [=] PARALLEL_RAJA_DEVICE(int i, int j) { - mview(1, i, j) = mview(0, i, j) * 2.0f; + // use both MultiViews + mview(1, i, j) = mview1p(i, 0, j) * 2.0f; }); RAJA::kernel(RAJA::make_tuple(RangeSegment(0, Y), RangeSegment(0, X)), diff --git a/tests/integration/raja-chai-tests.cpp b/tests/integration/raja-chai-tests.cpp index 621aa63b..6a664432 100644 --- a/tests/integration/raja-chai-tests.cpp +++ b/tests/integration/raja-chai-tests.cpp @@ -106,28 +106,33 @@ CUDA_TEST(ChaiTest, MultiView) all_arrays[0] = v1_array; all_arrays[1] = v2_array; - using view = chai::ManagedArrayMultiView >; + // default MultiView + using view = chai::ManagedArrayMultiView>; + view mview(all_arrays, RAJA::Layout<1>(10)); - view mymultiview(all_arrays, RAJA::Layout<1>(10)); + // MultiView with index in 1st position + using view1p = chai::ManagedArrayMultiView, 1>; + view1p mview1p(all_arrays, RAJA::Layout<1>(10)); RAJA::forall(RAJA::RangeSegment(0, 10), [=](int i) { - mymultiview(0,i) = static_cast(i * 1.0f); + mview(0,i) = static_cast(i * 1.0f); }); RAJA::forall(RAJA::RangeSegment(0, 10), [=] PARALLEL_RAJA_DEVICE(int i) { - mymultiview(1,i) = mymultiview(0,i) * 2.0f; + // use both MultiViews + mview(1,i) = mview1p(i,0) * 2.0f; }); RAJA::forall(RAJA::RangeSegment(0, 10), [=](int i) { - ASSERT_FLOAT_EQ(mymultiview(1,i), i * 2.0f); + ASSERT_FLOAT_EQ(mview(1,i), i * 2.0f); }); RAJA::forall(RAJA::RangeSegment(0, 10), [=] PARALLEL_RAJA_DEVICE(int i) { - mymultiview(1,i) *= 2.0f; + mview(1,i) *= 2.0f; }); // accessing pointer to v2_array - float* raw_v2 = mymultiview.data[1]; + float* raw_v2 = mview.data[1]; for (int i = 0; i < 10; i++) { ASSERT_FLOAT_EQ(raw_v2[i], i * 1.0f * 2.0f * 2.0f); ; From 2d66f44270333722e4f893fa8e4b9b9f7c104d3b Mon Sep 17 00:00:00 2001 From: Alan Dayton Date: Thu, 29 Oct 2020 16:12:31 -0700 Subject: [PATCH 12/18] Add support for simulation mode in the plugin --- src/chai/ArrayManager.hpp | 20 ++++++++++++++++++++ src/chai/RajaExecutionSpacePlugin.cpp | 16 ++++++++++++++-- 2 files changed, 34 insertions(+), 2 deletions(-) diff --git a/src/chai/ArrayManager.hpp b/src/chai/ArrayManager.hpp index 41237001..48d8b1e1 100644 --- a/src/chai/ArrayManager.hpp +++ b/src/chai/ArrayManager.hpp @@ -416,6 +416,18 @@ class ArrayManager */ bool syncIfNeeded(); +#if defined(CHAI_ENABLE_GPU_SIMULATION_MODE) + /*! + * \brief Turn the GPU simulation mode on or off. + */ + void setGPUSimMode(bool gpuSimMode) { m_gpu_sim_mode = gpuSimMode; } + + /*! + * \brief Return true if GPU simulation mode is on, false otherwise. + */ + bool getGPUSimMode() { return m_gpu_sim_mode; } +#endif + /*! * \brief Evicts the data in the given space. * @@ -523,6 +535,14 @@ class ArrayManager * GPU context */ bool m_synced_since_last_kernel = false; + +#if defined(CHAI_ENABLE_GPU_SIMULATION_MODE) + /*! + * Used by the RAJA plugin to determine whether the execution space should be + * CPU or GPU. + */ + bool m_gpu_sim_mode = false; +#endif }; } // end of namespace chai diff --git a/src/chai/RajaExecutionSpacePlugin.cpp b/src/chai/RajaExecutionSpacePlugin.cpp index 1f76675a..26188aff 100644 --- a/src/chai/RajaExecutionSpacePlugin.cpp +++ b/src/chai/RajaExecutionSpacePlugin.cpp @@ -22,13 +22,25 @@ RajaExecutionSpacePlugin::preCapture(const RAJA::util::PluginContext& p) { switch (p.platform) { case RAJA::Platform::host: - m_arraymanager->setExecutionSpace(chai::CPU); break; +#if defined(CHAI_ENABLE_GPU_SIMULATION_MODE) + if (m_arraymanager->getGPUSimMode()) { + m_arraymanager->setExecutionSpace(chai::GPU); + } + else { + m_arraymanager->setExecutionSpace(chai::CPU); + } +#else + m_arraymanager->setExecutionSpace(chai::CPU); +#endif + break; #if defined(CHAI_ENABLE_CUDA) case RAJA::Platform::cuda: - m_arraymanager->setExecutionSpace(chai::GPU); break; + m_arraymanager->setExecutionSpace(chai::GPU); + break; #endif default: m_arraymanager->setExecutionSpace(chai::NONE); + break; } } From 8c14958e55064bbb6a634447167ab575ccdcea05 Mon Sep 17 00:00:00 2001 From: David Beckingsale Date: Thu, 29 Oct 2020 16:17:49 -0700 Subject: [PATCH 13/18] Lazy init of ArrayManager in plugin --- src/chai/RajaExecutionSpacePlugin.cpp | 7 +++++-- src/chai/RajaExecutionSpacePlugin.hpp | 2 +- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/chai/RajaExecutionSpacePlugin.cpp b/src/chai/RajaExecutionSpacePlugin.cpp index 1f76675a..e5f4027f 100644 --- a/src/chai/RajaExecutionSpacePlugin.cpp +++ b/src/chai/RajaExecutionSpacePlugin.cpp @@ -12,14 +12,17 @@ namespace chai { -RajaExecutionSpacePlugin::RajaExecutionSpacePlugin() : - m_arraymanager(chai::ArrayManager::getInstance()) +RajaExecutionSpacePlugin::RajaExecutionSpacePlugin() { } void RajaExecutionSpacePlugin::preCapture(const RAJA::util::PluginContext& p) { + if (!m_arraymanager) { + m_arraymanager = chai::ArrayManager::getInstance(); + } + switch (p.platform) { case RAJA::Platform::host: m_arraymanager->setExecutionSpace(chai::CPU); break; diff --git a/src/chai/RajaExecutionSpacePlugin.hpp b/src/chai/RajaExecutionSpacePlugin.hpp index 4c164215..b9ccc36e 100644 --- a/src/chai/RajaExecutionSpacePlugin.hpp +++ b/src/chai/RajaExecutionSpacePlugin.hpp @@ -24,7 +24,7 @@ class RajaExecutionSpacePlugin : void postCapture(const RAJA::util::PluginContext& p) override; private: - chai::ArrayManager* m_arraymanager; + chai::ArrayManager* m_arraymanager{nullptr}; }; void linkRajaPlugin(); From 27f83d1ab3642cc53275018b380f15624d44f329 Mon Sep 17 00:00:00 2001 From: David Beckingsale Date: Mon, 2 Nov 2020 11:56:54 -0800 Subject: [PATCH 14/18] Update RAJA and BLT --- blt | 2 +- src/tpl/raja | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/blt b/blt index 4a73f821..cbe99c93 160000 --- a/blt +++ b/blt @@ -1 +1 @@ -Subproject commit 4a73f821a335cfdab68505c58dc5f16eec1521b6 +Subproject commit cbe99c93d0d83ca04f13018cdfed9a3663ea248c diff --git a/src/tpl/raja b/src/tpl/raja index a81a5303..3047fa72 160000 --- a/src/tpl/raja +++ b/src/tpl/raja @@ -1 +1 @@ -Subproject commit a81a53034b6209b6c47942f65846f5155e37d46f +Subproject commit 3047fa720132d19ee143b1fcdacaa72971f5988c From 1268a62331b951107db0f183259e7251bde41633 Mon Sep 17 00:00:00 2001 From: David Beckingsale Date: Mon, 2 Nov 2020 11:58:24 -0800 Subject: [PATCH 15/18] Update version number --- CMakeLists.txt | 2 +- README.md | 2 +- docs/sphinx/conf.py | 4 ++-- docs/sphinx/conf.py.in | 4 ++-- scripts/make_release_tarball.sh | 2 +- 5 files changed, 7 insertions(+), 7 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 7fc21c58..6110b9d3 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -7,7 +7,7 @@ cmake_policy(SET CMP0057 NEW) cmake_policy(SET CMP0048 NEW) -project(Chai LANGUAGES CXX VERSION 2.2.2) +project(Chai LANGUAGES CXX VERSION 2.3.0) set(ENABLE_CUDA Off CACHE BOOL "Enable CUDA") set(ENABLE_HIP Off CACHE BOOL "Enable HIP") diff --git a/README.md b/README.md index a0dd88d7..874907a7 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# CHAI v2.2 +# CHAI v2.3 [![Azure Build Status](https://dev.azure.com/davidbeckingsale/CHAI/_apis/build/status/LLNL.CHAI?branchName=develop)](https://dev.azure.com/davidbeckingsale/CHAI/_build/latest?definitionId=2&branchName=develop) [![Build Status](https://travis-ci.org/LLNL/CHAI.svg?branch=develop)](https://travis-ci.org/LLNL/CHAI) diff --git a/docs/sphinx/conf.py b/docs/sphinx/conf.py index 2955a46a..41c91830 100644 --- a/docs/sphinx/conf.py +++ b/docs/sphinx/conf.py @@ -61,9 +61,9 @@ # built documents. # # The short X.Y version. -version = u'2.2' +version = u'2.3' # The full version, including alpha/beta/rc tags. -release = u'2.2.2' +release = u'2.3.0' # The language for content autogenerated by Sphinx. Refer to documentation # for a list of supported languages. diff --git a/docs/sphinx/conf.py.in b/docs/sphinx/conf.py.in index 3302b3cd..a1c90b20 100644 --- a/docs/sphinx/conf.py.in +++ b/docs/sphinx/conf.py.in @@ -60,9 +60,9 @@ author = u'' # built documents. # # The short X.Y version. -version = u'2.2' +version = u'2.3' # The full version, including alpha/beta/rc tags. -release = u'2.2.2' +release = u'2.3.0' # The language for content autogenerated by Sphinx. Refer to documentation # for a list of supported languages. diff --git a/scripts/make_release_tarball.sh b/scripts/make_release_tarball.sh index 1d0e01bc..888c11a0 100755 --- a/scripts/make_release_tarball.sh +++ b/scripts/make_release_tarball.sh @@ -7,7 +7,7 @@ ############################################################################## TAR_CMD=gtar -VERSION=2.2.2 +VERSION=2.3.0 git archive --prefix=chai-${VERSION}/ -o chai-${VERSION}.tar HEAD 2> /dev/null From e508bbaaaac36dbed9ddc6425943cf11484098ac Mon Sep 17 00:00:00 2001 From: Alan Dayton Date: Mon, 2 Nov 2020 13:11:34 -0800 Subject: [PATCH 16/18] Rename getGPUSimMode to isGPUSimMode --- src/chai/ArrayManager.hpp | 2 +- src/chai/RajaExecutionSpacePlugin.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/chai/ArrayManager.hpp b/src/chai/ArrayManager.hpp index 48d8b1e1..1ef215df 100644 --- a/src/chai/ArrayManager.hpp +++ b/src/chai/ArrayManager.hpp @@ -425,7 +425,7 @@ class ArrayManager /*! * \brief Return true if GPU simulation mode is on, false otherwise. */ - bool getGPUSimMode() { return m_gpu_sim_mode; } + bool isGPUSimMode() { return m_gpu_sim_mode; } #endif /*! diff --git a/src/chai/RajaExecutionSpacePlugin.cpp b/src/chai/RajaExecutionSpacePlugin.cpp index 26188aff..34488269 100644 --- a/src/chai/RajaExecutionSpacePlugin.cpp +++ b/src/chai/RajaExecutionSpacePlugin.cpp @@ -23,7 +23,7 @@ RajaExecutionSpacePlugin::preCapture(const RAJA::util::PluginContext& p) switch (p.platform) { case RAJA::Platform::host: #if defined(CHAI_ENABLE_GPU_SIMULATION_MODE) - if (m_arraymanager->getGPUSimMode()) { + if (m_arraymanager->isGPUSimMode()) { m_arraymanager->setExecutionSpace(chai::GPU); } else { From 90802145ccd8e4b3874ef2e55495a725b808a724 Mon Sep 17 00:00:00 2001 From: Alan Dayton Date: Mon, 2 Nov 2020 13:19:48 -0800 Subject: [PATCH 17/18] Move GPU sim logic into setExecutionSpace --- src/chai/ArrayManager.cpp | 6 ++++++ src/chai/RajaExecutionSpacePlugin.cpp | 23 ++++------------------- 2 files changed, 10 insertions(+), 19 deletions(-) diff --git a/src/chai/ArrayManager.cpp b/src/chai/ArrayManager.cpp index 0d95afae..dce8ad96 100644 --- a/src/chai/ArrayManager.cpp +++ b/src/chai/ArrayManager.cpp @@ -158,6 +158,12 @@ void * ArrayManager::frontOfAllocation(void * pointer) { void ArrayManager::setExecutionSpace(ExecutionSpace space) { +#if defined(CHAI_ENABLE_GPU_SIMULATION_MODE) + if (isGPUSimMode()) { + space = chai::GPU; + } +#endif + CHAI_LOG(Debug, "Setting execution space to " << space); if (chai::GPU == space) { diff --git a/src/chai/RajaExecutionSpacePlugin.cpp b/src/chai/RajaExecutionSpacePlugin.cpp index ebb5b861..1f76675a 100644 --- a/src/chai/RajaExecutionSpacePlugin.cpp +++ b/src/chai/RajaExecutionSpacePlugin.cpp @@ -12,38 +12,23 @@ namespace chai { -RajaExecutionSpacePlugin::RajaExecutionSpacePlugin() +RajaExecutionSpacePlugin::RajaExecutionSpacePlugin() : + m_arraymanager(chai::ArrayManager::getInstance()) { } void RajaExecutionSpacePlugin::preCapture(const RAJA::util::PluginContext& p) { - if (!m_arraymanager) { - m_arraymanager = chai::ArrayManager::getInstance(); - } - switch (p.platform) { case RAJA::Platform::host: -#if defined(CHAI_ENABLE_GPU_SIMULATION_MODE) - if (m_arraymanager->isGPUSimMode()) { - m_arraymanager->setExecutionSpace(chai::GPU); - } - else { - m_arraymanager->setExecutionSpace(chai::CPU); - } -#else - m_arraymanager->setExecutionSpace(chai::CPU); -#endif - break; + m_arraymanager->setExecutionSpace(chai::CPU); break; #if defined(CHAI_ENABLE_CUDA) case RAJA::Platform::cuda: - m_arraymanager->setExecutionSpace(chai::GPU); - break; + m_arraymanager->setExecutionSpace(chai::GPU); break; #endif default: m_arraymanager->setExecutionSpace(chai::NONE); - break; } } From 03c9294f6b1a45bb12620447783e517ccd217889 Mon Sep 17 00:00:00 2001 From: Alan Dayton Date: Mon, 2 Nov 2020 13:23:11 -0800 Subject: [PATCH 18/18] Remove accidentally pulled in old version of develop --- src/chai/RajaExecutionSpacePlugin.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/chai/RajaExecutionSpacePlugin.cpp b/src/chai/RajaExecutionSpacePlugin.cpp index 1f76675a..e5f4027f 100644 --- a/src/chai/RajaExecutionSpacePlugin.cpp +++ b/src/chai/RajaExecutionSpacePlugin.cpp @@ -12,14 +12,17 @@ namespace chai { -RajaExecutionSpacePlugin::RajaExecutionSpacePlugin() : - m_arraymanager(chai::ArrayManager::getInstance()) +RajaExecutionSpacePlugin::RajaExecutionSpacePlugin() { } void RajaExecutionSpacePlugin::preCapture(const RAJA::util::PluginContext& p) { + if (!m_arraymanager) { + m_arraymanager = chai::ArrayManager::getInstance(); + } + switch (p.platform) { case RAJA::Platform::host: m_arraymanager->setExecutionSpace(chai::CPU); break;