functional2.hpp Source File

functional2.hpp Source File#

Composable Kernel: functional2.hpp Source File
functional2.hpp
Go to the documentation of this file.
1// SPDX-License-Identifier: MIT
2// Copyright (c) 2018-2025, Advanced Micro Devices, Inc. All rights reserved.
3
4#pragma once
5
9#include "ck/utility/type.hpp"
10
11namespace ck {
12
13namespace detail {
14
15template <class>
17
18template <index_t... Is>
20{
21 template <class F>
22 __host__ __device__ constexpr void operator()(F f) const
23 {
24 swallow{(f(Number<Is>{}), 0)...};
25 }
26};
27
28} // namespace detail
29
30// F signature: F(Number<Iter>)
31template <index_t NBegin, index_t NEnd, index_t Increment>
33{
34 __host__ __device__ constexpr static_for()
35 {
36 static_assert(Increment != 0 && (NEnd - NBegin) % Increment == 0,
37 "Wrong! should satisfy (NEnd - NBegin) % Increment == 0");
38 static_assert((Increment > 0 && NBegin <= NEnd) || (Increment < 0 && NBegin >= NEnd),
39 "wrongs! should (Increment > 0 && NBegin <= NEnd) || (Increment < 0 && "
40 "NBegin >= NEnd)");
41 }
42
43 template <class F>
44 __host__ __device__ constexpr void operator()(F f) const
45 {
47 f);
48 }
49};
50
51namespace detail {
52
53template <typename T, T... Is>
54struct applier
55{
56 template <typename F>
57 __host__ __device__ constexpr void operator()(F f) const
58 {
59 // tweak -fbracket-depth if compilation fails. Clang default limit is 256
60 (f(Number<Is>{}), ...);
61 }
62};
63
64template <int32_t Size> // == sizeof...(Is)
65using make_applier = __make_integer_seq<applier, index_t, Size>;
66
67} // namespace detail
68
69template <index_t N>
70struct static_for<0, N, 1> : detail::make_applier<N>
71{
72 using detail::make_applier<N>::operator();
73};
74
75template <typename... Is>
77{
78 template <typename F>
79 __host__ __device__ constexpr void operator()(F f) const
80 {
81 // tweak -fbracket-depth if compilation fails. Clang default limit is 256
82 (f(Is{}), ...);
83 }
84};
85
86template <typename... Ts>
88template <typename... Is>
89struct static_for_product<Tuple<Is...>> : public static_for_range<Is...>
90{
91};
92template <typename... Is, typename... Rest>
93struct static_for_product<Tuple<Is...>, Rest...>
94{
95 template <typename F>
96 __host__ __device__ constexpr void operator()(F f) const
97 {
98 static_for_product<Tuple<Is...>>{}([&](auto i0) { //
99 static_for_product<Rest...>{}([&](auto... is) { //
100 f(i0, is...);
101 });
102 });
103 }
104};
105
107{
108 template <typename T>
109 __host__ __device__ constexpr T&& operator()(T&& arg) const noexcept
110 {
111 return ck::forward<T>(arg);
112 }
113};
114
115} // namespace ck
Definition threadwise_tensor_slice_transfer_util.hpp:15
__make_integer_seq< applier, index_t, Size > make_applier
Definition functional2.hpp:65
Definition ck.hpp:268
int32_t index_t
Definition ck.hpp:299
integral_constant< index_t, N > Number
Definition number.hpp:12
Definition utility/sequence.hpp:43
Definition utility/tuple.hpp:117
Definition functional2.hpp:55
__host__ __device__ constexpr void operator()(F f) const
Definition functional2.hpp:57
__host__ __device__ constexpr void operator()(F f) const
Definition functional2.hpp:22
Definition functional2.hpp:16
Definition functional2.hpp:107
__host__ __device__ constexpr T && operator()(T &&arg) const noexcept
Definition functional2.hpp:109
__host__ __device__ constexpr void operator()(F f) const
Definition functional2.hpp:96
Definition functional2.hpp:87
Definition functional2.hpp:77
__host__ __device__ constexpr void operator()(F f) const
Definition functional2.hpp:79
__host__ __device__ constexpr static_for()
Definition functional2.hpp:34
__host__ __device__ constexpr void operator()(F f) const
Definition functional2.hpp:44
Definition utility/functional.hpp:22