Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
机器未来
Paddle
提交
b5a8a0d9
P
Paddle
项目概览
机器未来
/
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看板
未验证
提交
b5a8a0d9
编写于
3月 09, 2022
作者:
F
fwenguang
提交者:
GitHub
3月 09, 2022
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[MLU] add mlu buffer reader (#40131)
上级
041c4bca
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
84 addition
and
4 deletion
+84
-4
paddle/fluid/operators/reader/buffered_reader.cc
paddle/fluid/operators/reader/buffered_reader.cc
+68
-0
paddle/fluid/operators/reader/buffered_reader.h
paddle/fluid/operators/reader/buffered_reader.h
+12
-0
paddle/fluid/platform/stream_callback_manager.cc
paddle/fluid/platform/stream_callback_manager.cc
+4
-4
未找到文件。
paddle/fluid/operators/reader/buffered_reader.cc
浏览文件 @
b5a8a0d9
...
...
@@ -70,9 +70,25 @@ BufferedReader::BufferedReader(
stream_
=
platform
::
NpuStreamResourcePool
::
Instance
().
New
(
dev_idx
);
}
#endif
#ifdef PADDLE_WITH_MLU
if
(
platform
::
is_mlu_place
(
place_
))
{
int
dev_idx
=
place_
.
device
;
compute_stream_
=
((
platform
::
MLUDeviceContext
*
)(
platform
::
DeviceContextPool
::
Instance
()
.
Get
(
place_
)))
->
stream
();
events_
.
resize
(
buffer_size
);
for
(
auto
&
event
:
events_
)
{
event
=
platform
::
MluEventResourcePool
::
Instance
().
New
(
dev_idx
);
}
stream_
=
platform
::
MluStreamResourcePool
::
Instance
().
New
(
dev_idx
);
}
#endif
cpu_buffer_
.
resize
(
buffer_size
);
cuda_buffer_
.
resize
(
buffer_size
);
npu_buffer_
.
resize
(
buffer_size
);
mlu_buffer_
.
resize
(
buffer_size
);
ReadTillBufferFullAsync
();
}
...
...
@@ -256,6 +272,56 @@ void BufferedReader::ReadAsync(size_t i) {
platform
::
NPUStreamSync
(
stream_
.
get
());
}
#endif
#ifdef PADDLE_WITH_MLU
if
(
platform
::
is_mlu_place
(
place_
))
{
TensorVec
&
mlu
=
mlu_buffer_
[
i
];
if
(
mlu
.
empty
())
{
mlu
.
resize
(
cpu
.
size
());
}
else
{
PADDLE_ENFORCE_EQ
(
mlu
.
size
(),
cpu
.
size
(),
platform
::
errors
::
InvalidArgument
(
"Input tensor number on MLU and CPU devices are not matched. "
"The number on MLU is %d, on CPU is %d"
,
mlu
.
size
(),
cpu
.
size
()));
}
std
::
vector
<
void
*>
mlu_ptrs
;
mlu_ptrs
.
reserve
(
cpu
.
size
());
for
(
size_t
i
=
0
;
i
<
cpu
.
size
();
++
i
)
{
mlu
[
i
].
Resize
(
cpu
[
i
].
dims
());
mlu
[
i
].
set_layout
(
cpu
[
i
].
layout
());
mlu_ptrs
.
emplace_back
(
mlu
[
i
].
mutable_data
(
place_
,
cpu
[
i
].
type
()));
}
platform
::
SetMLUDeviceId
(
place_
.
device
);
PADDLE_ENFORCE_MLU_SUCCESS
(
cnPlaceNotifier
(
events_
[
i
].
get
(),
compute_stream_
));
PADDLE_ENFORCE_MLU_SUCCESS
(
cnWaitNotifier
(
events_
[
i
].
get
()));
platform
::
RecordEvent
record_event
(
"BufferedReader:MemoryCopy"
,
platform
::
TracerEventType
::
UserDefined
,
1
);
for
(
size_t
i
=
0
;
i
<
cpu
.
size
();
++
i
)
{
auto
cpu_place
=
cpu
[
i
].
place
();
auto
cpu_ptr
=
cpu
[
i
].
data
();
auto
mlu_ptr
=
mlu_ptrs
[
i
];
auto
size
=
cpu
[
i
].
numel
()
*
paddle
::
framework
::
DataTypeSize
(
cpu
[
i
].
dtype
());
if
((
platform
::
is_mlu_place
(
cpu_place
)))
{
memory
::
Copy
(
place_
,
mlu_ptr
,
cpu_place
,
cpu_ptr
,
size
,
stream_
.
get
());
}
else
{
memory
::
Copy
(
place_
,
mlu_ptr
,
cpu_place
,
cpu_ptr
,
size
,
stream_
.
get
());
platform
::
MLUStreamSync
(
stream_
.
get
());
}
mlu
[
i
].
set_lod
(
cpu
[
i
].
lod
());
}
platform
::
MLUStreamSync
(
stream_
.
get
());
}
#endif
return
i
;
}));
}
...
...
@@ -291,6 +357,8 @@ void BufferedReader::ReadNextImpl(std::vector<framework::LoDTensor> *out) {
*
out
=
std
::
move
(
cuda_buffer_
[
i
]);
}
else
if
(
platform
::
is_npu_place
(
place_
))
{
*
out
=
std
::
move
(
npu_buffer_
[
i
]);
}
else
if
(
platform
::
is_mlu_place
(
place_
))
{
*
out
=
std
::
move
(
mlu_buffer_
[
i
]);
}
else
{
*
out
=
std
::
move
(
cpu_buffer_
[
i
]);
}
...
...
paddle/fluid/operators/reader/buffered_reader.h
浏览文件 @
b5a8a0d9
...
...
@@ -29,6 +29,11 @@
#include "paddle/fluid/platform/device/npu/npu_info.h"
#include "paddle/fluid/platform/device/npu/npu_resource_pool.h"
#endif
#ifdef PADDLE_WITH_MLU
#include "paddle/fluid/platform/device/mlu/mlu_info.h"
#include "paddle/fluid/platform/device/mlu/mlu_resource_pool.h"
#endif
namespace
paddle
{
namespace
operators
{
namespace
reader
{
...
...
@@ -70,6 +75,7 @@ class BufferedReader : public framework::DecoratedReader {
std
::
vector
<
TensorVec
>
cpu_buffer_
;
std
::
vector
<
TensorVec
>
cuda_buffer_
;
std
::
vector
<
TensorVec
>
npu_buffer_
;
std
::
vector
<
TensorVec
>
mlu_buffer_
;
size_t
prev_pos_
{
-
1UL
};
#if defined(PADDLE_WITH_CUDA) || defined(PADDLE_WITH_HIP)
gpuStream_t
compute_stream_
;
...
...
@@ -82,6 +88,12 @@ class BufferedReader : public framework::DecoratedReader {
std
::
shared_ptr
<
platform
::
NpuStreamObject
>
stream_
;
std
::
vector
<
std
::
shared_ptr
<
platform
::
NpuEventObject
>>
events_
;
#endif
#ifdef PADDLE_WITH_MLU
mluStream
compute_stream_
;
std
::
shared_ptr
<
platform
::
MluStreamObject
>
stream_
;
std
::
vector
<
std
::
shared_ptr
<
platform
::
MluEventObject
>>
events_
;
#endif
};
}
// namespace reader
...
...
paddle/fluid/platform/stream_callback_manager.cc
浏览文件 @
b5a8a0d9
...
...
@@ -80,10 +80,10 @@ void StreamCallbackManager<Stream>::AddCallback(
#endif
#if PADDLE_WITH_MLU
VLOG
(
3
)
<<
"MLULaunchCallback at stream: "
<<
stream_
;
LOG
(
ERROR
)
<<
"f
ailed to call MLULaunchCallback, "
<<
"because mlu not support StreamAddCallback yet. "
<<
"function: "
<<
func
;
VLOG
(
3
)
<<
"MLULaunchCallback at stream: "
<<
stream_
<<
" F
ailed to call MLULaunchCallback, "
<<
"because mlu not support StreamAddCallback yet. "
<<
"function: "
<<
func
;
#endif
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录