Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle
提交
106b5514
P
Paddle
项目概览
PaddlePaddle
/
Paddle
大约 1 年 前同步成功
通知
2298
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看板
未验证
提交
106b5514
编写于
1月 26, 2022
作者:
B
baoachun
提交者:
GitHub
1月 26, 2022
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
support npu weight unified H2D copy before inference (#39160)
* support npu weight unified H2D copy * remove redundant variable
上级
b1a458ac
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
72 addition
and
9 deletion
+72
-9
paddle/fluid/inference/analysis/argument.h
paddle/fluid/inference/analysis/argument.h
+4
-0
paddle/fluid/inference/analysis/passes/ir_params_sync_among_devices_pass.cc
...ence/analysis/passes/ir_params_sync_among_devices_pass.cc
+58
-9
paddle/fluid/inference/analysis/passes/ir_params_sync_among_devices_pass.h
...rence/analysis/passes/ir_params_sync_among_devices_pass.h
+7
-0
paddle/fluid/inference/api/analysis_predictor.cc
paddle/fluid/inference/api/analysis_predictor.cc
+3
-0
未找到文件。
paddle/fluid/inference/analysis/argument.h
浏览文件 @
106b5514
...
...
@@ -282,6 +282,10 @@ struct Argument {
DECL_ARGUMENT_FIELD
(
ipu_batch_size
,
IpuBatchSize
,
int
);
DECL_ARGUMENT_FIELD
(
ipu_need_avg_shard
,
IpuNeedAvgShard
,
bool
);
// npu related
DECL_ARGUMENT_FIELD
(
use_npu
,
UseNpu
,
bool
);
DECL_ARGUMENT_FIELD
(
npu_device_id
,
NPUDeviceId
,
int
);
private:
std
::
unordered_set
<
std
::
string
>
valid_fields_
;
};
...
...
paddle/fluid/inference/analysis/passes/ir_params_sync_among_devices_pass.cc
浏览文件 @
106b5514
...
...
@@ -22,16 +22,50 @@ namespace paddle {
namespace
inference
{
namespace
analysis
{
void
IrParamsSyncAmongDevicesPass
::
RunImpl
(
Argument
*
argument
)
{
PADDLE_ENFORCE_EQ
(
argument
->
scope_valid
(),
true
,
platform
::
errors
::
PreconditionNotMet
(
"The scope field should be valid"
));
PADDLE_ENFORCE_EQ
(
argument
->
use_gpu_valid
(),
true
,
#ifdef PADDLE_WITH_ASCEND_CL
void
IrParamsSyncAmongDevicesPass
::
CopyParamsToNpu
(
Argument
*
argument
)
{
if
(
!
argument
->
use_npu
())
return
;
auto
&
graph
=
argument
->
main_graph
();
std
::
vector
<
std
::
string
>
repetitive_params
;
if
(
graph
.
Has
(
framework
::
ir
::
kRepetitiveParamAttr
))
repetitive_params
=
graph
.
Get
<
std
::
vector
<
std
::
string
>>
(
framework
::
ir
::
kRepetitiveParamAttr
);
LOG
(
INFO
)
<<
"Sync params from CPU to NPU"
;
PADDLE_ENFORCE_EQ
(
argument
->
npu_device_id_valid
(),
true
,
platform
::
errors
::
PreconditionNotMet
(
"The use_gpu field should be valid"
));
"The npu_device_id field should be valid"
));
platform
::
Place
place
=
platform
::
NPUPlace
(
argument
->
npu_device_id
());
auto
*
scope
=
argument
->
scope_ptr
();
std
::
vector
<
std
::
string
>
all_vars
=
scope
->
LocalVarNames
();
platform
::
Place
place
;
for
(
auto
&
var_name
:
all_vars
)
{
auto
*
var
=
scope
->
FindLocalVar
(
var_name
);
PADDLE_ENFORCE_NOT_NULL
(
var
,
platform
::
errors
::
PreconditionNotMet
(
"The var should not be nullptr"
));
if
(
var
->
IsType
<
framework
::
LoDTensor
>
()
||
var
->
IsType
<
framework
::
Tensor
>
())
{
auto
*
t
=
var
->
GetMutable
<
framework
::
LoDTensor
>
();
platform
::
CPUPlace
cpu_place
;
framework
::
LoDTensor
temp_tensor
;
temp_tensor
.
Resize
(
t
->
dims
());
temp_tensor
.
mutable_data
<
float
>
(
cpu_place
);
paddle
::
framework
::
TensorCopySync
(
*
t
,
cpu_place
,
&
temp_tensor
);
t
->
clear
();
paddle
::
framework
::
TensorCopySync
(
temp_tensor
,
place
,
t
);
}
}
}
#else
void
IrParamsSyncAmongDevicesPass
::
CopyParamsToGpu
(
Argument
*
argument
)
{
// The parameters are on the cpu, therefore, synchronization is not necessary.
if
(
!
argument
->
use_gpu
())
return
;
...
...
@@ -47,8 +81,7 @@ void IrParamsSyncAmongDevicesPass::RunImpl(Argument *argument) {
PADDLE_ENFORCE_EQ
(
argument
->
gpu_device_id_valid
(),
true
,
platform
::
errors
::
PreconditionNotMet
(
"The gpu_device_id field should be valid"
));
place
=
platform
::
CUDAPlace
(
argument
->
gpu_device_id
());
platform
::
Place
place
=
platform
::
CUDAPlace
(
argument
->
gpu_device_id
());
auto
*
scope
=
argument
->
scope_ptr
();
std
::
vector
<
std
::
string
>
all_vars
=
scope
->
LocalVarNames
();
...
...
@@ -100,6 +133,22 @@ void IrParamsSyncAmongDevicesPass::RunImpl(Argument *argument) {
}
}
#endif
void
IrParamsSyncAmongDevicesPass
::
RunImpl
(
Argument
*
argument
)
{
PADDLE_ENFORCE_EQ
(
argument
->
scope_valid
(),
true
,
platform
::
errors
::
PreconditionNotMet
(
"The scope field should be valid"
));
#ifdef PADDLE_WITH_ASCEND_CL
if
(
!
argument
->
use_npu_valid
())
return
;
CopyParamsToNpu
(
argument
);
#else
if
(
!
argument
->
use_gpu_valid
())
return
;
CopyParamsToGpu
(
argument
);
#endif
}
std
::
string
IrParamsSyncAmongDevicesPass
::
repr
()
const
{
return
"ir-params-sync-among-devices-pass"
;
}
...
...
paddle/fluid/inference/analysis/passes/ir_params_sync_among_devices_pass.h
浏览文件 @
106b5514
...
...
@@ -33,6 +33,13 @@ class IrParamsSyncAmongDevicesPass : public AnalysisPass {
public:
void
RunImpl
(
Argument
*
argument
)
override
;
std
::
string
repr
()
const
override
;
private:
#ifdef PADDLE_WITH_ASCEND_CL
void
CopyParamsToNpu
(
Argument
*
argument
);
#else
void
CopyParamsToGpu
(
Argument
*
argument
);
#endif
};
}
// namespace analysis
...
...
paddle/fluid/inference/api/analysis_predictor.cc
浏览文件 @
106b5514
...
...
@@ -668,6 +668,9 @@ void AnalysisPredictor::PrepareArgument() {
argument_
.
SetIpuBatchSize
(
config_
.
ipu_batch_size_
);
argument_
.
SetIpuNeedAvgShard
(
config_
.
ipu_need_avg_shard_
);
argument_
.
SetUseNpu
(
config_
.
use_npu_
);
argument_
.
SetNPUDeviceId
(
config_
.
npu_device_id
());
if
(
config_
.
use_mkldnn_
)
{
LOG
(
INFO
)
<<
"MKLDNN is enabled"
;
argument_
.
SetMKLDNNEnabledOpTypes
(
config_
.
mkldnn_enabled_op_types_
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录