Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
机器未来
Paddle
提交
1822f86e
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看板
未验证
提交
1822f86e
编写于
10月 15, 2019
作者:
L
liu zhengxi
提交者:
GitHub
10月 15, 2019
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix the PD_ZeroCopyPredictorRun output problem and cmake, test=release/1.6 (#20624)
上级
1ba0d70b
变更
8
隐藏空白更改
内联
并排
Showing
8 changed file
with
53 addition
and
26 deletion
+53
-26
paddle/fluid/inference/capi/CMakeLists.txt
paddle/fluid/inference/capi/CMakeLists.txt
+4
-6
paddle/fluid/inference/capi/c_api.cc
paddle/fluid/inference/capi/c_api.cc
+15
-3
paddle/fluid/inference/capi/c_api.h
paddle/fluid/inference/capi/c_api.h
+1
-1
paddle/fluid/inference/capi/pd_config.cc
paddle/fluid/inference/capi/pd_config.cc
+1
-0
paddle/fluid/inference/capi/pd_predictor.cc
paddle/fluid/inference/capi/pd_predictor.cc
+18
-14
paddle/fluid/inference/capi/pd_tensor.cc
paddle/fluid/inference/capi/pd_tensor.cc
+9
-0
paddle/fluid/inference/tests/api/analyzer_capi_int_tester.cc
paddle/fluid/inference/tests/api/analyzer_capi_int_tester.cc
+4
-1
paddle/fluid/inference/tests/api/analyzer_capi_tester.cc
paddle/fluid/inference/tests/api/analyzer_capi_tester.cc
+1
-1
未找到文件。
paddle/fluid/inference/capi/CMakeLists.txt
浏览文件 @
1822f86e
cc_library
(
pd_config SRCS pd_config.cc
)
cc_library
(
pd_predictor SRCS pd_predictor.cc
)
cc_library
(
pd_tensor SRCS pd_tensor.cc
)
cc_library
(
pd_c_api SRCS c_api.cc
)
cc_library
(
paddle_fluid_c SRCS c_api.cc DEPS paddle_fluid pd_config pd_predictor pd_tensor pd_c_api
)
cc_library
(
paddle_fluid_c_shared SHARED SRCS c_api.cc DEPS paddle_fluid pd_config pd_predictor pd_tensor pd_c_api
)
set
(
C_API_SRCS pd_config.cc pd_predictor.cc pd_tensor.cc c_api.cc
)
cc_library
(
paddle_fluid_c SRCS
${
C_API_SRCS
}
DEPS paddle_fluid
)
cc_library
(
paddle_fluid_c_shared SHARED SRCS
${
C_API_SRCS
}
DEPS paddle_fluid
)
set_target_properties
(
paddle_fluid_c_shared PROPERTIES OUTPUT_NAME paddle_fluid_c
)
if
(
WIN32
)
target_link_libraries
(
paddle_fluid_c_shared shlwapi.lib
)
...
...
paddle/fluid/inference/capi/c_api.cc
浏览文件 @
1822f86e
...
...
@@ -29,22 +29,34 @@ void PD_DeletePaddleBuf(PD_PaddleBuf* buf) {
if
(
buf
)
{
delete
buf
;
buf
=
nullptr
;
VLOG
(
3
)
<<
"PD_PaddleBuf delete successfully. "
;
}
}
void
PD_PaddleBufResize
(
PD_PaddleBuf
*
buf
,
size_t
length
)
{
PADDLE_ENFORCE_NOT_NULL
(
buf
);
buf
->
buf
.
Resize
(
length
);
}
void
PD_PaddleBufReset
(
PD_PaddleBuf
*
buf
,
void
*
data
,
size_t
length
)
{
PADDLE_ENFORCE_NOT_NULL
(
buf
);
buf
->
buf
.
Reset
(
data
,
length
);
}
bool
PD_PaddleBufEmpty
(
PD_PaddleBuf
*
buf
)
{
return
buf
->
buf
.
empty
();
}
bool
PD_PaddleBufEmpty
(
PD_PaddleBuf
*
buf
)
{
PADDLE_ENFORCE_NOT_NULL
(
buf
);
return
buf
->
buf
.
empty
();
}
void
*
PD_PaddleBufData
(
PD_PaddleBuf
*
buf
)
{
return
buf
->
buf
.
data
();
}
void
*
PD_PaddleBufData
(
PD_PaddleBuf
*
buf
)
{
PADDLE_ENFORCE_NOT_NULL
(
buf
);
return
buf
->
buf
.
data
();
}
size_t
PD_PaddleBufLength
(
PD_PaddleBuf
*
buf
)
{
return
buf
->
buf
.
length
();
}
size_t
PD_PaddleBufLength
(
PD_PaddleBuf
*
buf
)
{
PADDLE_ENFORCE_NOT_NULL
(
buf
);
return
buf
->
buf
.
length
();
}
}
// extern "C"
...
...
paddle/fluid/inference/capi/c_api.h
浏览文件 @
1822f86e
...
...
@@ -104,7 +104,7 @@ PADDLE_CAPI_EXPORT extern bool PD_PredictorRun(const PD_AnalysisConfig* config,
PADDLE_CAPI_EXPORT
extern
bool
PD_PredictorZeroCopyRun
(
const
PD_AnalysisConfig
*
config
,
PD_ZeroCopyData
*
inputs
,
int
in_size
,
PD_ZeroCopyData
*
output
,
int
**
out_size
);
PD_ZeroCopyData
*
*
output
,
int
**
out_size
);
// AnalysisConfig
enum
Precision
{
kFloat32
=
0
,
kInt8
,
kHalf
};
...
...
paddle/fluid/inference/capi/pd_config.cc
浏览文件 @
1822f86e
...
...
@@ -33,6 +33,7 @@ void PD_DeleteAnalysisConfig(PD_AnalysisConfig* config) {
if
(
config
)
{
delete
config
;
config
=
nullptr
;
VLOG
(
3
)
<<
"PD_AnalysisConfig delete successfully. "
;
}
}
...
...
paddle/fluid/inference/capi/pd_predictor.cc
浏览文件 @
1822f86e
...
...
@@ -28,6 +28,7 @@ extern "C" {
bool
PD_PredictorRun
(
const
PD_AnalysisConfig
*
config
,
PD_Tensor
*
inputs
,
int
in_size
,
PD_Tensor
*
output_data
,
int
**
out_size
,
int
batch_size
)
{
PADDLE_ENFORCE_NOT_NULL
(
config
);
auto
predictor
=
paddle
::
CreatePaddlePredictor
(
config
->
config
);
std
::
vector
<
paddle
::
PaddleTensor
>
in
;
for
(
int
i
=
0
;
i
<
in_size
;
++
i
)
{
...
...
@@ -47,9 +48,11 @@ bool PD_PredictorRun(const PD_AnalysisConfig* config, PD_Tensor* inputs,
bool
PD_PredictorZeroCopyRun
(
const
PD_AnalysisConfig
*
config
,
PD_ZeroCopyData
*
inputs
,
int
in_size
,
PD_ZeroCopyData
*
output
,
int
**
out_size
)
{
PD_ZeroCopyData
**
output
,
int
**
out_size
)
{
PADDLE_ENFORCE_NOT_NULL
(
config
);
auto
predictor
=
paddle
::
CreatePaddlePredictor
(
config
->
config
);
auto
input_names
=
predictor
->
GetInputNames
();
VLOG
(
3
)
<<
"The inputs' size is "
<<
input_names
.
size
();
PADDLE_ENFORCE_EQ
(
input_names
.
size
(),
in_size
,
"The number of input and the number of model's input must match. "
);
...
...
@@ -81,26 +84,27 @@ bool PD_PredictorZeroCopyRun(const PD_AnalysisConfig* config,
auto
output_names
=
predictor
->
GetOutputNames
();
int
osize
=
output_names
.
size
();
*
out_size
=
&
osize
;
output
=
new
PD_ZeroCopyData
[
osize
];
*
output
=
new
PD_ZeroCopyData
[
osize
];
VLOG
(
3
)
<<
"The output size is "
<<
osize
;
for
(
int
i
=
0
;
i
<
osize
;
++
i
)
{
LOG
(
INFO
)
<<
1
;
output
[
i
]
.
name
=
new
char
[
output_names
[
i
].
length
()
+
1
];
snprintf
(
output
[
i
]
.
name
,
output_names
[
i
].
length
()
+
1
,
"%s"
,
auto
&
output_i
=
(
*
output
)[
i
]
;
output
_i
.
name
=
new
char
[
output_names
[
i
].
length
()
+
1
];
snprintf
(
output
_i
.
name
,
output_names
[
i
].
length
()
+
1
,
"%s"
,
output_names
[
i
].
c_str
());
auto
output_t
=
predictor
->
GetOutputTensor
(
output_names
[
i
]);
output
[
i
]
.
dtype
=
ConvertToPDDataType
(
output_t
->
type
());
output
_i
.
dtype
=
ConvertToPDDataType
(
output_t
->
type
());
std
::
vector
<
int
>
output_shape
=
output_t
->
shape
();
output
[
i
]
.
shape
=
new
int
[
output_shape
.
size
()];
output
[
i
]
.
shape
=
output_shape
.
data
();
output
[
i
]
.
shape_size
=
output_shape
.
size
();
switch
(
output
[
i
]
.
dtype
)
{
output
_i
.
shape
=
new
int
[
output_shape
.
size
()];
output
_i
.
shape
=
output_shape
.
data
();
output
_i
.
shape_size
=
output_shape
.
size
();
switch
(
output
_i
.
dtype
)
{
case
PD_FLOAT32
:
{
std
::
vector
<
float
>
out_data
;
int
out_num
=
std
::
accumulate
(
output_shape
.
begin
(),
output_shape
.
end
(),
1
,
std
::
multiplies
<
int
>
());
out_data
.
resize
(
out_num
);
output_t
->
copy_to_cpu
(
out_data
.
data
());
output
[
i
]
.
data
=
static_cast
<
void
*>
(
out_data
.
data
());
output
_i
.
data
=
static_cast
<
void
*>
(
out_data
.
data
());
}
break
;
case
PD_INT32
:
{
std
::
vector
<
int32_t
>
out_data
;
...
...
@@ -108,7 +112,7 @@ bool PD_PredictorZeroCopyRun(const PD_AnalysisConfig* config,
1
,
std
::
multiplies
<
int
>
());
out_data
.
resize
(
out_num
);
output_t
->
copy_to_cpu
(
out_data
.
data
());
output
[
i
]
.
data
=
static_cast
<
void
*>
(
out_data
.
data
());
output
_i
.
data
=
static_cast
<
void
*>
(
out_data
.
data
());
}
break
;
case
PD_INT64
:
{
std
::
vector
<
int64_t
>
out_data
;
...
...
@@ -116,7 +120,7 @@ bool PD_PredictorZeroCopyRun(const PD_AnalysisConfig* config,
1
,
std
::
multiplies
<
int
>
());
out_data
.
resize
(
out_num
);
output_t
->
copy_to_cpu
(
out_data
.
data
());
output
[
i
]
.
data
=
static_cast
<
void
*>
(
out_data
.
data
());
output
_i
.
data
=
static_cast
<
void
*>
(
out_data
.
data
());
}
break
;
case
PD_UINT8
:
{
std
::
vector
<
uint8_t
>
out_data
;
...
...
@@ -124,7 +128,7 @@ bool PD_PredictorZeroCopyRun(const PD_AnalysisConfig* config,
1
,
std
::
multiplies
<
int
>
());
out_data
.
resize
(
out_num
);
output_t
->
copy_to_cpu
(
out_data
.
data
());
output
[
i
]
.
data
=
static_cast
<
void
*>
(
out_data
.
data
());
output
_i
.
data
=
static_cast
<
void
*>
(
out_data
.
data
());
}
break
;
default:
CHECK
(
false
)
<<
"Unsupport data type."
;
...
...
paddle/fluid/inference/capi/pd_tensor.cc
浏览文件 @
1822f86e
...
...
@@ -29,40 +29,49 @@ void PD_DeletePaddleTensor(PD_Tensor* tensor) {
if
(
tensor
)
{
delete
tensor
;
tensor
=
nullptr
;
VLOG
(
3
)
<<
"PD_Tensor delete successfully. "
;
}
}
void
PD_SetPaddleTensorName
(
PD_Tensor
*
tensor
,
char
*
name
)
{
PADDLE_ENFORCE_NOT_NULL
(
tensor
);
tensor
->
tensor
.
name
=
std
::
string
(
name
);
}
void
PD_SetPaddleTensorDType
(
PD_Tensor
*
tensor
,
PD_DataType
dtype
)
{
PADDLE_ENFORCE_NOT_NULL
(
tensor
);
tensor
->
tensor
.
dtype
=
paddle
::
ConvertToPaddleDType
(
dtype
);
}
void
PD_SetPaddleTensorData
(
PD_Tensor
*
tensor
,
PD_PaddleBuf
*
buf
)
{
PADDLE_ENFORCE_NOT_NULL
(
tensor
);
tensor
->
tensor
.
data
=
buf
->
buf
;
}
void
PD_SetPaddleTensorShape
(
PD_Tensor
*
tensor
,
int
*
shape
,
int
size
)
{
PADDLE_ENFORCE_NOT_NULL
(
tensor
);
tensor
->
tensor
.
shape
.
assign
(
shape
,
shape
+
size
);
}
const
char
*
PD_GetPaddleTensorName
(
const
PD_Tensor
*
tensor
)
{
PADDLE_ENFORCE_NOT_NULL
(
tensor
);
return
tensor
->
tensor
.
name
.
c_str
();
}
PD_DataType
PD_GetPaddleTensorDType
(
const
PD_Tensor
*
tensor
)
{
PADDLE_ENFORCE_NOT_NULL
(
tensor
);
return
ConvertToPDDataType
(
tensor
->
tensor
.
dtype
);
}
PD_PaddleBuf
*
PD_GetPaddleTensorData
(
const
PD_Tensor
*
tensor
)
{
PADDLE_ENFORCE_NOT_NULL
(
tensor
);
PD_PaddleBuf
*
ret
=
PD_NewPaddleBuf
();
ret
->
buf
=
tensor
->
tensor
.
data
;
return
ret
;
}
int
*
PD_GetPaddleTensorShape
(
const
PD_Tensor
*
tensor
,
int
**
size
)
{
PADDLE_ENFORCE_NOT_NULL
(
tensor
);
std
::
vector
<
int
>
shape
=
tensor
->
tensor
.
shape
;
int
s
=
shape
.
size
();
*
size
=
&
s
;
...
...
paddle/fluid/inference/tests/api/analyzer_capi_int_tester.cc
浏览文件 @
1822f86e
...
...
@@ -92,7 +92,10 @@ void zero_copy_run() {
inputs
[
1
].
shape
=
label_shape
;
inputs
[
1
].
shape_size
=
label_shape_size
;
PD_PredictorZeroCopyRun
(
config
,
inputs
,
in_size
,
outputs
,
&
out_size
);
PD_PredictorZeroCopyRun
(
config
,
inputs
,
in_size
,
&
outputs
,
&
out_size
);
LOG
(
INFO
)
<<
outputs
[
0
].
name
;
LOG
(
INFO
)
<<
outputs
[
0
].
shape_size
;
}
TEST
(
PD_ZeroCopyRun
,
zero_copy_run
)
{
...
...
paddle/fluid/inference/tests/api/analyzer_capi_tester.cc
浏览文件 @
1822f86e
...
...
@@ -74,7 +74,7 @@ void zero_copy_run() {
inputs
->
shape
=
shape
;
inputs
->
shape_size
=
shape_size
;
PD_PredictorZeroCopyRun
(
config
,
inputs
,
in_size
,
outputs
,
&
out_size
);
PD_PredictorZeroCopyRun
(
config
,
inputs
,
in_size
,
&
outputs
,
&
out_size
);
}
TEST
(
PD_ZeroCopyRun
,
zero_copy_run
)
{
zero_copy_run
<
float
>
();
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录