forked from kokkos/kokkos
-
Notifications
You must be signed in to change notification settings - Fork 3
/
submdspan.hpp
40 lines (37 loc) · 1.66 KB
/
submdspan.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
//@HEADER
// ************************************************************************
//
// Kokkos v. 4.0
// Copyright (2022) 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.
//
// 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
//
//@HEADER
#pragma once
#include "submdspan_extents.hpp"
#include "submdspan_mapping.hpp"
namespace MDSPAN_IMPL_STANDARD_NAMESPACE {
template <class ElementType, class Extents, class LayoutPolicy,
class AccessorPolicy, class... SliceSpecifiers>
MDSPAN_INLINE_FUNCTION
constexpr auto
submdspan(const mdspan<ElementType, Extents, LayoutPolicy, AccessorPolicy> &src,
SliceSpecifiers... slices) {
const auto sub_submdspan_mapping_result = submdspan_mapping(src.mapping(), slices...);
// NVCC has a problem with the deduction so lets figure out the type
using sub_mapping_t = std::remove_cv_t<decltype(sub_submdspan_mapping_result.mapping)>;
using sub_extents_t = typename sub_mapping_t::extents_type;
using sub_layout_t = typename sub_mapping_t::layout_type;
using sub_accessor_t = typename AccessorPolicy::offset_policy;
return mdspan<ElementType, sub_extents_t, sub_layout_t, sub_accessor_t>(
src.accessor().offset(src.data_handle(), sub_submdspan_mapping_result.offset),
sub_submdspan_mapping_result.mapping,
sub_accessor_t(src.accessor()));
}
} // namespace MDSPAN_IMPL_STANDARD_NAMESPACE