-
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] Refactor pass api of group fusion in CINN #55090
Merged
Merged
Changes from 7 commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
883802d
new group fuse pass api
zyfncg e5d2c4b
Merge branch 'develop' of https://github.com/PaddlePaddle/Paddle into…
zyfncg 0e762de
fix header
zyfncg e591127
Merge branch 'develop' of https://github.com/PaddlePaddle/Paddle into…
zyfncg 09c15b7
update
zyfncg f27d04b
change logic of get master node to fix bug
zyfncg 9889f1f
revert update for ReduceFuseReduce
zyfncg 6f58397
modify according review
zyfncg 3a9e029
Merge branch 'develop' of https://github.com/PaddlePaddle/Paddle into…
zyfncg cb9322e
modify by review
zyfncg 5fbcdf3
Merge branch 'develop' of https://github.com/PaddlePaddle/Paddle into…
zyfncg e4b08d6
refine
zyfncg 4702bc4
update
zyfncg b827767
fix code-format
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
core_gather_headers() | ||
|
||
gather_srcs(cinnapi_src SRCS op_node.cc tensor_node.cc) | ||
|
||
message(STATUS "srcs: ${cinnapi_src}") |
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,44 @@ | ||
The classes in this directory are the interface of group fusion pass, you can use these apis to build the stragey for group fusion. | ||
|
||
The Class and APIs are following: | ||
|
||
`OpGroup` : A set of op nodes, which will pass to cinn backend for generating kernel code. Two groups can fuse togather according to the rule of merging written in the passes. | ||
|
||
`OpNode` : Map the op in the program. | ||
|
||
`TensorNode` : Map the tensor in the program. | ||
|
||
`Shape` : The shape infomation of tensor | ||
|
||
`FusePassCtx` : The context is the parameter for the pass, it hold the data all you need in the pass. | ||
|
||
`FuseHelper` : We provide some util methods such as `DetectCycleIfFuse` in fuse_helper to simplify development of pass. | ||
|
||
| Class | method | description | | ||
| :--: | :--: | :--: | | ||
| OpGroup | kind()| Get the Kind of group | | ||
| | producers()| Get producer groups of current group | | ||
| | consumers() | Get consumer groups of current group | | ||
| | WalkOpNodes(const std::function<void(const OpNode&)>& VisitOpNode) | Visit the op_nodes in the group and execute the VisitOpNode function for each OpNode | | ||
| | | | | ||
| OpNode | kind() | Get the Kind of op_node | | ||
| | inputs() | Get input tensors of op_node | | ||
| | outputs() | Get output tensors of op_node | | ||
| | GetAttr(const std::string& attr_name) | Get attribute of op_node by attr name | | ||
| | | | | ||
| TensorNode | shape() | Get shape of tensor | | ||
| | producer() | Get the producer op_node of tensor | | ||
| | consumers() | Get the consumer op_nodes of tensor | | ||
| | | | | ||
| Shape | numel() | Get total number of elements in the shape | | ||
| | other methods are same with std::vector<int64_t> | | | ||
| | | | | ||
| LightwareFusePassCtx | PickOpGroup() | Get the current group in the pass context | | ||
| | void EnableFuse(const OpGroup& first, const OpGroup& second) | Mark the two groups which can fuse togather | | ||
| | fuse_helper() | Get the fuse_helper provided by pass context | | ||
| | | | | ||
| InputFusePassCtx | PickConsumersWithSameInputs() | Get all consumer groups for input tensors of graph | | ||
| | void EnableFuse(const OpGroup& first, const OpGroup& second) | Mark the two groups which can fuse togather | | ||
| | fuse_helper() | Get the fuse_helper provided by pass context | | ||
| | | | | ||
| FuseHelper | DetectCycleIfFuse(const OpGroup& first, const OpGroup& second) | Whether there is cycle in graph after fusing two groups | |
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,131 @@ | ||
// Copyright (c) 2023 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 <memory> | ||
|
||
#include "paddle/cinn/api/op_group.h" | ||
|
||
namespace cinn { | ||
namespace api { | ||
|
||
class FusePassContext { | ||
public: | ||
virtual ~FusePassCtx() {} | ||
|
||
virtual void EnableFuse(const OpGroup& first, const OpGroup& second) = 0; | ||
|
||
protected: | ||
FusePassCtx() = default; | ||
}; | ||
|
||
class LightwareFusePassCtx : public FusePassContext { | ||
public: | ||
virtual ~LightwareFusePassCtx() {} | ||
|
||
virtual const OpGroup& PickOpGroup() const = 0; | ||
|
||
virtual const FuseHelper& fuse_helper() const = 0; | ||
|
||
virtual void EnableFuse(const OpGroup& first, const OpGroup& second) = 0; | ||
|
||
protected: | ||
LightwareFusePassCtx() = default; | ||
}; | ||
|
||
class GraphGroupLightwareFusePassCtx final : public LightwareFusePassCtx { | ||
public: | ||
GraphGroupLightwareFusePassCtx( | ||
const FusionHelperBase* graph_group_fusion_helper, | ||
const OpGroup& group, | ||
const std::function<void(const OpGroup& first, const OpGroup& second)>& | ||
EnableFuse) | ||
: graph_group_fusion_helper_(graph_group_fusion_helper), | ||
group_(group), | ||
EnableFuse_(EnableFuse), | ||
fuse_helper_( | ||
new GraphGroupFuseHelper<GraphGroupLightwareFusePassCtx>(this)) {} | ||
|
||
const OpGroup& PickOpGroup() const override { return group_; } | ||
|
||
const FuseHelper& fuse_helper() const override { return *fuse_helper_; } | ||
|
||
void EnableFuse(const OpGroup& first, const OpGroup& second) override { | ||
EnableFuse_(first, second); | ||
} | ||
|
||
const FusionHelperBase& graph_group_fusion_helper() const { | ||
return *graph_group_fusion_helper_; | ||
} | ||
|
||
private: | ||
const FusionHelperBase* graph_group_fusion_helper_; | ||
const OpGroup& group_; | ||
const std::function<void(const OpGroup& first, const OpGroup& second)> | ||
EnableFuse_; | ||
const std::unique_ptr<const FuseHelper> fuse_helper_; | ||
}; | ||
|
||
class InputFusePassCtx : public FusePassCtx { | ||
public: | ||
virtual ~InputFusePassCtx() {} | ||
|
||
virtual const OpGroupList& PickConsumersWithSameInputs() const = 0; | ||
|
||
virtual const FuseHelper& fuse_helper() const = 0; | ||
|
||
virtual void EnableFuse(const OpGroup& first, const OpGroup& second) = 0; | ||
|
||
protected: | ||
InputFusePassCtx() = default; | ||
}; | ||
|
||
class GraphGroupInputFusePassCtx final : public InputFusePassCtx { | ||
public: | ||
GraphGroupInputFusePassCtx( | ||
const FusionHelperBase* graph_group_fusion_helper, | ||
const OpGroupList& groups, | ||
const std::function<void(const OpGroup& first, const OpGroup& second)>& | ||
EnableFuse) | ||
: graph_group_fusion_helper_(graph_group_fusion_helper), | ||
groups_(groups), | ||
EnableFuse_(EnableFuse), | ||
fuse_helper_( | ||
new GraphGroupFuseHelper<GraphGroupInputFusePassCtx>(this)) {} | ||
|
||
const OpGroupList& PickConsumersWithSameInputs() const override { | ||
return groups_; | ||
} | ||
|
||
const FuseHelper& fuse_helper() const override { return *fuse_helper_; } | ||
|
||
void EnableFuse(const OpGroup& first, const OpGroup& second) override { | ||
EnableFuse_(first, second); | ||
} | ||
|
||
const FusionHelperBase& graph_group_fusion_helper() const { | ||
return *graph_group_fusion_helper_; | ||
} | ||
|
||
private: | ||
const FusionHelperBase* graph_group_fusion_helper_; | ||
const OpGroupList& groups_; | ||
const std::function<void(const OpGroup& first, const OpGroup& second)> | ||
EnableFuse_; | ||
const std::unique_ptr<const FuseHelper> fuse_helper_; | ||
}; | ||
|
||
} // namespace api | ||
} // namespace cinn |
Oops, something went wrong.
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.
是不是叫
MarkFusible
更合适?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.
MarkFusible
这个命名挺好的 👍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.
赞同,已替换为
MarkFusible