Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle
提交
73c70654
P
Paddle
项目概览
PaddlePaddle
/
Paddle
大约 1 年 前同步成功
通知
2299
Star
20931
Fork
5422
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1423
列表
看板
标记
里程碑
合并请求
543
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
Paddle
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1,423
Issue
1,423
列表
看板
标记
里程碑
合并请求
543
合并请求
543
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
未验证
提交
73c70654
编写于
8月 08, 2023
作者:
H
hong
提交者:
GitHub
8月 08, 2023
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[NewIR]Polish new ir interpreter core cache (#56035)
* update * update cache * fix compile error
上级
d87d8b02
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
28 addition
and
19 deletion
+28
-19
paddle/fluid/eager/to_static/run_program_op_node.h
paddle/fluid/eager/to_static/run_program_op_node.h
+16
-14
paddle/fluid/framework/executor_cache.cc
paddle/fluid/framework/executor_cache.cc
+2
-2
paddle/fluid/framework/executor_cache.h
paddle/fluid/framework/executor_cache.h
+10
-3
未找到文件。
paddle/fluid/eager/to_static/run_program_op_node.h
浏览文件 @
73c70654
...
@@ -316,8 +316,6 @@ inline void RunProgramAPI(
...
@@ -316,8 +316,6 @@ inline void RunProgramAPI(
VLOG
(
2
)
<<
"RunProgramOp use interpretercore to execute program."
;
VLOG
(
2
)
<<
"RunProgramOp use interpretercore to execute program."
;
paddle
::
framework
::
Scope
*
global_inner_scope
=
out_scope_vec
->
front
();
paddle
::
framework
::
Scope
*
global_inner_scope
=
out_scope_vec
->
front
();
int64_t
scope_i
=
reinterpret_cast
<
std
::
uintptr_t
>
(
global_inner_scope
);
program_id
+=
0x9e3779b9
+
(
program_id
<<
6
)
+
(
scope_i
>>
2
);
VLOG
(
4
)
<<
"global_inner_scope:"
<<
global_inner_scope
;
VLOG
(
4
)
<<
"global_inner_scope:"
<<
global_inner_scope
;
...
@@ -362,7 +360,8 @@ inline void RunProgramAPI(
...
@@ -362,7 +360,8 @@ inline void RunProgramAPI(
paddle
::
framework
::
InterpreterCoreInfoCache
::
Instance
();
paddle
::
framework
::
InterpreterCoreInfoCache
::
Instance
();
std
::
shared_ptr
<
paddle
::
framework
::
InterpreterCore
>
interpreter_core
=
std
::
shared_ptr
<
paddle
::
framework
::
InterpreterCore
>
interpreter_core
=
nullptr
;
nullptr
;
if
(
!
interpretercore_info_cache
.
Has
(
program_id
,
/*is_grad=*/
false
))
{
if
(
!
interpretercore_info_cache
.
Has
(
program_id
,
global_inner_scope
,
/*is_grad=*/
false
))
{
paddle
::
platform
::
RecordEvent
record_event
(
paddle
::
platform
::
RecordEvent
record_event
(
"create_new_interpretercore"
,
"create_new_interpretercore"
,
paddle
::
platform
::
TracerEventType
::
UserDefined
,
paddle
::
platform
::
TracerEventType
::
UserDefined
,
...
@@ -420,7 +419,7 @@ inline void RunProgramAPI(
...
@@ -420,7 +419,7 @@ inline void RunProgramAPI(
}
}
interpretercore_info_cache
.
UpdateSkipEagerDeleteVars
(
interpretercore_info_cache
.
UpdateSkipEagerDeleteVars
(
program_id
,
false
,
skip_eager_delete_vars
);
program_id
,
global_inner_scope
,
false
,
skip_eager_delete_vars
);
VLOG
(
2
)
<<
"Get skip GC vars size is: "
<<
skip_eager_delete_vars
.
size
();
VLOG
(
2
)
<<
"Get skip GC vars size is: "
<<
skip_eager_delete_vars
.
size
();
}
else
{
}
else
{
paddle
::
platform
::
RecordEvent
record_event
(
paddle
::
platform
::
RecordEvent
record_event
(
...
@@ -429,8 +428,8 @@ inline void RunProgramAPI(
...
@@ -429,8 +428,8 @@ inline void RunProgramAPI(
1
);
1
);
VLOG
(
2
)
<<
"Get interpretercore cahce by program:"
<<
program_id
;
VLOG
(
2
)
<<
"Get interpretercore cahce by program:"
<<
program_id
;
// Step 1. get cache interpretercore
// Step 1. get cache interpretercore
auto
&
cached_value
=
auto
&
cached_value
=
interpretercore_info_cache
.
GetMutable
(
interpretercore_info_cache
.
GetMutable
(
program_id
,
/*is_grad=*/
false
);
program_id
,
global_inner_scope
,
/*is_grad=*/
false
);
interpreter_core
=
cached_value
.
core_
;
interpreter_core
=
cached_value
.
core_
;
// Step 2. update scope for cache interpretercore
// Step 2. update scope for cache interpretercore
details
::
ShareTensorsIntoScope
(
x
,
global_inner_scope
);
details
::
ShareTensorsIntoScope
(
x
,
global_inner_scope
);
...
@@ -500,8 +499,6 @@ inline void RunProgramGradAPI(
...
@@ -500,8 +499,6 @@ inline void RunProgramGradAPI(
paddle
::
framework
::
Scope
*
global_inner_scope
=
out_scope_vec
->
front
();
paddle
::
framework
::
Scope
*
global_inner_scope
=
out_scope_vec
->
front
();
int64_t
program_id
=
PADDLE_GET_CONST
(
int64_t
,
attrs
.
at
(
"program_id"
));
int64_t
program_id
=
PADDLE_GET_CONST
(
int64_t
,
attrs
.
at
(
"program_id"
));
int64_t
scope_i
=
reinterpret_cast
<
std
::
uintptr_t
>
(
global_inner_scope
);
program_id
+=
0x9e3779b9
+
(
program_id
<<
6
)
+
(
scope_i
>>
2
);
auto
place
=
egr
::
Controller
::
Instance
().
GetExpectedPlace
();
auto
place
=
egr
::
Controller
::
Instance
().
GetExpectedPlace
();
VLOG
(
2
)
<<
"RunProgramGradOp use interpretercore to execute program."
;
VLOG
(
2
)
<<
"RunProgramGradOp use interpretercore to execute program."
;
...
@@ -519,7 +516,8 @@ inline void RunProgramGradAPI(
...
@@ -519,7 +516,8 @@ inline void RunProgramGradAPI(
paddle
::
framework
::
InterpreterCoreInfoCache
::
Instance
();
paddle
::
framework
::
InterpreterCoreInfoCache
::
Instance
();
std
::
shared_ptr
<
paddle
::
framework
::
InterpreterCore
>
interpreter_core
=
std
::
shared_ptr
<
paddle
::
framework
::
InterpreterCore
>
interpreter_core
=
nullptr
;
nullptr
;
if
(
!
interpretercore_info_cache
.
Has
(
program_id
,
/*is_grad=*/
true
))
{
if
(
!
interpretercore_info_cache
.
Has
(
program_id
,
global_inner_scope
,
/*is_grad=*/
true
))
{
paddle
::
platform
::
RecordEvent
record_event
(
paddle
::
platform
::
RecordEvent
record_event
(
"create_new_interpretercore"
,
"create_new_interpretercore"
,
paddle
::
platform
::
TracerEventType
::
UserDefined
,
paddle
::
platform
::
TracerEventType
::
UserDefined
,
...
@@ -555,9 +553,10 @@ inline void RunProgramGradAPI(
...
@@ -555,9 +553,10 @@ inline void RunProgramGradAPI(
// share threadpool
// share threadpool
// NOTE(zhiqiu): this only works interpreter_core is executed strictly
// NOTE(zhiqiu): this only works interpreter_core is executed strictly
// after the related fwd_interpreter_core.
// after the related fwd_interpreter_core.
if
(
interpretercore_info_cache
.
Has
(
program_id
,
false
))
{
if
(
interpretercore_info_cache
.
Has
(
program_id
,
global_inner_scope
,
false
))
{
auto
fwd_interpreter_core
=
auto
fwd_interpreter_core
=
interpretercore_info_cache
.
GetMutable
(
program_id
,
/*is_grad=*/
false
)
interpretercore_info_cache
.
GetMutable
(
program_id
,
global_inner_scope
,
/*is_grad=*/
false
)
.
core_
;
.
core_
;
interpreter_core
->
ShareWorkQueueFrom
(
fwd_interpreter_core
);
interpreter_core
->
ShareWorkQueueFrom
(
fwd_interpreter_core
);
VLOG
(
4
)
<<
"Share workqueue from "
<<
fwd_interpreter_core
.
get
()
<<
" to "
VLOG
(
4
)
<<
"Share workqueue from "
<<
fwd_interpreter_core
.
get
()
<<
" to "
...
@@ -581,7 +580,10 @@ inline void RunProgramGradAPI(
...
@@ -581,7 +580,10 @@ inline void RunProgramGradAPI(
&
skip_eager_delete_vars
);
&
skip_eager_delete_vars
);
interpreter_core
->
SetSkipGcVars
(
skip_eager_delete_vars
);
interpreter_core
->
SetSkipGcVars
(
skip_eager_delete_vars
);
interpretercore_info_cache
.
UpdateSkipEagerDeleteVars
(
interpretercore_info_cache
.
UpdateSkipEagerDeleteVars
(
program_id
,
/*is_grad=*/
true
,
skip_eager_delete_vars
);
program_id
,
global_inner_scope
,
/*is_grad=*/
true
,
skip_eager_delete_vars
);
VLOG
(
2
)
<<
"Get skip GC vars size is: "
<<
skip_eager_delete_vars
.
size
();
VLOG
(
2
)
<<
"Get skip GC vars size is: "
<<
skip_eager_delete_vars
.
size
();
}
else
{
}
else
{
paddle
::
platform
::
RecordEvent
record_event
(
paddle
::
platform
::
RecordEvent
record_event
(
...
@@ -589,8 +591,8 @@ inline void RunProgramGradAPI(
...
@@ -589,8 +591,8 @@ inline void RunProgramGradAPI(
paddle
::
platform
::
TracerEventType
::
UserDefined
,
paddle
::
platform
::
TracerEventType
::
UserDefined
,
1
);
1
);
VLOG
(
2
)
<<
"Get interpretercore cahce by program:"
<<
program_id
;
VLOG
(
2
)
<<
"Get interpretercore cahce by program:"
<<
program_id
;
auto
&
cached_value
=
auto
&
cached_value
=
interpretercore_info_cache
.
GetMutable
(
interpretercore_info_cache
.
GetMutable
(
program_id
,
/*is_grad=*/
true
);
program_id
,
global_inner_scope
,
/*is_grad=*/
true
);
interpreter_core
=
cached_value
.
core_
;
interpreter_core
=
cached_value
.
core_
;
// update scope
// update scope
...
...
paddle/fluid/framework/executor_cache.cc
浏览文件 @
73c70654
...
@@ -312,7 +312,7 @@ std::shared_ptr<InterpreterCore> CreateProgramInterpreterCoreInfoToCache(
...
@@ -312,7 +312,7 @@ std::shared_ptr<InterpreterCore> CreateProgramInterpreterCoreInfoToCache(
place
,
program_desc
.
Block
(
0
),
scope
,
execution_config
));
place
,
program_desc
.
Block
(
0
),
scope
,
execution_config
));
auto
&
cached_value
=
auto
&
cached_value
=
interpretercore_info_cache
.
GetMutable
(
program_id
,
is_grad
);
interpretercore_info_cache
.
GetMutable
(
program_id
,
scope
,
is_grad
);
cached_value
.
core_
=
core
;
cached_value
.
core_
=
core
;
return
core
;
return
core
;
}
}
...
@@ -340,7 +340,7 @@ std::shared_ptr<InterpreterCore> CreateNewIRInterpreterCoreInfoToCache(
...
@@ -340,7 +340,7 @@ std::shared_ptr<InterpreterCore> CreateNewIRInterpreterCoreInfoToCache(
place
,
{},
std
::
move
(
ir_program
),
scope
,
execution_config
));
place
,
{},
std
::
move
(
ir_program
),
scope
,
execution_config
));
auto
&
cached_value
=
auto
&
cached_value
=
interpretercore_info_cache
.
GetMutable
(
program_id
,
is_grad
);
interpretercore_info_cache
.
GetMutable
(
program_id
,
scope
,
is_grad
);
cached_value
.
core_
=
core
;
cached_value
.
core_
=
core
;
return
core
;
return
core
;
}
}
...
...
paddle/fluid/framework/executor_cache.h
浏览文件 @
73c70654
...
@@ -187,26 +187,33 @@ class InterpreterCoreInfoCache {
...
@@ -187,26 +187,33 @@ class InterpreterCoreInfoCache {
public:
public:
static
InterpreterCoreInfoCache
&
Instance
();
static
InterpreterCoreInfoCache
&
Instance
();
bool
Has
(
int64_t
program_id
,
bool
is_grad
)
{
bool
Has
(
int64_t
program_id
,
const
framework
::
Scope
*
scope
,
bool
is_grad
)
{
int64_t
scope_i
=
reinterpret_cast
<
std
::
uintptr_t
>
(
scope
);
program_id
+=
0x9e3779b9
+
(
program_id
<<
6
)
+
(
scope_i
>>
2
);
return
info_map_
.
find
(
program_id
)
!=
info_map_
.
end
()
&&
return
info_map_
.
find
(
program_id
)
!=
info_map_
.
end
()
&&
info_map_
[
program_id
].
IsAvailable
(
is_grad
);
info_map_
[
program_id
].
IsAvailable
(
is_grad
);
}
}
InterpreterCoreInfo
::
CacheValue
&
GetMutable
(
int64_t
program_id
,
InterpreterCoreInfo
::
CacheValue
&
GetMutable
(
int64_t
program_id
,
const
framework
::
Scope
*
scope
,
bool
is_grad
)
{
bool
is_grad
)
{
int64_t
scope_i
=
reinterpret_cast
<
std
::
uintptr_t
>
(
scope
);
program_id
+=
0x9e3779b9
+
(
program_id
<<
6
)
+
(
scope_i
>>
2
);
return
info_map_
[
program_id
].
GetMutable
(
is_grad
);
return
info_map_
[
program_id
].
GetMutable
(
is_grad
);
}
}
void
UpdateSkipEagerDeleteVars
(
int64_t
program_id
,
void
UpdateSkipEagerDeleteVars
(
int64_t
program_id
,
const
framework
::
Scope
*
scope
,
bool
is_grad
,
bool
is_grad
,
const
std
::
set
<
std
::
string
>&
skip_vars
)
{
const
std
::
set
<
std
::
string
>&
skip_vars
)
{
auto
&
cached_value
=
GetMutable
(
program_id
,
is_grad
);
auto
&
cached_value
=
GetMutable
(
program_id
,
scope
,
is_grad
);
cached_value
.
skip_eager_delete_vars_
=
std
::
move
(
skip_vars
);
cached_value
.
skip_eager_delete_vars_
=
std
::
move
(
skip_vars
);
}
}
std
::
set
<
std
::
string
>&
GetSkipEagerDeleteVars
(
int64_t
program_id
,
std
::
set
<
std
::
string
>&
GetSkipEagerDeleteVars
(
int64_t
program_id
,
const
framework
::
Scope
*
scope
,
bool
is_grad
)
{
bool
is_grad
)
{
auto
&
cached_value
=
GetMutable
(
program_id
,
is_grad
);
auto
&
cached_value
=
GetMutable
(
program_id
,
scope
,
is_grad
);
return
cached_value
.
skip_eager_delete_vars_
;
return
cached_value
.
skip_eager_delete_vars_
;
}
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录