tvm
Loading...
Searching...
No Matches
manipulate.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_MANIPULATE_H_
25#define TVM_RELAX_ATTRS_MANIPULATE_H_
26
27#include <tvm/relax/expr.h>
28#include <tvm/tirx/index_map.h>
29
30namespace tvm {
31namespace relax {
32
34struct ConcatAttrs : public AttrsNode {
35 ffi::Optional<int64_t> axis;
36
37 static void RegisterReflection() {
38 namespace refl = tvm::ffi::reflection;
39 refl::ObjectDef<ConcatAttrs>().def_ro("axis", &ConcatAttrs::axis,
40 "The axis at which the input arrays are concatenated."
41 "Should lie in range `[-ndim, ndim)`.");
42 }
44}; // struct ConcatAttrs
45
47struct ExpandDimsAttrs : public AttrsNode {
48 ffi::Array<int64_t> axis;
49
50 static void RegisterReflection() {
51 namespace refl = tvm::ffi::reflection;
52 refl::ObjectDef<ExpandDimsAttrs>().def_ro(
53 "axis", &ExpandDimsAttrs::axis,
54 "The axes at which the input array are expanded. "
55 "All values are required to lie in range `[-data.ndim - 1, data.ndim]`, "
56 "with the convention of negative indexing.");
57 }
59}; // struct ExpandDimsAttrs
60
64 // pad_value is chosen to be of PrimExpr type, as it represents constant TIR POD expression. This
65 // needs to be revisited in case PrimExpr is evolved to represent symbolic expression in future.
66 ffi::Optional<PrimExpr> pad_value;
67
68 static void RegisterReflection() {
69 namespace refl = tvm::ffi::reflection;
70 refl::ObjectDef<LayoutTransformAttrs>()
71 .def_ro("index_map", &LayoutTransformAttrs::index_map,
72 "The layout transformation to apply.")
73 .def_ro(
75 "The specific value to be used to pad if the layout transform would result in implicit "
76 "padding. If not specified, the compiler is free to choose any value.");
77 }
78 TVM_FFI_DECLARE_OBJECT_INFO_FINAL("relax.attrs.LayoutTransformAttrs", LayoutTransformAttrs,
79 AttrsNode);
80}; // struct LayoutTransformAttrs
81
83struct PermuteDimsAttrs : public AttrsNode {
84 ffi::Optional<ffi::Array<int64_t>> axes;
85
86 static void RegisterReflection() {
87 namespace refl = tvm::ffi::reflection;
88 refl::ObjectDef<PermuteDimsAttrs>().def_ro(
89 "axes", &PermuteDimsAttrs::axes, "The target axes order, reverse order if not specified.");
90 }
92}; // struct PermuteDimsAttrs
93
95struct SplitAttrs : public AttrsNode {
96 ffi::ObjectRef indices_or_sections;
97 int axis;
98
99 static void RegisterReflection() {
100 namespace refl = tvm::ffi::reflection;
101 refl::ObjectDef<SplitAttrs>()
102 .def_ro("indices_or_sections", &SplitAttrs::indices_or_sections,
103 "The input array of indices or the number of split sections.")
104 .def_ro("axis", &SplitAttrs::axis, "The axis to be splitted");
105 }
107}; // struct SplitAttrs
108
110struct SqueezeAttrs : public AttrsNode {
111 ffi::Optional<ffi::Array<int64_t>> axis;
112
113 static void RegisterReflection() {
114 namespace refl = tvm::ffi::reflection;
115 refl::ObjectDef<SqueezeAttrs>().def_ro("axis", &SqueezeAttrs::axis,
116 "The axis to squeeze in the input tensor."
117 "If `axis = None`, all axis of dimension 1 get squeezed;"
118 "Else, the dimension in axes get squeezed."
119 "It is an error if an axis does not has dimension 1.");
120 }
122}; // struct SqueezeAttrs
123
125struct StackAttrs : public AttrsNode {
126 ffi::Optional<int64_t> axis;
127
128 static void RegisterReflection() {
129 namespace refl = tvm::ffi::reflection;
130 refl::ObjectDef<StackAttrs>().def_ro(
131 "axis", &StackAttrs::axis,
132 "The axis along which to stack the input tensors. "
133 "The axis will be inserted at this position in the output, "
134 "so it must be in range [-ndim-1, ndim] where ndim is the "
135 "number of dimensions of the input tensors.");
136 }
138}; // struct StackAttrs
139
141struct RepeatAttrs : public AttrsNode {
143 ffi::Optional<int64_t> axis;
144
145 static void RegisterReflection() {
146 namespace refl = tvm::ffi::reflection;
147 refl::ObjectDef<RepeatAttrs>()
148 .def_ro("repeats", &RepeatAttrs::repeats, "The number of repetitions.")
149 .def_ro("axis", &RepeatAttrs::axis,
150 "The axis along which to repeat values. The negative numbers are interpreted "
151 "counting from the backward. By default, use the flattened input array, and "
152 "return a flat output array.");
153 }
155}; // struct RepeatAttrs
156
158struct TileAttrs : public AttrsNode {
159 ffi::Array<int64_t> repeats;
160
161 static void RegisterReflection() {
162 namespace refl = tvm::ffi::reflection;
163 refl::ObjectDef<TileAttrs>().def_ro("repeats", &TileAttrs::repeats,
164 "The number of repetitions of data along each axis.");
165 }
167}; // struct TileAttrs
168
170struct FlipAttrs : public AttrsNode {
172
173 static void RegisterReflection() {
174 namespace refl = tvm::ffi::reflection;
175 refl::ObjectDef<FlipAttrs>().def_ro("axis", &FlipAttrs::axis,
176 "The axis along which to flip over.");
177 }
179}; // struct FlipAttrs
180
185
186 static void RegisterReflection() {
187 namespace refl = tvm::ffi::reflection;
188 refl::ObjectDef<ReverseSequenceAttrs>()
189 .def_ro("seq_axis", &ReverseSequenceAttrs::seq_axis,
190 "The axis along which to reverse variable length slices.")
191 .def_ro("batch_axis", &ReverseSequenceAttrs::batch_axis,
192 "The axis that indexes the batch.");
193 }
194 TVM_FFI_DECLARE_OBJECT_INFO_FINAL("relax.attrs.ReverseSequenceAttrs", ReverseSequenceAttrs,
195 AttrsNode);
196}; // struct ReverseSequenceAttrs
197
201
202 static void RegisterReflection() {
203 namespace refl = tvm::ffi::reflection;
204 refl::ObjectDef<GatherElementsAttrs>().def_ro("axis", &GatherElementsAttrs::axis,
205 "The axis along which to index.",
206 refl::DefaultValue(0));
207 }
208 TVM_FFI_DECLARE_OBJECT_INFO_FINAL("relax.attrs.GatherElementsAttrs", GatherElementsAttrs,
209 AttrsNode);
210}; // struct GatherElementsAttrs
211
213struct GatherNDAttrs : public AttrsNode {
215
216 static void RegisterReflection() {
217 namespace refl = tvm::ffi::reflection;
218 refl::ObjectDef<GatherNDAttrs>().def_ro("batch_dims", &GatherNDAttrs::batch_dims,
219 "The number of batch dims.", refl::DefaultValue(0));
220 }
222}; // struct GatherNDAttrs
223
225struct IndexPutAttrs : public AttrsNode {
227
228 static void RegisterReflection() {
229 namespace refl = tvm::ffi::reflection;
230 refl::ObjectDef<IndexPutAttrs>().def_ro(
231 "accumulate", &IndexPutAttrs::accumulate,
232 "Whether to accumulate (add) values rather than replace. "
233 "If true, performs tensor[indices] += values, "
234 "otherwise performs tensor[indices] = values.",
235 refl::DefaultValue(false));
236 }
238}; // struct IndexPutAttrs
239
241struct MeshgridAttrs : public AttrsNode {
242 ffi::Optional<ffi::String> indexing;
243
244 static void RegisterReflection() {
245 namespace refl = tvm::ffi::reflection;
246 refl::ObjectDef<MeshgridAttrs>().def_ro("indexing", &MeshgridAttrs::indexing,
247 "Specifies how the grid dimensions are ordered.");
248 }
250};
251
255 ffi::String reduction;
256
257 static void RegisterReflection() {
258 namespace refl = tvm::ffi::reflection;
259 refl::ObjectDef<ScatterElementsAttrs>()
260 .def_ro("axis", &ScatterElementsAttrs::axis, "The axis over which to select values.",
261 refl::DefaultValue(0))
262 .def_ro("reduction", &ScatterElementsAttrs::reduction,
263 "Reduction mode of the scatter elements, "
264 "either \"update\", \"add\", \"mul\", \"mean\", \"min\" or \"max\".",
265 refl::DefaultValue("update"));
266 }
267 TVM_FFI_DECLARE_OBJECT_INFO_FINAL("relax.attrs.ScatterElementsAttrs", ScatterElementsAttrs,
268 AttrsNode);
269}; // struct ScatterElementsAttrs
270
272struct ScatterNDAttrs : public AttrsNode {
273 ffi::String reduction;
274
275 static void RegisterReflection() {
276 namespace refl = tvm::ffi::reflection;
277 refl::ObjectDef<ScatterNDAttrs>().def_ro(
278 "reduction", &ScatterNDAttrs::reduction,
279 "Accumulation mode of the ScatterND, "
280 "either \"update\", \"add\", \"mul\", \"min\" or \"max\".",
281 refl::DefaultValue("update"));
282 }
284}; // struct ScatterNDAttrs
285
288 int axis;
289
290 static void RegisterReflection() {
291 namespace refl = tvm::ffi::reflection;
292 refl::ObjectDef<SliceScatterAttrs>().def_ro("axis", &SliceScatterAttrs::axis,
293 "the dimension to insert the slice into ",
294 refl::DefaultValue(0));
295 }
297}; // struct SliceScatterAttrs
298
300struct OneHotAttrs : public AttrsNode {
301 int depth;
302 int axis;
303
304 static void RegisterReflection() {
305 namespace refl = tvm::ffi::reflection;
306 refl::ObjectDef<OneHotAttrs>()
307 .def_ro("depth", &OneHotAttrs::depth, "Depth of the one hot dimension.")
308 .def_ro("axis", &OneHotAttrs::axis, "Axis to fill.", refl::DefaultValue(-1));
309 }
311}; // struct OneHotAttrs
312
313} // namespace relax
314} // namespace tvm
315
316#endif // TVM_RELAX_ATTRS_MANIPULATE_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
Definition index_map.h:192
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 concat operators.
Definition manipulate.h:34
static void RegisterReflection()
Definition manipulate.h:37
ffi::Optional< int64_t > axis
Definition manipulate.h:35
TVM_FFI_DECLARE_OBJECT_INFO_FINAL("relax.attrs.ConcatAttrs", ConcatAttrs, AttrsNode)
Attributes used in expand_dims operators.
Definition manipulate.h:47
static void RegisterReflection()
Definition manipulate.h:50
ffi::Array< int64_t > axis
Definition manipulate.h:48
TVM_FFI_DECLARE_OBJECT_INFO_FINAL("relax.attrs.ExpandDimsAttrs", ExpandDimsAttrs, AttrsNode)
Attributes used in flip operators.
Definition manipulate.h:170
static void RegisterReflection()
Definition manipulate.h:173
TVM_FFI_DECLARE_OBJECT_INFO_FINAL("relax.attrs.FlipAttrs", FlipAttrs, AttrsNode)
int64_t axis
Definition manipulate.h:171
Attributes used in gather_elements operators.
Definition manipulate.h:199
int64_t axis
Definition manipulate.h:200
static void RegisterReflection()
Definition manipulate.h:202
TVM_FFI_DECLARE_OBJECT_INFO_FINAL("relax.attrs.GatherElementsAttrs", GatherElementsAttrs, AttrsNode)
Attributes used in gather_nd operators.
Definition manipulate.h:213
int64_t batch_dims
Definition manipulate.h:214
TVM_FFI_DECLARE_OBJECT_INFO_FINAL("relax.attrs.GatherNDAttrs", GatherNDAttrs, AttrsNode)
static void RegisterReflection()
Definition manipulate.h:216
Attributes used in index_put operator.
Definition manipulate.h:225
TVM_FFI_DECLARE_OBJECT_INFO_FINAL("relax.attrs.IndexPutAttrs", IndexPutAttrs, AttrsNode)
bool accumulate
Definition manipulate.h:226
static void RegisterReflection()
Definition manipulate.h:228
Attributes used in layout_transform operator.
Definition manipulate.h:62
static void RegisterReflection()
Definition manipulate.h:68
ffi::Optional< PrimExpr > pad_value
Definition manipulate.h:66
tirx::IndexMap index_map
Definition manipulate.h:63
TVM_FFI_DECLARE_OBJECT_INFO_FINAL("relax.attrs.LayoutTransformAttrs", LayoutTransformAttrs, AttrsNode)
Attribute used in meshgrid operator.
Definition manipulate.h:241
ffi::Optional< ffi::String > indexing
Definition manipulate.h:242
TVM_FFI_DECLARE_OBJECT_INFO_FINAL("relax.attrs.MeshgridAttrs", MeshgridAttrs, AttrsNode)
static void RegisterReflection()
Definition manipulate.h:244
Attributes used in one_hot operator.
Definition manipulate.h:300
static void RegisterReflection()
Definition manipulate.h:304
int axis
Definition manipulate.h:302
TVM_FFI_DECLARE_OBJECT_INFO_FINAL("relax.attrs.OneHotAttrs", OneHotAttrs, AttrsNode)
int depth
Definition manipulate.h:301
Attributes used in permute_dims operator.
Definition manipulate.h:83
static void RegisterReflection()
Definition manipulate.h:86
ffi::Optional< ffi::Array< int64_t > > axes
Definition manipulate.h:84
TVM_FFI_DECLARE_OBJECT_INFO_FINAL("relax.attrs.PermuteDimsAttrs", PermuteDimsAttrs, AttrsNode)
Attributes used in repeat operators.
Definition manipulate.h:141
ffi::Optional< int64_t > axis
Definition manipulate.h:143
TVM_FFI_DECLARE_OBJECT_INFO_FINAL("relax.attrs.RepeatAttrs", RepeatAttrs, AttrsNode)
int repeats
Definition manipulate.h:142
static void RegisterReflection()
Definition manipulate.h:145
Attributes used in reverse_sequence operators.
Definition manipulate.h:182
int64_t batch_axis
Definition manipulate.h:184
static void RegisterReflection()
Definition manipulate.h:186
int64_t seq_axis
Definition manipulate.h:183
TVM_FFI_DECLARE_OBJECT_INFO_FINAL("relax.attrs.ReverseSequenceAttrs", ReverseSequenceAttrs, AttrsNode)
Attributes used in scatter_elements operators.
Definition manipulate.h:253
ffi::String reduction
Definition manipulate.h:255
TVM_FFI_DECLARE_OBJECT_INFO_FINAL("relax.attrs.ScatterElementsAttrs", ScatterElementsAttrs, AttrsNode)
static void RegisterReflection()
Definition manipulate.h:257
int64_t axis
Definition manipulate.h:254
Attributes used in scatter_nd operators.
Definition manipulate.h:272
TVM_FFI_DECLARE_OBJECT_INFO_FINAL("relax.attrs.ScatterNDAttrs", ScatterNDAttrs, AttrsNode)
static void RegisterReflection()
Definition manipulate.h:275
ffi::String reduction
Definition manipulate.h:273
Attributes used in slice_scatter operator.
Definition manipulate.h:287
static void RegisterReflection()
Definition manipulate.h:290
int axis
Definition manipulate.h:288
TVM_FFI_DECLARE_OBJECT_INFO_FINAL("relax.attrs.SliceScatterAttrs", SliceScatterAttrs, AttrsNode)
Attributes used in split operator.
Definition manipulate.h:95
static void RegisterReflection()
Definition manipulate.h:99
TVM_FFI_DECLARE_OBJECT_INFO_FINAL("relax.attrs.SplitAttrs", SplitAttrs, AttrsNode)
ffi::ObjectRef indices_or_sections
Definition manipulate.h:96
int axis
Definition manipulate.h:97
Attributes used in squeeze operators.
Definition manipulate.h:110
TVM_FFI_DECLARE_OBJECT_INFO_FINAL("relax.attrs.SqueezeAttrs", SqueezeAttrs, AttrsNode)
static void RegisterReflection()
Definition manipulate.h:113
ffi::Optional< ffi::Array< int64_t > > axis
Definition manipulate.h:111
Attributes used in stack operators.
Definition manipulate.h:125
ffi::Optional< int64_t > axis
Definition manipulate.h:126
static void RegisterReflection()
Definition manipulate.h:128
TVM_FFI_DECLARE_OBJECT_INFO_FINAL("relax.attrs.StackAttrs", StackAttrs, AttrsNode)
Attributes used in tile operators.
Definition manipulate.h:158
TVM_FFI_DECLARE_OBJECT_INFO_FINAL("relax.attrs.TileAttrs", TileAttrs, AttrsNode)
static void RegisterReflection()
Definition manipulate.h:161
ffi::Array< int64_t > repeats
Definition manipulate.h:159