functional4.hpp Source File

functional4.hpp Source File#

Composable Kernel: 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
11namespace ck {
12
13namespace detail {
14
15template <typename Indices>
17
18template <index_t... Is>
19struct 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
28template <typename Seq0, typename Seq1>
30
31// TODO: remove this, after properly implementing unpack that takes any number of containers
32template <index_t... Is, index_t... Js>
33struct 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
45template <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
54template <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 threadwise_tensor_slice_transfer_util.hpp:15
Definition ck.hpp:268
int32_t index_t
Definition ck.hpp:299
integral_constant< index_t, N > Number
Definition number.hpp:12
__host__ __device__ constexpr auto unpack(F &&f, X &&x)
Definition functional4.hpp:46
typename remove_reference< T >::type remove_reference_t
Definition type.hpp:292
__host__ __device__ constexpr auto unpack2(F &&f, X &&x, Y &&y)
Definition functional4.hpp:55
Definition utility/sequence.hpp:43
Definition utility/sequence.hpp:256
__host__ __device__ constexpr auto operator()(F &&f, X &&x, Y &&y) const
Definition functional4.hpp:36
Definition functional4.hpp:29
__host__ __device__ constexpr auto operator()(F &&f, X &&x) const
Definition functional4.hpp:22
Definition functional4.hpp:16