-
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
[DRR] C++ DRR (Declarative Rewrite Rule) of Paddle #55859
Merged
Merged
Changes from 227 commits
Commits
Show all changes
232 commits
Select commit
Hold shift + click to select a range
e41ee6d
fix cudnn 8.7+ bug on cudnnConvolutionBiasActivationForward
yuanlehome 9ecefe9
Merge branch 'develop' of https://github.com/PaddlePaddle/Paddle into…
yuanlehome d092636
Merge branch 'develop' of https://github.com/PaddlePaddle/Paddle into…
yuanlehome b74a6df
Merge branch 'develop' of https://github.com/PaddlePaddle/Paddle into…
yuanlehome 9ffdf8e
Merge branch 'develop' of https://github.com/PaddlePaddle/Paddle into…
yuanlehome 2ebb74e
Merge branch 'develop' of https://github.com/yuanlehome/Paddle into d…
yuanlehome 4350ddb
add drr_rewrite_pattern.h and remove_redundent_reshape demo
yuanlehome 665458d
add drr_context and pattern_graph class
zyfncg 5068af5
Merge pull request #2 from zyfncg/my_drr
yuanlehome 577161d
add test case
zyfncg 4d90c86
fix cmake file
zyfncg 37d179b
Merge pull request #3 from zyfncg/my_drr
yuanlehome 445210e
fix compile bug
zyfncg 29c69f0
fix runtime bug and refine code
zyfncg 4691895
Merge pull request #4 from zyfncg/my_drr
yuanlehome ac346c0
add MatchContext
zyfncg 984ca9d
update code
zyfncg 0dc6c0c
add impl of tensor_interface
zyfncg b86c832
fix compile bug
zyfncg 727a5c1
Merge pull request #6 from zyfncg/drr_attr
yuanlehome 61ff236
change smart ptr to pointor
gongshaotian b988494
change smart to pointor
gongshaotian e5deff3
change smart to pointor
gongshaotian 4608b5f
Replace 'weak_ptr' with pointer
gongshaotian 2d4df1a
modify weak_ptr use count==0 judgment logic
gongshaotian dd6bd6d
change smart to pointor
gongshaotian 7279d74
Merge pull request #7 from gongshaotian/drr
yuanlehome 344645a
Merge branch 'develop' into drr
yuanlehome 728d856
Merge branch 'drr' of https://github.com/gongshaotian/Paddle into drr
gongshaotian d1299b9
add match
yuanlehome a1c1e3f
add match
yuanlehome 43e1f02
remove OperationInterface
yuanlehome 68f2863
update
yuanlehome 5d1af8c
Add Rewrite impl of DrrRewritePattern
zyfncg cfa6b02
Merge branch 'drr' of https://github.com/gongshaotian/Paddle into drr
gongshaotian 7abe8db
refine code
yuanlehome 016b55e
fix compile bug
zyfncg 08f6549
Merge branch 'drr' of https://github.com/yuanlehome/Paddle into drr_ir
zyfncg b2b9998
rename ir_value to get in IrValue
zyfncg 4d0d26a
fix header include
zyfncg 4099c7a
Merge pull request #8 from zyfncg/drr_ir
yuanlehome a84b91c
add CreateOperation template demo
yuanlehome dedf54b
Merge branch 'drr' of https://github.com/yuanlehome/Paddle into drr
gongshaotian ced158f
Add GraphTopo class in pattern_graph
gongshaotian 1e3d00e
Reimplementing the GraphTopo class using queue
gongshaotian 9ced727
Reimplementing the GraphTopo class using queue
gongshaotian d0a932d
Optimize the access method of visited tensor
gongshaotian 78bf7b6
Considering that the inputs of opcall may be empty
gongshaotian 98e5d52
Merge pull request #10 from gongshaotian/drr_queue_topo
yuanlehome a98230c
Overloading the operator() method of Op, supporting dual tensor inputs
gongshaotian 9e68c4d
support attr
zyfncg e52472f
Merge branch 'drr' of https://github.com/yuanlehome/Paddle into drr_ir
zyfncg 78b60df
Merge commit 'refs/pull/11/head' of https://github.com/yuanlehome/Pad…
zyfncg b929f26
Merge pull request #11 from gongshaotian/op_extension
yuanlehome 2425095
1. Add Op class support for multi input and multi output function. 2.…
gongshaotian 7306e85
1. Add transferOP in createOption func
gongshaotian 998c30d
fix bug
zyfncg 1d80ce9
Merge branch 'drr' of https://github.com/yuanlehome/Paddle into drr_ir
zyfncg 0f1b187
fix NotifyOperationRemoved
zyfncg 341fd65
refine code
zyfncg 331d9a6
Fix axis bug in perm
gongshaotian 385b7d1
mupdate share_ptr
zyfncg 25d4a0a
Merge pull request #13 from zyfncg/drr_ir
yuanlehome 7b8cba9
Merge branch 'PaddlePaddle:develop' into drr
yuanlehome 25bd0c0
update
yuanlehome a3b3895
refine drr_test ut
yuanlehome 8312452
merge drr-pr#13
gongshaotian 82242b7
Modify according to review
gongshaotian c148e81
modify reshape_op
zyfncg b66f611
Merge commit 'refs/pull/14/head' of https://github.com/yuanlehome/Pad…
zyfncg 5282144
Merge pull request #14 from gongshaotian/op_extension
yuanlehome c99a9cd
format code
yuanlehome 15464bb
support vector<int> for attr
zyfncg 63383f5
Merge branch 'drr' of https://github.com/yuanlehome/Paddle into drr_opt
zyfncg 2a7c68f
fix drr test
yuanlehome 3ddb601
Merge pull request #15 from zyfncg/drr_opt
yuanlehome 1af27c5
refine code
yuanlehome 6b9e789
Resolve compilation loop dependencies
yuanlehome fb22619
add RequireNativeCall
zyfncg 11a452f
Merge branch 'drr' of https://github.com/yuanlehome/Paddle into drr_n…
zyfncg 8587d7c
support native_call in drr api
zyfncg cead1b7
Merge pull request #16 from zyfncg/drr_native_call
yuanlehome 56f6605
temp tensor prefix fix
yuanlehome ea94061
refine code
yuanlehome 674acbe
suport Tensor Assgin API in ResultPattern
zyfncg b2059bc
Merge branch 'drr' of https://github.com/yuanlehome/Paddle into drr_opt
zyfncg 0f531dc
refine test code
zyfncg 1c3ab40
Merge pull request #17 from zyfncg/drr_opt
yuanlehome 49d287c
Merge branch 'develop' of https://github.com/PaddlePaddle/Paddle into…
yuanlehome 78fecfa
refactor ther drr_pattern class
zyfncg bb1da4b
refine test case
zyfncg 9eeb511
rename DrrPatternBuilder to DrrPatternBase
zyfncg f0751d6
Merge pull request #18 from zyfncg/drr_pass
yuanlehome ef3b5ca
fix compile bug
zyfncg 3327a3e
adjust include
yuanlehome ce5929d
Add log info in DrrRewritePattern
zyfncg f3b71c2
Merge branch 'drr' of https://github.com/yuanlehome/Paddle into drr_pass
zyfncg e92436e
Merge pull request #19 from zyfncg/drr_pass
yuanlehome 7a862b4
use ir::get_type_name
yuanlehome 16f066a
use ir::get_type_name
yuanlehome a1d8c7e
support compute attrbute in drr pattern
zyfncg 7009ac4
Merge branch 'drr' of https://github.com/yuanlehome/Paddle into drr_attr
zyfncg cd8af21
refine code
zyfncg 524f15f
Merge pull request #20 from zyfncg/drr_attr
yuanlehome fed2f8b
Merge branch 'develop' of https://github.com/PaddlePaddle/Paddle into…
yuanlehome adcc73c
Add fusion testing code for fullOp and expandOp
35c9390
Standardize code format
gongshaotian da03ecb
Replace IR_THROW() with PADDLE_THROW()
gongshaotian c251ca9
Merge pull request #21 from gongshaotian/drr
yuanlehome 9964567
refine code
yuanlehome 4749ecd
add attention fuse demo
yuanlehome d0c17ea
update
yuanlehome 78c33b2
Merge branch 'develop' of https://github.com/PaddlePaddle/Paddle into…
yuanlehome cc642a5
fix compile error
yuanlehome df6f824
add multihead_matmul fuse pattern
yuanlehome 5aeec24
fix multihead_matmul
yuanlehome e959e60
Update drr_attention_fuse_test.cc
gongshaotian 5b6717d
Merge pull request #22 from gongshaotian/drr
yuanlehome ae3acc9
fix drr_attention_fuse_test compile
yuanlehome 51ba73c
add fused_gemm_epilogue in drr
zyfncg 98b57e1
attr support std::vector<int64_t>
yuanlehome ed332d3
add debug log
yuanlehome dc7aae6
update
yuanlehome f8fe52d
fix some bug
zyfncg d591592
Merge branch 'drr' of https://github.com/yuanlehome/Paddle into drr_pass
zyfncg f3c1d88
Merge pull request #23 from zyfncg/drr_pass
yuanlehome 728d65f
Merge branch 'develop' of https://github.com/PaddlePaddle/Paddle into…
yuanlehome 9235c31
fix confilct
zyfncg 91a5036
Merge pull request #24 from zyfncg/drr_pass
yuanlehome 185e0b2
Merge branch 'drr' of https://github.com/yuanlehome/Paddle into drr
yuanlehome 8ed5165
support subgraph replace in source pattern graph for drr
zyfncg ae5950a
Merge branch 'develop' of https://github.com/PaddlePaddle/Paddle into…
yuanlehome 92a3606
Improve the implementation of Drr and multihead_matmul_fuse_pass
yuanlehome 58804eb
Merge branch 'develop' of https://github.com/PaddlePaddle/Paddle into…
yuanlehome 0882e9f
add ReorderBlockOpsPass
zyfncg 55d4a95
Merge branch 'drr' of https://github.com/yuanlehome/Paddle into drr_pass
zyfncg 789d8c8
fix drr_attention_fuse_pass
yuanlehome 6311786
update
yuanlehome ede8fff
Merge branch 'develop' of https://github.com/PaddlePaddle/Paddle into…
yuanlehome cf62d06
Merge branch 'develop' of https://github.com/PaddlePaddle/Paddle into…
zyfncg 31b7407
Merge pull request #26 from zyfncg/merge_dev
yuanlehome b320ba4
Merge branch 'develop' of https://github.com/PaddlePaddle/Paddle into…
yuanlehome 749ebce
update reorder_block_ops_pass
zyfncg 4c6f31e
Merge branch 'drr' of https://github.com/yuanlehome/Paddle into drr_pass
zyfncg 8550e00
Merge branch 'develop' of https://github.com/PaddlePaddle/Paddle into…
yuanlehome e3c8a76
revert fusedgemm
yuanlehome 6693c8e
update
yuanlehome 623ed05
Merge branch 'develop' of https://github.com/PaddlePaddle/Paddle into…
yuanlehome c424305
Merge branch 'develop' of https://github.com/PaddlePaddle/Paddle into…
yuanlehome b17942f
Merge branch 'develop' of https://github.com/PaddlePaddle/Paddle into…
yuanlehome 1a05a2b
Merge branch 'develop' of https://github.com/PaddlePaddle/Paddle into…
yuanlehome 7260c1e
Merge branch 'develop' of https://github.com/PaddlePaddle/Paddle into…
yuanlehome fb5f482
Add Bottom2UpMatch() func
gongshaotian 6e88522
Merge branch 'drr' of https://github.com/yuanlehome/Paddle into drr_pass
zyfncg 4fa16af
merge code
zyfncg f641a9a
fix bug
gongshaotian 1afe1fc
add log & fix bug
gongshaotian 9c9c16b
refine cpp type trait
zyfncg 0833a06
Merge pull request #25 from zyfncg/drr_pass
yuanlehome bd3faea
Merge branch 'develop' of https://github.com/PaddlePaddle/Paddle into…
yuanlehome fe1325f
using oprand() & num_oprand() replace oprands()
gongshaotian c610650
fix conflict
yuanlehome ef3e954
Merge branch 'drr' of https://github.com/gongshaotian/Paddle into drr
gongshaotian 2b59813
fix compile
yuanlehome f4e9728
fix pd.xxx to pd_op.xxx
yuanlehome 2b2eba9
fix bug of delete op in drr
zyfncg bceb977
Merge pull request #29 from zyfncg/drr_pass
yuanlehome 64bcf90
add PatternGraphMatchV2 & FindOutputOp func
gongshaotian ef7700e
refactor ir operation creator
zyfncg 7876fe8
fix include pir
gongshaotian d18b803
Merge branch 'temp' into drr
gongshaotian 2ad0975
fix ir
gongshaotian 288b33c
merging
gongshaotian 67a2dfe
Split out dfsvisitor func from FindOutputOp func
gongshaotian a517dad
fix bug
gongshaotian b00ddd1
fix output op in source pattern bug
gongshaotian 235be4f
Debugging drr_test drr_attention_fuse_test passed!
gongshaotian 1c8b077
Debugging drr_fuse_linear_test passed!
gongshaotian 5f24312
Optimize the PatternGraphMatchV2 function interface and overload the …
gongshaotian aca0d4b
Modify comments and function names
gongshaotian 08cf893
auto code-gen for creating ir operation in drr
zyfncg c6e6b29
delete debug log
zyfncg a03896e
optimize the interface of MatchFromOutputToInput()
gongshaotian b3c7d26
Optimize SourcePatternGraph::OutputNodes judgment logic
gongshaotian 9de0a04
polish code
zyfncg 9f59cdd
Merge pull request #30 from zyfncg/drr_pass
yuanlehome 46a734a
using default operator=() in MatchContextImpl
gongshaotian 5239e7d
Merge pull request #32 from gongshaotian/drr_dfs_test
yuanlehome 10dba83
Merge branch 'develop' of https://github.com/PaddlePaddle/Paddle into…
zyfncg 43d5e48
Merge pull request #33 from zyfncg/merge_dev
yuanlehome 224e4b5
Merge branch 'develop' of https://github.com/PaddlePaddle/Paddle into…
zyfncg 85622b9
fix merge conflict
zyfncg b731d39
Merge pull request #34 from zyfncg/drr_pass
yuanlehome 0fe5784
create test case: drr_same_name_test
gongshaotian ba9f314
fix duplicate binding of ir op bug
gongshaotian dbef1ff
Merge branch 'drr' of https://github.com/gongshaotian/Paddle into drr
gongshaotian b3bcc66
Rename drr_same_name_test to drr_same_type_binding_test & Add graphic…
gongshaotian 17b39f9
Merge pull request #35 from gongshaotian/drr
yuanlehome 8d31696
Merge branch 'develop' into drr
yuanlehome 78eb5bc
refactor logic of insert point for creating new operation in drr
zyfncg 91240ea
Merge pull request #36 from zyfncg/drr_pass
yuanlehome a984879
update
yuanlehome 3df2f26
Merge branch 'develop' of https://github.com/PaddlePaddle/Paddle into…
yuanlehome d624336
fix compile error
yuanlehome 4993a22
fix some bug
zyfncg 8df68b8
Merge pull request #37 from zyfncg/drr_pass
yuanlehome 3b6cc17
Merge branch 'develop' of https://github.com/PaddlePaddle/Paddle into…
yuanlehome 3e166f2
fix codestyle
yuanlehome d3bc65d
fix bug
zyfncg c985ec7
Merge pull request #38 from zyfncg/drr_pass
yuanlehome b58a9d9
Update anchor node judgment logic
gongshaotian bffd25d
Merge pull request #39 from gongshaotian/drr
yuanlehome affa0fb
Merge branch 'develop' of https://github.com/PaddlePaddle/Paddle into…
yuanlehome e9db735
Merge branch 'develop' of https://github.com/PaddlePaddle/Paddle into…
yuanlehome 4bac4b1
Merge branch 'develop' of https://github.com/PaddlePaddle/Paddle into…
yuanlehome 3aabfe8
fix bug of link pir
zyfncg 77e8138
Merge branch 'drr' of https://github.com/yuanlehome/Paddle into drr_pass
zyfncg 7422169
Merge pull request #40 from zyfncg/drr_pass
yuanlehome a21c96b
fix codestyle
yuanlehome 6330309
self review v1
yuanlehome 8a0f5b4
Merge branch 'develop' of https://github.com/PaddlePaddle/Paddle into…
yuanlehome 2c6fb1e
refine code format
zyfncg 2866cb5
Merge branch 'drr' of https://github.com/yuanlehome/Paddle into drr_pass
zyfncg c80faa8
Merge pull request #41 from zyfncg/drr_pass
yuanlehome b0f9ce0
Merge branch 'drr' of https://github.com/yuanlehome/Paddle into drr
yuanlehome e9bb397
Merge branch 'develop' of https://github.com/PaddlePaddle/Paddle into…
yuanlehome 55573f8
set thread_local for count in op class
zyfncg ad3764f
fix compile on mac
yuanlehome 6d4ab15
remove unused .h in value.cc
yuanlehome 0430ba0
Merge pull request #42 from zyfncg/drr_pass
yuanlehome a1c093b
Merge branch 'drr' of https://github.com/yuanlehome/Paddle into drr
yuanlehome 61e4d31
fix compile
yuanlehome 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
add_subdirectory(dialect) | ||
add_subdirectory(transforms) | ||
add_subdirectory(drr) |
166 changes: 166 additions & 0 deletions
166
paddle/fluid/pir/dialect/op_generator/op_creator_drr_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,166 @@ | ||
# 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. | ||
|
||
import argparse | ||
|
||
import yaml | ||
from op_gen import OpCompatParser, OpInfoParser, to_pascal_case | ||
|
||
CPP_FILE_TEMPLATE = """ | ||
#include "paddle/fluid/pir/drr/ir_operation_factory.h" | ||
|
||
#include "paddle/fluid/pir/dialect/operator/ir/pd_op.h" | ||
#include "paddle/fluid/pir/dialect/operator/ir/manual_op.h" | ||
|
||
namespace pir {{ | ||
namespace drr {{ | ||
|
||
void OperationFactory::RegisterGeneratedOpCreator() {{ | ||
{body} | ||
}} | ||
|
||
}} // namespace drr | ||
}} // namespace pir | ||
|
||
""" | ||
|
||
NORMAL_FUNCTION_TEMPLATE = """ | ||
RegisterOperationCreator( | ||
"{op_name}", | ||
[](const std::vector<Value>& inputs, | ||
const pir::AttributeMap& attrs, | ||
pir::PatternRewriter& rewriter) {{ | ||
return rewriter.Build<paddle::dialect::{op_class_name}>( | ||
{params_code}); | ||
}}); | ||
""" | ||
|
||
MUTABLE_ATTR_FUNCTION_TEMPLATE = """ | ||
RegisterOperationCreator( | ||
"{op_name}", | ||
[](const std::vector<Value>& inputs, | ||
const pir::AttributeMap& attrs, | ||
pir::PatternRewriter& rewriter) {{ | ||
// mutable_attr is tensor | ||
if (inputs.size() > {inputs_num}) {{ | ||
return rewriter.Build<paddle::dialect::{op_class_name}>( | ||
{params_code_with_mutable_attr}); | ||
}} else {{ | ||
return rewriter.Build<paddle::dialect::{op_class_name}>( | ||
{params_code_no_mutable_attr}); | ||
}} | ||
}}); | ||
""" | ||
|
||
|
||
class OpCreatorCodeGen: | ||
def __init__(self, op_yaml_files, op_compat_yaml_file, dialect_name): | ||
self.op_info_items = self.parse_yaml(op_yaml_files, op_compat_yaml_file) | ||
self.dialect_name = dialect_name | ||
|
||
def parse_yaml(self, op_yaml_files, op_compat_yaml_file): | ||
op_compat_parser = OpCompatParser(op_compat_yaml_file) | ||
|
||
op_yaml_items = [] | ||
for yaml_file in op_yaml_files: | ||
with open(yaml_file, "r") as f: | ||
ops = yaml.safe_load(f) | ||
op_yaml_items = op_yaml_items + ops | ||
op_info_items = [] | ||
for op in op_yaml_items: | ||
op_compat_item = op_compat_parser.get_compat(op['name']) | ||
if ( | ||
op_compat_item is not None | ||
and op_compat_item['op'] == "pow" | ||
and 'scalar' in op_compat_item | ||
): | ||
op_compat_item = op_compat_item.pop('scalar') | ||
op_info_items.append(OpInfoParser(op, op_compat_item)) | ||
return op_info_items | ||
|
||
def gen_cpp_file_code(self, cpp_file_path): | ||
body_code = "" | ||
for op_info_item in self.op_info_items: | ||
if op_info_item.infer_meta_map is None: | ||
continue | ||
for phi_op_name in op_info_item.op_phi_name: | ||
ir_op_name = self.dialect_name + "." + phi_op_name | ||
params_no_mutable_attr = [] | ||
for i in range(len(op_info_item.input_name_list)): | ||
params_no_mutable_attr.append( | ||
f"inputs[{i}].dyn_cast<pir::OpResult>()" | ||
) | ||
if len(op_info_item.attribute_name_list) > 0: | ||
params_no_mutable_attr.append("attrs") | ||
|
||
if len(op_info_item.mutable_attribute_name_list) == 0: | ||
body_code += NORMAL_FUNCTION_TEMPLATE.format( | ||
op_name=ir_op_name, | ||
op_class_name=(to_pascal_case(phi_op_name) + "Op"), | ||
params_code=", ".join(params_no_mutable_attr), | ||
) | ||
else: | ||
params_with_mutable_attr = [] | ||
for i in range( | ||
len(op_info_item.input_name_list) | ||
+ len(op_info_item.mutable_attribute_name_list) | ||
): | ||
params_with_mutable_attr.append( | ||
f"inputs[{i}].dyn_cast<pir::OpResult>()" | ||
) | ||
if len(op_info_item.attribute_name_list) > len( | ||
op_info_item.mutable_attribute_name_list | ||
): | ||
# TODO(zyfncg): Currently Op::Build Interface doesn't support this case. | ||
continue | ||
# params_with_mutable_attr.append("attrs") | ||
|
||
body_code += MUTABLE_ATTR_FUNCTION_TEMPLATE.format( | ||
op_name=ir_op_name, | ||
inputs_num=len(op_info_item.input_name_list), | ||
op_class_name=(to_pascal_case(phi_op_name) + "Op"), | ||
params_code_with_mutable_attr=",".join( | ||
params_with_mutable_attr | ||
), | ||
params_code_no_mutable_attr=", ".join( | ||
params_no_mutable_attr | ||
), | ||
) | ||
|
||
with open(cpp_file_path, 'w') as f: | ||
f.write(CPP_FILE_TEMPLATE.format(body=body_code)) | ||
|
||
|
||
def ParseArguments(): | ||
parser = argparse.ArgumentParser( | ||
description='Generate Op Creator Files By Yaml' | ||
) | ||
parser.add_argument('--op_yaml_files', type=str) | ||
parser.add_argument('--op_compat_yaml_file', type=str) | ||
parser.add_argument('--dialect_name', type=str) | ||
parser.add_argument('--op_creator_file', type=str) | ||
return parser.parse_args() | ||
|
||
|
||
if __name__ == '__main__': | ||
args = ParseArguments() | ||
op_yaml_files = args.op_yaml_files.split(",") | ||
op_compat_yaml_file = args.op_compat_yaml_file | ||
op_creator_file = args.op_creator_file | ||
dialect_name = args.dialect_name | ||
|
||
code_gen = OpCreatorCodeGen( | ||
op_yaml_files, op_compat_yaml_file, dialect_name | ||
) | ||
code_gen.gen_cpp_file_code(op_creator_file) |
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,65 @@ | ||
file(GLOB DRR_SRCS "*.cc" "api/*.cc") | ||
|
||
set(op_creator_gen_file | ||
${PADDLE_SOURCE_DIR}/paddle/fluid/pir/dialect/op_generator/op_creator_drr_gen.py | ||
) | ||
set(op_compat_yaml_file ${PADDLE_SOURCE_DIR}/paddle/phi/api/yaml/op_compat.yaml) | ||
set(op_forward_yaml_file1 | ||
${PADDLE_SOURCE_DIR}/paddle/fluid/operators/generator/parsed_ops/ops.parsed.yaml | ||
) | ||
set(op_forward_yaml_file2 | ||
${PADDLE_SOURCE_DIR}/paddle/fluid/operators/generator/parsed_ops/legacy_ops.parsed.yaml | ||
) | ||
set(op_backward_yaml_file1 | ||
${PADDLE_SOURCE_DIR}/paddle/fluid/operators/generator/parsed_ops/backward_ops.parsed.yaml | ||
) | ||
set(op_backward_yaml_file2 | ||
${PADDLE_SOURCE_DIR}/paddle/fluid/operators/generator/parsed_ops/legacy_backward_ops.parsed.yaml | ||
) | ||
set(fused_op_forward_yaml_file | ||
${PADDLE_SOURCE_DIR}/paddle/fluid/operators/generator/parsed_ops/fused_ops.parsed.yaml | ||
) | ||
set(fused_op_backward_yaml_file | ||
${PADDLE_SOURCE_DIR}/paddle/fluid/operators/generator/parsed_ops/fused_backward.parsed.yaml | ||
) | ||
|
||
set(parsed_op_dir | ||
${PADDLE_SOURCE_DIR}/paddle/fluid/pir/dialect/operator/ir/generated) | ||
|
||
set(op_yaml_file3 ${parsed_op_dir}/ops.parsed.yaml) | ||
set(op_yaml_file4 ${parsed_op_dir}/ops_backward.parsed.yaml) | ||
|
||
set(op_yaml_files | ||
${op_forward_yaml_file1},${op_forward_yaml_file2},${op_backward_yaml_file1},${op_backward_yaml_file2},${fused_op_forward_yaml_file},${fused_op_backward_yaml_file},${op_yaml_file3},${op_yaml_file4} | ||
) | ||
|
||
set(op_creator_file | ||
${PADDLE_BINARY_DIR}/paddle/fluid/pir/drr/ir_op_factory_generated.cc) | ||
set(op_creator_file_tmp ${op_creator_file}.tmp) | ||
|
||
set(dialect_name pd_op) | ||
|
||
add_custom_command( | ||
OUTPUT ${op_creator_file} | ||
COMMAND | ||
${PYTHON_EXECUTABLE} ${op_creator_gen_file} --op_yaml_files ${op_yaml_files} | ||
--op_compat_yaml_file ${op_compat_yaml_file} --dialect_name ${dialect_name} | ||
--op_creator_file ${op_creator_file_tmp} | ||
COMMAND ${CMAKE_COMMAND} -E copy_if_different ${op_creator_file_tmp} | ||
${op_creator_file} | ||
COMMENT "copy_if_different ${op_creator_file}" | ||
DEPENDS ${op_creator_gen_file} | ||
${op_forward_yaml_file1} | ||
${op_forward_yaml_file2} | ||
${op_backward_yaml_file1} | ||
${op_backward_yaml_file2} | ||
${op_compat_yaml_file} | ||
${op_yaml_file3} | ||
${op_yaml_file4} | ||
pd_op_dialect_op | ||
VERBATIM) | ||
|
||
cc_library( | ||
drr | ||
SRCS ${DRR_SRCS} ${op_creator_file} | ||
DEPS pd_op_dialect pir) |
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,41 @@ | ||
// 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/drr/api/drr_pattern_context.h" | ||
#include "paddle/fluid/pir/drr/drr_rewrite_pattern.h" | ||
|
||
namespace pir { | ||
namespace drr { | ||
|
||
template <typename DrrPattern> | ||
class DrrPatternBase { | ||
public: | ||
virtual ~DrrPatternBase() = default; | ||
|
||
// Define the Drr Pattern. | ||
virtual void operator()(pir::drr::DrrPatternContext* ctx) const = 0; | ||
|
||
std::unique_ptr<DrrRewritePattern<DrrPattern>> Build( | ||
pir::IrContext* ir_context, pir::PatternBenefit benefit = 1) const { | ||
DrrPatternContext drr_context; | ||
this->operator()(&drr_context); | ||
return std::make_unique<DrrRewritePattern<DrrPattern>>( | ||
drr_context, ir_context, benefit); | ||
} | ||
}; | ||
|
||
} // namespace drr | ||
} // namespace pir |
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.
目前在如下目录中还存在一个 yaml 文件,该 yaml 文件中定义了 pir 单独定义的算子,是否需要纳入该自动生成体系中?:paddle/fluid/pir/dialect/operator/ir/ops.yaml
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.
paddle/fluid/pir/dialect/operator/ir/ops.yaml
应该是加入进来了,对应的是这两个解析后的文件吧?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.
可能需要,这个我们后面加上~