| 1 |
//@HEADER |
| 2 |
// ************************************************************************ |
| 3 |
// |
| 4 |
// Kokkos v. 4.0 |
| 5 |
// Copyright (2022) National Technology & Engineering |
| 6 |
// Solutions of Sandia, LLC (NTESS). |
| 7 |
// |
| 8 |
// Under the terms of Contract DE-NA0003525 with NTESS, |
| 9 |
// the U.S. Government retains certain rights in this software. |
| 10 |
// |
| 11 |
// Part of Kokkos, under the Apache License v2.0 with LLVM Exceptions. |
| 12 |
// See https://kokkos.org/LICENSE for license information. |
| 13 |
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 14 |
// |
| 15 |
//@HEADER |
| 16 |
|
| 17 |
#pragma once |
| 18 |
|
| 19 |
#include "submdspan_extents.hpp" |
| 20 |
#include "submdspan_mapping.hpp" |
| 21 |
|
| 22 |
namespace MDSPAN_IMPL_STANDARD_NAMESPACE { |
| 23 |
template <class ElementType, class Extents, class LayoutPolicy, |
| 24 |
class AccessorPolicy, class... SliceSpecifiers> |
| 25 |
MDSPAN_INLINE_FUNCTION |
| 26 |
constexpr auto |
| 27 |
submdspan(const mdspan<ElementType, Extents, LayoutPolicy, AccessorPolicy> &src, |
| 28 |
SliceSpecifiers... slices) { |
| 29 |
const auto sub_submdspan_mapping_result = submdspan_mapping(src.mapping(), slices...); |
| 30 |
// NVCC has a problem with the deduction so lets figure out the type |
| 31 |
using sub_mapping_t = std::remove_cv_t<decltype(sub_submdspan_mapping_result.mapping)>; |
| 32 |
using sub_extents_t = typename sub_mapping_t::extents_type; |
| 33 |
using sub_layout_t = typename sub_mapping_t::layout_type; |
| 34 |
using sub_accessor_t = typename AccessorPolicy::offset_policy; |
| 35 |
return mdspan<ElementType, sub_extents_t, sub_layout_t, sub_accessor_t>( |
| 36 |
src.accessor().offset(src.data_handle(), sub_submdspan_mapping_result.offset), |
| 37 |
sub_submdspan_mapping_result.mapping, |
| 38 |
sub_accessor_t(src.accessor())); |
| 39 |
} |
| 40 |
} // namespace MDSPAN_IMPL_STANDARD_NAMESPACE |