-
Notifications
You must be signed in to change notification settings - Fork 5.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[IR] Refine PhiKernelOp attributes name and delete some unused code2 (#…
…54944) * refine code * add some interface for phi kernel op * fix compile bug * delete unused code * support code * fix bug * refine code * delete unused code * fix compile bug * fix compile bug * delete unused code * add elementwise add op * fix compile bug * refine code * fix compile bug * add ut for attribute member function * delete unused code * refine ut
- Loading branch information
1 parent
b8e4d74
commit a7419ff
Showing
22 changed files
with
192 additions
and
109 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
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,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. | ||
|
||
# generator interfaces | ||
|
||
OP_INFER_SHAPE_TEMPLATE = """ | ||
void {op_name}::InferMeta( phi::InferMetaContext *infer_meta ) {{ | ||
auto fn = PD_INFER_META(phi::{infer_meta_func}); | ||
fn(infer_meta); | ||
}} | ||
""" | ||
|
||
|
||
def gen_op_infer_meta_str(op_info, op_class_name): | ||
op_infer_meta_str = "" | ||
if op_info.infer_meta_func: | ||
op_infer_meta_str = OP_INFER_SHAPE_TEMPLATE.format( | ||
op_name=op_class_name, | ||
infer_meta_func=op_info.infer_meta_func, | ||
) | ||
return op_infer_meta_str | ||
|
||
|
||
def gen_exclusive_interface_str(op_info): | ||
exclusive_interface_str = "" | ||
if op_info.infer_meta_func: | ||
exclusive_interface_str += ( | ||
" static void InferMeta( phi::InferMetaContext *infer_meta );" | ||
) | ||
return exclusive_interface_str |
55 changes: 55 additions & 0 deletions
55
paddle/fluid/ir/dialect/op_generator/op_member_func_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,55 @@ | ||
# 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. | ||
|
||
# generator op member function | ||
|
||
OP_GET_INPUT_TEMPLATE = """ ir::Value {input_name}() {{ return operand({input_index}); }} | ||
""" | ||
OP_GET_OUTPUT_TEMPLATE = """ ir::OpResult {output_name}() {{ return result({output_index}); }} | ||
""" | ||
OP_GET_ATTRIBUTE_TEMPLATE = """ ir::Attribute attribute(const std::string &name) {{ | ||
PADDLE_ENFORCE(attributes().count(name) > 0, | ||
phi::errors::PreconditionNotMet("Attribute is not exist.")); | ||
return attributes().at(name); | ||
}} | ||
template <typename T> | ||
T attribute(const std::string &name) {{ | ||
PADDLE_ENFORCE(attributes().count(name) > 0 && attributes().at(name).isa<T>(), | ||
phi::errors::PreconditionNotMet("Attribute is not right.")); | ||
return attributes().at(name).dyn_cast<T>(); | ||
}} | ||
""" | ||
|
||
|
||
def gen_op_get_inputs_outputs_str( | ||
op_input_name_list, op_mutable_attribute_name_list, op_output_name_list | ||
): | ||
op_get_inputs_outputs_str = "" | ||
for idx in range(len(op_input_name_list)): | ||
op_get_inputs_outputs_str += OP_GET_INPUT_TEMPLATE.format( | ||
input_name=op_input_name_list[idx], | ||
input_index=idx, | ||
) | ||
for idx in range(len(op_mutable_attribute_name_list)): | ||
op_get_inputs_outputs_str += OP_GET_INPUT_TEMPLATE.format( | ||
input_name=op_mutable_attribute_name_list[idx], | ||
input_index=idx + len(op_input_name_list), | ||
) | ||
for idx in range(len(op_output_name_list)): | ||
op_get_inputs_outputs_str += OP_GET_OUTPUT_TEMPLATE.format( | ||
output_name=op_output_name_list[idx], | ||
output_index=idx, | ||
) | ||
op_get_inputs_outputs_str += OP_GET_ATTRIBUTE_TEMPLATE | ||
return op_get_inputs_outputs_str |
2 changes: 1 addition & 1 deletion
2
paddle/fluid/ir/dialect/op_verify_gen.py → .../ir/dialect/op_generator/op_verify_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
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 was deleted.
Oops, something went wrong.
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
Oops, something went wrong.