25 #ifndef TVM_TE_SCHEDULE_H_ 26 #define TVM_TE_SCHEDULE_H_ 35 #include <unordered_map> 44 class IterVarRelationNode;
46 class IterVarAttrNode;
331 Schedule copy()
const;
353 bool include_inputs =
false);
363 TVM_DLL
Tensor cache_read(
const Tensor& tensor,
const std::string& scope,
398 TVM_DLL
Tensor cache_write(
const Tensor& tensor,
const std::string& scope);
421 Schedule normalize();
432 Schedule normalize_for_feature_extraction();
552 bool is_output{
false};
571 int num_child_stages{0};
575 v->Visit(
"origin_op", &origin_op);
576 v->Visit(
"all_iter_vars", &all_iter_vars);
577 v->Visit(
"leaf_iter_vars", &leaf_iter_vars);
578 v->Visit(
"env_threads", &env_threads);
579 v->Visit(
"relations", &relations);
580 v->Visit(
"iter_var_attrs", &iter_var_attrs);
581 v->Visit(
"attach_type", &attach_type);
582 v->Visit(
"attach_ivar", &attach_ivar);
583 v->Visit(
"attach_stage", &attach_stage);
584 v->Visit(
"scope", &scope);
585 v->Visit(
"is_output", &is_output);
587 v->Visit(
"layout_transforms", &layout_transforms);
588 v->Visit(
"axis_separators", &axis_separators);
589 v->Visit(
"group", &group);
590 v->Visit(
"num_child_stages", &num_child_stages);
593 static constexpr
const char* _type_key =
"Stage";
620 v->Visit(
"outputs", &outputs);
621 v->Visit(
"stages", &stages);
622 v->Visit(
"groups", &groups);
623 v->Visit(
"stage_map", &stage_map);
629 void InvalidateCache();
636 TVM_DLL
bool Contain(
const Operation& op)
const;
645 static constexpr
const char* _type_key =
"Schedule";
673 int dim_align_factor{0};
675 int dim_align_offset{0};
686 v->Visit(
"iter_type", &iter_type);
687 v->Visit(
"bind_thread", &bind_thread);
688 v->Visit(
"prefetch_data", &prefetch_data);
689 v->Visit(
"prefetch_offset", &prefetch_offset);
690 v->Visit(
"tensor_intrin", &tensor_intrin);
691 v->Visit(
"dim_align_factor", &dim_align_factor);
692 v->Visit(
"dim_align_offset", &dim_align_offset);
693 v->Visit(
"pragma_keys", &pragma_keys);
694 v->Visit(
"pragma_values", &pragma_values);
697 static constexpr
const char* _type_key =
"IterVarAttr";
704 static constexpr
const char* _type_key =
"IterVarRelation";
726 v->Visit(
"parent", &parent);
727 v->Visit(
"outer", &outer);
728 v->Visit(
"inner", &inner);
729 v->Visit(
"factor", &factor);
730 v->Visit(
"nparts", &nparts);
733 static constexpr
const char* _type_key =
"Split";
761 v->Visit(
"outer", &outer);
762 v->Visit(
"inner", &inner);
763 v->Visit(
"fused", &fused);
766 static constexpr
const char* _type_key =
"Fuse";
794 v->Visit(
"parent", &parent);
795 v->Visit(
"rebased", &rebased);
798 static constexpr
const char* _type_key =
"Rebase";
823 static constexpr
const char* _type_key =
"Singleton";
874 v->Visit(
"original_variables", &original_variables);
875 v->Visit(
"transformed_variables", &transformed_variables);
876 v->Visit(
"forward_transformation", &forward_transformation);
877 v->Visit(
"inverse_transformation", &inverse_transformation);
880 static constexpr
const char* _type_key =
"Transform";
905 static constexpr
const char* _type_key =
"SpecializedCondition";
924 TVM_DLL
static SpecializedCondition Current();
931 friend class Internal;
932 friend class With<SpecializedCondition>;
934 TVM_DLL
void EnterWithScope();
936 TVM_DLL
void ExitWithScope();
958 #endif // TVM_TE_SCHEDULE_H_ Array< Stage > groups
List of all stage groups.
Definition: schedule.h:610
Stage()
Definition: schedule.h:60
Split the parent domain into product of outer and iter.
Definition: schedule.h:712
Stage & compute_root()
Compute the function at group root.
Managed reference to RebaseNode.
Definition: schedule.h:806
represents a stage.
Definition: schedule.h:492
A custom smart pointer for Object.
Definition: object.h:358
IterVar bind_thread
The thread this iter Var binds, can be null.
Definition: schedule.h:662
Global schedule container For operations and all the operations they depend on. The schedule per Oper...
Definition: schedule.h:317
IterVar outer
The outer domain.
Definition: schedule.h:754
Stage operator[](const Tensor &tensor)
Short hand for getting the stage of tensor's operation.
Definition: schedule.h:342
void VisitAttrs(AttrVisitor *v)
Definition: schedule.h:573
Schedule create_schedule(Array< Operation > ops)
Create a schedule for array of ops(and their dependencies).
Definition: schedule.h:654
Stage(ObjectPtr< Object > n)
Definition: schedule.h:61
Array< Operation > outputs
The output operations in original data flow graph.
Definition: schedule.h:601
Definition: schedule.h:54
const IterVarRelationNode * operator->() const
access the internal node container
Definition: schedule.h:948
void VisitAttrs(AttrVisitor *v)
Definition: schedule.h:619
Fuse two domains into one domain.
Definition: schedule.h:751
Stage attach_stage
The stage this node attaches to.
Definition: schedule.h:548
runtime implementation for LibTorch/TorchScript.
Definition: analyzer.h:36
IterVar fused
The target domain.
Definition: schedule.h:758
IterVar inner
The inner domain.
Definition: schedule.h:719
Schedule()
Definition: schedule.h:319
Operation that produces tensors.
Definition: tensor.h:47
IterVar inner
The inner domain.
Definition: schedule.h:756
void VisitAttrs(AttrVisitor *v)
Definition: schedule.h:793
Iteration Variable, represents an iteration over an integer interval.
Definition: var.h:301
PrimExpr nparts
Number of parts, only factor or nparts can be given.
Definition: schedule.h:723
Stage, contains scheduling for a stage of computation.
Definition: schedule.h:58
IterVar attach_ivar
The attach point of this schedule.
Definition: schedule.h:546
Stage & compute_at(Stage parent, IterVar scope)
specify the schedule to be computed at the parent schedule's scope.
AttachType
the attachment type
Definition: schedule.h:49
Array< IntImm > axis_separators
List of axes after which to divide physical axes.
Definition: schedule.h:564
Specialized condition to enable op specialization.
Definition: schedule.h:912
base class of all object containers.
Definition: object.h:167
std::string scope
The thread storage scope level of the stage.
Definition: schedule.h:550
Array< IterVar > all_iter_vars
All the nodes in the iter var.
Definition: schedule.h:518
Stage & set_scope(std::string scope)
set the memory scope of the stage
Operation op
The operation of stage, can be different from original op. If it is null, then this stage is a group ...
Definition: schedule.h:498
Definition: schedule.h:51
Managed reference to SplitNode.
Definition: schedule.h:741
Stage & set_store_predicate(PrimExpr predicate)
Set the predicate to determine whether a store to the array should be performed. Use this when there ...
Defines a remapping of buffer indices.
IterVarAttr()
Definition: schedule.h:468
bool is_scheduled() const
whether the stage has been scheduled.
Stage & double_buffer()
Compute current stage with double buffering.
Container for specialization conditions.
Definition: schedule.h:894
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
TensorIntrin tensor_intrin
Tensor intrinsic used in tensorization, when the axis is marked as Tensorized.
Definition: schedule.h:671
Stage & unroll(IterVar var)
Unroll iteration.
IterVarType
Type of iteration variable. Each IterVar have a specific type.
Definition: var.h:178
Rebase the iteration to make min to be 0. This is useful to normalize the Schedule to make every leaf...
Definition: schedule.h:786
Stage group
The parent group of the current stage. The stage cannot be assigned to stages outside the group...
Definition: schedule.h:569
The schedule relation between IterVars can be Split, Fuse.
Definition: schedule.h:452
Managed reference to TensorIntrinNode.
Definition: tensor_intrin.h:93
Array< IndexMap > layout_transforms
Layout transformations to be applied onto the stage's tensors.
Definition: schedule.h:558
void VisitAttrs(AttrVisitor *v)
Definition: schedule.h:760
IterVarRelation(ObjectPtr< Object > n)
Definition: schedule.h:455
Definition: schedule.h:50
Array, container representing a contiguous sequence of ObjectRefs.
Definition: array.h:289
Definition: index_map.h:175
Stage & transform_layout(const Array< Var > &initial_indices, const Array< PrimExpr > &final_indices, Array< IterVar > *out_iter_vars=nullptr)
Defines a layout transformation to be applied to the buffer.
Stage & reorder(const Array< IterVar > &order)
Reorder the iteration.
Array< Tensor > prefetch_data
List of tensor to be prefetched in this loop.
Definition: schedule.h:664
const StageNode * operator->() const
access the internal node container
Definition: schedule.h:940
node container for IterVar attr
Definition: schedule.h:657
Managed reference to SingletonNode.
Definition: schedule.h:831
const IterVarAttrNode * operator->() const
access the internal node container
Definition: schedule.h:952
Stage & set_axis_separators(const Array< IntImm > &axis_separators)
Defines separators between groups of axes.
Stage & compute_inline()
Compute the function inline.
Array< IterVar > env_threads
Specify threads to be launched at the stage. This is only valid for composite ops such as Scan...
Definition: schedule.h:532
Stage & tile(IterVar x_parent, IterVar y_parent, PrimExpr x_factor, PrimExpr y_factor, IterVar *p_x_outer, IterVar *p_y_outer, IterVar *p_x_inner, IterVar *p_y_inner)
Perform tiling on two dimensions The final loop order from outmost to inner most are [x_outer...
const ScheduleNode * operator->() const
access the internal node container
Definition: schedule.h:943
#define TVM_DEFINE_OBJECT_REF_METHODS(TypeName, ParentType, ObjectName)
Definition: object.h:713
RAII wrapper function to enter and exit a context object similar to python's with syntax...
Definition: with.h:58
void VisitAttrs(AttrVisitor *v)
Definition: schedule.h:685
Data parallel iteration. This normally corresponds to axis of Tensor. Allow all IterVar manipulations...
Definition: var.h:187
Array< IterVar > leaf_iter_vars
The current active leaf iter vars in the stage.
Definition: schedule.h:526
Definition: schedule.h:52
IterVar parent
The parent domain.
Definition: schedule.h:715
Var var(std::string name_hint, DataType t=DataType::Int(32))
Construct a new Var expression.
Base class of all object reference.
Definition: object.h:511
Singleton iterator [0, 1)
Definition: schedule.h:816
Stage & parallel(IterVar var)
Parallelize iteration.
Definition: schedule.h:53
Tensor structure representing a possible input, or intermediate computation result.
Definition: tensor.h:102
Array< PrimExpr > pragma_keys
Additional pragma keys, array of StringImm.
Definition: schedule.h:679
Managed reference to FuseNode.
Definition: schedule.h:774
PrimExpr factor
The split factor.
Definition: schedule.h:721
Stage & env_threads(Array< IterVar > threads)
Specify environment threads that launched around the group's scope. This can only be used in group st...
constexpr const char * axis_separators
Marks the physical axis separators.
Definition: stmt.h:1441
Stage & vectorize(IterVar var)
Vectorize iteration.
#define TVM_DECLARE_FINAL_OBJECT_INFO(TypeName, ParentType)
helper macro to declare type information in a final class.
Definition: object.h:671
Tensor intrinsic operations.
Schedule(ObjectPtr< Object > n)
Definition: schedule.h:320
void VisitAttrs(AttrVisitor *v)
Definition: schedule.h:821
Stage & bind(IterVar ivar, IterVar thread_ivar)
Bind the IterVar to thread index.
Stage & rolling_buffer()
Compute current stage with rolling buffering.
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
Stage & pragma(IterVar var, const std::string &pragma_type, const PrimExpr &pragma_value=PrimExpr())
Annotate the iteration with pragma.
Map< IterVar, IterVarAttr > iter_var_attrs
additional attributes about iter var.
Definition: schedule.h:542
PrimExpr store_predicate
The predicate under which store can happen Use this when there can be duplicated threads doing the sa...
Definition: schedule.h:538
Array< IterVarRelation > relations
The relation bwteen of IterVars.
Definition: schedule.h:540
Stage GetAttachSpec() const
Get attachment spec of current stage. If the stage compute at Group root, this function will traverse...
IterVar rebased
The inner domain.
Definition: schedule.h:791
IterVarRelation()
Definition: schedule.h:454
Stage & split(IterVar parent, PrimExpr factor, IterVar *p_outer, IterVar *p_inner)
Split the parent by factor, generate.
IterVar outer
The outer domain.
Definition: schedule.h:717
Operation origin_op
The original operator. The op field can change during schedule to alternate the dataflow, while origin_op remains fixed.
Definition: schedule.h:504
Stage & fuse(IterVar outer, IterVar inner, IterVar *p_target)
Fuse the inner outer domain to the target.
IterVarAttr(ObjectPtr< Object > n)
Definition: schedule.h:469
void VisitAttrs(AttrVisitor *v)
Definition: schedule.h:903
base node of iteration var
Definition: schedule.h:702
Reference to PrimExprNode.
Definition: expr.h:112
void VisitAttrs(AttrVisitor *v)
Definition: schedule.h:725
node container for schedule
Definition: schedule.h:598
std::unordered_map< const Object *, Stage > op2stage_cache_
Internal stage map to map internal ops to stages. This is created on demand and can be invalidated...
Definition: schedule.h:617
Stage & storage_align(IterVar axis, int factor, int offset)
Set alignment requirement for specific dimension.
bool Contain(const Tensor &tensor) const
Check if the schedule contains a Tensor.
Definition: schedule.h:643
Object * get_mutable() const
Definition: object.h:576
Stage & split_by_nparts(IterVar parent, PrimExpr nparts, IterVar *p_outer, IterVar *p_inner)
Split the iteration with given number of parts.
Array< PrimExpr > prefetch_offset
The offset used in each prefetch.
Definition: schedule.h:666
Array< Stage > stages
list of all stages for ops. The stages are sorted in dependency order.
Definition: schedule.h:606
#define TVM_DECLARE_BASE_OBJECT_INFO(TypeName, ParentType)
helper macro to declare a base object type that can be inherited.
Definition: object.h:648
Additional scheduable attributes about IterVar.
Definition: schedule.h:466
Stage & tensorize(IterVar var, TensorIntrin f)
Replace computation of the current stage by tensor intrinsic f.
Array< PrimExpr > pragma_values
Additional values of pragma, if any.
Definition: schedule.h:683
Map< Operation, Stage > stage_map
map of original operation to the stages
Definition: schedule.h:612
Array< PrimExpr > clauses
List of conditions in conjunctive joint form (CNF). Each condition should be a simple expression...
Definition: schedule.h:901
IterVar iter
The singleton iterator.
Definition: schedule.h:819
Stage & prefetch(const Tensor &domain, IterVar var, PrimExpr offset)
Fetch data in advance.
RAII wrapper function to enter and exit a context object similar to python's with syntax...
IterVar parent
The parent domain.
Definition: schedule.h:789