Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
BaiXuePrincess
Paddle
提交
a1ad3a63
P
Paddle
项目概览
BaiXuePrincess
/
Paddle
与 Fork 源项目一致
Fork自
PaddlePaddle / Paddle
通知
1
Star
1
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看板
未验证
提交
a1ad3a63
编写于
12月 08, 2021
作者:
S
sneaxiy
提交者:
GitHub
12月 08, 2021
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Fix CUDA Graph H2D bug by restore host memory (#37774)
* fix CUDA Graph H2D bug again * fix no return bug
上级
9a2d327c
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
38 addition
and
28 deletion
+38
-28
paddle/fluid/operators/math/concat_and_split.cu
paddle/fluid/operators/math/concat_and_split.cu
+21
-28
paddle/fluid/platform/cuda_graph_with_memory_pool.h
paddle/fluid/platform/cuda_graph_with_memory_pool.h
+17
-0
未找到文件。
paddle/fluid/operators/math/concat_and_split.cu
浏览文件 @
a1ad3a63
...
@@ -287,13 +287,11 @@ class ConcatFunctor<platform::CUDADeviceContext, T> {
...
@@ -287,13 +287,11 @@ class ConcatFunctor<platform::CUDADeviceContext, T> {
const
T
**
dev_ins_data
=
nullptr
;
const
T
**
dev_ins_data
=
nullptr
;
if
(
!
has_same_shape
||
in_num
<
2
||
in_num
>
4
)
{
if
(
!
has_same_shape
||
in_num
<
2
||
in_num
>
4
)
{
tmp_dev_ins_data
=
memory
::
Alloc
(
context
,
in_num
*
sizeof
(
T
*
));
tmp_dev_ins_data
=
memory
::
Alloc
(
context
,
in_num
*
sizeof
(
T
*
));
{
auto
*
restored
=
platform
::
SkipCUDAGraphCaptureGuard
guard
;
platform
::
RestoreHostMemIfCapturingCUDAGraph
(
inputs_data
,
in_num
);
memory
::
Copy
(
BOOST_GET_CONST
(
platform
::
CUDAPlace
,
context
.
GetPlace
()),
memory
::
Copy
(
BOOST_GET_CONST
(
platform
::
CUDAPlace
,
context
.
GetPlace
()),
tmp_dev_ins_data
->
ptr
(),
platform
::
CPUPlace
(),
tmp_dev_ins_data
->
ptr
(),
platform
::
CPUPlace
(),
restored
,
static_cast
<
void
*>
(
inputs_data
),
in_num
*
sizeof
(
T
*
),
in_num
*
sizeof
(
T
*
),
context
.
stream
());
context
.
stream
());
}
dev_ins_data
=
reinterpret_cast
<
const
T
**>
(
tmp_dev_ins_data
->
ptr
());
dev_ins_data
=
reinterpret_cast
<
const
T
**>
(
tmp_dev_ins_data
->
ptr
());
}
}
...
@@ -317,13 +315,12 @@ class ConcatFunctor<platform::CUDADeviceContext, T> {
...
@@ -317,13 +315,12 @@ class ConcatFunctor<platform::CUDADeviceContext, T> {
}
else
{
}
else
{
auto
tmp_dev_ins_col_data
=
auto
tmp_dev_ins_col_data
=
memory
::
Alloc
(
context
,
inputs_col_num
*
sizeof
(
int64_t
));
memory
::
Alloc
(
context
,
inputs_col_num
*
sizeof
(
int64_t
));
{
platform
::
SkipCUDAGraphCaptureGuard
guard
;
auto
*
restored
=
platform
::
RestoreHostMemIfCapturingCUDAGraph
(
memory
::
Copy
(
BOOST_GET_CONST
(
platform
::
CUDAPlace
,
context
.
GetPlace
()),
inputs_col
,
inputs_col_num
);
tmp_dev_ins_col_data
->
ptr
(),
platform
::
CPUPlace
(),
memory
::
Copy
(
BOOST_GET_CONST
(
platform
::
CUDAPlace
,
context
.
GetPlace
()),
static_cast
<
void
*>
(
inputs_col
),
tmp_dev_ins_col_data
->
ptr
(),
platform
::
CPUPlace
(),
restored
,
inputs_col_num
*
sizeof
(
int64_t
),
context
.
stream
());
inputs_col_num
*
sizeof
(
int64_t
),
context
.
stream
());
}
int64_t
*
dev_ins_col_data
=
int64_t
*
dev_ins_col_data
=
static_cast
<
int64_t
*>
(
tmp_dev_ins_col_data
->
ptr
());
static_cast
<
int64_t
*>
(
tmp_dev_ins_col_data
->
ptr
());
...
@@ -422,13 +419,11 @@ class SplitFunctor<platform::CUDADeviceContext, T> {
...
@@ -422,13 +419,11 @@ class SplitFunctor<platform::CUDADeviceContext, T> {
T
**
dev_out_gpu_data
=
nullptr
;
T
**
dev_out_gpu_data
=
nullptr
;
if
(
!
has_same_shape
||
o_num
<
2
||
o_num
>
4
)
{
if
(
!
has_same_shape
||
o_num
<
2
||
o_num
>
4
)
{
tmp_dev_outs_data
=
memory
::
Alloc
(
context
,
o_num
*
sizeof
(
T
*
));
tmp_dev_outs_data
=
memory
::
Alloc
(
context
,
o_num
*
sizeof
(
T
*
));
{
auto
*
restored
=
platform
::
SkipCUDAGraphCaptureGuard
guard
;
platform
::
RestoreHostMemIfCapturingCUDAGraph
(
outputs_data
,
o_num
);
memory
::
Copy
(
BOOST_GET_CONST
(
platform
::
CUDAPlace
,
context
.
GetPlace
()),
memory
::
Copy
(
BOOST_GET_CONST
(
platform
::
CUDAPlace
,
context
.
GetPlace
()),
tmp_dev_outs_data
->
ptr
(),
platform
::
CPUPlace
(),
tmp_dev_outs_data
->
ptr
(),
platform
::
CPUPlace
(),
restored
,
reinterpret_cast
<
void
*>
(
outputs_data
),
o_num
*
sizeof
(
T
*
),
o_num
*
sizeof
(
T
*
),
context
.
stream
());
context
.
stream
());
}
dev_out_gpu_data
=
reinterpret_cast
<
T
**>
(
tmp_dev_outs_data
->
ptr
());
dev_out_gpu_data
=
reinterpret_cast
<
T
**>
(
tmp_dev_outs_data
->
ptr
());
}
}
...
@@ -452,13 +447,11 @@ class SplitFunctor<platform::CUDADeviceContext, T> {
...
@@ -452,13 +447,11 @@ class SplitFunctor<platform::CUDADeviceContext, T> {
}
else
{
}
else
{
auto
tmp_dev_ins_col_data
=
auto
tmp_dev_ins_col_data
=
memory
::
Alloc
(
context
,
outputs_cols_num
*
sizeof
(
int64_t
));
memory
::
Alloc
(
context
,
outputs_cols_num
*
sizeof
(
int64_t
));
{
auto
*
restored
=
platform
::
RestoreHostMemIfCapturingCUDAGraph
(
platform
::
SkipCUDAGraphCaptureGuard
guard
;
outputs_cols
,
outputs_cols_num
);
memory
::
Copy
(
BOOST_GET_CONST
(
platform
::
CUDAPlace
,
context
.
GetPlace
()),
memory
::
Copy
(
BOOST_GET_CONST
(
platform
::
CUDAPlace
,
context
.
GetPlace
()),
tmp_dev_ins_col_data
->
ptr
(),
platform
::
CPUPlace
(),
tmp_dev_ins_col_data
->
ptr
(),
platform
::
CPUPlace
(),
restored
,
reinterpret_cast
<
void
*>
(
outputs_cols
),
outputs_cols_num
*
sizeof
(
int64_t
),
context
.
stream
());
outputs_cols_num
*
sizeof
(
int64_t
),
context
.
stream
());
}
int64_t
*
dev_outs_col_data
=
int64_t
*
dev_outs_col_data
=
reinterpret_cast
<
int64_t
*>
(
tmp_dev_ins_col_data
->
ptr
());
reinterpret_cast
<
int64_t
*>
(
tmp_dev_ins_col_data
->
ptr
());
...
...
paddle/fluid/platform/cuda_graph_with_memory_pool.h
浏览文件 @
a1ad3a63
...
@@ -60,6 +60,23 @@ inline void AddResetCallbackIfCapturingCUDAGraph(Callback &&callback) {
...
@@ -60,6 +60,23 @@ inline void AddResetCallbackIfCapturingCUDAGraph(Callback &&callback) {
callback
();
callback
();
}
}
template
<
typename
T
>
inline
T
*
RestoreHostMemIfCapturingCUDAGraph
(
T
*
host_mem
,
size_t
size
)
{
static_assert
(
std
::
is_trivial
<
T
>::
value
,
"T must be trivial type"
);
static_assert
(
!
std
::
is_same
<
T
,
void
>::
value
,
"T cannot be void"
);
#ifdef PADDLE_WITH_CUDA
if
(
UNLIKELY
(
IsCUDAGraphCapturing
()))
{
size_t
nbytes
=
size
*
sizeof
(
T
);
void
*
new_host_mem
=
new
uint8_t
[
nbytes
];
std
::
memcpy
(
new_host_mem
,
host_mem
,
nbytes
);
AddResetCallbackIfCapturingCUDAGraph
(
[
new_host_mem
]
{
delete
[]
reinterpret_cast
<
uint8_t
*>
(
new_host_mem
);
});
return
reinterpret_cast
<
T
*>
(
new_host_mem
);
}
#endif
return
host_mem
;
}
class
SkipCUDAGraphCaptureGuard
{
class
SkipCUDAGraphCaptureGuard
{
DISABLE_COPY_AND_ASSIGN
(
SkipCUDAGraphCaptureGuard
);
DISABLE_COPY_AND_ASSIGN
(
SkipCUDAGraphCaptureGuard
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录