tvm
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 
30 namespace tvm {
31 namespace relax {
32 
34 struct 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 
47 struct 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;
73  ffi::Optional<ffi::Array<IntImm>> axis_separators;
79  ffi::Optional<ffi::Array<IntImm>> input_axis_separators;
80 
81  static void RegisterReflection() {
82  namespace refl = tvm::ffi::reflection;
83  refl::ObjectDef<LayoutTransformAttrs>()
84  .def_ro("index_map", &LayoutTransformAttrs::index_map,
85  "The layout transformation to apply.")
86  .def_ro(
87  "pad_value", &LayoutTransformAttrs::pad_value,
88  "The specific value to be used to pad if the layout transform would result in implicit "
89  "padding. If not specified, the compiler is free to choose any value.")
90  .def_ro("axis_separators", &LayoutTransformAttrs::axis_separators,
91  "The separators between input axes when generating flat output axes")
92  .def_ro("input_axis_separators", &LayoutTransformAttrs::input_axis_separators,
93  "The separators between axes to regenerate output");
94  }
95  TVM_FFI_DECLARE_OBJECT_INFO_FINAL("relax.attrs.LayoutTransformAttrs", LayoutTransformAttrs,
96  AttrsNode);
97 }; // struct LayoutTransformAttrs
98 
100 struct PermuteDimsAttrs : public AttrsNode {
101  ffi::Optional<ffi::Array<int64_t>> axes;
102 
103  static void RegisterReflection() {
104  namespace refl = tvm::ffi::reflection;
105  refl::ObjectDef<PermuteDimsAttrs>().def_ro(
106  "axes", &PermuteDimsAttrs::axes, "The target axes order, reverse order if not specified.");
107  }
109 }; // struct PermuteDimsAttrs
110 
112 struct SplitAttrs : public AttrsNode {
113  ffi::ObjectRef indices_or_sections;
114  int axis;
115 
116  static void RegisterReflection() {
117  namespace refl = tvm::ffi::reflection;
118  refl::ObjectDef<SplitAttrs>()
119  .def_ro("indices_or_sections", &SplitAttrs::indices_or_sections,
120  "The input array of indices or the number of split sections.")
121  .def_ro("axis", &SplitAttrs::axis, "The axis to be splitted");
122  }
124 }; // struct SplitAttrs
125 
127 struct SqueezeAttrs : public AttrsNode {
128  ffi::Optional<ffi::Array<int64_t>> axis;
129 
130  static void RegisterReflection() {
131  namespace refl = tvm::ffi::reflection;
132  refl::ObjectDef<SqueezeAttrs>().def_ro("axis", &SqueezeAttrs::axis,
133  "The axis to squeeze in the input tensor."
134  "If `axis = None`, all axis of dimension 1 get squeezed;"
135  "Else, the dimension in axes get squeezed."
136  "It is an error if an axis does not has dimension 1.");
137  }
139 }; // struct SqueezeAttrs
140 
142 struct StackAttrs : public AttrsNode {
143  ffi::Optional<int64_t> axis;
144 
145  static void RegisterReflection() {
146  namespace refl = tvm::ffi::reflection;
147  refl::ObjectDef<StackAttrs>().def_ro(
148  "axis", &StackAttrs::axis,
149  "The axis along which to stack the input tensors. "
150  "The axis will be inserted at this position in the output, "
151  "so it must be in range [-ndim-1, ndim] where ndim is the "
152  "number of dimensions of the input tensors.");
153  }
155 }; // struct StackAttrs
156 
158 struct RepeatAttrs : public AttrsNode {
159  int repeats;
160  ffi::Optional<int64_t> axis;
161 
162  static void RegisterReflection() {
163  namespace refl = tvm::ffi::reflection;
164  refl::ObjectDef<RepeatAttrs>()
165  .def_ro("repeats", &RepeatAttrs::repeats, "The number of repetitions.")
166  .def_ro("axis", &RepeatAttrs::axis,
167  "The axis along which to repeat values. The negative numbers are interpreted "
168  "counting from the backward. By default, use the flattened input array, and "
169  "return a flat output array.");
170  }
172 }; // struct RepeatAttrs
173 
175 struct TileAttrs : public AttrsNode {
176  ffi::Array<int64_t> repeats;
177 
178  static void RegisterReflection() {
179  namespace refl = tvm::ffi::reflection;
180  refl::ObjectDef<TileAttrs>().def_ro("repeats", &TileAttrs::repeats,
181  "The number of repetitions of data along each axis.");
182  }
184 }; // struct TileAttrs
185 
187 struct FlipAttrs : public AttrsNode {
188  int64_t axis;
189 
190  static void RegisterReflection() {
191  namespace refl = tvm::ffi::reflection;
192  refl::ObjectDef<FlipAttrs>().def_ro("axis", &FlipAttrs::axis,
193  "The axis along which to flip over.");
194  }
196 }; // struct FlipAttrs
197 
200  int64_t seq_axis;
201  int64_t batch_axis;
202 
203  static void RegisterReflection() {
204  namespace refl = tvm::ffi::reflection;
205  refl::ObjectDef<ReverseSequenceAttrs>()
206  .def_ro("seq_axis", &ReverseSequenceAttrs::seq_axis,
207  "The axis along which to reverse variable length slices.")
208  .def_ro("batch_axis", &ReverseSequenceAttrs::batch_axis,
209  "The axis that indexes the batch.");
210  }
211  TVM_FFI_DECLARE_OBJECT_INFO_FINAL("relax.attrs.ReverseSequenceAttrs", ReverseSequenceAttrs,
212  AttrsNode);
213 }; // struct ReverseSequenceAttrs
214 
217  int64_t axis;
218 
219  static void RegisterReflection() {
220  namespace refl = tvm::ffi::reflection;
221  refl::ObjectDef<GatherElementsAttrs>().def_ro("axis", &GatherElementsAttrs::axis,
222  "The axis along which to index.",
223  refl::DefaultValue(0));
224  }
225  TVM_FFI_DECLARE_OBJECT_INFO_FINAL("relax.attrs.GatherElementsAttrs", GatherElementsAttrs,
226  AttrsNode);
227 }; // struct GatherElementsAttrs
228 
230 struct GatherNDAttrs : public AttrsNode {
231  int64_t batch_dims;
232 
233  static void RegisterReflection() {
234  namespace refl = tvm::ffi::reflection;
235  refl::ObjectDef<GatherNDAttrs>().def_ro("batch_dims", &GatherNDAttrs::batch_dims,
236  "The number of batch dims.", refl::DefaultValue(0));
237  }
239 }; // struct GatherNDAttrs
240 
242 struct IndexPutAttrs : public AttrsNode {
244 
245  static void RegisterReflection() {
246  namespace refl = tvm::ffi::reflection;
247  refl::ObjectDef<IndexPutAttrs>().def_ro(
248  "accumulate", &IndexPutAttrs::accumulate,
249  "Whether to accumulate (add) values rather than replace. "
250  "If true, performs tensor[indices] += values, "
251  "otherwise performs tensor[indices] = values.",
252  refl::DefaultValue(false));
253  }
255 }; // struct IndexPutAttrs
256 
258 struct MeshgridAttrs : public AttrsNode {
259  ffi::Optional<ffi::String> indexing;
260 
261  static void RegisterReflection() {
262  namespace refl = tvm::ffi::reflection;
263  refl::ObjectDef<MeshgridAttrs>().def_ro("indexing", &MeshgridAttrs::indexing,
264  "Specifies how the grid dimensions are ordered.");
265  }
267 };
268 
271  int64_t axis;
272  ffi::String reduction;
273 
274  static void RegisterReflection() {
275  namespace refl = tvm::ffi::reflection;
276  refl::ObjectDef<ScatterElementsAttrs>()
277  .def_ro("axis", &ScatterElementsAttrs::axis, "The axis over which to select values.",
278  refl::DefaultValue(0))
279  .def_ro("reduction", &ScatterElementsAttrs::reduction,
280  "Reduction mode of the scatter elements, "
281  "either \"update\", \"add\", \"mul\", \"mean\", \"min\" or \"max\".",
282  refl::DefaultValue("update"));
283  }
284  TVM_FFI_DECLARE_OBJECT_INFO_FINAL("relax.attrs.ScatterElementsAttrs", ScatterElementsAttrs,
285  AttrsNode);
286 }; // struct ScatterElementsAttrs
287 
289 struct ScatterNDAttrs : public AttrsNode {
290  ffi::String reduction;
291 
292  static void RegisterReflection() {
293  namespace refl = tvm::ffi::reflection;
294  refl::ObjectDef<ScatterNDAttrs>().def_ro(
295  "reduction", &ScatterNDAttrs::reduction,
296  "Accumulation mode of the ScatterND, "
297  "either \"update\", \"add\", \"mul\", \"min\" or \"max\".",
298  refl::DefaultValue("update"));
299  }
301 }; // struct ScatterNDAttrs
302 
304 struct SliceScatterAttrs : public AttrsNode {
305  int axis;
306 
307  static void RegisterReflection() {
308  namespace refl = tvm::ffi::reflection;
309  refl::ObjectDef<SliceScatterAttrs>().def_ro("axis", &SliceScatterAttrs::axis,
310  "the dimension to insert the slice into ",
311  refl::DefaultValue(0));
312  }
314 }; // struct SliceScatterAttrs
315 
317 struct OneHotAttrs : public AttrsNode {
318  int depth;
319  int axis;
320 
321  static void RegisterReflection() {
322  namespace refl = tvm::ffi::reflection;
323  refl::ObjectDef<OneHotAttrs>()
324  .def_ro("depth", &OneHotAttrs::depth, "Depth of the one hot dimension.")
325  .def_ro("axis", &OneHotAttrs::axis, "Axis to fill.", refl::DefaultValue(-1));
326  }
328 }; // struct OneHotAttrs
329 
330 } // namespace relax
331 } // namespace tvm
332 
333 #endif // TVM_RELAX_ATTRS_MANIPULATE_H_
Base class of all attribute class.
Definition: attrs.h:49
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:187
static void RegisterReflection()
Definition: manipulate.h:190
TVM_FFI_DECLARE_OBJECT_INFO_FINAL("relax.attrs.FlipAttrs", FlipAttrs, AttrsNode)
int64_t axis
Definition: manipulate.h:188
Attributes used in gather_elements operators.
Definition: manipulate.h:216
int64_t axis
Definition: manipulate.h:217
static void RegisterReflection()
Definition: manipulate.h:219
TVM_FFI_DECLARE_OBJECT_INFO_FINAL("relax.attrs.GatherElementsAttrs", GatherElementsAttrs, AttrsNode)
Attributes used in gather_nd operators.
Definition: manipulate.h:230
int64_t batch_dims
Definition: manipulate.h:231
TVM_FFI_DECLARE_OBJECT_INFO_FINAL("relax.attrs.GatherNDAttrs", GatherNDAttrs, AttrsNode)
static void RegisterReflection()
Definition: manipulate.h:233
Attributes used in index_put operator.
Definition: manipulate.h:242
TVM_FFI_DECLARE_OBJECT_INFO_FINAL("relax.attrs.IndexPutAttrs", IndexPutAttrs, AttrsNode)
bool accumulate
Definition: manipulate.h:243
static void RegisterReflection()
Definition: manipulate.h:245
Attributes used in layout_transform operator.
Definition: manipulate.h:62
ffi::Optional< ffi::Array< IntImm > > axis_separators
Definition: manipulate.h:73
static void RegisterReflection()
Definition: manipulate.h:81
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)
ffi::Optional< ffi::Array< IntImm > > input_axis_separators
Definition: manipulate.h:79
Attribute used in meshgrid operator.
Definition: manipulate.h:258
ffi::Optional< ffi::String > indexing
Definition: manipulate.h:259
TVM_FFI_DECLARE_OBJECT_INFO_FINAL("relax.attrs.MeshgridAttrs", MeshgridAttrs, AttrsNode)
static void RegisterReflection()
Definition: manipulate.h:261
Attributes used in one_hot operator.
Definition: manipulate.h:317
static void RegisterReflection()
Definition: manipulate.h:321
int axis
Definition: manipulate.h:319
TVM_FFI_DECLARE_OBJECT_INFO_FINAL("relax.attrs.OneHotAttrs", OneHotAttrs, AttrsNode)
int depth
Definition: manipulate.h:318
Attributes used in permute_dims operator.
Definition: manipulate.h:100
static void RegisterReflection()
Definition: manipulate.h:103
ffi::Optional< ffi::Array< int64_t > > axes
Definition: manipulate.h:101
TVM_FFI_DECLARE_OBJECT_INFO_FINAL("relax.attrs.PermuteDimsAttrs", PermuteDimsAttrs, AttrsNode)
Attributes used in repeat operators.
Definition: manipulate.h:158
ffi::Optional< int64_t > axis
Definition: manipulate.h:160
TVM_FFI_DECLARE_OBJECT_INFO_FINAL("relax.attrs.RepeatAttrs", RepeatAttrs, AttrsNode)
int repeats
Definition: manipulate.h:159
static void RegisterReflection()
Definition: manipulate.h:162
Attributes used in reverse_sequence operators.
Definition: manipulate.h:199
int64_t batch_axis
Definition: manipulate.h:201
static void RegisterReflection()
Definition: manipulate.h:203
int64_t seq_axis
Definition: manipulate.h:200
TVM_FFI_DECLARE_OBJECT_INFO_FINAL("relax.attrs.ReverseSequenceAttrs", ReverseSequenceAttrs, AttrsNode)
Attributes used in scatter_elements operators.
Definition: manipulate.h:270
ffi::String reduction
Definition: manipulate.h:272
TVM_FFI_DECLARE_OBJECT_INFO_FINAL("relax.attrs.ScatterElementsAttrs", ScatterElementsAttrs, AttrsNode)
static void RegisterReflection()
Definition: manipulate.h:274
int64_t axis
Definition: manipulate.h:271
Attributes used in scatter_nd operators.
Definition: manipulate.h:289
TVM_FFI_DECLARE_OBJECT_INFO_FINAL("relax.attrs.ScatterNDAttrs", ScatterNDAttrs, AttrsNode)
static void RegisterReflection()
Definition: manipulate.h:292
ffi::String reduction
Definition: manipulate.h:290
Attributes used in slice_scatter operator.
Definition: manipulate.h:304
static void RegisterReflection()
Definition: manipulate.h:307
int axis
Definition: manipulate.h:305
TVM_FFI_DECLARE_OBJECT_INFO_FINAL("relax.attrs.SliceScatterAttrs", SliceScatterAttrs, AttrsNode)
Attributes used in split operator.
Definition: manipulate.h:112
static void RegisterReflection()
Definition: manipulate.h:116
TVM_FFI_DECLARE_OBJECT_INFO_FINAL("relax.attrs.SplitAttrs", SplitAttrs, AttrsNode)
ffi::ObjectRef indices_or_sections
Definition: manipulate.h:113
int axis
Definition: manipulate.h:114
Attributes used in squeeze operators.
Definition: manipulate.h:127
TVM_FFI_DECLARE_OBJECT_INFO_FINAL("relax.attrs.SqueezeAttrs", SqueezeAttrs, AttrsNode)
static void RegisterReflection()
Definition: manipulate.h:130
ffi::Optional< ffi::Array< int64_t > > axis
Definition: manipulate.h:128
Attributes used in stack operators.
Definition: manipulate.h:142
ffi::Optional< int64_t > axis
Definition: manipulate.h:143
static void RegisterReflection()
Definition: manipulate.h:145
TVM_FFI_DECLARE_OBJECT_INFO_FINAL("relax.attrs.StackAttrs", StackAttrs, AttrsNode)
Attributes used in tile operators.
Definition: manipulate.h:175
TVM_FFI_DECLARE_OBJECT_INFO_FINAL("relax.attrs.TileAttrs", TileAttrs, AttrsNode)
static void RegisterReflection()
Definition: manipulate.h:178
ffi::Array< int64_t > repeats
Definition: manipulate.h:176