Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle
提交
255e0cf9
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看板
未验证
提交
255e0cf9
编写于
9月 14, 2020
作者:
石
石晓伟
提交者:
GitHub
9月 14, 2020
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
error messages of inference/capi, test=develop (#27258)
上级
9437ce36
变更
5
显示空白变更内容
内联
并排
Showing
5 changed file
with
221 addition
and
62 deletion
+221
-62
paddle/fluid/inference/capi/c_api.cc
paddle/fluid/inference/capi/c_api.cc
+16
-5
paddle/fluid/inference/capi/c_api_internal.h
paddle/fluid/inference/capi/c_api_internal.h
+0
-1
paddle/fluid/inference/capi/pd_config.cc
paddle/fluid/inference/capi/pd_config.cc
+165
-43
paddle/fluid/inference/capi/pd_predictor.cc
paddle/fluid/inference/capi/pd_predictor.cc
+15
-5
paddle/fluid/inference/capi/pd_tensor.cc
paddle/fluid/inference/capi/pd_tensor.cc
+25
-8
未找到文件。
paddle/fluid/inference/capi/c_api.cc
浏览文件 @
255e0cf9
...
...
@@ -16,6 +16,7 @@
#include <vector>
#include "paddle/fluid/inference/capi/c_api_internal.h"
#include "paddle/fluid/inference/capi/paddle_c_api.h"
#include "paddle/fluid/platform/enforce.h"
using
paddle
::
ConvertToACPrecision
;
using
paddle
::
ConvertToPaddleDType
;
...
...
@@ -34,27 +35,37 @@ void PD_DeletePaddleBuf(PD_PaddleBuf* buf) {
}
void
PD_PaddleBufResize
(
PD_PaddleBuf
*
buf
,
size_t
length
)
{
PADDLE_ENFORCE_NOT_NULL
(
buf
);
PADDLE_ENFORCE_NOT_NULL
(
buf
,
paddle
::
platform
::
errors
::
InvalidArgument
(
"The pointer of Buffer shouldn't be nullptr"
));
buf
->
buf
.
Resize
(
length
);
}
void
PD_PaddleBufReset
(
PD_PaddleBuf
*
buf
,
void
*
data
,
size_t
length
)
{
PADDLE_ENFORCE_NOT_NULL
(
buf
);
PADDLE_ENFORCE_NOT_NULL
(
buf
,
paddle
::
platform
::
errors
::
InvalidArgument
(
"The pointer of Buffer shouldn't be nullptr"
));
buf
->
buf
.
Reset
(
data
,
length
);
}
bool
PD_PaddleBufEmpty
(
PD_PaddleBuf
*
buf
)
{
PADDLE_ENFORCE_NOT_NULL
(
buf
);
PADDLE_ENFORCE_NOT_NULL
(
buf
,
paddle
::
platform
::
errors
::
InvalidArgument
(
"The pointer of Buffer shouldn't be nullptr"
));
return
buf
->
buf
.
empty
();
}
void
*
PD_PaddleBufData
(
PD_PaddleBuf
*
buf
)
{
PADDLE_ENFORCE_NOT_NULL
(
buf
);
PADDLE_ENFORCE_NOT_NULL
(
buf
,
paddle
::
platform
::
errors
::
InvalidArgument
(
"The pointer of Buffer shouldn't be nullptr"
));
return
buf
->
buf
.
data
();
}
size_t
PD_PaddleBufLength
(
PD_PaddleBuf
*
buf
)
{
PADDLE_ENFORCE_NOT_NULL
(
buf
);
PADDLE_ENFORCE_NOT_NULL
(
buf
,
paddle
::
platform
::
errors
::
InvalidArgument
(
"The pointer of Buffer shouldn't be nullptr"
));
return
buf
->
buf
.
length
();
}
...
...
paddle/fluid/inference/capi/c_api_internal.h
浏览文件 @
255e0cf9
...
...
@@ -18,7 +18,6 @@
#include "paddle/fluid/inference/api/paddle_analysis_config.h"
#include "paddle/fluid/inference/api/paddle_api.h"
#include "paddle/fluid/inference/capi/paddle_c_api.h"
#include "paddle/fluid/platform/enforce.h"
using
PD_PaddleDType
=
paddle
::
PaddleDType
;
using
PD_ACPrecision
=
paddle
::
AnalysisConfig
::
Precision
;
...
...
paddle/fluid/inference/capi/pd_config.cc
浏览文件 @
255e0cf9
...
...
@@ -20,6 +20,7 @@
#include <vector>
#include "paddle/fluid/inference/capi/c_api_internal.h"
#include "paddle/fluid/inference/capi/paddle_c_api.h"
#include "paddle/fluid/platform/enforce.h"
using
paddle
::
ConvertToACPrecision
;
using
paddle
::
ConvertToPaddleDType
;
...
...
@@ -40,7 +41,10 @@ void PD_DeleteAnalysisConfig(PD_AnalysisConfig* config) {
void
PD_SetModel
(
PD_AnalysisConfig
*
config
,
const
char
*
model_dir
,
const
char
*
params_path
)
{
LOG
(
INFO
)
<<
model_dir
;
PADDLE_ENFORCE_NOT_NULL
(
config
);
PADDLE_ENFORCE_NOT_NULL
(
config
,
paddle
::
platform
::
errors
::
InvalidArgument
(
"The pointer of analysis configuration shouldn't be nullptr"
));
LOG
(
INFO
)
<<
std
::
string
(
model_dir
);
if
(
!
params_path
)
{
config
->
config
.
SetModel
(
std
::
string
(
model_dir
));
...
...
@@ -50,104 +54,164 @@ void PD_SetModel(PD_AnalysisConfig* config, const char* model_dir,
}
void
PD_SetProgFile
(
PD_AnalysisConfig
*
config
,
const
char
*
x
)
{
PADDLE_ENFORCE_NOT_NULL
(
config
);
PADDLE_ENFORCE_NOT_NULL
(
config
,
paddle
::
platform
::
errors
::
InvalidArgument
(
"The pointer of analysis configuration shouldn't be nullptr"
));
config
->
config
.
SetProgFile
(
std
::
string
(
x
));
}
void
PD_SetParamsFile
(
PD_AnalysisConfig
*
config
,
const
char
*
x
)
{
PADDLE_ENFORCE_NOT_NULL
(
config
);
PADDLE_ENFORCE_NOT_NULL
(
config
,
paddle
::
platform
::
errors
::
InvalidArgument
(
"The pointer of analysis configuration shouldn't be nullptr"
));
config
->
config
.
SetParamsFile
(
std
::
string
(
x
));
}
void
PD_SetOptimCacheDir
(
PD_AnalysisConfig
*
config
,
const
char
*
opt_cache_dir
)
{
PADDLE_ENFORCE_NOT_NULL
(
config
);
PADDLE_ENFORCE_NOT_NULL
(
config
,
paddle
::
platform
::
errors
::
InvalidArgument
(
"The pointer of analysis configuration shouldn't be nullptr"
));
config
->
config
.
SetOptimCacheDir
(
std
::
string
(
opt_cache_dir
));
}
const
char
*
PD_ModelDir
(
const
PD_AnalysisConfig
*
config
)
{
PADDLE_ENFORCE_NOT_NULL
(
config
);
PADDLE_ENFORCE_NOT_NULL
(
config
,
paddle
::
platform
::
errors
::
InvalidArgument
(
"The pointer of analysis configuration shouldn't be nullptr"
));
return
config
->
config
.
model_dir
().
c_str
();
}
const
char
*
PD_ProgFile
(
const
PD_AnalysisConfig
*
config
)
{
PADDLE_ENFORCE_NOT_NULL
(
config
);
PADDLE_ENFORCE_NOT_NULL
(
config
,
paddle
::
platform
::
errors
::
InvalidArgument
(
"The pointer of analysis configuration shouldn't be nullptr"
));
return
config
->
config
.
prog_file
().
c_str
();
}
const
char
*
PD_ParamsFile
(
const
PD_AnalysisConfig
*
config
)
{
PADDLE_ENFORCE_NOT_NULL
(
config
);
PADDLE_ENFORCE_NOT_NULL
(
config
,
paddle
::
platform
::
errors
::
InvalidArgument
(
"The pointer of analysis configuration shouldn't be nullptr"
));
return
config
->
config
.
params_file
().
c_str
();
}
void
PD_EnableUseGpu
(
PD_AnalysisConfig
*
config
,
int
memory_pool_init_size_mb
,
int
device_id
)
{
PADDLE_ENFORCE_NOT_NULL
(
config
);
PADDLE_ENFORCE_NOT_NULL
(
config
,
paddle
::
platform
::
errors
::
InvalidArgument
(
"The pointer of analysis configuration shouldn't be nullptr"
));
config
->
config
.
EnableUseGpu
(
static_cast
<
uint64_t
>
(
memory_pool_init_size_mb
),
device_id
);
}
void
PD_DisableGpu
(
PD_AnalysisConfig
*
config
)
{
PADDLE_ENFORCE_NOT_NULL
(
config
);
PADDLE_ENFORCE_NOT_NULL
(
config
,
paddle
::
platform
::
errors
::
InvalidArgument
(
"The pointer of analysis configuration shouldn't be nullptr"
));
config
->
config
.
DisableGpu
();
}
bool
PD_UseGpu
(
const
PD_AnalysisConfig
*
config
)
{
PADDLE_ENFORCE_NOT_NULL
(
config
);
PADDLE_ENFORCE_NOT_NULL
(
config
,
paddle
::
platform
::
errors
::
InvalidArgument
(
"The pointer of analysis configuration shouldn't be nullptr"
));
return
config
->
config
.
use_gpu
();
}
int
PD_GpuDeviceId
(
const
PD_AnalysisConfig
*
config
)
{
PADDLE_ENFORCE_NOT_NULL
(
config
);
PADDLE_ENFORCE_NOT_NULL
(
config
,
paddle
::
platform
::
errors
::
InvalidArgument
(
"The pointer of analysis configuration shouldn't be nullptr"
));
return
config
->
config
.
gpu_device_id
();
}
int
PD_MemoryPoolInitSizeMb
(
const
PD_AnalysisConfig
*
config
)
{
PADDLE_ENFORCE_NOT_NULL
(
config
);
PADDLE_ENFORCE_NOT_NULL
(
config
,
paddle
::
platform
::
errors
::
InvalidArgument
(
"The pointer of analysis configuration shouldn't be nullptr"
));
return
config
->
config
.
memory_pool_init_size_mb
();
}
float
PD_FractionOfGpuMemoryForPool
(
const
PD_AnalysisConfig
*
config
)
{
PADDLE_ENFORCE_NOT_NULL
(
config
);
PADDLE_ENFORCE_NOT_NULL
(
config
,
paddle
::
platform
::
errors
::
InvalidArgument
(
"The pointer of analysis configuration shouldn't be nullptr"
));
return
config
->
config
.
fraction_of_gpu_memory_for_pool
();
}
void
PD_EnableCUDNN
(
PD_AnalysisConfig
*
config
)
{
PADDLE_ENFORCE_NOT_NULL
(
config
);
PADDLE_ENFORCE_NOT_NULL
(
config
,
paddle
::
platform
::
errors
::
InvalidArgument
(
"The pointer of analysis configuration shouldn't be nullptr"
));
config
->
config
.
EnableCUDNN
();
}
bool
PD_CudnnEnabled
(
const
PD_AnalysisConfig
*
config
)
{
PADDLE_ENFORCE_NOT_NULL
(
config
);
PADDLE_ENFORCE_NOT_NULL
(
config
,
paddle
::
platform
::
errors
::
InvalidArgument
(
"The pointer of analysis configuration shouldn't be nullptr"
));
return
config
->
config
.
cudnn_enabled
();
}
void
PD_SwitchIrOptim
(
PD_AnalysisConfig
*
config
,
bool
x
)
{
PADDLE_ENFORCE_NOT_NULL
(
config
);
PADDLE_ENFORCE_NOT_NULL
(
config
,
paddle
::
platform
::
errors
::
InvalidArgument
(
"The pointer of analysis configuration shouldn't be nullptr"
));
config
->
config
.
SwitchIrOptim
(
x
);
}
bool
PD_IrOptim
(
const
PD_AnalysisConfig
*
config
)
{
PADDLE_ENFORCE_NOT_NULL
(
config
);
PADDLE_ENFORCE_NOT_NULL
(
config
,
paddle
::
platform
::
errors
::
InvalidArgument
(
"The pointer of analysis configuration shouldn't be nullptr"
));
return
config
->
config
.
ir_optim
();
}
void
PD_SwitchUseFeedFetchOps
(
PD_AnalysisConfig
*
config
,
bool
x
)
{
PADDLE_ENFORCE_NOT_NULL
(
config
);
PADDLE_ENFORCE_NOT_NULL
(
config
,
paddle
::
platform
::
errors
::
InvalidArgument
(
"The pointer of analysis configuration shouldn't be nullptr"
));
config
->
config
.
SwitchUseFeedFetchOps
(
x
);
}
bool
PD_UseFeedFetchOpsEnabled
(
const
PD_AnalysisConfig
*
config
)
{
PADDLE_ENFORCE_NOT_NULL
(
config
);
PADDLE_ENFORCE_NOT_NULL
(
config
,
paddle
::
platform
::
errors
::
InvalidArgument
(
"The pointer of analysis configuration shouldn't be nullptr"
));
return
config
->
config
.
use_feed_fetch_ops_enabled
();
}
void
PD_SwitchSpecifyInputNames
(
PD_AnalysisConfig
*
config
,
bool
x
)
{
PADDLE_ENFORCE_NOT_NULL
(
config
);
PADDLE_ENFORCE_NOT_NULL
(
config
,
paddle
::
platform
::
errors
::
InvalidArgument
(
"The pointer of analysis configuration shouldn't be nullptr"
));
config
->
config
.
SwitchSpecifyInputNames
(
x
);
}
bool
PD_SpecifyInputName
(
const
PD_AnalysisConfig
*
config
)
{
PADDLE_ENFORCE_NOT_NULL
(
config
);
PADDLE_ENFORCE_NOT_NULL
(
config
,
paddle
::
platform
::
errors
::
InvalidArgument
(
"The pointer of analysis configuration shouldn't be nullptr"
));
return
config
->
config
.
specify_input_name
();
}
...
...
@@ -155,110 +219,168 @@ void PD_EnableTensorRtEngine(PD_AnalysisConfig* config, int workspace_size,
int
max_batch_size
,
int
min_subgraph_size
,
Precision
precision
,
bool
use_static
,
bool
use_calib_mode
)
{
PADDLE_ENFORCE_NOT_NULL
(
config
);
PADDLE_ENFORCE_NOT_NULL
(
config
,
paddle
::
platform
::
errors
::
InvalidArgument
(
"The pointer of analysis configuration shouldn't be nullptr"
));
config
->
config
.
EnableTensorRtEngine
(
workspace_size
,
max_batch_size
,
min_subgraph_size
,
paddle
::
ConvertToACPrecision
(
precision
),
use_static
,
use_calib_mode
);
}
bool
PD_TensorrtEngineEnabled
(
const
PD_AnalysisConfig
*
config
)
{
PADDLE_ENFORCE_NOT_NULL
(
config
);
PADDLE_ENFORCE_NOT_NULL
(
config
,
paddle
::
platform
::
errors
::
InvalidArgument
(
"The pointer of analysis configuration shouldn't be nullptr"
));
return
config
->
config
.
tensorrt_engine_enabled
();
}
void
PD_SwitchIrDebug
(
PD_AnalysisConfig
*
config
,
bool
x
)
{
PADDLE_ENFORCE_NOT_NULL
(
config
);
PADDLE_ENFORCE_NOT_NULL
(
config
,
paddle
::
platform
::
errors
::
InvalidArgument
(
"The pointer of analysis configuration shouldn't be nullptr"
));
config
->
config
.
SwitchIrDebug
(
x
);
}
void
PD_EnableMKLDNN
(
PD_AnalysisConfig
*
config
)
{
PADDLE_ENFORCE_NOT_NULL
(
config
);
PADDLE_ENFORCE_NOT_NULL
(
config
,
paddle
::
platform
::
errors
::
InvalidArgument
(
"The pointer of analysis configuration shouldn't be nullptr"
));
config
->
config
.
EnableMKLDNN
();
}
void
PD_SetMkldnnCacheCapacity
(
PD_AnalysisConfig
*
config
,
int
capacity
)
{
PADDLE_ENFORCE_NOT_NULL
(
config
);
PADDLE_ENFORCE_NOT_NULL
(
config
,
paddle
::
platform
::
errors
::
InvalidArgument
(
"The pointer of analysis configuration shouldn't be nullptr"
));
config
->
config
.
SetMkldnnCacheCapacity
(
capacity
);
}
bool
PD_MkldnnEnabled
(
const
PD_AnalysisConfig
*
config
)
{
PADDLE_ENFORCE_NOT_NULL
(
config
);
PADDLE_ENFORCE_NOT_NULL
(
config
,
paddle
::
platform
::
errors
::
InvalidArgument
(
"The pointer of analysis configuration shouldn't be nullptr"
));
return
config
->
config
.
mkldnn_enabled
();
}
void
PD_SetCpuMathLibraryNumThreads
(
PD_AnalysisConfig
*
config
,
int
cpu_math_library_num_threads
)
{
PADDLE_ENFORCE_NOT_NULL
(
config
);
PADDLE_ENFORCE_NOT_NULL
(
config
,
paddle
::
platform
::
errors
::
InvalidArgument
(
"The pointer of analysis configuration shouldn't be nullptr"
));
config
->
config
.
SetCpuMathLibraryNumThreads
(
cpu_math_library_num_threads
);
}
int
PD_CpuMathLibraryNumThreads
(
const
PD_AnalysisConfig
*
config
)
{
PADDLE_ENFORCE_NOT_NULL
(
config
);
PADDLE_ENFORCE_NOT_NULL
(
config
,
paddle
::
platform
::
errors
::
InvalidArgument
(
"The pointer of analysis configuration shouldn't be nullptr"
));
return
config
->
config
.
cpu_math_library_num_threads
();
}
void
PD_EnableMkldnnQuantizer
(
PD_AnalysisConfig
*
config
)
{
PADDLE_ENFORCE_NOT_NULL
(
config
);
PADDLE_ENFORCE_NOT_NULL
(
config
,
paddle
::
platform
::
errors
::
InvalidArgument
(
"The pointer of analysis configuration shouldn't be nullptr"
));
config
->
config
.
EnableMkldnnQuantizer
();
}
bool
PD_MkldnnQuantizerEnabled
(
const
PD_AnalysisConfig
*
config
)
{
PADDLE_ENFORCE_NOT_NULL
(
config
);
PADDLE_ENFORCE_NOT_NULL
(
config
,
paddle
::
platform
::
errors
::
InvalidArgument
(
"The pointer of analysis configuration shouldn't be nullptr"
));
return
config
->
config
.
mkldnn_quantizer_enabled
();
}
void
PD_EnableMkldnnBfloat16
(
PD_AnalysisConfig
*
config
)
{
PADDLE_ENFORCE_NOT_NULL
(
config
,
paddle
::
platform
::
errors
::
NotFound
(
"PD_AnalysisConfig should not be null"
));
PADDLE_ENFORCE_NOT_NULL
(
config
,
paddle
::
platform
::
errors
::
InvalidArgument
(
"The pointer of analysis configuration shouldn't be nullptr"
));
config
->
config
.
EnableMkldnnBfloat16
();
}
bool
PD_MkldnnBfloat16Enabled
(
const
PD_AnalysisConfig
*
config
)
{
PADDLE_ENFORCE_NOT_NULL
(
config
,
paddle
::
platform
::
errors
::
NotFound
(
"PD_AnalysisConfig should not be null"
));
PADDLE_ENFORCE_NOT_NULL
(
config
,
paddle
::
platform
::
errors
::
InvalidArgument
(
"The pointer of analysis configuration shouldn't be nullptr"
));
return
config
->
config
.
mkldnn_bfloat16_enabled
();
}
void
PD_SetModelBuffer
(
PD_AnalysisConfig
*
config
,
const
char
*
prog_buffer
,
size_t
prog_buffer_size
,
const
char
*
params_buffer
,
size_t
params_buffer_size
)
{
PADDLE_ENFORCE_NOT_NULL
(
config
);
PADDLE_ENFORCE_NOT_NULL
(
config
,
paddle
::
platform
::
errors
::
InvalidArgument
(
"The pointer of analysis configuration shouldn't be nullptr"
));
config
->
config
.
SetModelBuffer
(
prog_buffer
,
prog_buffer_size
,
params_buffer
,
params_buffer_size
);
}
bool
PD_ModelFromMemory
(
const
PD_AnalysisConfig
*
config
)
{
PADDLE_ENFORCE_NOT_NULL
(
config
);
PADDLE_ENFORCE_NOT_NULL
(
config
,
paddle
::
platform
::
errors
::
InvalidArgument
(
"The pointer of analysis configuration shouldn't be nullptr"
));
return
config
->
config
.
model_from_memory
();
}
void
PD_EnableMemoryOptim
(
PD_AnalysisConfig
*
config
)
{
PADDLE_ENFORCE_NOT_NULL
(
config
);
PADDLE_ENFORCE_NOT_NULL
(
config
,
paddle
::
platform
::
errors
::
InvalidArgument
(
"The pointer of analysis configuration shouldn't be nullptr"
));
config
->
config
.
EnableMemoryOptim
();
}
bool
PD_MemoryOptimEnabled
(
const
PD_AnalysisConfig
*
config
)
{
PADDLE_ENFORCE_NOT_NULL
(
config
);
PADDLE_ENFORCE_NOT_NULL
(
config
,
paddle
::
platform
::
errors
::
InvalidArgument
(
"The pointer of analysis configuration shouldn't be nullptr"
));
return
config
->
config
.
enable_memory_optim
();
}
void
PD_EnableProfile
(
PD_AnalysisConfig
*
config
)
{
PADDLE_ENFORCE_NOT_NULL
(
config
);
PADDLE_ENFORCE_NOT_NULL
(
config
,
paddle
::
platform
::
errors
::
InvalidArgument
(
"The pointer of analysis configuration shouldn't be nullptr"
));
config
->
config
.
EnableProfile
();
}
bool
PD_ProfileEnabled
(
const
PD_AnalysisConfig
*
config
)
{
PADDLE_ENFORCE_NOT_NULL
(
config
);
PADDLE_ENFORCE_NOT_NULL
(
config
,
paddle
::
platform
::
errors
::
InvalidArgument
(
"The pointer of analysis configuration shouldn't be nullptr"
));
return
config
->
config
.
profile_enabled
();
}
void
PD_SetInValid
(
PD_AnalysisConfig
*
config
)
{
PADDLE_ENFORCE_NOT_NULL
(
config
);
PADDLE_ENFORCE_NOT_NULL
(
config
,
paddle
::
platform
::
errors
::
InvalidArgument
(
"The pointer of analysis configuration shouldn't be nullptr"
));
config
->
config
.
SetInValid
();
}
bool
PD_IsValid
(
const
PD_AnalysisConfig
*
config
)
{
PADDLE_ENFORCE_NOT_NULL
(
config
);
PADDLE_ENFORCE_NOT_NULL
(
config
,
paddle
::
platform
::
errors
::
InvalidArgument
(
"The pointer of analysis configuration shouldn't be nullptr"
));
return
config
->
config
.
is_valid
();
}
...
...
paddle/fluid/inference/capi/pd_predictor.cc
浏览文件 @
255e0cf9
...
...
@@ -22,6 +22,7 @@
#include "paddle/fluid/inference/api/paddle_api.h"
#include "paddle/fluid/inference/capi/c_api_internal.h"
#include "paddle/fluid/inference/capi/paddle_c_api.h"
#include "paddle/fluid/platform/enforce.h"
using
paddle
::
ConvertToACPrecision
;
using
paddle
::
ConvertToPaddleDType
;
...
...
@@ -81,7 +82,10 @@ 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
);
PADDLE_ENFORCE_NOT_NULL
(
config
,
paddle
::
platform
::
errors
::
InvalidArgument
(
"The pointer of analysis configuration shouldn't be nullptr"
));
VLOG
(
3
)
<<
"Predoctor: PD_PredictorRun. "
;
static
std
::
map
<
std
::
string
,
std
::
unique_ptr
<
paddle
::
PaddlePredictor
>>
predictors
;
...
...
@@ -111,7 +115,10 @@ 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
)
{
PADDLE_ENFORCE_NOT_NULL
(
config
);
PADDLE_ENFORCE_NOT_NULL
(
config
,
paddle
::
platform
::
errors
::
InvalidArgument
(
"The pointer of analysis configuration shouldn't be nullptr"
));
static
std
::
map
<
std
::
string
,
std
::
unique_ptr
<
paddle
::
PaddlePredictor
>>
predictors
;
if
(
!
predictors
.
count
(
config
->
config
.
model_dir
()))
{
...
...
@@ -144,7 +151,8 @@ bool PD_PredictorZeroCopyRun(const PD_AnalysisConfig* config,
input_t
->
copy_from_cpu
(
static_cast
<
uint8_t
*>
(
inputs
[
i
].
data
));
break
;
default:
CHECK
(
false
)
<<
"Unsupport data type."
;
PADDLE_THROW
(
paddle
::
platform
::
errors
::
InvalidArgument
(
"Unsupported data type."
));
break
;
}
}
...
...
@@ -227,7 +235,8 @@ void PD_SetZeroCopyInput(PD_Predictor* predictor,
input
->
copy_from_cpu
(
static_cast
<
uint8_t
*>
(
tensor
->
data
.
data
));
break
;
default:
CHECK
(
false
)
<<
"Unsupport data type."
;
PADDLE_THROW
(
paddle
::
platform
::
errors
::
InvalidArgument
(
"Unsupported data type."
));
break
;
}
...
...
@@ -294,7 +303,8 @@ void PD_GetZeroCopyOutput(PD_Predictor* predictor, PD_ZeroCopyTensor* tensor) {
output
->
copy_to_cpu
(
reinterpret_cast
<
uint8_t
*>
(
tensor
->
data
.
data
));
break
;
default:
CHECK
(
false
)
<<
"Unsupport data type."
;
PADDLE_THROW
(
paddle
::
platform
::
errors
::
InvalidArgument
(
"Unsupported data type."
));
break
;
}
}
...
...
paddle/fluid/inference/capi/pd_tensor.cc
浏览文件 @
255e0cf9
...
...
@@ -19,6 +19,7 @@
#include <vector>
#include "paddle/fluid/inference/capi/c_api_internal.h"
#include "paddle/fluid/inference/capi/paddle_c_api.h"
#include "paddle/fluid/platform/enforce.h"
using
paddle
::
ConvertToACPrecision
;
using
paddle
::
ConvertToPaddleDType
;
...
...
@@ -37,44 +38,60 @@ void PD_DeletePaddleTensor(PD_Tensor* tensor) {
}
void
PD_SetPaddleTensorName
(
PD_Tensor
*
tensor
,
char
*
name
)
{
PADDLE_ENFORCE_NOT_NULL
(
tensor
);
PADDLE_ENFORCE_NOT_NULL
(
tensor
,
paddle
::
platform
::
errors
::
InvalidArgument
(
"The pointer of tensor shouldn't be nullptr"
));
tensor
->
tensor
.
name
=
std
::
string
(
name
);
}
void
PD_SetPaddleTensorDType
(
PD_Tensor
*
tensor
,
PD_DataType
dtype
)
{
PADDLE_ENFORCE_NOT_NULL
(
tensor
);
PADDLE_ENFORCE_NOT_NULL
(
tensor
,
paddle
::
platform
::
errors
::
InvalidArgument
(
"The pointer of tensor shouldn't be nullptr"
));
tensor
->
tensor
.
dtype
=
paddle
::
ConvertToPaddleDType
(
dtype
);
}
void
PD_SetPaddleTensorData
(
PD_Tensor
*
tensor
,
PD_PaddleBuf
*
buf
)
{
PADDLE_ENFORCE_NOT_NULL
(
tensor
);
PADDLE_ENFORCE_NOT_NULL
(
tensor
,
paddle
::
platform
::
errors
::
InvalidArgument
(
"The pointer of tensor shouldn't be nullptr"
));
tensor
->
tensor
.
data
=
buf
->
buf
;
}
void
PD_SetPaddleTensorShape
(
PD_Tensor
*
tensor
,
int
*
shape
,
int
size
)
{
PADDLE_ENFORCE_NOT_NULL
(
tensor
);
PADDLE_ENFORCE_NOT_NULL
(
tensor
,
paddle
::
platform
::
errors
::
InvalidArgument
(
"The pointer of tensor shouldn't be nullptr"
));
tensor
->
tensor
.
shape
.
assign
(
shape
,
shape
+
size
);
}
const
char
*
PD_GetPaddleTensorName
(
const
PD_Tensor
*
tensor
)
{
PADDLE_ENFORCE_NOT_NULL
(
tensor
);
PADDLE_ENFORCE_NOT_NULL
(
tensor
,
paddle
::
platform
::
errors
::
InvalidArgument
(
"The pointer of tensor shouldn't be nullptr"
));
return
tensor
->
tensor
.
name
.
c_str
();
}
PD_DataType
PD_GetPaddleTensorDType
(
const
PD_Tensor
*
tensor
)
{
PADDLE_ENFORCE_NOT_NULL
(
tensor
);
PADDLE_ENFORCE_NOT_NULL
(
tensor
,
paddle
::
platform
::
errors
::
InvalidArgument
(
"The pointer of tensor shouldn't be nullptr"
));
return
ConvertToPDDataType
(
tensor
->
tensor
.
dtype
);
}
PD_PaddleBuf
*
PD_GetPaddleTensorData
(
const
PD_Tensor
*
tensor
)
{
PADDLE_ENFORCE_NOT_NULL
(
tensor
);
PADDLE_ENFORCE_NOT_NULL
(
tensor
,
paddle
::
platform
::
errors
::
InvalidArgument
(
"The pointer of tensor shouldn't be nullptr"
));
PD_PaddleBuf
*
ret
=
PD_NewPaddleBuf
();
ret
->
buf
=
tensor
->
tensor
.
data
;
return
ret
;
}
const
int
*
PD_GetPaddleTensorShape
(
const
PD_Tensor
*
tensor
,
int
*
size
)
{
PADDLE_ENFORCE_NOT_NULL
(
tensor
);
PADDLE_ENFORCE_NOT_NULL
(
tensor
,
paddle
::
platform
::
errors
::
InvalidArgument
(
"The pointer of tensor shouldn't be nullptr"
));
const
std
::
vector
<
int
>&
shape
=
tensor
->
tensor
.
shape
;
*
size
=
shape
.
size
();
return
shape
.
data
();
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录