Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New submdspan CPP 17 compatible #227

Merged
merged 27 commits into from
Jan 24, 2023
Merged
Show file tree
Hide file tree
Changes from 24 commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
e004a42
Added new submdspan implementation
crtrott Dec 29, 2022
8cfc22f
Fix build errors on Mac
crtrott Dec 30, 2022
9c97013
Add missing strides parameter
crtrott Jan 3, 2023
4bf8a09
Account for strided_index_range stride in submdspan
crtrott Jan 4, 2023
4defa5e
Fix bug in submdspan_extents for strided_index_range slice
crtrott Jan 4, 2023
39450c1
Fix missing include
crtrott Jan 6, 2023
aefb6e5
Expand submdspan typed test to actually do runtime check
crtrott Jan 6, 2023
f516e85
Add simple strided_index_range test
crtrott Jan 6, 2023
ce9c272
Clang 14 needed explicit structured binding construction
crtrott Jan 6, 2023
f558537
Fix some comments and rename map to mapping in mapping_offset
crtrott Jan 6, 2023
8a4586b
Rewrite the logic to preserve layout_right and layout_left
crtrott Jan 6, 2023
79c1232
Add more tests
crtrott Jan 6, 2023
55c9979
Reformatting submdspan_extents
crtrott Jan 6, 2023
4749d80
Apply clang-format to submdspan files
crtrott Jan 6, 2023
c8e33dc
Backport new submdspan to C++17
crtrott Jan 6, 2023
8ff29f8
Make new submdspan work with NVCC and test on device
crtrott Jan 6, 2023
fa91897
Disable submdspan in C++14 mode
crtrott Jan 6, 2023
36b9376
Delete old submdspan impl
crtrott Jan 6, 2023
471ecbc
Update license files where missing
crtrott Jan 6, 2023
d7f2b3e
Based on Marks Review: always use C++17 inv_map_rank
crtrott Jan 6, 2023
a08fc05
Fix a comment
crtrott Jan 6, 2023
277bb26
Test submdspan customization point
crtrott Jan 7, 2023
7b80df4
Apply some changes suggested in review.
crtrott Jan 9, 2023
15899dc
Support and add test for compile time zero length/stride index range
crtrott Jan 9, 2023
98c6086
Fix some warnings and rename parameter pack
crtrott Jan 24, 2023
b4a7aeb
Actually run the submdspan test on device too
crtrott Jan 24, 2023
c99e6e5
Fix warnings
crtrott Jan 24, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,11 @@ if(MDSPAN_ENABLE_EXAMPLES)
endif()

if(MDSPAN_ENABLE_BENCHMARKS)
add_subdirectory(benchmarks)
if(NOT MDSPAN_CXX_STANDARD STREQUAL "14")
add_subdirectory(benchmarks)
else()
MESSAGE(FATAL_ERROR "Benchmarks are not available in C++14 mode. Turn MDSPAN_ENABLE_BENCHMARKS OFF or use C++17 or newer.")
endif()
endif()

if(MDSPAN_ENABLE_COMP_BENCH)
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ When not in C++23 mode the implementation deviates from the proposal as follows:

### C++14
- deduction guides don't exist
- submdspan (P2630) is not available - an earlier variant of submdspan is available up to release 0.5 in C++14 mode
- benchmarks are not available (they need submdspan)



Expand Down
2 changes: 2 additions & 0 deletions compilation_tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,7 @@ if(NOT MDSPAN_ENABLE_CUDA)
add_compilation_test(ctest_compressed_pair_layout)
endif()
add_compilation_test(ctest_constexpr_dereference)
if(NOT CMAKE_CXX_STANDARD STREQUAL "14")
add_compilation_test(ctest_constexpr_submdspan)
endif()
add_compilation_test(ctest_constexpr_layouts)
558 changes: 0 additions & 558 deletions include/experimental/__p0009_bits/submdspan.hpp

This file was deleted.

34 changes: 34 additions & 0 deletions include/experimental/__p2630_bits/strided_index_range.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@

//@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

namespace std {
namespace experimental {

// Slice Specifier allowing for strides and compile time extent
template <class OffsetType, class ExtentType, class StrideType>
struct strided_index_range {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is called strided_slice now in the paper, but I'm OK with doing the rename as a separate PR.

using offset_type = OffsetType;
using extent_type = ExtentType;
using stride_type = StrideType;

OffsetType offset;
ExtentType extent;
StrideType stride;
};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we consider enforcing the Mandates here?

Suggested change
};
static_assert(is_integral_v<OffsetType> || is_integral_constant_v<OffsetType>);
static_assert(is_integral_v<ExtentType> || is_integral_constant_v<ExtentType>);
static_assert(is_integral_v<StrideType> || is_integral_constant_v<StrideType>);
};

In the change above, is_integral_constant_v is defined as follows.

template<class T>
struct is_integral_constant : std::false_type {};

template<std::integral T, T Value>
struct is_integral_constant<std::integral_constant<T, Value>> : std::true_type {};

template<class T>
constexpr inline bool is_integral_constant_v = is_integral_constant<T>::value;


} // experimental
} // std
40 changes: 40 additions & 0 deletions include/experimental/__p2630_bits/submdspan.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,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

#include "submdspan_extents.hpp"
#include "submdspan_mapping.hpp"

namespace std {
namespace experimental {
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_mapping_offset = 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_mapping_offset.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_mapping_offset.offset),
sub_mapping_offset.mapping,
sub_accessor_t(src.accessor()));
}
} // namespace experimental
} // namespace std
Loading