Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
吃玉米的猫
Paddle
提交
1382cd22
P
Paddle
项目概览
吃玉米的猫
/
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,发现更多精彩内容 >>
未验证
提交
1382cd22
编写于
6月 09, 2021
作者:
J
Jacek Czaja
提交者:
GitHub
6月 09, 2021
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[oneDNN] First fix to #33021 (#33174)
* - First fix to #33021
上级
32ef95d7
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
193 addition
and
15 deletion
+193
-15
paddle/fluid/inference/tests/api/CMakeLists.txt
paddle/fluid/inference/tests/api/CMakeLists.txt
+4
-5
paddle/fluid/inference/tests/api/analyzer_detect_functional_mkldnn_tester.cc
...nce/tests/api/analyzer_detect_functional_mkldnn_tester.cc
+153
-0
paddle/fluid/platform/device_context.cc
paddle/fluid/platform/device_context.cc
+25
-6
paddle/fluid/platform/device_context.h
paddle/fluid/platform/device_context.h
+11
-4
未找到文件。
paddle/fluid/inference/tests/api/CMakeLists.txt
浏览文件 @
1382cd22
...
@@ -325,11 +325,10 @@ inference_analysis_api_test(test_analyzer_ocr ${OCR_INSTALL_DIR} analyzer_vis_te
...
@@ -325,11 +325,10 @@ inference_analysis_api_test(test_analyzer_ocr ${OCR_INSTALL_DIR} analyzer_vis_te
# densebox
# densebox
set
(
DENSEBOX_INSTALL_DIR
"
${
INFERENCE_DEMO_INSTALL_DIR
}
/densebox"
)
set
(
DENSEBOX_INSTALL_DIR
"
${
INFERENCE_DEMO_INSTALL_DIR
}
/densebox"
)
download_data_without_verify
(
${
DENSEBOX_INSTALL_DIR
}
"densebox.tar.gz"
)
download_data_without_verify
(
${
DENSEBOX_INSTALL_DIR
}
"densebox.tar.gz"
)
#inference_analysis_test(test_analyzer_detect SRCS analyzer_detect_tester.cc
inference_analysis_test
(
test_analyzer_detect_functional_mkldnn SRCS analyzer_detect_functional_mkldnn_tester.cc
# EXTRA_DEPS ${INFERENCE_EXTRA_DEPS}
EXTRA_DEPS
${
INFERENCE_EXTRA_DEPS
}
# ARGS --infer_model=${DENSEBOX_INSTALL_DIR}/model --infer_data=${DENSEBOX_INSTALL_DIR}/detect_input_50.txt
ARGS --infer_model=
${
DENSEBOX_INSTALL_DIR
}
/model --infer_data=
${
DENSEBOX_INSTALL_DIR
}
/detect_input_50.txt
# --infer_shape=${DENSEBOX_INSTALL_DIR}/shape_50.txt)
--infer_shape=
${
DENSEBOX_INSTALL_DIR
}
/shape_50.txt
)
#set_property(TEST test_analyzer_detect PROPERTY ENVIRONMENT GLOG_vmodule=analysis_predictor=2)
# mobilenet with transpose op
# mobilenet with transpose op
set
(
MOBILENET_INSTALL_DIR
"
${
INFERENCE_DEMO_INSTALL_DIR
}
/mobilenet"
)
set
(
MOBILENET_INSTALL_DIR
"
${
INFERENCE_DEMO_INSTALL_DIR
}
/mobilenet"
)
...
...
paddle/fluid/inference/tests/api/analyzer_detect_functional_mkldnn_tester.cc
0 → 100644
浏览文件 @
1382cd22
/* Copyright (c) 2021 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 <gtest/gtest.h>
#include <fstream>
#include <iostream>
#include "paddle/fluid/inference/tests/api/tester_helper.h"
#include "paddle/fluid/platform/device_context.h"
#include "paddle/fluid/platform/place.h"
DEFINE_string
(
infer_shape
,
""
,
"data shape file"
);
DEFINE_int32
(
sample
,
20
,
"number of sample"
);
namespace
paddle
{
namespace
inference
{
namespace
analysis
{
struct
Record
{
std
::
vector
<
float
>
data
;
std
::
vector
<
int32_t
>
shape
;
};
Record
ProcessALine
(
const
std
::
string
&
line
,
const
std
::
string
&
shape_line
)
{
VLOG
(
3
)
<<
"process a line"
;
Record
record
;
std
::
vector
<
std
::
string
>
data_strs
;
split
(
line
,
' '
,
&
data_strs
);
for
(
auto
&
d
:
data_strs
)
{
record
.
data
.
push_back
(
std
::
stof
(
d
));
}
std
::
vector
<
std
::
string
>
shape_strs
;
split
(
shape_line
,
' '
,
&
shape_strs
);
for
(
auto
&
s
:
shape_strs
)
{
record
.
shape
.
push_back
(
std
::
stoi
(
s
));
}
return
record
;
}
void
SetConfig
(
AnalysisConfig
*
cfg
)
{
cfg
->
SetModel
(
FLAGS_infer_model
+
"/model"
,
FLAGS_infer_model
+
"/params"
);
cfg
->
DisableGpu
();
// cfg->SwitchIrDebug(); // Enable to have graphs dumped
cfg
->
SwitchSpecifyInputNames
(
false
);
cfg
->
SetCpuMathLibraryNumThreads
(
FLAGS_cpu_num_threads
);
}
void
SetInput
(
std
::
vector
<
std
::
vector
<
PaddleTensor
>>
*
inputs
,
const
std
::
string
&
line
,
const
std
::
string
&
shape_line
)
{
auto
record
=
ProcessALine
(
line
,
shape_line
);
PaddleTensor
input
;
input
.
shape
=
record
.
shape
;
input
.
dtype
=
PaddleDType
::
FLOAT32
;
size_t
input_size
=
record
.
data
.
size
()
*
sizeof
(
float
);
input
.
data
.
Resize
(
input_size
);
memcpy
(
input
.
data
.
data
(),
record
.
data
.
data
(),
input_size
);
std
::
vector
<
PaddleTensor
>
input_slots
;
input_slots
.
assign
({
input
});
(
*
inputs
).
emplace_back
(
input_slots
);
}
#ifdef PADDLE_WITH_MKLDNN
int
GetNumCachedObjects
(
void
)
{
auto
&
pool
=
platform
::
DeviceContextPool
::
Instance
();
platform
::
CPUPlace
place
;
auto
onednn_dev_ctx
=
dynamic_cast
<
platform
::
MKLDNNDeviceContext
*>
(
pool
.
Get
(
place
));
return
onednn_dev_ctx
->
GetCachedObjectsNumber
();
}
void
validate_cache_onednn
(
int
cache_capacity
=
1
)
{
AnalysisConfig
cfg
;
SetConfig
(
&
cfg
);
cfg
.
EnableMKLDNN
();
cfg
.
SetMkldnnCacheCapacity
(
cache_capacity
);
auto
predictor
=
CreatePaddlePredictor
<
AnalysisConfig
>
(
cfg
);
std
::
vector
<
std
::
vector
<
PaddleTensor
>>
ref_outputs
;
std
::
vector
<
std
::
vector
<
PaddleTensor
>>
input_slots_all
;
std
::
ifstream
file
(
FLAGS_infer_data
);
std
::
ifstream
infer_file
(
FLAGS_infer_shape
);
std
::
vector
<
std
::
string
>
lines
;
std
::
vector
<
std
::
string
>
shape_lines
;
// Let's work with 4 samples
auto
num_samples
=
4
;
ref_outputs
.
resize
(
num_samples
);
lines
.
resize
(
num_samples
);
shape_lines
.
resize
(
num_samples
);
// Let's remember number of cached objects before
// execution and after every single execution
std
::
vector
<
int
>
cache_filling
;
cache_filling
.
push_back
(
GetNumCachedObjects
());
// compute sequentially prediction
for
(
int
i
=
0
;
i
<
num_samples
;
++
i
)
{
std
::
getline
(
file
,
lines
[
i
]);
std
::
getline
(
infer_file
,
shape_lines
[
i
]);
SetInput
(
&
input_slots_all
,
lines
[
i
],
shape_lines
[
i
]);
predictor
->
Run
(
input_slots_all
[
i
],
&
ref_outputs
[
i
],
FLAGS_batch_size
);
// record number of cached objects
cache_filling
.
push_back
(
GetNumCachedObjects
());
}
file
.
close
();
infer_file
.
close
();
predictor
.
reset
(
nullptr
);
cache_filling
.
push_back
(
GetNumCachedObjects
());
// Compare results
// First and last value should be equal e.g. before using cache (empty) and
// after releasing executor
PADDLE_ENFORCE_EQ
(
cache_filling
[
0
],
cache_filling
[
cache_filling
.
size
()
-
1
],
platform
::
errors
::
Fatal
(
"Cache size before execution and after "
"releasing Executor do not match"
));
// Iterate to check if cache is not increasing
// over exceeding cache capacity
if
(
cache_capacity
!=
0
)
{
for
(
int
i
=
cache_capacity
+
1
;
i
<
num_samples
+
1
;
++
i
)
{
PADDLE_ENFORCE_EQ
(
cache_filling
[
cache_capacity
],
cache_filling
[
i
],
platform
::
errors
::
Fatal
(
"Cache capacity should not increase "
"after full capacity is used"
));
}
}
}
TEST
(
Analyzer_detect
,
validate_cache_onednn
)
{
validate_cache_onednn
(
2
/*cache_capacity */
);
}
#endif
}
// namespace analysis
}
// namespace inference
}
// namespace paddle
paddle/fluid/platform/device_context.cc
浏览文件 @
1382cd22
...
@@ -563,7 +563,7 @@ Place CUDAPinnedDeviceContext::GetPlace() const { return place_; }
...
@@ -563,7 +563,7 @@ Place CUDAPinnedDeviceContext::GetPlace() const { return place_; }
MKLDNNDeviceContext
::
MKLDNNDeviceContext
(
CPUPlace
place
)
MKLDNNDeviceContext
::
MKLDNNDeviceContext
(
CPUPlace
place
)
:
CPUDeviceContext
(
place
),
p_blobmap_
()
{
:
CPUDeviceContext
(
place
),
p_blobmap_
()
{
p_blobmap_
.
reset
(
new
BlobMap
());
p_blobmap_
.
reset
(
new
BlobMap
());
p_exec_items_
.
reset
(
new
Exec
Map
());
p_exec_items_
.
reset
(
new
Exec
Shape
());
p_mutex_
.
reset
(
new
std
::
mutex
());
p_mutex_
.
reset
(
new
std
::
mutex
());
}
}
...
@@ -644,10 +644,15 @@ void MKLDNNDeviceContext::ResetBlobMap(void* ptr) {
...
@@ -644,10 +644,15 @@ void MKLDNNDeviceContext::ResetBlobMap(void* ptr) {
if
(
ptr
==
nullptr
)
{
if
(
ptr
==
nullptr
)
{
p_blobmap_
->
clear
();
p_blobmap_
->
clear
();
}
else
{
}
else
{
for
(
auto
&
v
:
(
*
p_exec_items_
)[
ptr
])
{
// Iterate through all shapes and release
(
v
.
first
)
->
erase
(
v
.
second
);
// for each shape and active executor all entries
// of this executor
for
(
auto
&
s
:
*
p_exec_items_
)
{
for
(
auto
&
v
:
(
*
s
.
second
)[
ptr
])
{
(
v
.
first
)
->
erase
(
v
.
second
);
}
s
.
second
->
erase
(
ptr
);
}
}
p_exec_items_
->
erase
(
ptr
);
}
}
}
else
{
}
else
{
VLOG
(
3
)
<<
"Prevented Clearing DNNL cache."
;
VLOG
(
3
)
<<
"Prevented Clearing DNNL cache."
;
...
@@ -655,11 +660,24 @@ void MKLDNNDeviceContext::ResetBlobMap(void* ptr) {
...
@@ -655,11 +660,24 @@ void MKLDNNDeviceContext::ResetBlobMap(void* ptr) {
}
}
}
}
void
MKLDNNDeviceContext
::
RemoveShapeEntriesWithExecutor
(
void
)
const
{
p_exec_items_
->
erase
(
p_exec_items_
->
begin
());
}
void
MKLDNNDeviceContext
::
LinkEntryWithExecutor
(
BlobPtr_t
<
KeyBlob
>
pblob
,
void
MKLDNNDeviceContext
::
LinkEntryWithExecutor
(
BlobPtr_t
<
KeyBlob
>
pblob
,
KeyBlob
::
iterator
it
)
const
{
KeyBlob
::
iterator
it
)
const
{
// Take current input shape from TLS
// Take current executor addess from TLS
// Take current executor addess from TLS
// and for this executor's items add the one defined with arguments
// and for this executor's items add the one defined with arguments
(
*
p_exec_items_
)[
tls
().
get_curr_exec
()].
push_back
(
std
::
make_pair
(
pblob
,
it
));
auto
key_it
=
p_exec_items_
->
insert
(
std
::
make_pair
(
tls
().
cur_input_shape_str
,
std
::
make_shared
<
ExecMap
>
()))
.
first
;
(
*
key_it
->
second
)[
tls
().
get_curr_exec
()].
push_back
(
std
::
make_pair
(
pblob
,
it
));
VLOG
(
3
)
<<
"LinkEntryWithExecutor, shapes: "
<<
p_exec_items_
->
size
()
<<
" curr exec size: "
<<
(
*
key_it
->
second
)[
tls
().
get_curr_exec
()].
size
()
<<
"
\n
"
;
}
}
void
MKLDNNDeviceContext
::
BlockNextCacheClearing
()
{
void
MKLDNNDeviceContext
::
BlockNextCacheClearing
()
{
...
@@ -716,6 +734,7 @@ void MKLDNNDeviceContext::SetBlob(const std::string& name,
...
@@ -716,6 +734,7 @@ void MKLDNNDeviceContext::SetBlob(const std::string& name,
VLOG
(
2
)
<<
"sid="
<<
sid
VLOG
(
2
)
<<
"sid="
<<
sid
<<
", remove all blobs of shape: "
<<
sBlob
->
begin
()
->
first
;
<<
", remove all blobs of shape: "
<<
sBlob
->
begin
()
->
first
;
sBlob
->
erase
(
sBlob
->
begin
()
->
first
);
sBlob
->
erase
(
sBlob
->
begin
()
->
first
);
RemoveShapeEntriesWithExecutor
();
}
}
pBlob
=
std
::
make_shared
<
KeyBlob
>
();
pBlob
=
std
::
make_shared
<
KeyBlob
>
();
(
*
sBlob
)[
tls
().
cur_input_shape_str
]
=
pBlob
;
(
*
sBlob
)[
tls
().
cur_input_shape_str
]
=
pBlob
;
...
@@ -739,7 +758,7 @@ void MKLDNNDeviceContext::SetBlob(const std::string& name,
...
@@ -739,7 +758,7 @@ void MKLDNNDeviceContext::SetBlob(const std::string& name,
return
;
return
;
}
}
unsigned
int
MKLDNNDeviceContext
::
GetCachedObjectsNumber
(
void
)
{
unsigned
int
MKLDNNDeviceContext
::
GetCachedObjectsNumber
(
void
)
const
{
unsigned
int
num_entries
=
0
;
unsigned
int
num_entries
=
0
;
for
(
auto
const
&
l3
:
*
p_blobmap_
)
{
for
(
auto
const
&
l3
:
*
p_blobmap_
)
{
for
(
auto
const
&
l2
:
*
(
l3
.
second
))
{
for
(
auto
const
&
l2
:
*
(
l3
.
second
))
{
...
...
paddle/fluid/platform/device_context.h
浏览文件 @
1382cd22
...
@@ -749,8 +749,14 @@ class MKLDNNDeviceContext : public CPUDeviceContext {
...
@@ -749,8 +749,14 @@ class MKLDNNDeviceContext : public CPUDeviceContext {
using
ShapeBlob
=
umap_key_string_t
<
KeyBlob
>
;
using
ShapeBlob
=
umap_key_string_t
<
KeyBlob
>
;
using
BlobMap
=
umap_value_smart_t
<
int
,
ShapeBlob
>
;
using
BlobMap
=
umap_value_smart_t
<
int
,
ShapeBlob
>
;
using
ExecMap
=
std
::
unordered_map
<
// Auxillary two-level structure (shape, executor) to easier control
void
*
,
std
::
vector
<
std
::
pair
<
BlobPtr_t
<
KeyBlob
>
,
KeyBlob
::
iterator
>>>
;
// clearing cache objects related to specific executor
using
ExecKey
=
void
*
;
using
ExecMapCacheIterPair
=
std
::
pair
<
BlobPtr_t
<
KeyBlob
>
,
KeyBlob
::
iterator
>
;
using
ExecMap
=
std
::
unordered_map
<
ExecKey
,
std
::
vector
<
ExecMapCacheIterPair
>>
;
using
ExecShape
=
std
::
unordered_map
<
std
::
string
,
std
::
shared_ptr
<
ExecMap
>>
;
explicit
MKLDNNDeviceContext
(
CPUPlace
place
);
explicit
MKLDNNDeviceContext
(
CPUPlace
place
);
...
@@ -759,6 +765,7 @@ class MKLDNNDeviceContext : public CPUDeviceContext {
...
@@ -759,6 +765,7 @@ class MKLDNNDeviceContext : public CPUDeviceContext {
// Register object to currently used executor's map
// Register object to currently used executor's map
void
LinkEntryWithExecutor
(
BlobPtr_t
<
KeyBlob
>
,
KeyBlob
::
iterator
)
const
;
void
LinkEntryWithExecutor
(
BlobPtr_t
<
KeyBlob
>
,
KeyBlob
::
iterator
)
const
;
void
RemoveShapeEntriesWithExecutor
(
void
)
const
;
// Remove all entries from the blob map
// Remove all entries from the blob map
void
ResetBlobMap
(
void
*
ptr
);
void
ResetBlobMap
(
void
*
ptr
);
...
@@ -773,7 +780,7 @@ class MKLDNNDeviceContext : public CPUDeviceContext {
...
@@ -773,7 +780,7 @@ class MKLDNNDeviceContext : public CPUDeviceContext {
void
SetBlob
(
const
std
::
string
&
name
,
std
::
shared_ptr
<
void
>
data
)
const
;
void
SetBlob
(
const
std
::
string
&
name
,
std
::
shared_ptr
<
void
>
data
)
const
;
// Calculate number of oneDNN objects cached
// Calculate number of oneDNN objects cached
unsigned
int
GetCachedObjectsNumber
(
void
);
unsigned
int
GetCachedObjectsNumber
(
void
)
const
;
// Find a saved blob. Return nullptr if not found
// Find a saved blob. Return nullptr if not found
std
::
shared_ptr
<
void
>
GetBlob
(
const
std
::
string
&
name
)
const
;
std
::
shared_ptr
<
void
>
GetBlob
(
const
std
::
string
&
name
)
const
;
...
@@ -786,7 +793,7 @@ class MKLDNNDeviceContext : public CPUDeviceContext {
...
@@ -786,7 +793,7 @@ class MKLDNNDeviceContext : public CPUDeviceContext {
std
::
shared_ptr
<
BlobMap
>
p_blobmap_
;
std
::
shared_ptr
<
BlobMap
>
p_blobmap_
;
// Map key is pointer of executor and value is a data(iterator in map) needed
// Map key is pointer of executor and value is a data(iterator in map) needed
// to erase
// to erase
std
::
shared_ptr
<
Exec
Map
>
p_exec_items_
;
std
::
shared_ptr
<
Exec
Shape
>
p_exec_items_
;
std
::
shared_ptr
<
std
::
mutex
>
p_mutex_
;
std
::
shared_ptr
<
std
::
mutex
>
p_mutex_
;
bool
block_next_cache_clearing_
=
false
;
bool
block_next_cache_clearing_
=
false
;
};
};
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录