Skip to content
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] OneDNN Pir onednn instruction #60257

Merged

Conversation

wanghuancoder
Copy link
Contributor

@wanghuancoder wanghuancoder commented Dec 22, 2023

PR types

New features

PR changes

Others

Description

PIR支持OneDNN,机制建设——OneDNN Dialect添加。
目前,本地测试Program中有use_mkldnn的单测,经过ProgramTranslator已经能够成功运行到Instruction。
并支持了OneDNNPhiKernelInstruction,并跑通了Conv2d。

IR转换如下:

IR before lowering = {
 (%0) = "pd_op.feed" () {col:(Int32)1,is_persisable:[false],name:"Filter",stop_gradient:[false]} : () -> pd_op.tensor<6x3x3x3xf32>
 (%1) = "pd_op.feed" () {col:(Int32)0,is_persisable:[false],name:"Input",stop_gradient:[false]} : () -> pd_op.tensor<2x3x5x5xf32>
 (%2) = "pd_onednn_op.conv2d" (%1, %0) {data_format:"NCHW",dilations:[(Int32)1,(Int32)1],groups:(Int32)1,is_persisable:[false],is_test:false,padding_algorithm:"EXPLICIT",paddings:[(Int32)0,(Int32)0],stop_gradient:[false],strides:[(Int32)1,(Int32)1]} : (pd_op.tensor<2x3x5x5xf32>, pd_op.tensor<6x3x3x3xf32>) -> pd_op.tensor<2x6x3x3xf32>
 (%3) = "pd_op.fetch" (%2) {col:(Int32)0,name:"Output"} : (pd_op.tensor<2x6x3x3xf32>) -> pd_op.tensor<2x6x3x3xf32>
}
IR after lowering = {
 (%0) = "(phi_kernel)" () {col:(Int32)1,is_persisable:[false],kernel_key:<backend:CPU|layout:Undefined(AnyLayout)|dtype:float32>,kernel_name:"",name:"Filter",op_name:"pd_op.feed",stop_gradient:[false]} : () -> cpu_tensor<6x3x3x3xf32>
 (%1) = "(phi_kernel)" () {col:(Int32)0,is_persisable:[false],kernel_key:<backend:CPU|layout:Undefined(AnyLayout)|dtype:float32>,kernel_name:"",name:"Input",op_name:"pd_op.feed",stop_gradient:[false]} : () -> cpu_tensor<2x3x5x5xf32>
 (%2) = "pd_onednn_kernel.phi_kernel" (%1, %0) {data_format:"NCHW",dilations:[(Int32)1,(Int32)1],dynamic_fallback:false,extra_args:["is_test"],groups:(Int32)1,is_onednn_only:false,is_persisable:[false],is_test:false,kernel_key:<backend:ONEDNN|layout:ONEDNN|dtype:float32>,kernel_name:"conv2d",layout_transform_arg:"data_format",layout_transform_inputs:["input"],op_name:"pd_onednn_op.conv2d",padding_algorithm:"EXPLICIT",paddings:[(Int32)0,(Int32)0],stop_gradient:[false],strides:[(Int32)1,(Int32)1]} : (cpu_tensor<2x3x5x5xf32>, cpu_tensor<6x3x3x3xf32>) -> cpu_tensor<2x6x3x3xf32>
 (%3) = "onednn_to_paddle_layout(phi_kernel)" (%2) {dst_layout:(Int32)0,is_persisable:[false],kernel_key:<backend:CPU|layout:Undefined(AnyLayout)|dtype:float32>,kernel_name:"onednn_to_paddle_layout",op_name:"pd_op.onednn_to_paddle_layout"} : (cpu_tensor<2x6x3x3xf32>) -> cpu_tensor<2x6x3x3xf32>
 (%4) = "fetch(phi_kernel)" (%3) {col:(Int32)0,kernel_key:<backend:CPU|layout:Undefined(AnyLayout)|dtype:float32>,kernel_name:"fetch",name:"Output",op_name:"pd_op.fetch"} : (cpu_tensor<2x6x3x3xf32>) -> cpu_tensor<2x6x3x3xf32>
}

Pcard-67164

winter-wang
winter-wang previously approved these changes Dec 26, 2023
Copy link
Contributor

@winter-wang winter-wang left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

kangguangli
kangguangli previously approved these changes Dec 26, 2023
Copy link
Contributor

@kangguangli kangguangli left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM for program translator part.

Aurelius84
Aurelius84 previously approved these changes Dec 26, 2023
Copy link
Contributor

@Aurelius84 Aurelius84 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@@ -5,6 +5,24 @@ if(NOT (WITH_CINN AND NOT CINN_ONLY))
${CMAKE_CURRENT_SOURCE_DIR}/instruction/cinn_jit_instruction.cc)
endif()

if(NOT WITH_MKLDNN)
list(
REMOVE_ITEM
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

REMOVE_ITEM支持移除多个,可以合并:https://cmake.org/cmake/help/v3.0/command/list.html

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done, thx!

Copy link
Contributor

@yuanlehome yuanlehome left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Copy link
Contributor

@XiaoguangHu01 XiaoguangHu01 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@phlrain phlrain self-requested a review December 28, 2023 02:10
@wanghuancoder wanghuancoder merged commit b81deac into PaddlePaddle:develop Dec 28, 2023
Wanglongzhi2001 pushed a commit to Wanglongzhi2001/Paddle that referenced this pull request Jan 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants