Skip to content

Commit

Permalink
snapshot mdspan namespace changes (kokkos#6162)
Browse files Browse the repository at this point in the history
* kokkos#6161: update mdspan and fix namespaces. Also import from std namespace if using system mdspan

* kokkos#6161: fix formatting

* kokkos#6161: apply mdspan changes from kokkos/mdspan#271

* kokkos#6161: make namespace qualification consistent

* kokkos#6161: fix last inconsistent namespace qual

* kokkos#6161: fix formatting

* kokkos#6161: use old C++14-compatible traits

* kokkos#6161: copy latest mdspan stable with maybe_static_array bug fix

* kokkos#6161: don't snapshot the stdmode headers as we don't use them and it can cause only conflicts

* kokkos#6161: add -DKokkos_ENABLE_IMPL_MDSPAN=ON config to the generic github ci build, nvhpc, and two cuda ci builds

* kokkos#6161: use feature test macro instead of presence of header to avoid pulling in partial mdspan implementations

* kokkos#6161: use mdspan, layout_*, and default_accessor from std namespace if using compiler-provided mdspan

* kokkos#6161: fix formatting

* kokkos#6161: guard <version> include with c++20 or above

* kokkos#6161: disable standard mdspan if using CUDA or HIP since it may not be compatible

* kokkos#6161: format fix

* Work around CUDA 11.0 deduction failure for tuple

* Do not use mdspan from compiler by default even if header is detected

* kokkos#6161: make snapshot consistent with mdspan

---------

Co-authored-by: Christian Trott <crtrott@sandia.gov>
  • Loading branch information
nmm0 and crtrott committed Jun 15, 2023
1 parent 8d410bd commit 3163aef
Show file tree
Hide file tree
Showing 34 changed files with 1,822 additions and 3,135 deletions.
1 change: 1 addition & 0 deletions .github/workflows/continuous-integration-workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ jobs:
-DKokkos_ENABLE_DEPRECATED_CODE_4=ON \
-DKokkos_ENABLE_DEPRECATION_WARNINGS=OFF \
-DKokkos_ENABLE_COMPILER_WARNINGS=ON \
-DKokkos_ENABLE_IMPL_MDSPAN=ON \
-DCMAKE_CXX_FLAGS="-Werror ${{ matrix.cxx_extra_flags }}" \
-DCMAKE_CXX_COMPILER=${{ matrix.cxx }} \
-DCMAKE_CXX_COMPILER_LAUNCHER=ccache \
Expand Down
3 changes: 3 additions & 0 deletions .jenkins
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ pipeline {
-DKokkos_ENABLE_CUDA=ON \
-DKokkos_ENABLE_CUDA_LAMBDA=ON \
-DKokkos_ENABLE_OPENMP=ON \
-DKokkos_ENABLE_IMPL_MDSPAN=ON \
.. && \
make -j8 && ctest --verbose'''
}
Expand Down Expand Up @@ -392,6 +393,7 @@ pipeline {
-DKokkos_ENABLE_DEPRECATED_CODE_3=ON \
-DKokkos_ENABLE_DEPRECATED_CODE_4=ON \
-DKokkos_ENABLE_DEPRECATION_WARNINGS=OFF \
-DKokkos_ENABLE_IMPL_MDSPAN=ON \
-DCMAKE_INSTALL_PREFIX=${PWD}/../install \
.. && \
make -j8 install && \
Expand Down Expand Up @@ -455,6 +457,7 @@ pipeline {
-DKokkos_ENABLE_CUDA=ON \
-DKokkos_ENABLE_CUDA_LAMBDA=ON \
-DKokkos_ENABLE_LIBDL=OFF \
-DKokkos_ENABLE_IMPL_MDSPAN=ON \
.. && \
make -j8 && ctest --verbose && \
cd ../example/build_cmake_in_tree && \
Expand Down
2 changes: 1 addition & 1 deletion cmake/kokkos_enable_options.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ KOKKOS_ENABLE_OPTION(DESUL_ATOMICS_EXTERNAL OFF "Whether to use an external desu

KOKKOS_ENABLE_OPTION(IMPL_MDSPAN OFF "Whether to enable experimental mdspan support")
KOKKOS_ENABLE_OPTION(MDSPAN_EXTERNAL OFF BOOL "Whether to use an external version of mdspan")
KOKKOS_ENABLE_OPTION(IMPL_SKIP_COMPILER_MDSPAN OFF BOOL "Whether to use an internal version of mdspan even if the compiler supports mdspan")
KOKKOS_ENABLE_OPTION(IMPL_SKIP_COMPILER_MDSPAN ON BOOL "Whether to use an internal version of mdspan even if the compiler supports mdspan")
mark_as_advanced(Kokkos_ENABLE_IMPL_MDSPAN)
mark_as_advanced(Kokkos_ENABLE_MDSPAN_EXTERNAL)
mark_as_advanced(Kokkos_ENABLE_IMPL_SKIP_COMPILER_MDSPAN)
Expand Down
10 changes: 5 additions & 5 deletions core/src/View/MDSpan/Kokkos_MDSpan_Extents.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ struct ExtentFromDimension {
// Kokkos uses a dimension of '0' to denote a dynamic dimension.
template <>
struct ExtentFromDimension<std::size_t{0}> {
static constexpr std::size_t value = std::experimental::dynamic_extent;
static constexpr std::size_t value = dynamic_extent;
};

template <std::size_t N>
Expand All @@ -63,7 +63,7 @@ struct DimensionFromExtent {
};

template <>
struct DimensionFromExtent<std::experimental::dynamic_extent> {
struct DimensionFromExtent<dynamic_extent> {
static constexpr std::size_t value = std::size_t{0};
};

Expand All @@ -73,9 +73,9 @@ struct ExtentsFromDimension;
template <class IndexType, class Dimension, std::size_t... Indices>
struct ExtentsFromDimension<IndexType, Dimension,
std::index_sequence<Indices...>> {
using type = std::experimental::extents<
IndexType,
ExtentFromDimension<Dimension::static_extent(Indices)>::value...>;
using type =
extents<IndexType,
ExtentFromDimension<Dimension::static_extent(Indices)>::value...>;
};

template <class Extents, class Indices>
Expand Down
24 changes: 20 additions & 4 deletions core/src/View/MDSpan/Kokkos_MDSpan_Header.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,28 @@ static_assert(false,
#define KOKKOS_EXPERIMENTAL_MDSPAN_HPP

// Look for the right mdspan
#if __has_include(<mdspan>)
#if __cplusplus >= 202002L
#include <version>
#endif

// Only use standard library mdspan if we are not running Cuda or HIP.
// Likely these implementations won't be supported on device, so we should use
// our own device-compatible version for now.
#if (__cpp_lib_mdspan >= 202207L) && !defined(KOKKOS_ENABLE_CUDA) && \
!defined(KOKKOS_ENABLE_HIP)
#include <mdspan>
namespace mdspan_ns = std;
namespace Kokkos {
using std::default_accessor;
using std::dextents;
using std::dynamic_extent;
using std::extents;
using std::layout_left;
using std::layout_right;
using std::layout_stride;
using std::mdspan;
} // namespace Kokkos
#else
#include <experimental/mdspan>
namespace mdspan_ns = std::experimental;
#include <mdspan/mdspan.hpp>
#endif

#endif // KOKKOS_EXPERIMENTAL_MDSPAN_HPP
4 changes: 2 additions & 2 deletions core/unit_test/TestMDSpan.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,12 @@ void test_mdspan_minimal_functional() {
"FillSequence", Kokkos::RangePolicy<TEST_EXECSPACE>(0, N),
KOKKOS_LAMBDA(int i) { a(i) = i; });

mdspan_ns::mdspan<int, mdspan_ns::dextents<int, 1>> a_mds(a.data(), N);
Kokkos::mdspan<int, Kokkos::dextents<int, 1>> a_mds(a.data(), N);
int errors;
Kokkos::parallel_reduce(
"CheckMinimalMDSpan", Kokkos::RangePolicy<TEST_EXECSPACE>(0, N),
KOKKOS_LAMBDA(int i, int& err) {
mdspan_ns::mdspan<int, mdspan_ns::dextents<int, 1>> b_mds(a.data(), N);
Kokkos::mdspan<int, Kokkos::dextents<int, 1>> b_mds(a.data(), N);
#ifdef KOKKOS_ENABLE_CXX23
if (a_mds[i] != i) err++;
if (b_mds[i] != i) err++;
Expand Down
53 changes: 23 additions & 30 deletions core/unit_test/view/TestExtentsDatatypeConversion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,55 +35,48 @@ constexpr bool extent_matches_datatype =

// Conversion from DataType to extents
// 0-rank view
static_assert(
datatype_matches_extent<double, std::experimental::extents<std::size_t>>);
static_assert(datatype_matches_extent<double, Kokkos::extents<std::size_t>>);

// Only dynamic
static_assert(datatype_matches_extent<
double***, std::experimental::extents<
std::size_t, std::experimental::dynamic_extent,
std::experimental::dynamic_extent,
std::experimental::dynamic_extent>>);
double***,
Kokkos::extents<std::size_t, Kokkos::dynamic_extent,
Kokkos::dynamic_extent, Kokkos::dynamic_extent>>);
// Only static
static_assert(datatype_matches_extent<
double[2][3][17],
std::experimental::extents<std::size_t, std::size_t{2},
std::size_t{3}, std::size_t{17}>>);
static_assert(
datatype_matches_extent<double[2][3][17],
Kokkos::extents<std::size_t, std::size_t{2},
std::size_t{3}, std::size_t{17}>>);

// Both dynamic and static
static_assert(datatype_matches_extent<
double* * [3][2][8],
std::experimental::extents<
std::size_t, std::experimental::dynamic_extent,
std::experimental::dynamic_extent, std::size_t{3},
std::size_t{2}, std::size_t{8}>>);
Kokkos::extents<std::size_t, Kokkos::dynamic_extent,
Kokkos::dynamic_extent, std::size_t{3},
std::size_t{2}, std::size_t{8}>>);

// Conversion from extents to DataType
// 0-rank extents
static_assert(extent_matches_datatype<double, double,
std::experimental::extents<std::size_t>>);
static_assert(
extent_matches_datatype<double, double, Kokkos::extents<std::size_t>>);

// only dynamic
static_assert(
extent_matches_datatype<double****, double,
std::experimental::extents<
std::size_t, std::experimental::dynamic_extent,
std::experimental::dynamic_extent,
std::experimental::dynamic_extent,
std::experimental::dynamic_extent>>);
static_assert(extent_matches_datatype<
double****, double,
Kokkos::extents<std::size_t, Kokkos::dynamic_extent,
Kokkos::dynamic_extent, Kokkos::dynamic_extent,
Kokkos::dynamic_extent>>);

// only static
static_assert(
extent_matches_datatype<double[7][5][3], double,
std::experimental::extents<std::size_t, 7, 5, 3>>);
static_assert(extent_matches_datatype<double[7][5][3], double,
Kokkos::extents<std::size_t, 7, 5, 3>>);

// both dynamic and static
static_assert(
extent_matches_datatype<double** * [20][45], double,
std::experimental::extents<
std::size_t, std::experimental::dynamic_extent,
std::experimental::dynamic_extent,
std::experimental::dynamic_extent, 20, 45>>);
Kokkos::extents<std::size_t, Kokkos::dynamic_extent,
Kokkos::dynamic_extent,
Kokkos::dynamic_extent, 20, 45>>);
} // namespace

#endif // KOKKOS_ENABLE_IMPL_MDSPAN
54 changes: 12 additions & 42 deletions tpls/mdspan/include/experimental/__p0009_bits/compressed_pair.hpp
Original file line number Diff line number Diff line change
@@ -1,46 +1,18 @@
/*
//@HEADER
// ************************************************************************
//
// Kokkos v. 2.0
// Copyright (2019) Sandia Corporation
// Kokkos v. 4.0
// Copyright (2022) National Technology & Engineering
// Solutions of Sandia, LLC (NTESS).
//
// Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
// 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:
// Part of Kokkos, under the Apache License v2.0 with LLVM Exceptions.
// See https://kokkos.org/LICENSE for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
// 1. Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
//
// 2. 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.
//
// 3. Neither the name of the Corporation nor the names of the
// contributors may be used to endorse or promote products derived from
// this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "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 SANDIA CORPORATION OR THE
// 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 Christian R. Trott (crtrott@sandia.gov)
//
// ************************************************************************
//@HEADER
*/

#pragma once

#include "macros.hpp"
Expand All @@ -50,8 +22,7 @@
# include "no_unique_address.hpp"
#endif

namespace std {
namespace experimental {
namespace MDSPAN_IMPL_STANDARD_NAMESPACE {
namespace detail {

// For no unique address emulation, this is the case taken when neither are empty.
Expand Down Expand Up @@ -93,7 +64,7 @@ template <class _T, class _U, class _Enable = void> struct __compressed_pair {
template <class _T, class _U>
struct __compressed_pair<
_T, _U,
enable_if_t<_MDSPAN_TRAIT(is_empty, _T) && !_MDSPAN_TRAIT(is_empty, _U)>>
std::enable_if_t<_MDSPAN_TRAIT(std::is_empty, _T) && !_MDSPAN_TRAIT(std::is_empty, _U)>>
: private _T {
_U __u_val;
MDSPAN_FORCE_INLINE_FUNCTION _MDSPAN_CONSTEXPR_14 _T &__first() noexcept {
Expand Down Expand Up @@ -130,7 +101,7 @@ struct __compressed_pair<
template <class _T, class _U>
struct __compressed_pair<
_T, _U,
enable_if_t<!_MDSPAN_TRAIT(is_empty, _T) && _MDSPAN_TRAIT(is_empty, _U)>>
std::enable_if_t<!_MDSPAN_TRAIT(std::is_empty, _T) && _MDSPAN_TRAIT(std::is_empty, _U)>>
: private _U {
_T __t_val;
MDSPAN_FORCE_INLINE_FUNCTION _MDSPAN_CONSTEXPR_14 _T &__first() noexcept { return __t_val; }
Expand Down Expand Up @@ -168,7 +139,7 @@ struct __compressed_pair<
template <class _T, class _U>
struct __compressed_pair<
_T, _U,
enable_if_t<_MDSPAN_TRAIT(is_empty, _T) && _MDSPAN_TRAIT(is_empty, _U)>>
std::enable_if_t<_MDSPAN_TRAIT(std::is_empty, _T) && _MDSPAN_TRAIT(std::is_empty, _U)>>
// We need to use the __no_unique_address_emulation wrapper here to avoid
// base class ambiguities.
#ifdef _MDSPAN_COMPILER_MSVC
Expand Down Expand Up @@ -221,5 +192,4 @@ struct __compressed_pair<
#endif // !defined(_MDSPAN_USE_ATTRIBUTE_NO_UNIQUE_ADDRESS)

} // end namespace detail
} // end namespace experimental
} // end namespace std
} // end namespace MDSPAN_IMPL_STANDARD_NAMESPACE

0 comments on commit 3163aef

Please sign in to comment.