Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle
提交
457fe72c
P
Paddle
项目概览
PaddlePaddle
/
Paddle
1 年多 前同步成功
通知
2302
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看板
未验证
提交
457fe72c
编写于
1月 05, 2022
作者:
W
Wilber
提交者:
GitHub
1月 05, 2022
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
inference c_api support std::string (#38667) (#38710)
上级
dd339f4e
变更
8
隐藏空白更改
内联
并排
Showing
8 changed file
with
55 addition
and
7 deletion
+55
-7
paddle/fluid/inference/capi_exp/pd_config.cc
paddle/fluid/inference/capi_exp/pd_config.cc
+2
-4
paddle/fluid/inference/capi_exp/pd_config.h
paddle/fluid/inference/capi_exp/pd_config.h
+1
-1
paddle/fluid/inference/capi_exp/pd_types.h
paddle/fluid/inference/capi_exp/pd_types.h
+5
-0
paddle/fluid/inference/capi_exp/pd_utils.cc
paddle/fluid/inference/capi_exp/pd_utils.cc
+23
-0
paddle/fluid/inference/capi_exp/pd_utils.h
paddle/fluid/inference/capi_exp/pd_utils.h
+9
-0
paddle/fluid/inference/capi_exp/utils_internal.h
paddle/fluid/inference/capi_exp/utils_internal.h
+8
-0
paddle/fluid/inference/goapi/config.go
paddle/fluid/inference/goapi/config.go
+2
-2
paddle/fluid/inference/tests/api/analyzer_capi_exp_tester.cc
paddle/fluid/inference/tests/api/analyzer_capi_exp_tester.cc
+5
-0
未找到文件。
paddle/fluid/inference/capi_exp/pd_config.cc
浏览文件 @
457fe72c
...
...
@@ -459,12 +459,10 @@ __pd_give PD_OneDimArrayCstr* PD_ConfigAllPasses(
std
::
vector
<
std
::
string
>
passes
=
config
->
pass_builder
()
->
AllPasses
();
return
paddle_infer
::
CvtVecToOneDimArrayCstr
(
passes
);
}
const
cha
r
*
PD_ConfigSummary
(
__pd_keep
PD_Config
*
pd_config
)
{
__pd_give
PD_Cst
r
*
PD_ConfigSummary
(
__pd_keep
PD_Config
*
pd_config
)
{
CHECK_AND_CONVERT_PD_CONFIG
;
auto
sum_str
=
config
->
Summary
();
char
*
c
=
reinterpret_cast
<
char
*>
(
malloc
(
sum_str
.
length
()
+
1
));
snprintf
(
c
,
sum_str
.
length
()
+
1
,
"%s"
,
sum_str
.
c_str
());
return
c
;
return
paddle_infer
::
CvtStrToCstr
(
sum_str
);
}
}
// extern "C"
paddle/fluid/inference/capi_exp/pd_config.h
浏览文件 @
457fe72c
...
...
@@ -705,7 +705,7 @@ PADDLE_CAPI_EXPORT extern __pd_give PD_OneDimArrayCstr* PD_ConfigAllPasses(
///
/// \return Return config info.
///
PADDLE_CAPI_EXPORT
extern
const
cha
r
*
PD_ConfigSummary
(
PADDLE_CAPI_EXPORT
extern
__pd_give
PD_Cst
r
*
PD_ConfigSummary
(
__pd_keep
PD_Config
*
pd_config
);
#ifdef __cplusplus
...
...
paddle/fluid/inference/capi_exp/pd_types.h
浏览文件 @
457fe72c
...
...
@@ -34,6 +34,11 @@ typedef struct PD_OneDimArrayCstr {
char
**
data
;
}
PD_OneDimArrayCstr
;
// std::vector<std::string>
typedef
struct
PD_Cstr
{
size_t
size
;
char
*
data
;
}
PD_Cstr
;
// std::string
typedef
struct
PD_TwoDimArraySize
{
size_t
size
;
PD_OneDimArraySize
**
data
;
...
...
paddle/fluid/inference/capi_exp/pd_utils.cc
浏览文件 @
457fe72c
...
...
@@ -78,6 +78,17 @@ void PD_OneDimArrayCstrDestroy(__pd_take PD_OneDimArrayCstr* array) {
delete
array
;
}
}
void
PD_CstrDestroy
(
__pd_take
PD_Cstr
*
cstr
)
{
if
(
cstr
!=
NULL
)
{
if
(
cstr
->
size
!=
0
)
{
cstr
->
size
=
0
;
delete
[]
cstr
->
data
;
cstr
->
data
=
NULL
;
}
delete
cstr
;
}
}
namespace
paddle_infer
{
__pd_give
PD_OneDimArrayCstr
*
CvtVecToOneDimArrayCstr
(
...
...
@@ -101,6 +112,18 @@ std::vector<std::string> CvtOneDimArrayToVecCstr(
return
vec
;
}
__pd_give
PD_Cstr
*
CvtStrToCstr
(
const
std
::
string
&
str
)
{
PD_Cstr
*
cstr
=
new
PD_Cstr
;
if
(
str
.
empty
())
{
cstr
->
size
=
0
;
cstr
->
data
=
NULL
;
}
else
{
cstr
->
size
=
str
.
length
()
+
1
;
cstr
->
data
=
new
char
[
str
.
length
()
+
1
];
memcpy
(
cstr
->
data
,
str
.
c_str
(),
str
.
length
()
+
1
);
}
return
cstr
;
}
}
// namespace paddle_infer
#define DESTROY_TWO_DIM_ARRAY(type) \
...
...
paddle/fluid/inference/capi_exp/pd_utils.h
浏览文件 @
457fe72c
...
...
@@ -65,6 +65,15 @@ PADDLE_CAPI_EXPORT extern void PD_OneDimArraySizeDestroy(
PADDLE_CAPI_EXPORT
extern
void
PD_TwoDimArraySizeDestroy
(
__pd_take
PD_TwoDimArraySize
*
array
);
///
/// \brief Destroy the PD_Cstr object pointed to by the pointer.
/// NOTE: if input string is empty, the return PD_Cstr's size is
/// 0 and data is NULL.
///
/// \param[in] cstr pointer to the PD_Cstr object.
///
PADDLE_CAPI_EXPORT
extern
void
PD_CstrDestroy
(
__pd_take
PD_Cstr
*
cstr
);
#ifdef __cplusplus
}
// extern "C"
#endif
paddle/fluid/inference/capi_exp/utils_internal.h
浏览文件 @
457fe72c
...
...
@@ -114,6 +114,14 @@ __pd_give PD_TwoDimArraySize* CvtVecToTwoDimArraySize(
std
::
vector
<
std
::
vector
<
size_t
>>
CvtTwoDimArrayToVecSize
(
__pd_keep
const
PD_TwoDimArraySize
*
array
);
///
/// \brief Convert the 'std::string' object to a 'PD_Cstr' object.
///
/// \param[in] vec source object.
/// \return target object.
///
__pd_give
PD_Cstr
*
CvtStrToCstr
(
const
std
::
string
&
vec
);
///
/// \brief Convert the 'PD_PlaceType' object to a 'paddle_infer::PlaceType'
/// object.
...
...
paddle/fluid/inference/goapi/config.go
浏览文件 @
457fe72c
...
...
@@ -833,7 +833,7 @@ func (config *Config) AllPasses() []string {
///
func
(
config
*
Config
)
Summary
()
string
{
cSummary
:=
C
.
PD_ConfigSummary
(
config
.
c
)
summary
:=
C
.
GoString
(
cSummary
)
C
.
free
(
unsafe
.
Pointer
(
cSummary
)
)
summary
:=
C
.
GoString
(
cSummary
.
data
)
C
.
PD_CstrDestroy
(
cSummary
)
return
summary
}
paddle/fluid/inference/tests/api/analyzer_capi_exp_tester.cc
浏览文件 @
457fe72c
...
...
@@ -18,7 +18,9 @@ limitations under the License. */
#include <string>
#include <vector>
#include "paddle/fluid/inference/capi_exp/pd_config.h"
#include "paddle/fluid/inference/capi_exp/pd_inference_api.h"
#include "paddle/fluid/inference/capi_exp/pd_utils.h"
#include "paddle/fluid/inference/tests/api/tester_helper.h"
namespace
paddle
{
...
...
@@ -34,6 +36,8 @@ void predictor_run() {
PD_ConfigSetCpuMathLibraryNumThreads
(
config
,
10
);
PD_ConfigSwitchIrDebug
(
config
,
TRUE
);
PD_ConfigSetModel
(
config
,
prog_file
.
c_str
(),
params_file
.
c_str
());
PD_Cstr
*
config_summary
=
PD_ConfigSummary
(
config
);
LOG
(
INFO
)
<<
config_summary
->
data
;
PD_Predictor
*
predictor
=
PD_PredictorCreate
(
config
);
PD_Tensor
*
tensor
=
PD_PredictorGetInputHandle
(
predictor
,
"data"
);
...
...
@@ -51,6 +55,7 @@ void predictor_run() {
delete
[]
input
;
PD_TensorDestroy
(
tensor
);
PD_CstrDestroy
(
config_summary
);
PD_PredictorDestroy
(
predictor
);
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录