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  }
51 }; // struct SortAttrs
52 
54 struct ArgsortAttrs : public AttrsNodeReflAdapter<ArgsortAttrs> {
55  int axis;
56  bool descending;
58 
59  static void RegisterReflection() {
60  namespace refl = tvm::ffi::reflection;
61  refl::ObjectDef<ArgsortAttrs>()
62  .def_ro("axis", &ArgsortAttrs::axis,
63  "Axis along which the argsort is computed."
64  "The default the last axis is used.",
65  refl::DefaultValue(-1))
66  .def_ro("descending", &ArgsortAttrs::descending,
67  "Whether to argsort in descending order."
68  "If it is not specified, it defaults to the ascending order.",
69  refl::DefaultValue(false))
70  .def_ro("dtype", &ArgsortAttrs::dtype, "DType of the output indices.",
71  refl::DefaultValue(NullValue<DataType>()));
72  }
74 }; // struct ArgsortAttrs
75 
77 struct TopKAttrs : public AttrsNodeReflAdapter<TopKAttrs> {
78  int k;
79  int axis;
80  bool largest;
81  ffi::String ret_type;
83 
84  static void RegisterReflection() {
85  namespace refl = tvm::ffi::reflection;
86  refl::ObjectDef<TopKAttrs>()
87  .def_ro("k", &TopKAttrs::k, "Number of top elements to select")
88  .def_ro("axis", &TopKAttrs::axis, "Axis along which to sort the input tensor.",
89  refl::DefaultValue(-1))
90  .def_ro("ret_type", &TopKAttrs::ret_type,
91  "The return type [both, values, indices]."
92  "both - return both top k data and indices."
93  "values - return top k data only."
94  "indices - return top k indices only.",
95  refl::DefaultValue("both"))
96  .def_ro("largest", &TopKAttrs::largest,
97  "Whether to return largest or smallest elements."
98  "By default, return the largest k elements.",
99  refl::DefaultValue(true))
100  .def_ro("dtype", &TopKAttrs::dtype, "Data type of the output indices.",
101  refl::DefaultValue(NullValue<DataType>()));
102  }
104 }; // struct TopKAttrs
105 
106 } // namespace relax
107 } // namespace tvm
108 
109 #endif // TVM_RELAX_ATTRS_SORTING_H_
Adapter for AttrsNode with the new reflection API.
Definition: attrs.h:385
Base class of all attribute class.
Definition: attrs.h:102
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:54
TVM_FFI_DECLARE_OBJECT_INFO_FINAL("relax.attrs.ArgsortAttrs", ArgsortAttrs, BaseAttrsNode)
static void RegisterReflection()
Definition: sorting.h:59
DataType dtype
Definition: sorting.h:57
int axis
Definition: sorting.h:55
bool descending
Definition: sorting.h:56
Attributes used in sort operator.
Definition: sorting.h:34
static void RegisterReflection()
Definition: sorting.h:38
bool descending
Definition: sorting.h:36
int axis
Definition: sorting.h:35
TVM_FFI_DECLARE_OBJECT_INFO_FINAL("relax.attrs.SortAttrs", SortAttrs, BaseAttrsNode)
Attributes used in topk operator.
Definition: sorting.h:77
int k
Definition: sorting.h:78
DataType dtype
Definition: sorting.h:82
ffi::String ret_type
Definition: sorting.h:81
TVM_FFI_DECLARE_OBJECT_INFO_FINAL("relax.attrs.TopKAttrs", TopKAttrs, BaseAttrsNode)
int axis
Definition: sorting.h:79
static void RegisterReflection()
Definition: sorting.h:84
bool largest
Definition: sorting.h:80