-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Meta Schedule][M3a] Traced Schedule
- Loading branch information
Showing
6 changed files
with
285 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,165 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
#include "./traced_schedule.h" | ||
|
||
namespace tvm { | ||
namespace tir { | ||
|
||
Schedule Schedule::Traced(IRModule mod, int debug_mode, | ||
ScheduleErrorRenderLevel error_render_level) { | ||
ObjectPtr<TracedScheduleNode> n = make_object<TracedScheduleNode>(); | ||
n->state_ = ScheduleState(mod, debug_mode); | ||
n->error_render_level_ = error_render_level; | ||
n->symbol_table_ = {}; | ||
n->analyzer_ = std::make_unique<arith::Analyzer>(); | ||
n->trace_ = Trace(); | ||
return Schedule(std::move(n)); | ||
} | ||
|
||
Schedule TracedScheduleNode::Copy() const { | ||
ObjectPtr<TracedScheduleNode> n = make_object<TracedScheduleNode>(); | ||
ConcreteScheduleNode::Copy(&n->state_, &n->symbol_table_); | ||
n->error_render_level_ = this->error_render_level_; | ||
n->analyzer_ = std::make_unique<arith::Analyzer>(); | ||
n->trace_ = Trace(this->trace_->insts, this->trace_->decisions); | ||
return Schedule(std::move(n)); | ||
} | ||
|
||
/******** Schedule: Sampling ********/ | ||
|
||
/******** Schedule: Get blocks & loops ********/ | ||
|
||
BlockRV TracedScheduleNode::GetBlock(const String& name, const String& func_name) { | ||
BlockRV result = ConcreteScheduleNode::GetBlock(name, func_name); | ||
|
||
static const InstructionKind& kind = InstructionKind::Get("GetBlock"); | ||
trace_->Append(/*inst=*/Instruction(/*kind=*/kind, // | ||
/*inputs=*/{}, | ||
/*attrs=*/{name, func_name}, | ||
/*outputs=*/{result})); | ||
return result; | ||
} | ||
|
||
Array<LoopRV> TracedScheduleNode::GetLoops(const BlockRV& block_rv) { | ||
Array<LoopRV> results = ConcreteScheduleNode::GetLoops(block_rv); | ||
|
||
static const InstructionKind& kind = InstructionKind::Get("GetLoops"); | ||
trace_->Append(/*inst=*/Instruction(/*kind=*/kind, // | ||
/*inputs=*/{block_rv}, | ||
/*attrs=*/{}, | ||
/*outputs=*/{results.begin(), results.end()})); | ||
return results; | ||
} | ||
|
||
/******** Schedule: Transform loops ********/ | ||
|
||
LoopRV TracedScheduleNode::Fuse(const Array<LoopRV>& loop_rvs) { | ||
LoopRV result = ConcreteScheduleNode::Fuse(loop_rvs); | ||
|
||
static const InstructionKind& kind = InstructionKind::Get("Fuse"); | ||
trace_->Append(/*inst=*/Instruction(/*kind=*/kind, | ||
/*inputs=*/{loop_rvs.begin(), loop_rvs.end()}, | ||
/*attrs=*/{}, | ||
/*outputs=*/{result})); | ||
return result; | ||
} | ||
|
||
Array<LoopRV> TracedScheduleNode::Split(const LoopRV& loop_rv, | ||
const Array<Optional<ExprRV>>& factor_rvs) { | ||
Array<LoopRV> results = ConcreteScheduleNode::Split(loop_rv, factor_rvs); | ||
|
||
std::vector<ObjectRef> inputs; | ||
inputs.reserve(1 + factor_rvs.size()); | ||
inputs.push_back(loop_rv); | ||
for (const ObjectRef& obj : factor_rvs) { | ||
inputs.push_back(obj); | ||
} | ||
|
||
static const InstructionKind& kind = InstructionKind::Get("Split"); | ||
trace_->Append(/*inst=*/Instruction(/*kind=*/kind, | ||
/*inputs=*/inputs, | ||
/*attrs=*/{}, | ||
/*outputs=*/{results.begin(), results.end()})); | ||
return results; | ||
} | ||
|
||
/******** Schedule: Manipulate ForKind ********/ | ||
|
||
/******** Schedule: Insert cache stages ********/ | ||
|
||
/******** Schedule: Compute location ********/ | ||
|
||
void TracedScheduleNode::ComputeInline(const BlockRV& block_rv) { | ||
ConcreteScheduleNode::ComputeInline(block_rv); | ||
|
||
static const InstructionKind& kind = InstructionKind::Get("ComputeInline"); | ||
trace_->Append(/*inst=*/Instruction(/*kind=*/kind, | ||
/*inputs=*/{block_rv}, | ||
/*attrs=*/{}, | ||
/*outputs=*/{})); | ||
} | ||
|
||
void TracedScheduleNode::ReverseComputeInline(const BlockRV& block_rv) { | ||
ConcreteScheduleNode::ReverseComputeInline(block_rv); | ||
|
||
static const InstructionKind& kind = InstructionKind::Get("ReverseComputeInline"); | ||
trace_->Append(/*inst=*/Instruction(/*kind=*/kind, | ||
/*inputs=*/{block_rv}, | ||
/*attrs=*/{}, | ||
/*outputs=*/{})); | ||
} | ||
|
||
/******** Schedule: Reduction ********/ | ||
|
||
BlockRV TracedScheduleNode::RFactor(const LoopRV& loop_rv, int factor_axis) { | ||
BlockRV result = ConcreteScheduleNode::RFactor(loop_rv, factor_axis); | ||
static const InstructionKind& kind = InstructionKind::Get("RFactor"); | ||
trace_->Append(/*inst=*/Instruction(/*kind=*/kind, | ||
/*inputs=*/{loop_rv}, | ||
/*attrs=*/{Integer(factor_axis)}, | ||
/*outputs=*/{result})); | ||
return result; | ||
} | ||
|
||
/******** Schedule: Blockize & Tensorize ********/ | ||
|
||
/******** Schedule: Annotation ********/ | ||
|
||
/******** Schedule: Misc ********/ | ||
|
||
void TracedScheduleNode::EnterPostproc() { | ||
ConcreteScheduleNode::EnterPostproc(); | ||
static const InstructionKind& kind = InstructionKind::Get("EnterPostproc"); | ||
trace_->Append(/*inst=*/Instruction(/*kind=*/kind, | ||
/*inputs=*/{}, | ||
/*attrs=*/{}, | ||
/*outputs=*/{})); | ||
} | ||
|
||
/******** FFI ********/ | ||
|
||
TVM_REGISTER_NODE_TYPE(TracedScheduleNode); | ||
TVM_REGISTER_GLOBAL("tir.schedule.TracedSchedule") | ||
.set_body_typed([](IRModule mod, int debug_mode, int error_render_level) -> Schedule { | ||
return Schedule::Traced(mod, debug_mode, | ||
static_cast<ScheduleErrorRenderLevel>(error_render_level)); | ||
}); | ||
|
||
} // namespace tir | ||
} // namespace tvm |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
#ifndef TVM_TIR_SCHEDULE_TRACED_SCHEDULE_H_ | ||
#define TVM_TIR_SCHEDULE_TRACED_SCHEDULE_H_ | ||
|
||
#include "./concrete_schedule.h" | ||
|
||
namespace tvm { | ||
namespace tir { | ||
|
||
class TracedScheduleNode : public ConcreteScheduleNode { | ||
friend class Schedule; | ||
|
||
protected: | ||
Trace trace_; | ||
|
||
public: | ||
void VisitAttrs(tvm::AttrVisitor* v) { | ||
// `state_` is not visited | ||
// `error_render_level_` is not visited | ||
// `symbol_table_` is not visited | ||
// `analyzer_` is not visitied | ||
// `trace_` is not visited | ||
} | ||
|
||
~TracedScheduleNode() = default; | ||
|
||
static constexpr const char* _type_key = "tir.TracedSchedule"; | ||
TVM_DECLARE_FINAL_OBJECT_INFO(TracedScheduleNode, ScheduleNode); | ||
|
||
public: | ||
Optional<Trace> trace() const final { return trace_; } | ||
Schedule Copy() const final; | ||
|
||
public: | ||
/******** Schedule: Sampling ********/ | ||
|
||
/******** Schedule: Get blocks & loops ********/ | ||
BlockRV GetBlock(const String& name, const String& func_name = "main") final; | ||
Array<LoopRV> GetLoops(const BlockRV& block_rv) final; | ||
/******** Schedule: Transform loops ********/ | ||
LoopRV Fuse(const Array<LoopRV>& loop_rvs) final; | ||
Array<LoopRV> Split(const LoopRV& loop_rv, const Array<Optional<ExprRV>>& factor_rvs) final; | ||
/******** Schedule: Manipulate ForKind ********/ | ||
/******** Schedule: Insert cache stages ********/ | ||
/******** Schedule: Compute location ********/ | ||
void ComputeInline(const BlockRV& block_rv) final; | ||
void ReverseComputeInline(const BlockRV& block_rv) final; | ||
/******** Schedule: Reduction ********/ | ||
BlockRV RFactor(const LoopRV& loop_rv, int factor_axis) final; | ||
/******** Schedule: Blockize & Tensorize ********/ | ||
/******** Schedule: Annotation ********/ | ||
/******** Schedule: Misc ********/ | ||
void EnterPostproc() final; | ||
}; | ||
|
||
} // namespace tir | ||
} // namespace tvm | ||
|
||
#endif // TVM_TIR_SCHEDULE_TRACED_SCHEDULE_H_ |