1/*
2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements. See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership. The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License. You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing,
13 * software distributed under the License is distributed on an
14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 * KIND, either express or implied. See the License for the
16 * specific language governing permissions and limitations
17 * under the License.
18 */
19
20/*!
21 * \file tvm/relay/attrs/reduce.h
22 * \brief Auxiliary attributes for reduce operators.
23 */
24#ifndef TVM_RELAY_ATTRS_REDUCE_H_
25#define TVM_RELAY_ATTRS_REDUCE_H_
26
27#include <tvm/ir/attrs.h>
28
29#include <string>
30
31namespace tvm {
32namespace relay {
33
34/*! \brief Attributes for Reduce operators */
35struct ReduceAttrs : public tvm::AttrsNode<ReduceAttrs> {
36 Array<Integer> axis;
37 bool keepdims;
38 bool exclude;
39
40 TVM_DECLARE_ATTRS(ReduceAttrs, "relay.attrs.ReduceAttrs") {
41 TVM_ATTR_FIELD(axis)
42 .set_default(NullValue<Array<Integer>>())
43 .describe(R"code(The axis or axes along which to perform the reduction.
44
45 The default, `axis=()`, will compute over all elements into a
46 scalar array with shape `(1,)`.
47
48 If `axis` is int, a reduction is performed on a particular axis.
49
50 If `axis` is a tuple of ints, a reduction is performed on all the axes
51 specified in the tuple.
52
53 If `exclude` is true, reduction will be performed on the axes that are
54 NOT in axis instead.)code");
55
56 TVM_ATTR_FIELD(keepdims).set_default(false).describe(
57 "If this is set to `True`, the reduced axes are left "
58 "in the result as dimension with size one.");
59 TVM_ATTR_FIELD(exclude).set_default(false).describe(
60 "Whether to perform reduction on axis that are NOT in axis instead.");
61 }
62};
63
64/*! \brief Attributes for Reduce operators which reduce by finding a single element. E.g. argmin */
65struct ArgReduceAttrs : public tvm::AttrsNode<ArgReduceAttrs> {
66 Array<Integer> axis;
67 bool keepdims;
68 bool select_last_index;
69 bool exclude;
70
71 TVM_DECLARE_ATTRS(ArgReduceAttrs, "relay.attrs.ArgReduceAttrs") {
72 TVM_ATTR_FIELD(axis)
73 .set_default(NullValue<Array<Integer>>())
74 .describe(R"code(The axis or axes along which to perform the reduction.
75
76 The default, `axis=()`, will compute over all elements into a
77 scalar array with shape `(1,)`.
78
79 If `axis` is int, a reduction is performed on a particular axis.
80
81 If `axis` is a tuple of ints, a reduction is performed on all the axes
82 specified in the tuple.
83
84 If `exclude` is true, reduction will be performed on the axes that are
85 NOT in axis instead.)code");
86
87 TVM_ATTR_FIELD(keepdims).set_default(false).describe(
88 "If this is set to `True`, the reduced axes are left "
89 "in the result as dimension with size one.");
90 TVM_ATTR_FIELD(select_last_index)
91 .set_default(false)
92 .describe(
93 "Whether to select the last index if the target element appears multiple times, else "
94 "select the first index which the target element appears");
95 TVM_ATTR_FIELD(exclude).set_default(false).describe(
96 "Whether to perform reduction on axis that are NOT in axis instead.");
97 }
98};
99
100struct VarianceAttrs : public tvm::AttrsNode<VarianceAttrs> {
101 Array<Integer> axis;
102 bool keepdims;
103 bool exclude;
104 bool unbiased;
105
106 TVM_DECLARE_ATTRS(VarianceAttrs, "relay.attrs.VarianceAttrs") {
107 TVM_ATTR_FIELD(axis)
108 .set_default(NullValue<Array<Integer>>())
109 .describe(R"code(The axis or axes along which to perform the reduction.
110
111 The default, `axis=()`, will compute over all elements into a
112 scalar array with shape `(1,)`.
113
114 If `axis` is int, a reduction is performed on a particular axis.
115
116 If `axis` is a tuple of ints, a reduction is performed on all the axes
117 specified in the tuple.
118
119 If `exclude` is true, reduction will be performed on the axes that are
120 NOT in axis instead.)code");
121
122 TVM_ATTR_FIELD(keepdims).set_default(false).describe(
123 "If this is set to `True`, the reduced axes are left "
124 "in the result as dimension with size one.");
125 TVM_ATTR_FIELD(exclude).set_default(false).describe(
126 "Whether to perform reduction on axis that are NOT in axis instead.");
127 TVM_ATTR_FIELD(unbiased).set_default(false).describe("Whether to use the unbiased estimation.");
128 }
129};
130} // namespace relay
131} // namespace tvm
132#endif // TVM_RELAY_ATTRS_REDUCE_H_
133