-
Notifications
You must be signed in to change notification settings - Fork 5.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[CINN][Backend Pass Update No.3] Update extern_call_process pass #70191
Merged
Hongqing-work
merged 10 commits into
PaddlePaddle:develop
from
Albresky:cinn-pass-extern_call_process
Dec 26, 2024
Merged
Changes from 6 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
7c6f36c
[CINN] Apply new ir&pass to extern_call_process op
Albresky ff8a701
delete old extern_call_process opt
Albresky 74a39ba
Merge branch 'PaddlePaddle:develop' into cinn-pass-extern_call_process
Albresky aae274d
Update header path
Albresky 0ea7870
Fix RemoveTupleGetStatements
Albresky 636d078
Merge branch 'PaddlePaddle:develop' into cinn-pass-extern_call_process
Albresky 570026d
Merge branch 'PaddlePaddle:develop' into cinn-pass-extern_call_process
Albresky 6e526f5
Update pass for extern_call_process; remove pass for TupleGet
Albresky 62589cf
Merge branch 'PaddlePaddle:develop' into cinn-pass-extern_call_process
Albresky ac4cd73
Update comment
Albresky File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
// Copyright (c) 2024 PaddlePaddle Authors. All Rights Reserved. | ||
// | ||
// Licensed 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 "paddle/cinn/optim/extern_call_process_pass.h" | ||
#include "paddle/cinn/ir/utils/ir_compare.h" | ||
|
||
namespace cinn { | ||
namespace optim { | ||
|
||
namespace { | ||
|
||
void ProcessMultiOutputStore(BlockRef block) { | ||
const auto& stmts = block->stmts(); | ||
std::vector<StmtRef> new_stmts; | ||
|
||
for (const auto& stmt : stmts) { | ||
if (stmt.isa<ir::Store>()) { | ||
auto* store_op = stmt.as<ir::Store>(); | ||
auto* call = store_op->value.As<ir::Call>(); | ||
if (call && call->is_extern_call() && !call->write_args.empty()) { | ||
new_stmts.emplace_back(store_op->value); | ||
} else { | ||
new_stmts.emplace_back(stmt); | ||
} | ||
} else { | ||
new_stmts.emplace_back(stmt); | ||
} | ||
} | ||
|
||
block->set_stmts(new_stmts); | ||
} | ||
|
||
void RemoveTupleGetStatements(BlockRef block) { | ||
const auto& stmts = block->stmts(); | ||
std::vector<StmtRef> new_stmts; | ||
|
||
for (const auto& stmt : stmts) { | ||
if (stmt.isa<ir::Call>()) { | ||
auto* call = stmt.as<ir::Call>(); | ||
if (call && call->is_extern_call() && call->is_tuple_get()) { | ||
continue; | ||
} | ||
} | ||
new_stmts.emplace_back(stmt); | ||
} | ||
|
||
block->set_stmts(new_stmts); | ||
} | ||
|
||
} // namespace | ||
|
||
LogicalResult ExternCallMultiOutputShallowStorePass::Run(ir::stmt::BlockRef block) { | ||
ProcessMultiOutputStore(block); | ||
return LogicalResult::success(); | ||
} | ||
|
||
LogicalResult ExternCallRemoveTupleGetStatementsPass::Run(ir::stmt::BlockRef block) { | ||
RemoveTupleGetStatements(block); | ||
return LogicalResult::success(); | ||
} | ||
|
||
std::unique_ptr<BlockPass> CreateExternCallMultiOutputShallowStorePass() { | ||
return std::make_unique<ExternCallMultiOutputShallowStorePass>(); | ||
} | ||
|
||
std::unique_ptr<BlockPass> CreateExternCallRemoveTupleGetStatementsPass() { | ||
return std::make_unique<ExternCallRemoveTupleGetStatementsPass>(); | ||
} | ||
|
||
} // namespace optim | ||
} // namespace cinn |
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,36 @@ | ||
// Copyright (c) 2024 PaddlePaddle Authors. All Rights Reserved. | ||
// | ||
// Licensed 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. | ||
|
||
#pragma once | ||
|
||
#include "paddle/cinn/pass/pass.h" | ||
|
||
namespace cinn { | ||
namespace optim { | ||
|
||
class ExternCallMultiOutputShallowStorePass : public BlockPass { | ||
public: | ||
LogicalResult Run(ir::stmt::BlockRef block) override; | ||
}; | ||
|
||
class ExternCallRemoveTupleGetStatementsPass : public BlockPass { | ||
public: | ||
LogicalResult Run(ir::stmt::BlockRef block) override; | ||
}; | ||
|
||
std::unique_ptr<BlockPass> CreateExternCallMultiOutputShallowStorePass(); | ||
std::unique_ptr<BlockPass> CreateExternCallRemoveTupleGetStatementsPass(); | ||
|
||
} // namespace optim | ||
} // namespace cinn |
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 |
---|---|---|
|
@@ -22,7 +22,7 @@ | |
#include "paddle/cinn/optim/cast_bool_to_int8.h" | ||
#include "paddle/cinn/optim/eliminate_broadcast_in_forloop.h" | ||
#include "paddle/cinn/optim/eliminate_invariant_loop.h" | ||
#include "paddle/cinn/optim/extern_call_process.h" | ||
#include "paddle/cinn/optim/extern_call_process_pass.h" | ||
#include "paddle/cinn/optim/fold_cinn_call_arguments.h" | ||
#include "paddle/cinn/optim/if_fusion_pass.h" | ||
#include "paddle/cinn/optim/insert_debug_log_callee.h" | ||
|
@@ -99,8 +99,13 @@ ir::LoweredFunc Optimize(ir::LoweredFunc fn, | |
MapExternCall(&copied->body, target); | ||
VLOG(10) << "After Optimize MapExternCall:" << copied; | ||
|
||
ExternCallMultiOutputShallowStore(&copied->body); | ||
VLOG(10) << "After Optimize ExternCallMultiOutputShallowStore:" << copied; | ||
// ExternCallMultiOutputShallowStore(&copied->body); | ||
BlockPassManager pass_manager; | ||
pass_manager.AddPass(CreateExternCallMultiOutputShallowStorePass()); | ||
pass_manager.AddPass(CreateExternCallRemoveTupleGetStatementsPass()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ExternCallRemoveTupleGetStatements没有使用,且之前没有实现,可以不实现并删除 |
||
pass_manager.Run(copied); | ||
VLOG(10) << "After Optimize ExternCallMultiOutputShallowStore and ExternCallRemoveTupleGetStatements:" << copied; | ||
|
||
// Simplify already contains CastSimplify | ||
Simplify(&copied->body); | ||
VLOG(10) << "After Optimize Simplify:" << copied; | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
call现在是个Expr,如果要它脱离store成为一条stmt需要使用Evaluate stmt包装一下