Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle
提交
5662adcc
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看板
未验证
提交
5662adcc
编写于
4月 07, 2023
作者:
W
wenzhe.wang
提交者:
GitHub
4月 07, 2023
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[CustomDevice] Add enable custom device C Api (#52568)
fix bugs Co-authored-by:
N
wenzhe.wang
<
wenzhe.wang@xdxct.com
>
上级
41226d55
变更
4
显示空白变更内容
内联
并排
Showing
4 changed file
with
64 addition
and
2 deletion
+64
-2
paddle/fluid/inference/capi_exp/pd_common.h
paddle/fluid/inference/capi_exp/pd_common.h
+5
-2
paddle/fluid/inference/capi_exp/pd_config.cc
paddle/fluid/inference/capi_exp/pd_config.cc
+23
-0
paddle/fluid/inference/capi_exp/pd_config.h
paddle/fluid/inference/capi_exp/pd_config.h
+32
-0
paddle/fluid/inference/capi_exp/pd_utils.cc
paddle/fluid/inference/capi_exp/pd_utils.cc
+4
-0
未找到文件。
paddle/fluid/inference/capi_exp/pd_common.h
浏览文件 @
5662adcc
...
...
@@ -66,8 +66,11 @@ typedef int8_t PD_Bool;
PD_ENUM
(
PD_PrecisionType
){
PD_PRECISION_FLOAT32
=
0
,
PD_PRECISION_INT8
,
PD_PRECISION_HALF
};
PD_ENUM
(
PD_PlaceType
){
PD_PLACE_UNK
=
-
1
,
PD_PLACE_CPU
,
PD_PLACE_GPU
,
PD_PLACE_XPU
};
PD_ENUM
(
PD_PlaceType
){
PD_PLACE_UNK
=
-
1
,
PD_PLACE_CPU
,
PD_PLACE_GPU
,
PD_PLACE_XPU
,
PD_PLACE_CUSTOM
};
PD_ENUM
(
PD_DataType
){
PD_DATA_UNK
=
-
1
,
...
...
paddle/fluid/inference/capi_exp/pd_config.cc
浏览文件 @
5662adcc
...
...
@@ -193,6 +193,29 @@ int32_t PD_ConfigNpuDeviceId(__pd_keep PD_Config* pd_config) {
CHECK_AND_CONVERT_PD_CONFIG
;
return
config
->
npu_device_id
();
}
void
PD_ConfigEnableCustomDevice
(
__pd_keep
PD_Config
*
pd_config
,
char
*
device_type
,
int32_t
device_id
)
{
CHECK_AND_CONVERT_PD_CONFIG
;
config
->
EnableCustomDevice
(
device_type
,
device_id
);
}
PD_Bool
PD_ConfigUseCustomDevice
(
__pd_keep
PD_Config
*
pd_config
)
{
CHECK_AND_CONVERT_PD_CONFIG
;
return
config
->
use_custom_device
();
}
int32_t
PD_ConfigCustomDeviceId
(
__pd_keep
PD_Config
*
pd_config
)
{
CHECK_AND_CONVERT_PD_CONFIG
;
return
config
->
custom_device_id
();
}
char
*
PD_ConfigCustomDeviceType
(
__pd_keep
PD_Config
*
pd_config
)
{
CHECK_AND_CONVERT_PD_CONFIG
;
auto
device_type_str
=
config
->
custom_device_type
();
char
*
c
=
reinterpret_cast
<
char
*>
(
malloc
(
device_type_str
.
length
()
+
1
));
snprintf
(
c
,
device_type_str
.
length
()
+
1
,
"%s"
,
device_type_str
.
c_str
());
return
c
;
}
int32_t
PD_ConfigMemoryPoolInitSizeMb
(
__pd_keep
PD_Config
*
pd_config
)
{
CHECK_AND_CONVERT_PD_CONFIG
;
return
config
->
memory_pool_init_size_mb
();
...
...
paddle/fluid/inference/capi_exp/pd_config.h
浏览文件 @
5662adcc
...
...
@@ -254,6 +254,38 @@ PADDLE_CAPI_EXPORT extern int32_t PD_ConfigXpuDeviceId(
PADDLE_CAPI_EXPORT
extern
int32_t
PD_ConfigNpuDeviceId
(
__pd_keep
PD_Config
*
pd_config
);
///
/// \brief Turn on custome device.
///
/// \param[in] pd_config config
/// \param[in] device_type device type
/// \param[in] device_id device_id the custome device card to use.
///
PADDLE_CAPI_EXPORT
extern
void
PD_ConfigEnableCustomDevice
(
__pd_keep
PD_Config
*
pd_config
,
char
*
device_type
,
int32_t
device_id
);
///
/// \brief A boolean state telling whether the custom device is turned on.
///
/// \param[in] pd_config config
/// \return Whether the custom device is turned on.
///
PADDLE_CAPI_EXPORT
extern
PD_Bool
PD_ConfigUseCustomDevice
(
__pd_keep
PD_Config
*
pd_config
);
///
/// \brief Get the custom device id.
///
/// \param[in] pd_config config
/// \return int The custom device id.
///
PADDLE_CAPI_EXPORT
extern
int32_t
PD_ConfigCustomDeviceId
(
__pd_keep
PD_Config
*
pd_config
);
/// \brief Get the custom device type.
///
/// \param[in] pd_config config
/// \return string The custom device type.
///
PADDLE_CAPI_EXPORT
extern
char
*
PD_ConfigCustomDeviceType
(
__pd_keep
PD_Config
*
pd_config
);
///
/// \brief Get the initial size in MB of the GPU memory pool.
///
/// \param[in] pd_onfig config
...
...
paddle/fluid/inference/capi_exp/pd_utils.cc
浏览文件 @
5662adcc
...
...
@@ -221,6 +221,8 @@ PlaceType CvtToCxxPlaceType(PD_PlaceType place_type) {
return
PlaceType
::
kGPU
;
case
PD_PLACE_XPU
:
return
PlaceType
::
kXPU
;
case
PD_PLACE_CUSTOM
:
return
PlaceType
::
kCUSTOM
;
default:
PADDLE_THROW
(
paddle
::
platform
::
errors
::
InvalidArgument
(
"Unsupport paddle place type %d."
,
place_type
));
...
...
@@ -236,6 +238,8 @@ PD_PlaceType CvtFromCxxPlaceType(PlaceType place_type) {
return
PD_PLACE_GPU
;
case
PlaceType
::
kXPU
:
return
PD_PLACE_XPU
;
case
PlaceType
::
kCUSTOM
:
return
PD_PLACE_CUSTOM
;
default:
return
PD_PLACE_UNK
;
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录