tvm
sorting.h
Go to the documentation of this file.
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 
24 #ifndef TVM_RELAX_ATTRS_SORTING_H_
25 #define TVM_RELAX_ATTRS_SORTING_H_
26 
27 #include <tvm/relax/expr.h>
28 #include <tvm/tir/index_map.h>
29 
30 namespace tvm {
31 namespace relax {
32 
34 struct SortAttrs : public AttrsNodeReflAdapter<SortAttrs> {
35  int axis;
36  bool descending;
37 
38  static void RegisterReflection() {
39  namespace refl = tvm::ffi::reflection;
40  refl::ObjectDef<SortAttrs>()
41  .def_ro("axis", &SortAttrs::axis,
42  "Axis along which the sort is computed."
43  "The default the last axis is used.",
44  refl::DefaultValue(-1))
45  .def_ro("descending", &SortAttrs::descending,
46  "Whether to sort in descending order."
47  "If it is not specified, it defaults to the ascending order.",
48  refl::DefaultValue(false));
49  }
50 
51  static constexpr const char* _type_key = "relax.attrs.SortAttrs";
53 }; // struct SortAttrs
54 
56 struct ArgsortAttrs : public AttrsNodeReflAdapter<ArgsortAttrs> {
57  int axis;
58  bool descending;
60 
61  static void RegisterReflection() {
62  namespace refl = tvm::ffi::reflection;
63  refl::ObjectDef<ArgsortAttrs>()
64  .def_ro("axis", &ArgsortAttrs::axis,
65  "Axis along which the argsort is computed."
66  "The default the last axis is used.",
67  refl::DefaultValue(-1))
68  .def_ro("descending", &ArgsortAttrs::descending,
69  "Whether to argsort in descending order."
70  "If it is not specified, it defaults to the ascending order.",
71  refl::DefaultValue(false))
72  .def_ro("dtype", &ArgsortAttrs::dtype, "DType of the output indices.",
73  refl::DefaultValue(NullValue<DataType>()));
74  }
75 
76  static constexpr const char* _type_key = "relax.attrs.ArgsortAttrs";
78 }; // struct ArgsortAttrs
79 
81 struct TopKAttrs : public AttrsNodeReflAdapter<TopKAttrs> {
82  int k;
83  int axis;
84  bool largest;
85  String ret_type;
87 
88  static void RegisterReflection() {
89  namespace refl = tvm::ffi::reflection;
90  refl::ObjectDef<TopKAttrs>()
91  .def_ro("k", &TopKAttrs::k, "Number of top elements to select")
92  .def_ro("axis", &TopKAttrs::axis, "Axis along which to sort the input tensor.",
93  refl::DefaultValue(-1))
94  .def_ro("ret_type", &TopKAttrs::ret_type,
95  "The return type [both, values, indices]."
96  "both - return both top k data and indices."
97  "values - return top k data only."
98  "indices - return top k indices only.",
99  refl::DefaultValue("both"))
100  .def_ro("largest", &TopKAttrs::largest,
101  "Whether to return largest or smallest elements."
102  "By default, return the largest k elements.",
103  refl::DefaultValue(true))
104  .def_ro("dtype", &TopKAttrs::dtype, "Data type of the output indices.",
105  refl::DefaultValue(NullValue<DataType>()));
106  }
107 
108  static constexpr const char* _type_key = "relax.attrs.TopKAttrs";
110 }; // struct TopKAttrs
111 
112 } // namespace relax
113 } // namespace tvm
114 
115 #endif // TVM_RELAX_ATTRS_SORTING_H_
Adapter for AttrsNode with the new reflection API.
Definition: attrs.h:384
Base class of all attribute class.
Definition: attrs.h:103
Runtime primitive data type.
Definition: data_type.h:47
Defines a remapping of buffer indices.
Definition: repr_printer.h:91
Performance counters for profiling via the PAPI library.
Definition: analyzer.h:37
DataType NullValue< DataType >()
Definition: attrs.h:61
Attributes used in argsort operator.
Definition: sorting.h:56
static constexpr const char * _type_key
Definition: sorting.h:76
static void RegisterReflection()
Definition: sorting.h:61
TVM_FFI_DECLARE_FINAL_OBJECT_INFO(ArgsortAttrs, BaseAttrsNode)
DataType dtype
Definition: sorting.h:59
int axis
Definition: sorting.h:57
bool descending
Definition: sorting.h:58
Attributes used in sort operator.
Definition: sorting.h:34
static void RegisterReflection()
Definition: sorting.h:38
bool descending
Definition: sorting.h:36
TVM_FFI_DECLARE_FINAL_OBJECT_INFO(SortAttrs, BaseAttrsNode)
int axis
Definition: sorting.h:35
static constexpr const char * _type_key
Definition: sorting.h:51
Attributes used in topk operator.
Definition: sorting.h:81
int k
Definition: sorting.h:82
String ret_type
Definition: sorting.h:85
DataType dtype
Definition: sorting.h:86
TVM_FFI_DECLARE_FINAL_OBJECT_INFO(TopKAttrs, BaseAttrsNode)
static constexpr const char * _type_key
Definition: sorting.h:108
int axis
Definition: sorting.h:83
static void RegisterReflection()
Definition: sorting.h:88
bool largest
Definition: sorting.h:84