tvm
Loading...
Searching...
No Matches
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_S_TIR_SCHEDULE_TRACE_H_
20#define TVM_S_TIR_SCHEDULE_TRACE_H_
21
22#include <tvm/ir/prim/expr.h>
24
25namespace tvm {
26namespace s_tir {
27using namespace tvm::tirx;
28
29// Forward declaration
30class Trace;
31
42 ffi::TypedFunction<Any(const Instruction& inst, const ffi::Array<Any>& inputs,
43 const ffi::Array<Any>& attrs, const Any& decision)>;
44
60class TraceNode : public ffi::Object {
61 public:
63 ffi::Array<Instruction> insts;
65 ffi::Map<Instruction, Any> decisions;
66
67 static void RegisterReflection() {
68 namespace refl = tvm::ffi::reflection;
69 refl::ObjectDef<TraceNode>()
70 .def_ro("insts", &TraceNode::insts)
71 .def_ro("decisions", &TraceNode::decisions);
72 }
73
74 static constexpr const bool _type_mutable = true;
75 TVM_FFI_DECLARE_OBJECT_INFO_FINAL("s_tir.Trace", TraceNode, ffi::Object);
76
77 public:
83 Any GetDecision(const Instruction& inst) const;
88 void Append(Instruction inst);
96 void Append(Instruction inst, Any decision);
101 ffi::Optional<Instruction> Pop();
110 void ApplyToSchedule(Schedule sch, bool remove_postproc,
111 FTraceDecisionProvider decision_provider = nullptr) const;
117 ffi::ObjectRef AsJSON(bool remove_postproc) const;
123 ffi::Array<ffi::String> AsPython(bool remove_postproc) const;
132 Trace WithDecision(Instruction inst, Any decision, bool remove_postproc) const;
138 Trace Simplified(bool remove_postproc) const;
139};
140
145class Trace : public ffi::ObjectRef {
146 public:
154 explicit Trace(ffi::Array<Instruction> insts, ffi::Map<Instruction, Any> decisions);
160 static void ApplyJSONToSchedule(ffi::ObjectRef json, Schedule sch);
161
163};
164
165} // namespace s_tir
166} // namespace tvm
167
168#endif // TVM_S_TIR_SCHEDULE_TRACE_H_
Managed reference to InstructionNode.
Definition instruction.h:194
Managed reference to ScheduleObj.
Definition schedule.h:887
An execution trace of a scheduling program.
Definition trace.h:60
void ApplyToSchedule(Schedule sch, bool remove_postproc, FTraceDecisionProvider decision_provider=nullptr) const
Apply the trace to a TensorIR schedule.
void Append(Instruction inst, Any decision)
Append a new instruction with a random decision to the trace.
ffi::Array< ffi::String > AsPython(bool remove_postproc) const
Serialize the trace as a sequence of python statements.
ffi::Optional< Instruction > Pop()
Remove the last instruction, along with the decision made on that instruction, if any.
static constexpr const bool _type_mutable
Definition trace.h:74
ffi::Array< Instruction > insts
The instructions invoked so far in the program execution.
Definition trace.h:63
Any GetDecision(const Instruction &inst) const
Retrieve the decision made on a specific instruction.
void Append(Instruction inst)
Append a new instruction to the trace.
static void RegisterReflection()
Definition trace.h:67
Trace Simplified(bool remove_postproc) const
Simplify the trace with dead-code elimination.
ffi::ObjectRef AsJSON(bool remove_postproc) const
Serialize the trace as a JSON-style object.
TVM_FFI_DECLARE_OBJECT_INFO_FINAL("s_tir.Trace", TraceNode, ffi::Object)
ffi::Map< Instruction, Any > decisions
The random decisions made upon those instructions.
Definition trace.h:65
Trace WithDecision(Instruction inst, Any decision, bool remove_postproc) const
Create a new trace with an instruction whose decision is changed, assuming this instruction exists in...
Managed reference to TraceNode.
Definition trace.h:145
Trace()
Default constructor. Creating an empty trace.
static void ApplyJSONToSchedule(ffi::ObjectRef json, Schedule sch)
Apply a JSON-serialized trace to a TensorIR schedule.
Trace(ffi::Array< Instruction > insts, ffi::Map< Instruction, Any > decisions)
Constructor. Creating a trace from existing instructions and their decisions.
TVM_FFI_DEFINE_OBJECT_REF_METHODS_NOTNULLABLE(Trace, ffi::ObjectRef, TraceNode)
TIR expressions.
ffi::TypedFunction< Any(const Instruction &inst, const ffi::Array< Any > &inputs, const ffi::Array< Any > &attrs, const Any &decision)> FTraceDecisionProvider
A callback that allows users to mutate decisions on the fly when applying instructions....
Definition trace.h:43
Backend-defined execution hierarchy nodes shared by layouts and tile calls.
Definition axis_group_graph.h:41
An object that builds and maintains block scope and StmtSref mapping for Dependence analysis.
Definition attr.h:23