diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 8fc5d102..da3757f9 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -95,11 +95,11 @@ if (${Kokkos_DIR_FOUND}) message(STATUS "Magistrate: Kokkos kernels disabled") set(KERNELS 0) endif() + message(STATUS "Magistrate: Kokkos (Version ${Kokkos_VERSION}) enabled") target_compile_definitions( ${MAGISTRATE_LIBRARY} PUBLIC MAGISTRATE_KOKKOS_ENABLED=1 MAGISTRATE_KOKKOS_KERNELS_ENABLED=${KERNELS} ) - message(STATUS "Magistrate: Kokkos enabled") target_link_libraries(${MAGISTRATE_LIBRARY} PUBLIC Kokkos::kokkos) endif() diff --git a/src/checkpoint/checkpoint.h b/src/checkpoint/checkpoint.h index 06d9504d..8ce173fe 100644 --- a/src/checkpoint/checkpoint.h +++ b/src/checkpoint/checkpoint.h @@ -69,6 +69,7 @@ #include "checkpoint/container/kokkos_unordered_map_serialize.h" #include "checkpoint/container/kokkos_pair_serialize.h" +#include "checkpoint/container/kokkos_array.h" #include "checkpoint/container/kokkos_complex_serialize.h" #include "checkpoint/checkpoint_api.h" diff --git a/src/checkpoint/container/array_serialize.h b/src/checkpoint/container/array_serialize.h index d5c0851d..99f57fad 100644 --- a/src/checkpoint/container/array_serialize.h +++ b/src/checkpoint/container/array_serialize.h @@ -53,7 +53,7 @@ namespace checkpoint { template void serialize(Serializer& s, std::array& array) { - dispatch::serializeArray(s, &array[0], array.size()); + dispatch::serializeArray(s, array.data(), array.size()); } } /* end namespace checkpoint */ diff --git a/src/checkpoint/container/kokkos_array.h b/src/checkpoint/container/kokkos_array.h new file mode 100644 index 00000000..d40762b2 --- /dev/null +++ b/src/checkpoint/container/kokkos_array.h @@ -0,0 +1,73 @@ +/* +//@HEADER +// ***************************************************************************** +// +// kokkos_array.h +// DARMA/magistrate => Serialization Library +// +// Copyright 2019 National Technology & Engineering Solutions of Sandia, LLC +// (NTESS). Under the terms of Contract DE-NA0003525 with NTESS, the U.S. +// Government retains certain rights in this software. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are met: +// +// * Redistributions of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistributions in binary form must reproduce the above copyright notice, +// this list of conditions and the following disclaimer in the documentation +// and/or other materials provided with the distribution. +// +// * Neither the name of the copyright holder nor the names of its +// contributors may be used to endorse or promote products derived from this +// software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE +// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +// POSSIBILITY OF SUCH DAMAGE. +// +// Questions? Contact darma@sandia.gov +// +// ***************************************************************************** +//@HEADER +*/ + +#if !defined INCLUDED_SRC_CHECKPOINT_CONTAINER_KOKKOS_ARRAY_H +#define INCLUDED_SRC_CHECKPOINT_CONTAINER_KOKKOS_ARRAY_H + +#include "checkpoint/common.h" +#include "checkpoint/serializers/serializers_headers.h" + +#if MAGISTRATE_KOKKOS_ENABLED + +#include + +namespace checkpoint { + +#if KOKKOS_VERSION_LESS(4, 4, 0) +template +void serialize(Serializer& s, Kokkos::Array& array) { + static_assert(std::is_void_v< Proxy >, "Magistrate does not support serializing Kokkos Arrays with proxies"); + dispatch::serializeArray(s, array.data(), array.size()); +} +#else +template +void serialize(Serializer& s, Kokkos::Array& array) { + dispatch::serializeArray(s, array.data(), array.size()); +} +#endif + +} /* end namespace checkpoint */ + +#endif /*MAGISTRATE_KOKKOS_ENABLED*/ + +#endif /*INCLUDED_SRC_CHECKPOINT_CONTAINER_KOKKOS_ARRAY_H*/ diff --git a/tests/unit/test_footprinter.cc b/tests/unit/test_footprinter.cc index 993b3fb4..f3f12ea3 100644 --- a/tests/unit/test_footprinter.cc +++ b/tests/unit/test_footprinter.cc @@ -665,12 +665,15 @@ TEST_F(TestFootprinter, test_kokkos_pair) { EXPECT_EQ(checkpoint::getMemoryFootprint(pairIntInt), expected_size); } // 'pair' without second element + // This is deprecated in Kokkos >= 4.4 +#if KOKKOS_VERSION_LESS(4, 4, 0) { auto pairIntVoid = Kokkos::pair(10); auto expected_size = sizeof(pairIntVoid.first); EXPECT_EQ(checkpoint::getMemoryFootprint(pairIntVoid), expected_size); } +#endif // KOKKOS_VERSION_LESS(4, 4, 0) } TEST_F(TestFootprinter, test_kokkos_complex) { diff --git a/tests/unit/test_kokkos_serialize_array.cc b/tests/unit/test_kokkos_serialize_array.cc new file mode 100644 index 00000000..78ebc01b --- /dev/null +++ b/tests/unit/test_kokkos_serialize_array.cc @@ -0,0 +1,86 @@ +/* +//@HEADER +// ***************************************************************************** +// +// test_kokkos_serialize_array.cc +// DARMA/magistrate => Serialization Library +// +// Copyright 2019 National Technology & Engineering Solutions of Sandia, LLC +// (NTESS). Under the terms of Contract DE-NA0003525 with NTESS, the U.S. +// Government retains certain rights in this software. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are met: +// +// * Redistributions of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistributions in binary form must reproduce the above copyright notice, +// this list of conditions and the following disclaimer in the documentation +// and/or other materials provided with the distribution. +// +// * Neither the name of the copyright holder nor the names of its +// contributors may be used to endorse or promote products derived from this +// software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE +// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +// POSSIBILITY OF SUCH DAMAGE. +// +// Questions? Contact darma@sandia.gov +// +// ***************************************************************************** +//@HEADER +*/ + +#include +#if MAGISTRATE_KOKKOS_ENABLED + +#include "test_commons.h" + +namespace checkpoint { namespace tests { namespace unit { + +struct KokkosArrayTest : virtual testing::Test { }; + +template +static void test_kokkos_array(Kokkos::Array& refArray) { + using array_type = Kokkos::Array; + + auto serialized = checkpoint::serialize(refArray); + auto deserialized = checkpoint::deserialize(serialized->getBuffer()); + auto& outArray = *deserialized; + + for (size_t i = 0; i < N; ++i ) + ASSERT_EQ(refArray[i], outArray[i]); +} + +TEST_F(KokkosArrayTest, test_kokkos_array) { + using namespace ::checkpoint; + + auto arr1 = Kokkos::Array< int, 5 >{ 1, 2, 3, 4, 5 }; + test_kokkos_array(arr1); + + auto arr2 = Kokkos::Array< float, 3 >{ 3.14f, 2.71f, 365.242f }; + test_kokkos_array(arr2); + + auto arr3 = Kokkos::Array< double, 2 >{ 3.14, 2.71 }; + test_kokkos_array(arr3); + + auto arr4 = Kokkos::Array< int, 1 >{ 3 }; + test_kokkos_array(arr4); + + auto empty_arr = Kokkos::Array< double, 0 >{}; + test_kokkos_array(empty_arr); +} + +}}} // namespace checkpoint::tests::unit + +#endif /*MAGISTRATE_KOKKOS_ENABLED*/ diff --git a/tests/unit/test_kokkos_serialize_pair.cc b/tests/unit/test_kokkos_serialize_pair.cc index 528ce679..dbaa28ff 100644 --- a/tests/unit/test_kokkos_serialize_pair.cc +++ b/tests/unit/test_kokkos_serialize_pair.cc @@ -73,8 +73,10 @@ TEST_F(KokkosPairTest, test_kokkos_pair) { auto pairUnsignedVector = Kokkos::pair>{30, {2, 3, 4 ,5}}; test_kokkos_pair(pairUnsignedVector); +#if KOKKOS_VERSION_LESS(4, 4, 0) auto pairIntVoid = Kokkos::pair(100); test_kokkos_pair(pairIntVoid); +#endif } }}} // namespace checkpoint::tests::unit