Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle
提交
d71b9ba7
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看板
未验证
提交
d71b9ba7
编写于
7月 29, 2021
作者:
L
Leo Chen
提交者:
GitHub
7月 29, 2021
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[NPU] Avoid cpu tensor freed before copying to npu completed (#34475)
上级
76710e5f
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
27 addition
and
10 deletion
+27
-10
paddle/fluid/framework/tensor_util.cc
paddle/fluid/framework/tensor_util.cc
+27
-6
paddle/fluid/operators/lookup_table_v2_op_npu.cc
paddle/fluid/operators/lookup_table_v2_op_npu.cc
+0
-4
未找到文件。
paddle/fluid/framework/tensor_util.cc
浏览文件 @
d71b9ba7
...
@@ -25,7 +25,7 @@ limitations under the License. */
...
@@ -25,7 +25,7 @@ limitations under the License. */
#include "paddle/fluid/platform/complex.h"
#include "paddle/fluid/platform/complex.h"
#include "paddle/fluid/platform/profiler.h"
#include "paddle/fluid/platform/profiler.h"
#ifdef PADDLE_WITH_MKLDNN
#ifdef PADDLE_WITH_MKLDNN
#include "dnnl_debug.h"
#include "dnnl_debug.h"
// NOLINT
#endif
#endif
namespace
paddle
{
namespace
paddle
{
...
@@ -112,11 +112,32 @@ void TensorCopy(const Tensor& src, const platform::Place& dst_place,
...
@@ -112,11 +112,32 @@ void TensorCopy(const Tensor& src, const platform::Place& dst_place,
}
}
else
if
(
platform
::
is_cpu_place
(
src_place
)
&&
// NOLINT
else
if
(
platform
::
is_cpu_place
(
src_place
)
&&
// NOLINT
platform
::
is_npu_place
(
dst_place
))
{
platform
::
is_npu_place
(
dst_place
))
{
auto
stream
=
// 1. cpu tensor -> npu pinned tensor
reinterpret_cast
<
const
platform
::
NPUDeviceContext
&>
(
ctx
).
stream
();
platform
::
NPUPinnedPlace
npu_pinned_place
;
memory
::
Copy
(
BOOST_GET_CONST
(
platform
::
NPUPlace
,
dst_place
),
dst_ptr
,
Tensor
npu_pinned_tensor
;
BOOST_GET_CONST
(
platform
::
CPUPlace
,
src_place
),
src_ptr
,
size
,
npu_pinned_tensor
.
Resize
(
src
.
dims
());
stream
);
auto
npu_pinned_ptr
=
npu_pinned_tensor
.
mutable_data
(
npu_pinned_place
,
src
.
type
());
memory
::
Copy
(
npu_pinned_place
,
npu_pinned_ptr
,
BOOST_GET_CONST
(
platform
::
CPUPlace
,
src_place
),
src_ptr
,
size
);
// 2. async copy npu pinned tensor -> npu tensor
memory
::
Copy
(
BOOST_GET_CONST
(
platform
::
NPUPlace
,
dst_place
),
dst_ptr
,
npu_pinned_place
,
npu_pinned_ptr
,
size
,
reinterpret_cast
<
const
platform
::
NPUDeviceContext
&>
(
ctx
).
stream
());
// 3. record event
auto
npu_pinned_allocator
=
static_cast
<
paddle
::
memory
::
allocation
::
NPUPinnedAllocator
*>
(
paddle
::
memory
::
allocation
::
AllocatorFacade
::
Instance
()
.
GetAllocator
(
npu_pinned_place
)
.
get
());
paddle
::
memory
::
allocation
::
Allocation
*
allocation
=
npu_pinned_tensor
.
Holder
().
get
();
npu_pinned_allocator
->
RecordEvent
(
allocation
,
reinterpret_cast
<
const
platform
::
NPUDeviceContext
&>
(
ctx
).
stream
());
}
}
else
if
(
platform
::
is_npu_place
(
src_place
)
&&
// NOLINT
else
if
(
platform
::
is_npu_place
(
src_place
)
&&
// NOLINT
platform
::
is_npu_place
(
dst_place
))
{
platform
::
is_npu_place
(
dst_place
))
{
...
...
paddle/fluid/operators/lookup_table_v2_op_npu.cc
浏览文件 @
d71b9ba7
...
@@ -40,10 +40,6 @@ class LookupTableV2NPUKernel : public framework::OpKernel<T> {
...
@@ -40,10 +40,6 @@ class LookupTableV2NPUKernel : public framework::OpKernel<T> {
platform
::
errors
::
InvalidArgument
(
"npu only accept LoDTensor"
));
platform
::
errors
::
InvalidArgument
(
"npu only accept LoDTensor"
));
output_t
->
mutable_data
<
T
>
(
ctx
.
GetPlace
());
output_t
->
mutable_data
<
T
>
(
ctx
.
GetPlace
());
// add copy ids to ensure ids_t is prepared.
std
::
vector
<
int
>
ids
;
TensorToVector
(
*
ids_t
,
ctx
.
device_context
(),
&
ids
);
NpuOpRunner
runner
;
NpuOpRunner
runner
;
runner
.
SetType
(
"GatherV2"
)
runner
.
SetType
(
"GatherV2"
)
.
AddInput
(
*
table_t
)
.
AddInput
(
*
table_t
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录