Commit 9c777b67 authored by Lei Wang's avatar Lei Wang Committed by LeiWang1999
Browse files

[Pass] Introduce flag to diable cp async lowering (#633)

* [Enhancement] Update PipelinePlanner to support async copy configuration

- Modified the `Substitute` method in `PipelinePlanner` to accept a `use_async_copy` parameter, allowing for more flexible pipeline planning based on async copy requirements.
- Updated the constructor of `PipelinePlanner` to initialize the `use_async_copy_` member variable.
- Adjusted the logic in the pipeline planning process to conditionally apply async copy annotations based on the new parameter.
- Commented out the `LoopVectorizeDynamic` call in `LowerAndLegalize` to prevent unintended modifications during the legalizing phase.

* Refactor PipelinePlanning function for improved readability

- Adjusted the formatting of the `use_async_copy` variable assignment in the `PipelinePlanning` function to enhance code clarity and maintainability.
parent eec47592
...@@ -165,8 +165,8 @@ private: ...@@ -165,8 +165,8 @@ private:
class PipelinePlanner : public StmtExprMutator { class PipelinePlanner : public StmtExprMutator {
public: public:
static Stmt Substitute(const PrimFunc &f) { static Stmt Substitute(const PrimFunc &f, bool use_async_copy = true) {
PipelinePlanner substituter; PipelinePlanner substituter(use_async_copy);
for (const auto &[_, buffer] : f->buffer_map) { for (const auto &[_, buffer] : f->buffer_map) {
substituter.buffer_data_to_buffer_.Set(buffer->data, buffer); substituter.buffer_data_to_buffer_.Set(buffer->data, buffer);
} }
...@@ -179,6 +179,7 @@ public: ...@@ -179,6 +179,7 @@ public:
private: private:
PipelinePlanner() = default; PipelinePlanner() = default;
PipelinePlanner(bool use_async_copy) : use_async_copy_(use_async_copy) {}
/*! \brief Information about a pipeline stage /*! \brief Information about a pipeline stage
* *
...@@ -262,7 +263,7 @@ private: ...@@ -262,7 +263,7 @@ private:
} }
} }
annotations.Set(tir::attr::software_pipeline_stage, stage_anno); annotations.Set(tir::attr::software_pipeline_stage, stage_anno);
if (TargetHasAsyncCopy(target_)) if (TargetHasAsyncCopy(target_) && use_async_copy_)
annotations.Set(tir::attr::software_pipeline_async_stages, annotations.Set(tir::attr::software_pipeline_async_stages,
Array<Integer>{0}); Array<Integer>{0});
auto for_node = GetRef<For>(loop); auto for_node = GetRef<For>(loop);
...@@ -459,7 +460,7 @@ private: ...@@ -459,7 +460,7 @@ private:
annotations.Set(tir::attr::software_pipeline_stage, Array<Integer>(stages)); annotations.Set(tir::attr::software_pipeline_stage, Array<Integer>(stages));
annotations.Set(tir::attr::software_pipeline_order, Array<Integer>(orders)); annotations.Set(tir::attr::software_pipeline_order, Array<Integer>(orders));
if (TargetHasAsyncCopy(target_)) if (TargetHasAsyncCopy(target_) && use_async_copy_)
annotations.Set(tir::attr::software_pipeline_async_stages, annotations.Set(tir::attr::software_pipeline_async_stages,
Array<Integer>{0}); Array<Integer>{0});
...@@ -480,13 +481,16 @@ private: ...@@ -480,13 +481,16 @@ private:
Map<Var, Buffer> buffer_data_to_buffer_; Map<Var, Buffer> buffer_data_to_buffer_;
Target target_; Target target_;
bool use_async_copy_;
}; };
tvm::transform::Pass PipelinePlanning() { tvm::transform::Pass PipelinePlanning() {
using namespace tir::transform; using namespace tir::transform;
auto pass_func = [=](PrimFunc f, IRModule m, PassContext ctx) { auto pass_func = [=](PrimFunc f, IRModule m, PassContext ctx) {
bool use_async_copy =
ctx->GetConfig<Bool>("tir.use_async_copy", Bool(true)).value();
PrimFuncNode *fptr = f.CopyOnWrite(); PrimFuncNode *fptr = f.CopyOnWrite();
fptr->body = PipelinePlanner::Substitute(f); fptr->body = PipelinePlanner::Substitute(f, use_async_copy);
return f; return f;
}; };
return CreatePrimFuncPass(pass_func, 0, "tl.PipelinePlanning", {}); return CreatePrimFuncPass(pass_func, 0, "tl.PipelinePlanning", {});
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment