diff --git a/paddle/fluid/inference/capi_exp/pd_common.h b/paddle/fluid/inference/capi_exp/pd_common.h index ee389bc35b96d8f24b85e70187ea71c5d50ec801..6581d09fabf7a0a8b72c6b8741addddb2d46bc5f 100644 --- a/paddle/fluid/inference/capi_exp/pd_common.h +++ b/paddle/fluid/inference/capi_exp/pd_common.h @@ -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, diff --git a/paddle/fluid/inference/capi_exp/pd_config.cc b/paddle/fluid/inference/capi_exp/pd_config.cc index 9b19874e0b907c698d45f80b7194b29ba6daff06..a36573016faf2942de95836629fc182c9cceeee0 100644 --- a/paddle/fluid/inference/capi_exp/pd_config.cc +++ b/paddle/fluid/inference/capi_exp/pd_config.cc @@ -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(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(); diff --git a/paddle/fluid/inference/capi_exp/pd_config.h b/paddle/fluid/inference/capi_exp/pd_config.h index a2e050f9f7306b0eba63699f5499f1c0db6e2776..458973d2a830accd9325217cb243ed87c468e8d4 100644 --- a/paddle/fluid/inference/capi_exp/pd_config.h +++ b/paddle/fluid/inference/capi_exp/pd_config.h @@ -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 diff --git a/paddle/fluid/inference/capi_exp/pd_utils.cc b/paddle/fluid/inference/capi_exp/pd_utils.cc index b455e79dbd6763c0522f53d314bcbb9c3290882a..4482e4bc098d61d3881171f4c38b5d65e31ea450 100644 --- a/paddle/fluid/inference/capi_exp/pd_utils.cc +++ b/paddle/fluid/inference/capi_exp/pd_utils.cc @@ -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; }