alpaka
Abstraction Library for Parallel Kernel Acceleration
Loading...
Searching...
No Matches
IDataSource.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 a multidimensional data source.
20 *
21 * @details
22 *
23 * An object that implements the interface returns a value for a multidimensional index. Therefore, it behaves
24 * like multidimensional memory that can only be read. It is not permitted to write a new value to an index
25 * position. An `IDataSource` object has an immutable, fixed multidimensional size. The `IDataSource` object is
26 * not required to reference the storage. It may create or calculate the data instead of reading it from
27 * memory.
28 *
29 * The immutable extent is required for algorithms such as `alpaka::onHost::transform`.
30 *
31 * @param t Object that implements the `IDataSource` interface. May or may not have a const modifier.
32 * @param vec Vector with the same number of elements as the dimension of the `IDataSource` like object.
33 * Used to call the access operator.
34 *
35 *
36 * @section membertypes Member types
37 * - <b>T::value_type</b>: The element type. May or may not be const.
38 * - <b>T::index_type</b>: The index type of the pitch.
39 *
40 * @note The access operator [] with an integral as an argument is only available if the dimension is one.
41 **/
42 template<typename T>
43 concept IDataSource = requires(T t, alpaka::Vec<typename T::index_type, T::dim()> vec) {
44 typename T::value_type;
45 typename T::index_type;
46
47 /* Non const data sources must be assignable.
48 * You can NOT assign const data sources to non const dta sources because this will remove the const-ness.
49 */
50 requires concepts::AssignableFrom<std::decay_t<T>, std::decay_t<T>>;
51
52 // only the non-const type is moveable
53 requires std::movable<std::remove_const_t<T>>;
54
55 /// The bool operator returns true if the access operator returns valid values. For example, memory
56 /// access may be invalid after moving the DataSource.
57 static_cast<bool>(t);
58
59 { T::dim() } -> std::same_as<uint32_t>;
60
61 /* check multi-dimensional access operator
62 if T has no reference type, the access operator needs to return a copy
63 `|| requires { typename T::reference; }` is only required, that the statement becomes true in any case
64 */
65 requires (!requires { typename T::reference; } &&
66 requires { { t[vec] } -> std::same_as<typename T::value_type>;})
67 || requires { typename T::reference; };
68
69 /* check 1-dimensional access operator
70 checking for (T::dim() != 1u) disables the access operator requirement for multidimensional
71 IDataSources */
72 requires
73 (T::dim() != 1u) ||
74 (T::dim() == 1u && !requires { typename T::reference; } &&
75 requires {{ t[0] } -> std::same_as<typename T::value_type>; })
76 || requires { typename T::reference; };
77
78 // typically the alignment of the value_type.
79 { t.getAlignment() } -> alpaka::concepts::Alignment;
80 /// @todo implement concept alpaka::concepts::Extents and use it as return value
81 t.getExtents();
82 /// @todo implement concept alpaka::concepts::Pitches and use it as return value
83 t.getPitches();
84 };
85 } // namespace impl
86
87 template<typename T, typename T_ValueType = alpaka::NotRequired>
92} // namespace alpaka::concepts
Concept to check for an alignment object.
Definition Alignment.hpp:89
Check whether the specified data type T_To can be assigned to T_From.
Check whether the specified data type matches the expected type, or if the expected type is alpaka::N...
Interface concept for objects describing a multidimensional data source.