-
Notifications
You must be signed in to change notification settings - Fork 5.9k
[PIR] pir onednn support conv2d_transpose #61165
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
Changes from 17 commits
7793377
982a92e
12bb0ff
e392093
40e0d32
17cee13
c39f166
1c5314b
becbbda
483be0d
abb757d
fe450ae
a15fb6e
9a3ad90
fd721b0
dce0f81
a3dd5d5
094c382
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -23,6 +23,9 @@ | |
| #include "paddle/pir/include/core/builtin_op.h" | ||
| #include "paddle/pir/include/core/operation.h" | ||
| #include "paddle/pir/include/core/value.h" | ||
| #ifdef PADDLE_WITH_DNNL | ||
| #include "build/paddle/fluid/pir/dialect/operator/ir/onednn_op.h" | ||
| #endif | ||
|
|
||
| namespace paddle { | ||
| namespace drr { | ||
|
|
@@ -61,6 +64,114 @@ void OperationFactory::RegisterManualOpCreator() { | |
| attrs.at("bias").dyn_cast<pir::FloatAttribute>().data(), | ||
| attrs.at("bias_after_scale").dyn_cast<pir::BoolAttribute>().data()); | ||
| }); | ||
|
|
||
| #ifdef PADDLE_WITH_DNNL | ||
| op_creator_map["onednn_op.conv2d_transpose_bias"] = | ||
| [](const std::vector<pir::Value>& inputs, | ||
| const pir::AttributeMap& attrs, | ||
| pir::PatternRewriter& rewriter) { | ||
| if (inputs.size() == 4) { | ||
| IR_ENFORCE( | ||
| attrs.find("strides") != attrs.end(), | ||
| "'strides' Attribute is expected for Conv2dTransposeBiasOp. "); | ||
| std::vector<int> strides; | ||
| for (size_t i = 0; | ||
| i < attrs.at("strides").dyn_cast<pir::ArrayAttribute>().size(); | ||
| i++) { | ||
| strides.push_back(attrs.at("strides") | ||
| .dyn_cast<pir::ArrayAttribute>() | ||
| .at(i) | ||
| .dyn_cast<pir::Int32Attribute>() | ||
| .data()); | ||
| } | ||
|
Comment on lines
+77
to
+86
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ArrayAttribute转普通vector有没有提供一些工具函数,用公共函数能省不少行
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 这一块我觉得可以放在pattern实现里的
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 这个是从生成的代码里copy过来的。这样的工具函数暂时没有。先写成这样吧。
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
pattern是负责匹配的。匹配阶段好像只有“描述”信息,没有实例化Operation。pattern能实现承载这个逻辑吗? |
||
|
|
||
| IR_ENFORCE( | ||
| attrs.find("paddings") != attrs.end(), | ||
| "'paddings' Attribute is expected for Conv2dTransposeBiasOp. "); | ||
| std::vector<int> paddings; | ||
| for (size_t i = 0; | ||
| i < attrs.at("paddings").dyn_cast<pir::ArrayAttribute>().size(); | ||
| i++) { | ||
| paddings.push_back(attrs.at("paddings") | ||
| .dyn_cast<pir::ArrayAttribute>() | ||
| .at(i) | ||
| .dyn_cast<pir::Int32Attribute>() | ||
| .data()); | ||
| } | ||
|
|
||
| IR_ENFORCE(attrs.find("output_padding") != attrs.end(), | ||
| "'output_padding' Attribute is expected for " | ||
| "Conv2dTransposeBiasOp. "); | ||
| std::vector<int> output_padding; | ||
| for (size_t i = 0; i < attrs.at("output_padding") | ||
| .dyn_cast<pir::ArrayAttribute>() | ||
| .size(); | ||
| i++) { | ||
| output_padding.push_back(attrs.at("output_padding") | ||
| .dyn_cast<pir::ArrayAttribute>() | ||
| .at(i) | ||
| .dyn_cast<pir::Int32Attribute>() | ||
| .data()); | ||
| } | ||
|
|
||
| IR_ENFORCE(attrs.find("padding_algorithm") != attrs.end(), | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 禁止使用IR_ENFORCE, 这儿需要改成PADDLE_ENFORCE_EQ。其它地方类似。具体参考https://github.com/PaddlePaddle/Paddle/wiki/PADDLE_ENFORCE-Rewriting-Specification |
||
| "'padding_algorithm' Attribute is expected for " | ||
| "Conv2dTransposeBiasOp. "); | ||
| std::string padding_algorithm = attrs.at("padding_algorithm") | ||
| .dyn_cast<pir::StrAttribute>() | ||
| .AsString(); | ||
|
|
||
| IR_ENFORCE( | ||
| attrs.find("groups") != attrs.end(), | ||
| "'groups' Attribute is expected for Conv2dTransposeBiasOp. "); | ||
| int groups = | ||
| attrs.at("groups").dyn_cast<pir::Int32Attribute>().data(); | ||
|
|
||
| IR_ENFORCE( | ||
| attrs.find("dilations") != attrs.end(), | ||
| "'dilations' Attribute is expected for Conv2dTransposeBiasOp. "); | ||
| std::vector<int> dilations; | ||
| for (size_t i = 0; | ||
| i < attrs.at("dilations").dyn_cast<pir::ArrayAttribute>().size(); | ||
| i++) { | ||
| dilations.push_back(attrs.at("dilations") | ||
| .dyn_cast<pir::ArrayAttribute>() | ||
| .at(i) | ||
| .dyn_cast<pir::Int32Attribute>() | ||
| .data()); | ||
| } | ||
|
|
||
| IR_ENFORCE(attrs.find("data_format") != attrs.end(), | ||
| "'data_format' Attribute is expected for " | ||
| "Conv2dTransposeBiasOp. "); | ||
| std::string data_format = | ||
| attrs.at("data_format").dyn_cast<pir::StrAttribute>().AsString(); | ||
|
|
||
| IR_ENFORCE( | ||
| attrs.find("is_test") != attrs.end(), | ||
| "'is_test' Attribute is expected for Conv2dTransposeBiasOp. "); | ||
| bool is_test = | ||
| attrs.at("is_test").dyn_cast<pir::BoolAttribute>().data(); | ||
|
|
||
| return rewriter.Build<paddle::onednn::dialect::Conv2dTransposeBiasOp>( | ||
| inputs[0], | ||
| inputs[1], | ||
| inputs[2], | ||
| inputs[3], | ||
| strides, | ||
| paddings, | ||
| output_padding, | ||
| padding_algorithm, | ||
| groups, | ||
| dilations, | ||
| data_format, | ||
| is_test); | ||
| } | ||
|
|
||
| return rewriter.Build<paddle::onednn::dialect::Conv2dTransposeBiasOp>( | ||
| inputs[0], inputs[1], inputs[2], attrs); | ||
| }; | ||
| #endif | ||
| } | ||
|
|
||
| pir::Attribute CreateIrAttribute(const std::any& obj) { | ||
|
|
||
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.
build前缀需要删去
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.
好的好的,感谢感谢。现在每次从icoding里复制文件路径都带build,汗