Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
TonyTonyFun
Paddle
提交
012886df
P
Paddle
项目概览
TonyTonyFun
/
Paddle
与 Fork 源项目一致
Fork自
PaddlePaddle / Paddle
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
Paddle
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
未验证
提交
012886df
编写于
3月 30, 2020
作者:
J
Jacek Czaja
提交者:
GitHub
3月 30, 2020
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[DNNL] Softmax mkldnn op inplace support (#23197)
上级
75ebb48a
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
105 addition
and
1 deletion
+105
-1
paddle/fluid/operators/CMakeLists.txt
paddle/fluid/operators/CMakeLists.txt
+4
-0
paddle/fluid/operators/mkldnn/inplace_op_tests.cmake
paddle/fluid/operators/mkldnn/inplace_op_tests.cmake
+2
-0
paddle/fluid/operators/mkldnn/softmax_mkldnn_op.cc
paddle/fluid/operators/mkldnn/softmax_mkldnn_op.cc
+4
-1
paddle/fluid/operators/mkldnn/test_mkldnn_op_inplace.cc
paddle/fluid/operators/mkldnn/test_mkldnn_op_inplace.cc
+95
-0
未找到文件。
paddle/fluid/operators/CMakeLists.txt
浏览文件 @
012886df
...
...
@@ -132,3 +132,7 @@ set(GLOB_OP_LIB ${OP_LIBRARY} CACHE INTERNAL "Global OP library")
add_subdirectory
(
benchmark
)
cc_test
(
op_debug_string_test SRCS op_debug_string_test.cc DEPS elementwise_add_op
)
if
(
WITH_MKLDNN
)
include
(
mkldnn/inplace_op_tests.cmake
)
endif
()
paddle/fluid/operators/mkldnn/inplace_op_tests.cmake
0 → 100644
浏览文件 @
012886df
cc_test
(
test_mkldnn_op_inplace SRCS mkldnn/test_mkldnn_op_inplace.cc DEPS op_registry softmax_op softmax scope device_context enforce executor
)
paddle/fluid/operators/mkldnn/softmax_mkldnn_op.cc
浏览文件 @
012886df
...
...
@@ -93,8 +93,11 @@ class SoftmaxMKLDNNKernel : public paddle::framework::OpKernel<T> {
ctx
.
GetPlace
(),
ctx
.
OutputName
(
"Out"
));
auto
softmax_src_memory_p
=
handler
.
AcquireSrcMemory
(
input
);
auto
softmax_dst_memory_p
=
handler
.
AcquireDstMemory
(
output
);
auto
softmax_p
=
handler
.
AcquireForwardPrimitive
();
// For Inplace src and and dst are the same memory object
auto
softmax_dst_memory_p
=
input
->
Holder
()
==
output
->
Holder
()
?
softmax_src_memory_p
:
handler
.
AcquireDstMemory
(
output
);
mkldnn
::
stream
astream
(
dev_ctx
.
GetEngine
());
softmax_p
->
execute
(
astream
,
{{
MKLDNN_ARG_SRC
,
*
softmax_src_memory_p
},
...
...
paddle/fluid/operators/mkldnn/test_mkldnn_op_inplace.cc
0 → 100644
浏览文件 @
012886df
// Copyright (c) 2020 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.
#include <algorithm>
#include <cstdlib>
#include <memory>
#include <random>
#include "gtest/gtest.h"
#include "paddle/fluid/framework/lod_tensor.h"
#include "paddle/fluid/framework/op_registry.h"
#include "paddle/fluid/framework/operator.h"
#include "paddle/fluid/framework/scope.h"
#include "paddle/fluid/platform/device_context.h"
#include "paddle/fluid/platform/enforce.h"
#include "paddle/fluid/platform/place.h"
USE_OP
(
softmax
);
USE_OP_DEVICE_KERNEL
(
softmax
,
MKLDNN
);
namespace
paddle
{
namespace
operators
{
template
<
typename
T
>
bool
TestMain
(
const
platform
::
Place
&
place
,
const
framework
::
DDim
&
dims
)
{
framework
::
Scope
scope
;
auto
*
x
=
scope
.
Var
(
"x"
)
->
GetMutable
<
framework
::
LoDTensor
>
();
auto
*
y
=
scope
.
Var
(
"y"
)
->
GetMutable
<
framework
::
LoDTensor
>
();
x
->
Resize
(
dims
);
y
->
Resize
(
dims
);
size_t
numel
=
static_cast
<
size_t
>
(
framework
::
product
(
dims
));
auto
x_ptr
=
x
->
mutable_data
<
T
>
(
place
);
auto
y_ptr
=
y
->
mutable_data
<
T
>
(
place
);
std
::
uniform_real_distribution
<
T
>
dist
(
static_cast
<
T
>
(
10.0
),
static_cast
<
T
>
(
20.0
));
std
::
mt19937
engine
;
for
(
size_t
i
=
0
;
i
<
numel
;
++
i
)
{
x_ptr
[
i
]
=
dist
(
engine
);
y_ptr
[
i
]
=
static_cast
<
T
>
(
0
);
}
auto
&
pool
=
platform
::
DeviceContextPool
::
Instance
();
// Out of place (reference) computation
auto
op_ref
=
framework
::
OpRegistry
::
CreateOp
(
"softmax"
,
{{
"X"
,
{
"x"
}}},
{{
"Out"
,
{
"y"
}}},
{{
"use_mkldnn"
,
{
true
}}});
op_ref
->
Run
(
scope
,
place
);
pool
.
Get
(
place
)
->
Wait
();
// Get reference (out of place) result
auto
&
ref_tensor
=
scope
.
FindVar
(
"y"
)
->
Get
<
framework
::
LoDTensor
>
();
// In-place (to be tested) computation
auto
op
=
framework
::
OpRegistry
::
CreateOp
(
"softmax"
,
{{
"X"
,
{
"x"
}}},
{{
"Out"
,
{
"x"
}}},
{{
"use_mkldnn"
,
{
true
}}});
op
->
Run
(
scope
,
place
);
platform
::
DeviceContextPool
::
Instance
().
Get
(
place
)
->
Wait
();
// Get in-place result
auto
&
out_tensor
=
scope
.
FindVar
(
"x"
)
->
Get
<
framework
::
LoDTensor
>
();
PADDLE_ENFORCE_EQ
(
&
out_tensor
,
x
,
platform
::
errors
::
InvalidArgument
(
"Input and output vars should share tensor for In-place test"
));
// compare results
auto
*
ref_ptr
=
ref_tensor
.
data
<
T
>
();
auto
*
out_ptr
=
out_tensor
.
data
<
T
>
();
bool
is_equal
=
std
::
equal
(
out_ptr
,
out_ptr
+
numel
,
ref_ptr
);
return
is_equal
;
}
TEST
(
test_softmax_inplace
,
cpu_place
)
{
framework
::
DDim
dims
({
32
,
64
});
platform
::
CPUPlace
p
;
ASSERT_TRUE
(
TestMain
<
float
>
(
p
,
dims
));
}
}
// namespace operators
}
// namespace paddle
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录