未验证 提交 5662adcc 编写于 作者: W wenzhe.wang 提交者: GitHub

[CustomDevice] Add enable custom device C Api (#52568)

fix bugs
Co-authored-by: Nwenzhe.wang <wenzhe.wang@xdxct.com>
上级 41226d55
......@@ -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,
......
......@@ -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();
......
......@@ -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
......
......@@ -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.
先完成此消息的编辑!
想要评论请 注册