Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
机器未来
Paddle
提交
fc002405
P
Paddle
项目概览
机器未来
/
Paddle
与 Fork 源项目一致
Fork自
PaddlePaddle / Paddle
通知
1
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
Paddle
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
未验证
提交
fc002405
编写于
1月 28, 2021
作者:
W
Wojciech Uss
提交者:
GitHub
1月 28, 2021
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
A fix for oneDNN matmul kernel. Fixes issue #30309 (#30723)
上级
46989e88
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
32 addition
and
18 deletion
+32
-18
paddle/fluid/operators/mkldnn/matmul_mkldnn_op.cc
paddle/fluid/operators/mkldnn/matmul_mkldnn_op.cc
+14
-14
python/paddle/fluid/tests/unittests/mkldnn/test_matmul_mkldnn_op.py
...dle/fluid/tests/unittests/mkldnn/test_matmul_mkldnn_op.py
+18
-4
未找到文件。
paddle/fluid/operators/mkldnn/matmul_mkldnn_op.cc
浏览文件 @
fc002405
...
...
@@ -188,34 +188,34 @@ class MatMulFactory {
memory
::
dims
strides_y
;
std
::
tie
(
mat_dim_y
,
strides_y
)
=
GetInputDimsAndStrides
(
ctx
,
"Y"
);
const
auto
x_bs
=
mat_dim_x
.
batch_size_
;
const
auto
y_bs
=
mat_dim_y
.
batch_size_
;
auto
x_bs
=
mat_dim_x
.
batch_size_
;
auto
y_bs
=
mat_dim_y
.
batch_size_
;
PADDLE_ENFORCE_EQ
(
x_bs
>
0
&&
y_bs
>
0
&&
x_bs
!=
y_bs
,
false
,
platform
::
errors
::
InvalidArgument
(
"If batch sizes of X and Y are positive,"
"they have to be equal."
));
// Store 1 if both batches are zero, otherwise save the nonzero batch
const
memory
::
dim
BS
=
x_bs
||
y_bs
?
std
::
max
(
x_bs
,
y_bs
)
:
1
;
memory
::
dim
out_bs
=
x_bs
||
y_bs
?
std
::
max
(
x_bs
,
y_bs
)
:
1
;
const
memory
::
dim
M
=
mat_dim_x
.
height_
;
const
memory
::
dim
N
=
mat_dim_y
.
width_
;
const
memory
::
dim
K
=
mat_dim_x
.
width_
;
batch_size_
=
1
;
auto
b
=
BS
;
if
(
BS
>
1
&&
(
IsOutputFused
(
ctx
)
||
IsInputFused
(
ctx
)))
{
if
(
out_bs
>
1
&&
(
IsOutputFused
(
ctx
)
||
IsInputFused
(
ctx
)))
{
auto
&
x_dims
=
ctx
.
Input
<
Tensor
>
(
"X"
)
->
dims
();
auto
&
y_dims
=
ctx
.
Input
<
Tensor
>
(
"Y"
)
->
dims
();
batch_size_
=
x_bs
>
y_bs
?
x_dims
[
0
]
:
y_dims
[
0
];
b
=
BS
/
batch_size_
;
x_bs
/=
batch_size_
;
y_bs
/=
batch_size_
;
out_bs
/=
batch_size_
;
}
memory
::
dims
x_dims
=
{
b
,
M
,
K
};
memory
::
dims
y_dims
=
{
b
,
K
,
N
};
memory
::
dims
out_dims
=
{
b
,
M
,
N
};
memory
::
dims
x_dims
=
{
x_bs
>
0
?
x_bs
:
1
,
M
,
K
};
memory
::
dims
y_dims
=
{
y_bs
>
0
?
y_bs
:
1
,
K
,
N
};
memory
::
dims
out_dims
=
{
out_bs
,
M
,
N
};
x_offset_
=
b
*
M
*
K
*
sizeof
(
XT
);
y_offset_
=
b
*
K
*
N
*
sizeof
(
YT
);
out_offset_
=
b
*
M
*
N
*
sizeof
(
OT
);
x_offset_
=
x_bs
*
M
*
K
*
sizeof
(
XT
);
y_offset_
=
y_bs
*
K
*
N
*
sizeof
(
YT
);
out_offset_
=
out_bs
*
M
*
N
*
sizeof
(
OT
);
// Translate transA and transB
if
(
strides_x
.
empty
())
...
...
@@ -226,7 +226,7 @@ class MatMulFactory {
:
memory
::
dims
{
N
*
K
,
1
,
K
};
memory
::
dims
out_strides
=
memory
::
dims
{
M
*
N
,
N
,
1
};
CorrectStridesWhenFloatOutputFused
(
ctx
,
N
,
b
,
&
out_strides
);
CorrectStridesWhenFloatOutputFused
(
ctx
,
N
,
out_bs
,
&
out_strides
);
return
{
x_dims
,
y_dims
,
out_dims
,
strides_x
,
strides_y
,
out_strides
};
}
...
...
python/paddle/fluid/tests/unittests/mkldnn/test_matmul_mkldnn_op.py
浏览文件 @
fc002405
...
...
@@ -48,6 +48,20 @@ class TestDnnlMatMulOp(OpTest):
self
.
check_output
()
class
TestDnnlMatMulOpMixedDims1
(
TestDnnlMatMulOp
):
def
generate_data
(
self
):
self
.
x
=
np
.
random
.
random
((
17
,
2
,
3
)).
astype
(
"float32"
)
self
.
y
=
np
.
random
.
random
((
3
,
4
)).
astype
(
"float32"
)
self
.
out
=
np
.
matmul
(
self
.
x
,
self
.
y
)
class
TestDnnlMatMulOpMixedDims2
(
TestDnnlMatMulOp
):
def
generate_data
(
self
):
self
.
x
=
np
.
random
.
random
((
2
,
3
)).
astype
(
"float32"
)
self
.
y
=
np
.
random
.
random
((
17
,
3
,
4
)).
astype
(
"float32"
)
self
.
out
=
np
.
matmul
(
self
.
x
,
self
.
y
)
class
TestDnnlMatMulOpAlpha
(
TestDnnlMatMulOp
):
def
generate_data
(
self
):
self
.
x
=
np
.
random
.
random
((
17
,
2
,
3
)).
astype
(
"float32"
)
...
...
@@ -396,10 +410,10 @@ class TestMatMulOpTransposeReshapeBasicFloat(
TestMatMulOpTransposeReshapeEmptyFloat
):
def
generate_data
(
self
):
self
.
bs
=
8
self
.
x
=
np
.
random
.
random
(
[
self
.
bs
,
12
,
128
,
128
]).
astype
(
self
.
data_type_
)
self
.
y
=
np
.
random
.
random
(
[
self
.
bs
,
12
,
128
,
64
]).
astype
(
self
.
data_type_
)
self
.
x
=
np
.
random
.
random
(
[
self
.
bs
,
12
,
128
,
128
]).
astype
(
self
.
data_type_
)
self
.
y
=
np
.
random
.
random
(
[
self
.
bs
,
12
,
128
,
64
]).
astype
(
self
.
data_type_
)
def
init_params_and_out
(
self
):
self
.
transpose_out
=
[
0
,
2
,
1
,
3
]
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录