Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Crayon鑫
Paddle
提交
d234aa02
P
Paddle
项目概览
Crayon鑫
/
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看板
未验证
提交
d234aa02
编写于
7月 03, 2019
作者:
T
Tao Luo
提交者:
GitHub
7月 03, 2019
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add transfer_scope_cache unit-test (#18467)
test=develop
上级
7c6f2350
变更
3
显示空白变更内容
内联
并排
Showing
3 changed file
with
40 addition
and
24 deletion
+40
-24
paddle/fluid/framework/transfer_scope_cache.cc
paddle/fluid/framework/transfer_scope_cache.cc
+0
-22
paddle/fluid/framework/transfer_scope_cache.h
paddle/fluid/framework/transfer_scope_cache.h
+0
-2
paddle/fluid/inference/tests/api/analyzer_bert_tester.cc
paddle/fluid/inference/tests/api/analyzer_bert_tester.cc
+40
-0
未找到文件。
paddle/fluid/framework/transfer_scope_cache.cc
浏览文件 @
d234aa02
...
...
@@ -46,27 +46,5 @@ Scope* TryCreateTransferScope(OpKernelType type0, OpKernelType type1,
return
new_scope
;
}
void
RemoveKidsFromTransferScopeCache
(
Scope
*
scope
)
{
auto
it
=
global_transfer_scope_cache
().
find
(
scope
);
if
(
it
!=
global_transfer_scope_cache
().
end
())
{
global_transfer_scope_cache
().
erase
(
it
);
}
for
(
auto
*
s
:
scope
->
kids
())
{
auto
it
=
global_transfer_scope_cache
().
find
(
s
);
if
(
it
!=
global_transfer_scope_cache
().
end
())
{
global_transfer_scope_cache
().
erase
(
it
);
}
}
// remove global transfer data cache
auto
&
cache
=
global_transfer_data_cache
();
for
(
auto
it
=
cache
.
begin
();
it
!=
cache
.
end
();)
{
if
(
it
->
second
==
scope
)
it
=
cache
.
erase
(
it
);
else
it
++
;
}
}
}
// namespace framework
}
// namespace paddle
paddle/fluid/framework/transfer_scope_cache.h
浏览文件 @
d234aa02
...
...
@@ -35,7 +35,5 @@ static size_t CombineHash(size_t seed, size_t a) {
Scope
*
TryCreateTransferScope
(
OpKernelType
type0
,
OpKernelType
type1
,
const
Scope
*
scope
);
void
RemoveKidsFromTransferScopeCache
(
Scope
*
scope
);
}
// namespace framework
}
// namespace paddle
paddle/fluid/inference/tests/api/analyzer_bert_tester.cc
浏览文件 @
d234aa02
...
...
@@ -12,6 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
#include "paddle/fluid/framework/transfer_scope_cache.h"
#include "paddle/fluid/inference/tests/api/tester_helper.h"
namespace
paddle
{
...
...
@@ -228,5 +229,44 @@ TEST(Analyzer_bert, compare_determine) {
CompareDeterministic
(
reinterpret_cast
<
const
PaddlePredictor
::
Config
*>
(
&
cfg
),
inputs
);
}
TEST
(
Analyzer_bert
,
transfer_scope_cache
)
{
AnalysisConfig
config
;
SetConfig
(
&
config
);
std
::
vector
<
PaddleTensor
>
input
,
output
;
auto
predictor
=
CreatePaddlePredictor
<
AnalysisConfig
>
(
config
);
int
threads_num
=
10
;
std
::
vector
<
std
::
thread
>
threads
;
std
::
unordered_set
<
std
::
unordered_set
<
paddle
::
framework
::
Scope
*>
*>
global_transfer_scope_cache
;
std
::
unordered_set
<
std
::
unordered_map
<
size_t
,
paddle
::
framework
::
Scope
*>
*>
global_transfer_data_cache
;
std
::
ifstream
fin
(
FLAGS_infer_data
);
std
::
string
line
;
for
(
int
i
=
0
;
i
<
threads_num
;
i
++
)
{
threads
.
emplace_back
([
&
,
i
]()
{
std
::
getline
(
fin
,
line
);
ParseLine
(
line
,
&
input
);
predictor
->
Run
(
input
,
&
output
,
FLAGS_batch_size
);
global_transfer_scope_cache
.
insert
(
&
paddle
::
framework
::
global_transfer_scope_cache
());
global_transfer_data_cache
.
insert
(
&
paddle
::
framework
::
global_transfer_data_cache
());
});
threads
[
0
].
join
();
threads
.
clear
();
std
::
vector
<
PaddleTensor
>
().
swap
(
input
);
}
// Since paddle::framework::global_transfer_scope_cache() and
// paddle::framework::global_transfer_data_cache() are thread_local,
// their pointer should be different among different thread id.
PADDLE_ENFORCE
(
global_transfer_scope_cache
.
size
(),
threads_num
);
PADDLE_ENFORCE
(
global_transfer_data_cache
.
size
(),
threads_num
);
}
}
// namespace inference
}
// namespace paddle
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录