tvm
frame.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 #ifndef TVM_SCRIPT_IR_BUILDER_TIR_FRAME_H_
20 #define TVM_SCRIPT_IR_BUILDER_TIR_FRAME_H_
21 
24 #include <tvm/tir/stmt.h>
25 
26 namespace tvm {
27 namespace script {
28 namespace ir_builder {
29 namespace tir {
30 
37  public:
40 
43  v->Visit("stmts", &stmts);
44  }
45 
46  static constexpr const char* _type_key = "script.ir_builder.tir.TIRFrame";
48 };
49 
55 class TIRFrame : public IRBuilderFrame {
56  public:
58 
59  protected:
60  TIRFrame() = default;
61 };
62 
69  public:
86 
89  v->Visit("name", &name);
90  v->Visit("args", &args);
91  v->Visit("ret_type", &ret_type);
92  v->Visit("buffer_map", &buffer_map);
93  v->Visit("preflattened_buffer_map", &preflattened_buffer_map);
94  v->Visit("attrs", &attrs);
95  v->Visit("env_threads", &env_threads);
96  v->Visit("root_alloc_buffers", &root_alloc_buffers);
97  }
98 
99  static constexpr const char* _type_key = "script.ir_builder.tir.PrimFuncFrame";
101 
102  public:
107  void ExitWithScope() final;
108 };
109 
115 class PrimFuncFrame : public TIRFrame {
116  public:
118 };
119 
125 class BlockFrameNode : public TIRFrameNode {
126  public:
152 
155  v->Visit("name", &name);
156  v->Visit("iter_vars", &iter_vars);
157  v->Visit("reads", &reads);
158  v->Visit("writes", &writes);
159  v->Visit("init", &init);
160  v->Visit("alloc_buffers", &alloc_buffers);
161  v->Visit("match_buffers", &match_buffers);
162  v->Visit("annotations", &annotations);
163  v->Visit("iter_values", &iter_values);
164  v->Visit("predicate", &predicate);
165  v->Visit("no_realize", &no_realize);
166  }
167 
168  static constexpr const char* _type_key = "script.ir_builder.tir.BlockFrame";
170 
171  public:
176  void ExitWithScope() final;
177 };
178 
185 class BlockFrame : public TIRFrame {
186  public:
188 };
189 
196  public:
198 
199  static constexpr const char* _type_key = "script.ir_builder.tir.BlockInitFrame";
201 
202  public:
207  void EnterWithScope() final;
212  void ExitWithScope() final;
213 };
214 
220 class BlockInitFrame : public TIRFrame {
221  public:
223 };
224 
230 class ForFrameNode : public TIRFrameNode {
231  public:
240  Array<tvm::tir::Var> loop_vars, Array<Range> loop_extents, tvm::tir::Stmt loop_body)>;
247 
250  v->Visit("vars", &vars);
251  v->Visit("doms", &doms);
252  // `f_make_for_loop` is not visited.
253  }
254 
255  static constexpr const char* _type_key = "script.ir_builder.tir.ForFrame";
257 
258  public:
263  void ExitWithScope() final;
264 };
265 
271 class ForFrame : public TIRFrame {
272  public:
274 };
275 
283  public:
288 
291  v->Visit("condition", &condition);
292  v->Visit("message", &message);
293  }
294 
295  static constexpr const char* _type_key = "script.ir_builder.tir.AssertFrame";
297 
298  public:
303  void ExitWithScope() final;
304 };
305 
311 class AssertFrame : public TIRFrame {
312  public:
314 };
315 
321 class LetFrameNode : public TIRFrameNode {
322  public:
327 
330  v->Visit("var", &var);
331  v->Visit("value", &value);
332  }
333 
334  static constexpr const char* _type_key = "script.ir_builder.tir.LetFrame";
336 
337  public:
342  void ExitWithScope() final;
343 };
344 
350 class LetFrame : public TIRFrame {
351  public:
353 };
354 
360  public:
367 
370  v->Visit("extent", &extent);
371  v->Visit("attr_key", &attr_key);
372  v->Visit("iter_var", &iter_var);
373  }
374 
375  static constexpr const char* _type_key = "script.ir_builder.tir.LaunchThreadFrame";
377 
378  public:
383  void ExitWithScope() final;
384 };
385 
391 class LaunchThreadFrame : public TIRFrame {
392  public:
395 };
396 
403  public:
410 
413  v->Visit("buffer_slice", &buffer_slice);
414  v->Visit("storage_scope", &storage_scope);
415  v->Visit("condition", &condition);
416  }
417 
418  static constexpr const char* _type_key = "script.ir_builder.tir.RealizeFrame";
420 
421  public:
426  void ExitWithScope() final;
427 };
428 
434 class RealizeFrame : public TIRFrame {
435  public:
437 };
438 
445  public:
458 
461  v->Visit("extents", &extents);
462  v->Visit("dtype", &dtype);
463  v->Visit("storage_scope", &storage_scope);
464  v->Visit("condition", &condition);
465  v->Visit("annotations", &annotations);
466  v->Visit("buffer", &buffer);
467  }
468 
469  static constexpr const char* _type_key = "script.ir_builder.tir.AllocateFrame";
471 
472  public:
477  void ExitWithScope() final;
478 };
479 
485 class AllocateFrame : public TIRFrame {
486  public:
488 };
489 
496  public:
507 
510  v->Visit("dtype", &dtype);
511  v->Visit("extents", &extents);
512  v->Visit("data", &data);
513  v->Visit("buffer", &buffer);
514  v->Visit("annotations", &annotations);
515  }
516 
517  static constexpr const char* _type_key = "script.ir_builder.tir.AllocateConstFrame";
519 
520  public:
525  void ExitWithScope() final;
526 };
527 
533 class AllocateConstFrame : public TIRFrame {
534  public:
537 };
543 class AttrFrameNode : public TIRFrameNode {
544  public:
551 
554  v->Visit("node", &node);
555  v->Visit("attr_key", &attr_key);
556  v->Visit("value", &value);
557  }
558 
559  static constexpr const char* _type_key = "script.ir_builder.tir.AttrFrame";
561 
562  public:
567  void ExitWithScope() final;
568 };
569 
575 class AttrFrame : public TIRFrame {
576  public:
578 };
579 
585 class WhileFrameNode : public TIRFrameNode {
586  public:
589 
592  v->Visit("condition", &condition);
593  }
594 
595  static constexpr const char* _type_key = "script.ir_builder.tir.WhileFrame";
597 
598  public:
603  void ExitWithScope() final;
604 };
605 
611 class WhileFrame : public TIRFrame {
612  public:
614 };
615 
621 class IfFrameNode : public TIRFrameNode {
622  public:
629 
632  v->Visit("condition", &condition);
633  v->Visit("then_stmts", &then_stmts);
634  v->Visit("else_stmts", &else_stmts);
635  }
636 
637  static constexpr const char* _type_key = "script.ir_builder.tir.IfFrame";
639 
640  public:
645  void ExitWithScope() final;
646 };
647 
653 class IfFrame : public TIRFrame {
654  public:
656 };
657 
663 class ThenFrameNode : public TIRFrameNode {
664  public:
665  static constexpr const char* _type_key = "script.ir_builder.tir.ThenFrame";
667 
668  public:
673  void EnterWithScope() final;
678  void ExitWithScope() final;
679 };
680 
686 class ThenFrame : public TIRFrame {
687  public:
689 };
690 
696 class ElseFrameNode : public TIRFrameNode {
697  public:
698  static constexpr const char* _type_key = "script.ir_builder.tir.ElseFrame";
700 
701  public:
706  void EnterWithScope() final;
711  void ExitWithScope() final;
712 };
713 
719 class ElseFrame : public TIRFrame {
720  public:
722 };
723 
725  public:
727 
730  v->Visit("buffer", &buffer);
731  }
732 
733  static constexpr const char* _type_key = "script.ir_builder.tir.DeclBufferFrame";
735 
736  public:
737  void ExitWithScope() final;
738 };
739 
740 class DeclBufferFrame : public TIRFrame {
741  public:
743 };
744 
745 } // namespace tir
746 } // namespace ir_builder
747 } // namespace script
748 } // namespace tvm
749 
750 #endif // TVM_SCRIPT_IR_BUILDER_TIR_FRAME_H_
void VisitAttrs(tvm::AttrVisitor *v)
Definition: frame.h:552
A frame represents the allocate constant.
Definition: frame.h:495
A frame represents the allocate.
Definition: frame.h:444
Managed reference to IfFrameNode.
Definition: frame.h:653
Managed reference to PrimFuncFrameNode.
Definition: frame.h:115
Managed reference to an IRBuilderFrameNode.
Definition: base.h:100
Optional< Map< String, ObjectRef > > attrs
Additional attributes storing the meta-data.
Definition: frame.h:81
virtual void EnterWithScope()
The method called when entering RAII scope.
A frame that represents attribute node.
Definition: frame.h:543
#define TVM_DEFINE_MUTABLE_NOTNULLABLE_OBJECT_REF_METHODS(TypeName, ParentType, ObjectName)
Definition: object.h:758
Map< String, ObjectRef > annotations
Additional annotation hints.
Definition: frame.h:455
A frame that represents the block.
Definition: frame.h:125
tvm::runtime::NDArray data
The data associated with the constant.
Definition: frame.h:502
Map< tvm::tir::Var, tvm::tir::Buffer > buffer_map
Maps some parameters to specific Buffer data structures.
Definition: frame.h:77
Array< tvm::tir::Buffer > root_alloc_buffers
The buffer allocated in root block.
Definition: frame.h:85
Optional< tvm::tir::Stmt > init
The init statement of the bolck.
Definition: frame.h:136
void VisitAttrs(tvm::AttrVisitor *v)
Definition: frame.h:590
Optional< Array< tvm::tir::BufferRegion > > reads
The read buffer regions of the block.
Definition: frame.h:132
Managed reference to LaunchThreadFrameNode.
Definition: frame.h:391
Managed reference to AllocateConstFrameNode.
Definition: frame.h:533
void VisitAttrs(tvm::AttrVisitor *v)
Definition: frame.h:728
tvm::tir::Buffer buffer
The buffer.
Definition: frame.h:457
Managed reference to BlockFrameNode.
Definition: frame.h:185
runtime implementation for LibTorch/TorchScript.
Definition: analyzer.h:36
Managed reference to RealizeFrameNode.
Definition: frame.h:434
PrimExpr message
The output error message when the assertion failed.
Definition: frame.h:287
Managed reference to WhileFrameNode.
Definition: frame.h:611
PrimExpr value
The value of the attribute.
Definition: frame.h:550
TVM_DECLARE_BASE_OBJECT_INFO(TIRFrameNode, IRBuilderFrameNode)
String storage_scope
The storage scope associated with this realization.
Definition: frame.h:407
a named variable in TIR
Definition: var.h:88
Array< Range > doms
The domains of iteration.
Definition: frame.h:244
Iteration Variable, represents an iteration over an integer interval.
Definition: var.h:301
Array< tvm::tir::Var > vars
The loop variable.
Definition: frame.h:242
Array< tvm::tir::IterVar > iter_vars
The variables of the block.
Definition: frame.h:130
PrimExpr condition
The PrimExpr to test.
Definition: frame.h:285
Array< PrimExpr > extents
The extents of the allocate.
Definition: frame.h:500
String attr_key
The attribute key, could be either virtual_thread or thread_extent.
Definition: frame.h:364
A frame that represents the for loop.
Definition: frame.h:230
Managed reference to BufferRegionNode.
Definition: stmt.h:1137
ObjectRef node
The node to annotate the attribute.
Definition: frame.h:546
Managed NDArray. The array is backed by reference counted blocks.
Definition: ndarray.h:59
A frame that represents while loop.
Definition: frame.h:585
Array< tvm::tir::Stmt > stmts
The Stmt within in this frame.
Definition: frame.h:39
Optional< Array< tvm::tir::Stmt > > else_stmts
The stetements in the false branch.
Definition: frame.h:628
A frame that represents else.
Definition: frame.h:696
void VisitAttrs(tvm::AttrVisitor *v)
Definition: frame.h:508
Map< tvm::tir::Var, tvm::tir::IterVar > env_threads
The variable map bound to thread env.
Definition: frame.h:83
void VisitAttrs(tvm::AttrVisitor *v)
Definition: frame.h:289
Visitor class to get the attributes of an AST/IR node. The content is going to be called for each fie...
Definition: reflection.h:52
Managed reference to LetFrameNode.
Definition: frame.h:350
TIR statements.
Optional< Array< tvm::tir::Stmt > > then_stmts
The statements in the true branch.
Definition: frame.h:626
String attr_key
Attribute type key.
Definition: frame.h:548
Runtime primitive data type.
Definition: data_type.h:41
Managed reference to ForFrameNode.
Definition: frame.h:271
void VisitAttrs(tvm::AttrVisitor *v)
Definition: frame.h:411
void VisitAttrs(tvm::AttrVisitor *v)
Definition: frame.h:328
Map< tvm::tir::Var, tvm::tir::Buffer > preflattened_buffer_map
The buffer map prior to flattening.
Definition: frame.h:79
void VisitAttrs(tvm::AttrVisitor *v)
Definition: frame.h:630
Array< tvm::tir::Var > args
Function parameters.
Definition: frame.h:73
Array, container representing a contiguous sequence of ObjectRefs.
Definition: array.h:289
void VisitAttrs(tvm::AttrVisitor *v)
Definition: base.h:69
A frame represents the let binding expression, which binds a var.
Definition: frame.h:321
A frame that represents the assert statement. Proceeds if the condition is true, otherwise aborts wit...
Definition: frame.h:282
void VisitAttrs(tvm::AttrVisitor *v)
Definition: frame.h:368
void VisitAttrs(tvm::AttrVisitor *v)
Definition: frame.h:153
Managed reference to TIRFrameNode.
Definition: frame.h:55
Container of all statements.
Definition: stmt.h:57
String storage_scope
The storage scope.
Definition: frame.h:451
Optional< Map< String, ObjectRef > > annotations
The annotation of the block.
Definition: frame.h:142
tvm::tir::Buffer buffer
Definition: frame.h:726
PrimExpr extent
The extent of environment thread.
Definition: frame.h:362
Reference to string objects.
Definition: string.h:97
void VisitAttrs(tvm::AttrVisitor *v)
Definition: frame.h:87
Array< PrimExpr > iter_values
The corresponding values of the iter vars.
Definition: frame.h:144
Optional< String > name
The name of the block.
Definition: frame.h:71
PrimExpr value
The value we bind var to.
Definition: frame.h:326
Array< PrimExpr > extents
The extents of the allocate.
Definition: frame.h:447
Array< tvm::tir::Buffer > alloc_buffers
The buffer allocated in the block.
Definition: frame.h:138
Optional< Type > ret_type
The return type of the function.
Definition: frame.h:75
PrimExpr condition
The termination condition of while.
Definition: frame.h:588
A frame that represents the PrimFunc containing TIR statements.
Definition: frame.h:68
bool no_realize
The flag whether to construct BlockRealize or Block.
Definition: frame.h:151
DataType dtype
The data type of the buffer.
Definition: frame.h:498
tvm::tir::Var var
The variable we bind to.
Definition: frame.h:324
PrimExpr condition
The condition of the if statement.
Definition: frame.h:624
Base class of all object reference.
Definition: object.h:511
A frame that represents if statement.
Definition: frame.h:621
DataType dtype
The data type of the buffer.
Definition: frame.h:449
Array< tvm::tir::MatchBufferRegion > match_buffers
The match buffer regions.
Definition: frame.h:140
Managed reference to AssertFrameNode.
Definition: frame.h:311
Map< String, ObjectRef > annotations
Additional annotations about the allocation.
Definition: frame.h:506
tvm::tir::BufferRegion buffer_slice
The region of buffer access.
Definition: frame.h:405
Buffer is a symbolic n-darray structure. It is a composition of primitive symbolic types...
Definition: buffer.h:160
#define TVM_DECLARE_FINAL_OBJECT_INFO(TypeName, ParentType)
helper macro to declare type information in a final class.
Definition: object.h:671
A frame that represents the block initialization statment.
Definition: frame.h:195
void VisitAttrs(tvm::AttrVisitor *v)
Definition: frame.h:197
String name
The name of the block.
Definition: frame.h:128
Managed reference to ThenFrameNode.
Definition: frame.h:686
FMakeForLoop f_make_for_loop
The for loop generating function.
Definition: frame.h:246
PrimExpr condition
The condition.
Definition: frame.h:453
The LaunchThreadFrameNode.
Definition: frame.h:359
A frame that represents then.
Definition: frame.h:663
Map container of NodeRef->NodeRef in DSL graph. Map implements copy on write semantics, which means map is mutable but copy will happen when array is referenced in more than two places.
Definition: map.h:1271
virtual void ExitWithScope()
The method called when exiting RAII scope.
Optional< PrimExpr > predicate
The predicate of the block realization, the block will only be executed when the predicate is true...
Definition: frame.h:149
Optional container that to represent to a Nullable variant of T.
Definition: optional.h:51
tvm::tir::Buffer buffer
The buffer.
Definition: frame.h:504
PrimExpr condition
The condition expression.
Definition: frame.h:409
void VisitAttrs(tvm::AttrVisitor *v)
Definition: frame.h:248
Reference to PrimExprNode.
Definition: expr.h:112
static constexpr const char * _type_key
Definition: frame.h:46
Managed reference to AttrFrameNode.
Definition: frame.h:575
Managed reference to ElseFrameNode.
Definition: frame.h:719
Optional< Array< tvm::tir::BufferRegion > > writes
The write buffer regions of the block.
Definition: frame.h:134
A frame that represents realization.
Definition: frame.h:402
Managed reference to AllocateFrameNode.
Definition: frame.h:485
void VisitAttrs(tvm::AttrVisitor *v)
Definition: frame.h:459
tvm::tir::IterVar iter_var
The iteration variable.
Definition: frame.h:366
Managed reference to BlockInitFrameNode.
Definition: frame.h:220
A base frame that represents the TIR fame with body of statements.
Definition: frame.h:36
void VisitAttrs(tvm::AttrVisitor *v)
Definition: frame.h:41