-
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
[PIR] Add parse kernel key interface #59124
Merged
zhangbo9674
merged 8 commits into
PaddlePaddle:develop
from
zhangbo9674:dev/refine_parse_kernel_key
Nov 20, 2023
+187
−4
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
17da4a5
add interface
zhangbo9674 328f9a0
add interface
zhangbo9674 5c2bf8e
add code
zhangbo9674 183dc70
fix
zhangbo9674 b020fc7
fix
zhangbo9674 4a97a9a
fix
zhangbo9674 dab550b
fix
zhangbo9674 9f717df
fix
zhangbo9674 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
24 changes: 24 additions & 0 deletions
24
paddle/fluid/pir/dialect/op_generator/parse_kernel_key_gen.py
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,24 @@ | ||
# Copyright (c) 2023 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. | ||
|
||
OP_GET_KERNEL_TYPE_FOR_VAR_TEMPLATE = """ | ||
std::tuple<phi::DataType, phi::Backend> {op_name}::ParseKernelKey(pir::Operation *op) {{ | ||
VLOG(4) << "Parse kernel key for op: {op_name}"; | ||
return {op_name}ParseKernelKey(op); | ||
}} | ||
""" | ||
|
||
|
||
def gen_parse_kernel_key_str(op_class_name): | ||
return OP_GET_KERNEL_TYPE_FOR_VAR_TEMPLATE.format(op_name=op_class_name) |
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
63 changes: 63 additions & 0 deletions
63
paddle/fluid/pir/dialect/operator/interface/parse_kernel_key.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,63 @@ | ||
// Copyright (c) 2023 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/fluid/pir/dialect/operator/ir/op_type.h" | ||
#include "paddle/fluid/pir/dialect/operator/utils/utils.h" | ||
#include "paddle/phi/common/backend.h" | ||
#include "paddle/phi/common/data_type.h" | ||
#include "paddle/pir/core/op_base.h" | ||
|
||
using KernelKeyTuple = std::tuple<phi::DataType, phi::Backend>; | ||
|
||
namespace paddle { | ||
namespace dialect { | ||
class ParseKernelKeyInterface | ||
: public pir::OpInterfaceBase<ParseKernelKeyInterface> { | ||
public: | ||
struct Concept { | ||
explicit Concept(KernelKeyTuple (*parse_kernel_key)(pir::Operation *op)) | ||
: parse_kernel_key_(parse_kernel_key) {} | ||
KernelKeyTuple (*parse_kernel_key_)(pir::Operation *op); | ||
}; | ||
|
||
template <class ConcreteOp> | ||
struct Model : public Concept { | ||
static KernelKeyTuple ParseKernelKey(pir::Operation *op) { | ||
return ConcreteOp::ParseKernelKey(op); | ||
} | ||
|
||
Model() : Concept(ParseKernelKey) {} | ||
}; | ||
|
||
/// Constructor | ||
ParseKernelKeyInterface(pir::Operation *op, Concept *impl) | ||
: pir::OpInterfaceBase<ParseKernelKeyInterface>(op), impl_(impl) {} | ||
|
||
KernelKeyTuple ParseKernelKey(pir::Operation *op) { | ||
return impl_->parse_kernel_key_(op); | ||
} | ||
|
||
private: | ||
Concept *impl_; | ||
}; | ||
|
||
// Register the ParseKernelKeyInterface for unique op. | ||
KernelKeyTuple UniqueOpParseKernelKey(pir::Operation *op); | ||
|
||
} // namespace dialect | ||
} // namespace paddle | ||
|
||
IR_DECLARE_EXPLICIT_TYPE_ID(paddle::dialect::ParseKernelKeyInterface) |
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
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.
这个是不是放到单独的.cc文件里面比较好
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.
暂时仅有这一个函数,后续有需求再单独放在一个文件中