alpaka
Abstraction Library for Parallel Kernel Acceleration
Loading...
Searching...
No Matches
IMdSpan.hpp
Go to the documentation of this file.
1/* Copyright 2025 Simeon Ehrig
2 * SPDX-License-Identifier: MPL-2.0
3 */
4
5#pragma once
6
7#include "alpaka/Vec.hpp"
11#include "alpaka/trait.hpp"
12
13#include <concepts>
14
15namespace alpaka::concepts
16{
17 namespace impl
18 {
19 /** @brief Interface concept for objects describing multidimensional memory access.
20 *
21 * @details
22 *
23 * An object of type `alpaka::mdspan` does not store any information about the storage location, e.g., whether
24 * the memory is located on a CPU or a GPU. The interface corresponds to that of a standard library container
25 * with continuous memory, but has some differences to support multidimensional memory. For example, instead of
26 * the member function `size()`, which returns the 1D size, `alpaka::mdspan` like objects provides the function
27 *`getExtents()`, which returns the size of each dimension.
28 *
29 * @param t Object of type `alpaka::mdspan`. May or may not have a const modifier.
30 * @param mut_t Mutable object of type `alpaka::mdspan`. Does not have a const modifier.
31 * @param const_t Constant object of type `alpaka::mdspan`. Does have a const modifier.
32 * @param vec Vector with the same number of elements as the dimension of the `alpaka::mdspan` like object.
33 * Used to call the access operator.
34 *
35 * @section components Components
36 *
37 * An `alpaka::mdspan` like object contains 4 components:
38 * - A pointer to the actual memory.
39 * - An extents object that describes the number of dimensions and their respective sizes.
40 * - A pitch object that specifies how many bytes are required to jump to the next element in each dimension.
41 * - An alignment object that describes how the elements are aligned in memory, see:
42 * alpaka::concepts::Alignment
43 *
44 * @section membertypes Member types
45 * - <b>T::reference</b>: The element reference type is either const or non-const, depending on
46 *`T::value_type`.
47 * - <b>T::const_reference</b>: The constant reference type for an element. Always const.
48 * - <b>T::pointer</b>: The element pointer type is either const or non-const, depending on
49 *`T::value_type`.
50 * - <b>T::const_pointer</b>: The constant pointer type for an element. Always pointer-to-const.
51 **/
52 template<typename T, typename T_Mut, typename T_Const>
53 concept IMdSpan
54 = requires(T t, T_Mut mut_t, T_Const const_t, alpaka::Vec<typename T::index_type, T::dim()> vec) {
55 requires IDataSource<T>;
56
57 typename T::reference;
58 typename T::const_reference;
59 typename T::pointer;
60 typename T::const_pointer;
61
62 { *mut_t } -> std::same_as<typename T::reference>;
63 { *const_t } -> std::same_as<typename T::const_reference>;
64 { mut_t.data() } -> std::same_as<typename T::pointer>;
65 { const_t.data() } -> std::same_as<typename T::const_pointer>;
66
67 { mut_t[vec] } -> std::same_as<typename T::reference>;
68 { const_t[vec] } -> std::same_as<typename T::const_reference>;
69 // only if MdSpan like object is 1D, the access operator with an integral is available
70 requires(T::dim() != 1u) || (T::dim() == 1u && requires {
71 { mut_t[typename T::index_type{0}] } -> std::same_as<typename T::reference>;
72 });
73 requires(T::dim() != 1u) || (T::dim() == 1u && requires {
74 { const_t[typename T::index_type{0}] } -> std::same_as<typename T::const_reference>;
75 });
76 /// @todo add getSlice, getConstSlice and getView, getConstView functions
77 };
78
79 } // namespace impl
80
81 /** @brief Interface concept for objects describing multidimensional memory access.
82 *
83 * @details
84 * An object of type `alpaka::mdspan` does not store any information about the storage location, e.g., whether
85 * the memory is located on a CPU or a GPU.
86 *
87 * @attention Use `alpaka::IMdSpan` to restrict types in your code. The actual interface is described in
88 * alpaka::concepts::impl::IMdSpan.
89 **/
90 template<typename T, typename T_ValueType = alpaka::NotRequired>
91 concept IMdSpan = requires {
92 requires impl::IMdSpan<
93 std::remove_reference_t<T>,
94 std::remove_const_t<std::remove_reference_t<T>>,
95 std::add_const_t<std::remove_reference_t<T>>>;
97 };
98} // namespace alpaka::concepts
Check whether the specified data type matches the expected type, or if the expected type is alpaka::N...
Interface concept for objects describing multidimensional memory access.
Definition IMdSpan.hpp:91
Interface concept for objects describing a multidimensional data source.
Interface concept for objects describing multidimensional memory access.
Definition IMdSpan.hpp:54