tvm
trace.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_TIR_SCHEDULE_TRACE_H_
20 #define TVM_TIR_SCHEDULE_TRACE_H_
21 
23 
24 namespace tvm {
25 namespace tir {
26 
27 // Forward declaration
28 class Trace;
29 
40  const Instruction& inst, const Array<ObjectRef>& inputs, const Array<ObjectRef>& attrs,
41  const Optional<ObjectRef>& decision)>;
42 
58 class TraceNode : public runtime::Object {
59  public:
64 
66  v->Visit("insts", &insts);
67  v->Visit("decisions", &decisions);
68  }
69 
70  static constexpr const char* _type_key = "tir.Trace";
72 
73  public:
84  void Append(Instruction inst);
92  void Append(Instruction inst, ObjectRef decision);
106  void ApplyToSchedule(Schedule sch, bool remove_postproc,
107  FTraceDecisionProvider decision_provider = nullptr) const;
113  ObjectRef AsJSON(bool remove_postproc) const;
119  Array<String> AsPython(bool remove_postproc) const;
128  Trace WithDecision(Instruction inst, ObjectRef decision, bool remove_postproc) const;
134  Trace Simplified(bool remove_postproc) const;
135 };
136 
141 class Trace : public runtime::ObjectRef {
142  public:
144  Trace();
156  static void ApplyJSONToSchedule(ObjectRef json, Schedule sch);
157 
159 };
160 
161 } // namespace tir
162 } // namespace tvm
163 
164 #endif // TVM_TIR_SCHEDULE_TRACE_H_
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
Array, container representing a contiguous sequence of ObjectRefs.
Definition: array.h:289
Map container of NodeRef->NodeRef in DSL graph. Map implements copy on write semantics,...
Definition: map.h:1271
Base class of all object reference.
Definition: object.h:519
base class of all object containers.
Definition: object.h:171
Optional container that to represent to a Nullable variant of T.
Definition: optional.h:51
Please refer to TypedPackedFunc<R(Args..)>.
Definition: packed_func.h:63
Managed reference to InstructionNode.
Definition: instruction.h:192
Managed reference to ScheduleNode.
Definition: schedule.h:877
An execution trace of a scheduling program.
Definition: trace.h:58
Trace WithDecision(Instruction inst, ObjectRef decision, bool remove_postproc) const
Create a new trace with an instruction whose decision is changed, assuming this instruction exists in...
Map< Instruction, ObjectRef > decisions
The random decisions made upon those instructions.
Definition: trace.h:63
void VisitAttrs(tvm::AttrVisitor *v)
Definition: trace.h:65
void Append(Instruction inst, ObjectRef decision)
Append a new instruction with a random decision to the trace.
ObjectRef AsJSON(bool remove_postproc) const
Serialize the trace as a JSON-style object.
void ApplyToSchedule(Schedule sch, bool remove_postproc, FTraceDecisionProvider decision_provider=nullptr) const
Apply the trace to a TensorIR schedule.
TVM_DECLARE_FINAL_OBJECT_INFO(TraceNode, runtime::Object)
Optional< Instruction > Pop()
Remove the last instruction, along with the decision made on that instruction, if any.
Optional< ObjectRef > GetDecision(const Instruction &inst) const
Retrieve the decision made on a specific instruction.
Array< String > AsPython(bool remove_postproc) const
Serialize the trace as a sequence of python statements.
Trace Simplified(bool remove_postproc) const
Simplify the trace with dead-code elimination.
static constexpr const char * _type_key
Definition: trace.h:70
Array< Instruction > insts
The instructions invoked so far in the program execution.
Definition: trace.h:61
void Append(Instruction inst)
Append a new instruction to the trace.
Managed reference to TraceNode.
Definition: trace.h:141
TVM_DEFINE_MUTABLE_NOTNULLABLE_OBJECT_REF_METHODS(Trace, runtime::ObjectRef, TraceNode)
Trace()
Default constructor. Creating an empty trace.
static void ApplyJSONToSchedule(ObjectRef json, Schedule sch)
Apply a JSON-serialized trace to a TensorIR schedule.
Trace(Array< Instruction > insts, Map< Instruction, ObjectRef > decisions)
Constructor. Creating a trace from existing instructions and their decisions.
runtime implementation for LibTorch/TorchScript.
Definition: analyzer.h:36