alpaka
Abstraction Library for Parallel Kernel Acceleration
Loading...
Searching...
No Matches
iota.hpp
Go to the documentation of this file.
1/* Copyright 2025 René Widera
2 * SPDX-License-Identifier: MPL-2.0
3 */
4
5#pragma once
6
9
10#include <type_traits>
11
12namespace alpaka::onHost
13{
14 /** Fill data with sequentially increasing index (iota value).
15 *
16 * For multidimensional memory, the iota value is increased fastest in the last dimension.
17 *
18 * @tparam T_DataType Iota type which is used. Type must be convertible to the value type of the output data. Only
19 * fundamental types are allowed.
20 * @param queue The queue to execute the algorithm.
21 * @param exec The executor to use for the kernel execution.
22 * @param initValue Index of the first element.
23 * @param out0 Output data to set the iota value. Any kind of alpaka View/MdSpan is supported. The product of the
24 * extents must fit into the precision of the index_type.
25 * @param outOther Additional output data to set the iota value. The extents must be at least as large as out0. Any
26 * kind of alpaka View/MdSpan is supported.
27 * @{
28 */
29 template<typename T_DataType, typename T_Device, alpaka::concepts::QueueKind T_QueueKind>
30 requires(std::is_fundamental_v<T_DataType>)
31 inline void iota(
34 T_DataType const& initValue,
35 alpaka::concepts::IMdSpan auto&& out0,
36 alpaka::concepts::IMdSpan auto&&... outOther)
37 requires(
38 std::is_convertible_v<T_DataType, alpaka::trait::GetValueType_t<ALPAKA_TYPEOF(out0)>>
39 && std::conjunction_v<
40 std::is_convertible<T_DataType, typename alpaka::trait::GetValueType_t<ALPAKA_TYPEOF(outOther)>>...>)
41 {
42 if constexpr(exec == alpaka::exec::anyExecutor)
43 {
44 internal::iota(
45 queue,
46 defaultExecutor(queue.getDevice()),
48 initValue,
49 ALPAKA_FORWARD(out0),
50 ALPAKA_FORWARD(outOther)...);
51 }
52 else
53 internal::iota(
54 queue,
55 exec,
57 initValue,
58 ALPAKA_FORWARD(out0),
59 ALPAKA_FORWARD(outOther)...);
60 }
61
62 /**
63 * An available default executor will be selected automatically. The default executor is the executor with the most
64 * parallelism/performance.
65 */
66 template<typename T_DataType, typename T_Device, alpaka::concepts::QueueKind T_QueueKind>
67 requires(std::is_fundamental_v<T_DataType>)
68 inline void iota(
70 T_DataType const& initValue,
71 alpaka::concepts::IMdSpan auto&& out0,
72 alpaka::concepts::IMdSpan auto&&... outOther)
73 requires(
74 std::is_convertible_v<T_DataType, alpaka::trait::GetValueType_t<ALPAKA_TYPEOF(out0)>>
75 && std::conjunction_v<
76 std::is_convertible<T_DataType, typename alpaka::trait::GetValueType_t<ALPAKA_TYPEOF(outOther)>>...>)
77 {
78 internal::iota<T_DataType>(
79 queue,
80 defaultExecutor(queue.getDevice()),
82 initValue,
83 ALPAKA_FORWARD(out0),
84 ALPAKA_FORWARD(outOther)...);
85 }
86
87 /** @} */
88} // namespace alpaka::onHost
#define ALPAKA_TYPEOF(...)
Get the type of instance.
Definition common.hpp:154
#define ALPAKA_FORWARD(instance)
Perfectly forward an instance as argument.
Definition common.hpp:148
Concept to check for an executor.
Definition trait.hpp:133
Interface concept for objects describing multidimensional memory access.
Definition IMdSpan.hpp:91
constexpr AnyExecutor anyExecutor
Automatic executor selection.
Definition executor.hpp:33
Functionality which is usable on the host CPU controller thread.
Definition api.hpp:40
constexpr auto defaultExecutor(internal::concepts::DeviceHandle auto deviceHandle)
Select a default executor for the given device.
Definition trait.hpp:169
decltype(auto) getExtents(auto &&any)
Object extents.
Definition interface.hpp:25
void iota(Queue< T_Device, T_QueueKind > const &queue, alpaka::concepts::Executor auto const exec, T_DataType const &initValue, alpaka::concepts::IMdSpan auto &&out0, alpaka::concepts::IMdSpan auto &&... outOther)
Fill data with sequentially increasing index (iota value).
Definition iota.hpp:31
typename GetValueType< T >::type GetValueType_t
Definition trait.hpp:65