-
Notifications
You must be signed in to change notification settings - Fork 5.7k
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] Support injective group fusion #61197
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
ad067f1
support injective group fusion
zyfncg 1c9379c
Merge branch 'develop' of https://github.com/PaddlePaddle/Paddle into…
zyfncg ffee527
[CINN+PIR]Fix IsSupportCINN Logic
Aurelius84 ce45ad3
fix comment
Aurelius84 8f878a1
Merge commit 'refs/pull/61225/head' of https://github.com/PaddlePaddl…
zyfncg 6a14bf7
merge gather_nd
zyfncg 7c772ef
Merge branch 'develop' of https://github.com/PaddlePaddle/Paddle into…
zyfncg 51c809b
refactor some trick code
zyfncg 2889e53
revert some code
zyfncg fb05023
fix bug
zyfncg 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
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
49 changes: 49 additions & 0 deletions
49
paddle/cinn/hlir/dialect/operator/transforms/group_merge/special_ops_fusion_rule.cc
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,49 @@ | ||
// 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/hlir/dialect/operator/transforms/group_merge/special_ops_fusion_rule.h" | ||
|
||
#include "paddle/cinn/hlir/dialect/operator/ir/cinn_op.h" | ||
#include "paddle/cinn/hlir/dialect/operator/ir/manual_op.h" | ||
#include "paddle/fluid/pir/dialect/operator/ir/pd_op.h" | ||
|
||
namespace cinn { | ||
namespace dialect { | ||
namespace ir { | ||
|
||
bool GatherNdFusionFule(const ::pir::Operation* consumer, | ||
OpPatternKind producer_group_pattern) { | ||
if (producer_group_pattern == OpPatternKind::kReduction) { | ||
return false; | ||
} | ||
return true; | ||
} | ||
|
||
bool SliceFusionFule(const ::pir::Operation* consumer, | ||
OpPatternKind producer_group_pattern) { | ||
if (producer_group_pattern == OpPatternKind::kReduction) { | ||
return false; | ||
} | ||
return true; | ||
} | ||
|
||
void SpecialOpsFusionRule::Init() { | ||
RegisterConsumerOpRule(paddle::dialect::GatherNdOp::name(), | ||
&GatherNdFusionFule); | ||
RegisterConsumerOpRule(cinn::dialect::SliceOp::name(), &SliceFusionFule); | ||
} | ||
|
||
} // namespace ir | ||
} // namespace dialect | ||
} // namespace cinn |
78 changes: 78 additions & 0 deletions
78
paddle/cinn/hlir/dialect/operator/transforms/group_merge/special_ops_fusion_rule.h
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,78 @@ | ||
// Copyright (c) 2024 CINN 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/hlir/framework/op.h" | ||
#include "paddle/pir/core/operation.h" | ||
|
||
namespace cinn { | ||
namespace dialect { | ||
namespace ir { | ||
|
||
using OpPatternKind = hlir::framework::OpPatternKind; | ||
|
||
class SpecialOpsFusionRule { | ||
public: | ||
typedef bool (*RuleFunc)(const ::pir::Operation*, OpPatternKind); | ||
|
||
static const SpecialOpsFusionRule& GetInstance() { | ||
thread_local static SpecialOpsFusionRule instance; | ||
return instance; | ||
} | ||
|
||
bool ProducerOpAllowsFusion(const ::pir::Operation* producer, | ||
OpPatternKind consumer_group_pattern) const { | ||
auto iter = producer_op_rules_.find(producer->name()); | ||
if (iter != producer_op_rules_.end()) { | ||
return iter->second(producer, consumer_group_pattern); | ||
} | ||
return true; | ||
} | ||
|
||
bool ConsumerOpAllowsFusion(const ::pir::Operation* consumer, | ||
OpPatternKind producer_group_pattern) const { | ||
auto iter = consumer_op_rules_.find(consumer->name()); | ||
if (iter != consumer_op_rules_.end()) { | ||
return iter->second(consumer, producer_group_pattern); | ||
} | ||
return true; | ||
} | ||
|
||
private: | ||
SpecialOpsFusionRule() { Init(); } | ||
|
||
SpecialOpsFusionRule(const SpecialOpsFusionRule&) = delete; | ||
SpecialOpsFusionRule(const SpecialOpsFusionRule&&) = delete; | ||
SpecialOpsFusionRule& operator=(const SpecialOpsFusionRule&) = delete; | ||
|
||
void Init(); | ||
|
||
void RegisterProducerOpRule(const std::string& producer_op_name, | ||
RuleFunc rule) { | ||
producer_op_rules_[producer_op_name] = rule; | ||
} | ||
|
||
void RegisterConsumerOpRule(const std::string& consumer_op_name, | ||
RuleFunc rule) { | ||
consumer_op_rules_[consumer_op_name] = rule; | ||
} | ||
|
||
std::map<std::string, RuleFunc> producer_op_rules_; | ||
std::map<std::string, RuleFunc> consumer_op_rules_; | ||
}; | ||
|
||
} // namespace ir | ||
} // namespace dialect | ||
} // 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
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
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.
这是能融合slice/concat的tricky代码吗?
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.
是的,这里的判断不算很tricky,如果融合规则明确的话,后面是可以直接使用的