reduction_operator_mapping.hpp Source File

reduction_operator_mapping.hpp Source File#

Composable Kernel: reduction_operator_mapping.hpp Source File
reduction_operator_mapping.hpp
Go to the documentation of this file.
1// SPDX-License-Identifier: MIT
2// Copyright (c) 2018-2023, Advanced Micro Devices, Inc. All rights reserved.
3
4#pragma once
5
9// FIXME: can it be replaced with ck::Tuple?
10#include <tuple>
11
12namespace ck {
13
14// The templated struct reduce_binary_operator maps the enum Ids of binary operators to their
15// respective functor classes.
16// The boolean member "indexable" are also provided in reduce_binary_operactor for
17// easier checking by the upper-layer codes in the kernels.
18
19template <ReduceTensorOp Op>
21
22template <>
24{
26
27 static constexpr bool indexable = false;
28};
29
30template <>
32{
34
35 static constexpr bool indexable = false;
36};
37
38template <>
40{
42
43 static constexpr bool indexable = true;
44};
45
46template <>
48{
50
51 static constexpr bool indexable = true;
52};
53
54template <>
56{
58
59 static constexpr bool indexable = true;
60};
61
62template <>
64{
66
67 static constexpr bool indexable = false;
68};
69
70template <>
72{
74
75 static constexpr bool indexable = false;
76};
77
78template <>
80{
82
83 static constexpr bool indexable = false;
84};
85
86// The templated struct reduce_unary_operator maps the enum Ids of Reduce operators to two unary
87// functor classes.
88// The two unary functors are called before and afer the Reduction is executed respectively
89template <ReduceTensorOp Op, bool IsFirstReduce, bool IsLastReduce>
91{
94
95 static std::tuple<InElementwiseOperation, AccElementwiseOperation>
97 {
98 (void)reduceLength;
99 return std::make_tuple(InElementwiseOperation{}, AccElementwiseOperation{});
100 };
101};
102
103template <bool IsFirstReduce>
104struct reduce_unary_operator<ReduceTensorOp::AVG, IsFirstReduce, true>
105{
108
109 static std::tuple<InElementwiseOperation, AccElementwiseOperation>
111 {
112 return std::make_tuple(InElementwiseOperation{}, AccElementwiseOperation{reduceLength});
113 };
114};
115
116template <bool IsLastReduce>
117struct reduce_unary_operator<ReduceTensorOp::NORM1, true, IsLastReduce>
118{
121
122 static std::tuple<InElementwiseOperation, AccElementwiseOperation>
124 {
125 (void)reduceLength;
126 return std::make_tuple(InElementwiseOperation{}, AccElementwiseOperation{});
127 };
128};
129
130template <bool IsLastReduce>
131struct reduce_unary_operator<ReduceTensorOp::AMAX, true, IsLastReduce>
132{
135
136 static std::tuple<InElementwiseOperation, AccElementwiseOperation>
138 {
139 (void)reduceLength;
140 return std::make_tuple(InElementwiseOperation{}, AccElementwiseOperation{});
141 };
142};
143
144template <>
146{
149
150 static std::tuple<InElementwiseOperation, AccElementwiseOperation>
152 {
153 (void)reduceLength;
154 return std::make_tuple(InElementwiseOperation{}, AccElementwiseOperation{});
155 };
156};
157
158template <>
160{
163
164 static std::tuple<InElementwiseOperation, AccElementwiseOperation>
166 {
167 (void)reduceLength;
168 return std::make_tuple(InElementwiseOperation{}, AccElementwiseOperation{});
169 };
170};
171
172template <>
174{
177
178 static std::tuple<InElementwiseOperation, AccElementwiseOperation>
180 {
181 (void)reduceLength;
182 return std::make_tuple(InElementwiseOperation{}, AccElementwiseOperation{});
183 };
184};
185
186} // namespace ck
Definition ck.hpp:268
ReduceTensorOp
Definition reduction_enums.hpp:9
@ NORM2
Definition reduction_enums.hpp:17
@ MAX
Definition reduction_enums.hpp:13
@ MUL
Definition reduction_enums.hpp:11
@ NORM1
Definition reduction_enums.hpp:16
@ AMAX
Definition reduction_enums.hpp:14
@ ADD
Definition reduction_enums.hpp:10
@ MIN
Definition reduction_enums.hpp:12
@ AVG
Definition reduction_enums.hpp:15
signed int int32_t
Definition stdint.h:123
Definition reduction_operator.hpp:409
Definition reduction_operator.hpp:37
Definition reduction_operator.hpp:163
Definition reduction_operator.hpp:285
Definition reduction_operator.hpp:114
static constexpr bool indexable
Definition reduction_operator_mapping.hpp:27
reduce::Add opType
Definition reduction_operator_mapping.hpp:25
static constexpr bool indexable
Definition reduction_operator_mapping.hpp:59
reduce::AMax opType
Definition reduction_operator_mapping.hpp:57
reduce::Add opType
Definition reduction_operator_mapping.hpp:65
static constexpr bool indexable
Definition reduction_operator_mapping.hpp:67
reduce::Max opType
Definition reduction_operator_mapping.hpp:49
static constexpr bool indexable
Definition reduction_operator_mapping.hpp:51
static constexpr bool indexable
Definition reduction_operator_mapping.hpp:43
reduce::Min opType
Definition reduction_operator_mapping.hpp:41
static constexpr bool indexable
Definition reduction_operator_mapping.hpp:35
reduce::Mul opType
Definition reduction_operator_mapping.hpp:33
reduce::Add opType
Definition reduction_operator_mapping.hpp:73
static constexpr bool indexable
Definition reduction_operator_mapping.hpp:75
reduce::Add opType
Definition reduction_operator_mapping.hpp:81
static constexpr bool indexable
Definition reduction_operator_mapping.hpp:83
Definition reduction_operator_mapping.hpp:20
static std::tuple< InElementwiseOperation, AccElementwiseOperation > GetElementwiseOperator(int32_t reduceLength)
Definition reduction_operator_mapping.hpp:137
tensor_operation::element_wise::PassThrough AccElementwiseOperation
Definition reduction_operator_mapping.hpp:134
tensor_operation::element_wise::UnaryAbs InElementwiseOperation
Definition reduction_operator_mapping.hpp:133
tensor_operation::element_wise::PassThrough InElementwiseOperation
Definition reduction_operator_mapping.hpp:106
static std::tuple< InElementwiseOperation, AccElementwiseOperation > GetElementwiseOperator(int32_t reduceLength)
Definition reduction_operator_mapping.hpp:110
tensor_operation::element_wise::UnaryDivide AccElementwiseOperation
Definition reduction_operator_mapping.hpp:107
static std::tuple< InElementwiseOperation, AccElementwiseOperation > GetElementwiseOperator(int32_t reduceLength)
Definition reduction_operator_mapping.hpp:123
tensor_operation::element_wise::UnaryAbs InElementwiseOperation
Definition reduction_operator_mapping.hpp:119
tensor_operation::element_wise::PassThrough AccElementwiseOperation
Definition reduction_operator_mapping.hpp:120
tensor_operation::element_wise::UnarySqrt AccElementwiseOperation
Definition reduction_operator_mapping.hpp:176
static std::tuple< InElementwiseOperation, AccElementwiseOperation > GetElementwiseOperator(int32_t reduceLength)
Definition reduction_operator_mapping.hpp:179
tensor_operation::element_wise::PassThrough InElementwiseOperation
Definition reduction_operator_mapping.hpp:175
tensor_operation::element_wise::UnarySquare InElementwiseOperation
Definition reduction_operator_mapping.hpp:147
static std::tuple< InElementwiseOperation, AccElementwiseOperation > GetElementwiseOperator(int32_t reduceLength)
Definition reduction_operator_mapping.hpp:151
tensor_operation::element_wise::PassThrough AccElementwiseOperation
Definition reduction_operator_mapping.hpp:148
tensor_operation::element_wise::UnarySqrt AccElementwiseOperation
Definition reduction_operator_mapping.hpp:162
static std::tuple< InElementwiseOperation, AccElementwiseOperation > GetElementwiseOperator(int32_t reduceLength)
Definition reduction_operator_mapping.hpp:165
tensor_operation::element_wise::UnarySquare InElementwiseOperation
Definition reduction_operator_mapping.hpp:161
Definition reduction_operator_mapping.hpp:91
tensor_operation::element_wise::PassThrough AccElementwiseOperation
Definition reduction_operator_mapping.hpp:93
static std::tuple< InElementwiseOperation, AccElementwiseOperation > GetElementwiseOperator(int32_t reduceLength)
Definition reduction_operator_mapping.hpp:96
tensor_operation::element_wise::PassThrough InElementwiseOperation
Definition reduction_operator_mapping.hpp:92
Definition tensor_operation/gpu/element/unary_element_wise_operation.hpp:340
Definition tensor_operation/gpu/element/unary_element_wise_operation.hpp:765
Definition tensor_operation/gpu/element/unary_element_wise_operation.hpp:701
Definition tensor_operation/gpu/element/unary_element_wise_operation.hpp:797
Definition tensor_operation/gpu/element/unary_element_wise_operation.hpp:747