tvm
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
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:
84 
87  v->Visit("name", &name);
88  v->Visit("args", &args);
89  v->Visit("ret_type", &ret_type);
90  v->Visit("buffer_map", &buffer_map);
91  v->Visit("attrs", &attrs);
92  v->Visit("env_threads", &env_threads);
93  v->Visit("root_alloc_buffers", &root_alloc_buffers);
94  }
95 
96  static constexpr const char* _type_key = "script.ir_builder.tir.PrimFuncFrame";
98 
99  public:
104  void ExitWithScope() final;
105 };
106 
112 class PrimFuncFrame : public TIRFrame {
113  public:
115 };
116 
122 class BlockFrameNode : public TIRFrameNode {
123  public:
149 
152  v->Visit("name", &name);
153  v->Visit("iter_vars", &iter_vars);
154  v->Visit("reads", &reads);
155  v->Visit("writes", &writes);
156  v->Visit("init", &init);
157  v->Visit("alloc_buffers", &alloc_buffers);
158  v->Visit("match_buffers", &match_buffers);
159  v->Visit("annotations", &annotations);
160  v->Visit("iter_values", &iter_values);
161  v->Visit("predicate", &predicate);
162  v->Visit("no_realize", &no_realize);
163  }
164 
165  static constexpr const char* _type_key = "script.ir_builder.tir.BlockFrame";
167 
168  public:
173  void ExitWithScope() final;
174 };
175 
182 class BlockFrame : public TIRFrame {
183  public:
185 };
186 
193  public:
195 
196  static constexpr const char* _type_key = "script.ir_builder.tir.BlockInitFrame";
198 
199  public:
204  void EnterWithScope() final;
209  void ExitWithScope() final;
210 };
211 
217 class BlockInitFrame : public TIRFrame {
218  public:
220 };
221 
227 class ForFrameNode : public TIRFrameNode {
228  public:
237  Array<tvm::tir::Var> loop_vars, Array<Range> loop_extents, tvm::tir::Stmt loop_body)>;
244 
247  v->Visit("vars", &vars);
248  v->Visit("doms", &doms);
249  // `f_make_for_loop` is not visited.
250  }
251 
252  static constexpr const char* _type_key = "script.ir_builder.tir.ForFrame";
254 
255  public:
260  void ExitWithScope() final;
261 };
262 
268 class ForFrame : public TIRFrame {
269  public:
271 };
272 
280  public:
285 
288  v->Visit("condition", &condition);
289  v->Visit("message", &message);
290  }
291 
292  static constexpr const char* _type_key = "script.ir_builder.tir.AssertFrame";
294 
295  public:
300  void ExitWithScope() final;
301 };
302 
308 class AssertFrame : public TIRFrame {
309  public:
311 };
312 
318 class LetFrameNode : public TIRFrameNode {
319  public:
324 
327  v->Visit("var", &var);
328  v->Visit("value", &value);
329  }
330 
331  static constexpr const char* _type_key = "script.ir_builder.tir.LetFrame";
333 
334  public:
339  void ExitWithScope() final;
340 };
341 
347 class LetFrame : public TIRFrame {
348  public:
350 };
351 
357  public:
364 
367  v->Visit("extent", &extent);
368  v->Visit("attr_key", &attr_key);
369  v->Visit("iter_var", &iter_var);
370  }
371 
372  static constexpr const char* _type_key = "script.ir_builder.tir.LaunchThreadFrame";
374 
375  public:
380  void ExitWithScope() final;
381 };
382 
388 class LaunchThreadFrame : public TIRFrame {
389  public:
392 };
393 
400  public:
407 
410  v->Visit("buffer_slice", &buffer_slice);
411  v->Visit("storage_scope", &storage_scope);
412  v->Visit("condition", &condition);
413  }
414 
415  static constexpr const char* _type_key = "script.ir_builder.tir.RealizeFrame";
417 
418  public:
423  void ExitWithScope() final;
424 };
425 
431 class RealizeFrame : public TIRFrame {
432  public:
434 };
435 
442  public:
455 
458  v->Visit("extents", &extents);
459  v->Visit("dtype", &dtype);
460  v->Visit("storage_scope", &storage_scope);
461  v->Visit("condition", &condition);
462  v->Visit("annotations", &annotations);
463  v->Visit("buffer_var", &buffer_var);
464  }
465 
466  static constexpr const char* _type_key = "script.ir_builder.tir.AllocateFrame";
468 
469  public:
474  void ExitWithScope() final;
475 };
476 
482 class AllocateFrame : public TIRFrame {
483  public:
485 };
486 
493  public:
504 
507  v->Visit("dtype", &dtype);
508  v->Visit("extents", &extents);
509  v->Visit("data", &data);
510  v->Visit("buffer_var", &buffer_var);
511  v->Visit("annotations", &annotations);
512  }
513 
514  static constexpr const char* _type_key = "script.ir_builder.tir.AllocateConstFrame";
516 
517  public:
522  void ExitWithScope() final;
523 };
524 
530 class AllocateConstFrame : public TIRFrame {
531  public:
534 };
540 class AttrFrameNode : public TIRFrameNode {
541  public:
548 
551  v->Visit("node", &node);
552  v->Visit("attr_key", &attr_key);
553  v->Visit("value", &value);
554  }
555 
556  static constexpr const char* _type_key = "script.ir_builder.tir.AttrFrame";
558 
559  public:
564  void ExitWithScope() final;
565 };
566 
572 class AttrFrame : public TIRFrame {
573  public:
575 };
576 
582 class WhileFrameNode : public TIRFrameNode {
583  public:
586 
589  v->Visit("condition", &condition);
590  }
591 
592  static constexpr const char* _type_key = "script.ir_builder.tir.WhileFrame";
594 
595  public:
600  void ExitWithScope() final;
601 };
602 
608 class WhileFrame : public TIRFrame {
609  public:
611 };
612 
618 class IfFrameNode : public TIRFrameNode {
619  public:
626 
629  v->Visit("condition", &condition);
630  v->Visit("then_stmts", &then_stmts);
631  v->Visit("else_stmts", &else_stmts);
632  }
633 
634  static constexpr const char* _type_key = "script.ir_builder.tir.IfFrame";
636 
637  public:
642  void ExitWithScope() final;
643 };
644 
650 class IfFrame : public TIRFrame {
651  public:
653 };
654 
660 class ThenFrameNode : public TIRFrameNode {
661  public:
662  static constexpr const char* _type_key = "script.ir_builder.tir.ThenFrame";
664 
665  public:
670  void EnterWithScope() final;
675  void ExitWithScope() final;
676 };
677 
683 class ThenFrame : public TIRFrame {
684  public:
686 };
687 
693 class ElseFrameNode : public TIRFrameNode {
694  public:
695  static constexpr const char* _type_key = "script.ir_builder.tir.ElseFrame";
697 
698  public:
703  void EnterWithScope() final;
708  void ExitWithScope() final;
709 };
710 
716 class ElseFrame : public TIRFrame {
717  public:
719 };
720 
722  public:
726  bool allocated;
727 
730  v->Visit("buffer", &buffer);
731  v->Visit("allocated", &allocated);
732  }
733 
734  static constexpr const char* _type_key = "script.ir_builder.tir.DeclBufferFrame";
736 
737  public:
738  void ExitWithScope() final;
739 };
740 
741 class DeclBufferFrame : public TIRFrame {
742  public:
744 };
745 
746 } // namespace tir
747 } // namespace ir_builder
748 } // namespace script
749 } // namespace tvm
750 
751 #endif // TVM_SCRIPT_IR_BUILDER_TIR_FRAME_H_
void VisitAttrs(tvm::AttrVisitor *v)
Definition: frame.h:549
A frame represents the allocate constant.
Definition: frame.h:492
A frame represents the allocate.
Definition: frame.h:441
Managed reference to IfFrameNode.
Definition: frame.h:650
Managed reference to PrimFuncFrameNode.
Definition: frame.h:112
Managed reference to an IRBuilderFrameNode.
Definition: base.h:100
Optional< Map< String, ObjectRef > > attrs
Additional attributes storing the meta-data.
Definition: frame.h:79
virtual void EnterWithScope()
The method called when entering RAII scope.
A frame that represents attribute node.
Definition: frame.h:540
#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:452
A frame that represents the block.
Definition: frame.h:122
tvm::runtime::NDArray data
The data associated with the constant.
Definition: frame.h:499
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:83
Optional< tvm::tir::Stmt > init
The init statement of the bolck.
Definition: frame.h:133
void VisitAttrs(tvm::AttrVisitor *v)
Definition: frame.h:587
Optional< Array< tvm::tir::BufferRegion > > reads
The read buffer regions of the block.
Definition: frame.h:129
Managed reference to LaunchThreadFrameNode.
Definition: frame.h:388
Managed reference to AllocateConstFrameNode.
Definition: frame.h:530
void VisitAttrs(tvm::AttrVisitor *v)
Definition: frame.h:728
Managed reference to BlockFrameNode.
Definition: frame.h:182
runtime implementation for LibTorch/TorchScript.
Definition: analyzer.h:36
Managed reference to RealizeFrameNode.
Definition: frame.h:431
PrimExpr message
The output error message when the assertion failed.
Definition: frame.h:284
Managed reference to WhileFrameNode.
Definition: frame.h:608
PrimExpr value
The value of the attribute.
Definition: frame.h:547
TVM_DECLARE_BASE_OBJECT_INFO(TIRFrameNode, IRBuilderFrameNode)
String storage_scope
The storage scope associated with this realization.
Definition: frame.h:404
a named variable in TIR
Definition: var.h:88
Array< Range > doms
The domains of iteration.
Definition: frame.h:241
Iteration Variable, represents an iteration over an integer interval.
Definition: var.h:308
Array< tvm::tir::Var > vars
The loop variable.
Definition: frame.h:239
Array< tvm::tir::IterVar > iter_vars
The variables of the block.
Definition: frame.h:127
PrimExpr condition
The PrimExpr to test.
Definition: frame.h:282
Array< PrimExpr > extents
The extents of the allocate.
Definition: frame.h:497
String attr_key
The attribute key, could be either virtual_thread or thread_extent.
Definition: frame.h:361
A frame that represents the for loop.
Definition: frame.h:227
Managed reference to BufferRegionNode.
Definition: stmt.h:1099
ObjectRef node
The node to annotate the attribute.
Definition: frame.h:543
Managed NDArray. The array is backed by reference counted blocks.
Definition: ndarray.h:51
A frame that represents while loop.
Definition: frame.h:582
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:625
A frame that represents else.
Definition: frame.h:693
void VisitAttrs(tvm::AttrVisitor *v)
Definition: frame.h:505
Map< tvm::tir::Var, tvm::tir::IterVar > env_threads
The variable map bound to thread env.
Definition: frame.h:81
void VisitAttrs(tvm::AttrVisitor *v)
Definition: frame.h:286
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:347
TIR statements.
Optional< Array< tvm::tir::Stmt > > then_stmts
The statements in the true branch.
Definition: frame.h:623
String attr_key
Attribute type key.
Definition: frame.h:545
Runtime primitive data type.
Definition: data_type.h:41
Managed reference to ForFrameNode.
Definition: frame.h:268
void VisitAttrs(tvm::AttrVisitor *v)
Definition: frame.h:408
void VisitAttrs(tvm::AttrVisitor *v)
Definition: frame.h:325
void VisitAttrs(tvm::AttrVisitor *v)
Definition: frame.h:627
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:318
A frame that represents the assert statement. Proceeds if the condition is true, otherwise aborts wit...
Definition: frame.h:279
void VisitAttrs(tvm::AttrVisitor *v)
Definition: frame.h:365
void VisitAttrs(tvm::AttrVisitor *v)
Definition: frame.h:150
Managed reference to TIRFrameNode.
Definition: frame.h:55
Container of all statements.
Definition: stmt.h:59
String storage_scope
The storage scope.
Definition: frame.h:448
Optional< Map< String, ObjectRef > > annotations
The annotation of the block.
Definition: frame.h:139
tvm::tir::Buffer buffer
The declared buffer.
Definition: frame.h:724
PrimExpr extent
The extent of environment thread.
Definition: frame.h:359
Reference to string objects.
Definition: string.h:98
void VisitAttrs(tvm::AttrVisitor *v)
Definition: frame.h:85
Array< PrimExpr > iter_values
The corresponding values of the iter vars.
Definition: frame.h:141
Optional< String > name
The name of the block.
Definition: frame.h:71
PrimExpr value
The value we bind var to.
Definition: frame.h:323
Array< PrimExpr > extents
The extents of the allocate.
Definition: frame.h:444
Array< tvm::tir::Buffer > alloc_buffers
The buffer allocated in the block.
Definition: frame.h:135
Optional< Type > ret_type
The return type of the function.
Definition: frame.h:75
PrimExpr condition
The termination condition of while.
Definition: frame.h:585
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:148
DataType dtype
The data type of the buffer.
Definition: frame.h:495
tvm::tir::Var var
The variable we bind to.
Definition: frame.h:321
PrimExpr condition
The condition of the if statement.
Definition: frame.h:621
Base class of all object reference.
Definition: object.h:511
A frame that represents if statement.
Definition: frame.h:618
DataType dtype
The data type of the buffer.
Definition: frame.h:446
Array< tvm::tir::MatchBufferRegion > match_buffers
The match buffer regions.
Definition: frame.h:137
Managed reference to AssertFrameNode.
Definition: frame.h:308
Map< String, ObjectRef > annotations
Additional annotations about the allocation.
Definition: frame.h:503
tvm::tir::BufferRegion buffer_slice
The region of buffer access.
Definition: frame.h:402
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:192
void VisitAttrs(tvm::AttrVisitor *v)
Definition: frame.h:194
String name
The name of the block.
Definition: frame.h:125
Managed reference to ThenFrameNode.
Definition: frame.h:683
FMakeForLoop f_make_for_loop
The for loop generating function.
Definition: frame.h:243
PrimExpr condition
The condition.
Definition: frame.h:450
tvm::tir::Var buffer_var
The buffer var.
Definition: frame.h:454
The LaunchThreadFrameNode.
Definition: frame.h:356
A frame that represents then.
Definition: frame.h:660
bool allocated
The buffer allocated or not.
Definition: frame.h:726
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:146
Optional container that to represent to a Nullable variant of T.
Definition: optional.h:51
PrimExpr condition
The condition expression.
Definition: frame.h:406
void VisitAttrs(tvm::AttrVisitor *v)
Definition: frame.h:245
Reference to PrimExprNode.
Definition: expr.h:114
static constexpr const char * _type_key
Definition: frame.h:46
Managed reference to AttrFrameNode.
Definition: frame.h:572
Managed reference to ElseFrameNode.
Definition: frame.h:716
Optional< Array< tvm::tir::BufferRegion > > writes
The write buffer regions of the block.
Definition: frame.h:131
A frame that represents realization.
Definition: frame.h:399
Managed reference to AllocateFrameNode.
Definition: frame.h:482
void VisitAttrs(tvm::AttrVisitor *v)
Definition: frame.h:456
tvm::tir::IterVar iter_var
The iteration variable.
Definition: frame.h:363
Managed reference to BlockInitFrameNode.
Definition: frame.h:217
tvm::tir::Var buffer_var
The buffer var.
Definition: frame.h:501
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