/home/docs/checkouts/readthedocs.org/user_builds/advanced-micro-devices-composable-kernel/checkouts/develop/include/ck/utility/functional4.hpp Source File

/home/docs/checkouts/readthedocs.org/user_builds/advanced-micro-devices-composable-kernel/checkouts/develop/include/ck/utility/functional4.hpp Source File#

Composable Kernel: /home/docs/checkouts/readthedocs.org/user_builds/advanced-micro-devices-composable-kernel/checkouts/develop/include/ck/utility/functional4.hpp Source File
functional4.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 #ifndef CK_FUNCTIONAL4_HPP
5 #define CK_FUNCTIONAL4_HPP
6 
7 #include "sequence.hpp"
8 #include "tuple.hpp"
9 #include "array.hpp"
10 
11 namespace ck {
12 
13 namespace detail {
14 
15 template <typename Indices>
16 struct unpack_impl;
17 
18 template <index_t... Is>
19 struct unpack_impl<Sequence<Is...>>
20 {
21  template <typename F, typename X>
22  __host__ __device__ constexpr auto operator()(F&& f, X&& x) const
23  {
24  return ck::forward<F>(f)(ck::forward<X>(x).At(Number<Is>{})...);
25  }
26 };
27 
28 template <typename Seq0, typename Seq1>
29 struct unpack2_impl;
30 
31 // TODO: remove this, after properly implementing unpack that takes any number of containers
32 template <index_t... Is, index_t... Js>
33 struct unpack2_impl<Sequence<Is...>, Sequence<Js...>>
34 {
35  template <typename F, typename X, typename Y>
36  __host__ __device__ constexpr auto operator()(F&& f, X&& x, Y&& y) const
37  {
38  return ck::forward<F>(f)(ck::forward<X>(x).At(Number<Is>{})...,
39  ck::forward<Y>(y).At(Number<Js>{})...);
40  }
41 };
42 
43 } // namespace detail
44 
45 template <typename F, typename X>
46 __host__ __device__ constexpr auto unpack(F&& f, X&& x)
47 {
48  using X_ = remove_reference_t<X>;
49  return detail::unpack_impl<typename arithmetic_sequence_gen<0, X_::Size(), 1>::type>{}(
50  ck::forward<F>(f), ck::forward<X>(x));
51 }
52 
53 // TODO: properly implement unpack that takes any number of containers
54 template <typename F, typename X, typename Y>
55 __host__ __device__ constexpr auto unpack2(F&& f, X&& x, Y&& y)
56 {
57  using X_ = remove_reference_t<X>;
58  using Y_ = remove_reference_t<Y>;
59  return detail::unpack2_impl<typename arithmetic_sequence_gen<0, X_::Size(), 1>::type,
60  typename arithmetic_sequence_gen<0, Y_::Size(), 1>::type>{}(
61  ck::forward<F>(f), ck::forward<X>(x), ck::forward<Y>(y));
62 }
63 
64 } // namespace ck
65 #endif
Definition: ck.hpp:267
typename remove_reference< T >::type remove_reference_t
Definition: type.hpp:292
__host__ constexpr __device__ auto unpack2(F &&f, X &&x, Y &&y)
Definition: functional4.hpp:55
__host__ constexpr __device__ auto unpack(F &&f, X &&x)
Definition: functional4.hpp:46
int32_t index_t
Definition: ck.hpp:298
Definition: sequence.hpp:43
Definition: sequence.hpp:256
__host__ constexpr __device__ auto operator()(F &&f, X &&x, Y &&y) const
Definition: functional4.hpp:36
Definition: functional4.hpp:29
__host__ constexpr __device__ auto operator()(F &&f, X &&x) const
Definition: functional4.hpp:22
Definition: functional4.hpp:16
Definition: integral_constant.hpp:20