tvm
Loading...
Searching...
No Matches
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/tirx/index_map.h>
29
30namespace tvm {
31namespace relax {
32
34struct SortAttrs : public AttrsNode {
35 int axis;
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
54struct ArgsortAttrs : public AttrsNode {
55 int axis;
57 ffi::Optional<DLDataType> dtype;
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 }
73}; // struct ArgsortAttrs
74
76struct TopKAttrs : public AttrsNode {
77 int k;
78 int axis;
79 bool largest;
80 ffi::String ret_type;
81 ffi::Optional<DLDataType> dtype;
82
83 static void RegisterReflection() {
84 namespace refl = tvm::ffi::reflection;
85 refl::ObjectDef<TopKAttrs>()
86 .def_ro("k", &TopKAttrs::k, "Number of top elements to select")
87 .def_ro("axis", &TopKAttrs::axis, "Axis along which to sort the input tensor.",
88 refl::DefaultValue(-1))
89 .def_ro("ret_type", &TopKAttrs::ret_type,
90 "The return type [both, values, indices]."
91 "both - return both top k data and indices."
92 "values - return top k data only."
93 "indices - return top k indices only.",
94 refl::DefaultValue("both"))
95 .def_ro("largest", &TopKAttrs::largest,
96 "Whether to return largest or smallest elements."
97 "By default, return the largest k elements.",
98 refl::DefaultValue(true))
99 .def_ro("dtype", &TopKAttrs::dtype, "Data type of the output indices.");
100 }
102}; // struct TopKAttrs
103
104} // namespace relax
105} // namespace tvm
106
107#endif // TVM_RELAX_ATTRS_SORTING_H_
Base class of all attribute class.
Definition attrs.h:49
RAII wrapper function to enter and exit a context object similar to python's with syntax.
Definition with_context.h:59
Defines a remapping of buffer indices.
An object that builds and maintains block scope and StmtSref mapping for Dependence analysis.
Definition analyzer.h:40
Attributes used in argsort operator.
Definition sorting.h:54
ffi::Optional< DLDataType > dtype
Definition sorting.h:57
static void RegisterReflection()
Definition sorting.h:59
TVM_FFI_DECLARE_OBJECT_INFO_FINAL("relax.attrs.ArgsortAttrs", ArgsortAttrs, AttrsNode)
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, AttrsNode)
Attributes used in topk operator.
Definition sorting.h:76
int k
Definition sorting.h:77
ffi::Optional< DLDataType > dtype
Definition sorting.h:81
ffi::String ret_type
Definition sorting.h:80
int axis
Definition sorting.h:78
TVM_FFI_DECLARE_OBJECT_INFO_FINAL("relax.attrs.TopKAttrs", TopKAttrs, AttrsNode)
static void RegisterReflection()
Definition sorting.h:83
bool largest
Definition sorting.h:79