-
Notifications
You must be signed in to change notification settings - Fork 5.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[CINN] Support injective group fusion (#61197)
* support injective group fusion * [CINN+PIR]Fix IsSupportCINN Logic * fix comment * merge gather_nd * refactor some trick code * revert some code * fix bug --------- Co-authored-by: Aurelius84 <zhangliujie@baidu.com>
- Loading branch information
1 parent
6054d64
commit 79f3b1c
Showing
8 changed files
with
207 additions
and
9 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
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