From 9896ac1e60135887b4d429c5d2b71c96e93a862c Mon Sep 17 00:00:00 2001 From: Asthestarsfalll <72954905+Asthestarsfalll@users.noreply.github.com> Date: Tue, 29 Nov 2022 17:57:02 +0800 Subject: [PATCH] [PHI decoupling]migrate enforce_custom.h from fluid to phi (#48422) * migrate enforce_custom.h from fluid to phi * move to backends/custom/ --- paddle/fluid/platform/device/device_wrapper.h | 2 +- paddle/phi/backends/custom/custom_device.cc | 4 +-- .../backends}/custom/enforce_custom.h | 33 ++++++++----------- 3 files changed, 17 insertions(+), 22 deletions(-) rename paddle/{fluid/platform/device => phi/backends}/custom/enforce_custom.h (74%) diff --git a/paddle/fluid/platform/device/device_wrapper.h b/paddle/fluid/platform/device/device_wrapper.h index 6803a39a4f..f38ff74ae7 100644 --- a/paddle/fluid/platform/device/device_wrapper.h +++ b/paddle/fluid/platform/device/device_wrapper.h @@ -40,8 +40,8 @@ limitations under the License. */ #endif #ifdef PADDLE_WITH_CUSTOM_DEVICE -#include "paddle/fluid/platform/device/custom/enforce_custom.h" #include "paddle/phi/backends/callback_manager.h" +#include "paddle/phi/backends/custom/enforce_custom.h" #include "paddle/phi/backends/device_guard.h" #include "paddle/phi/backends/device_manager.h" #include "paddle/phi/backends/event.h" diff --git a/paddle/phi/backends/custom/custom_device.cc b/paddle/phi/backends/custom/custom_device.cc index 3b438b562c..2c986df278 100644 --- a/paddle/phi/backends/custom/custom_device.cc +++ b/paddle/phi/backends/custom/custom_device.cc @@ -12,16 +12,16 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include "paddle/fluid/platform/device/custom/enforce_custom.h" #include "paddle/fluid/platform/device_context.h" -#include "paddle/phi/common/data_type.h" #include "paddle/phi/backends/callback_manager.h" +#include "paddle/phi/backends/custom/enforce_custom.h" #include "paddle/phi/backends/device_base.h" #include "paddle/phi/backends/device_guard.h" #include "paddle/phi/backends/device_manager.h" #include "paddle/phi/backends/event.h" #include "paddle/phi/backends/stream.h" +#include "paddle/phi/common/data_type.h" static bool operator==(const C_Device_st& d1, const C_Device_st& d2) { return d1.id == d2.id; diff --git a/paddle/fluid/platform/device/custom/enforce_custom.h b/paddle/phi/backends/custom/enforce_custom.h similarity index 74% rename from paddle/fluid/platform/device/custom/enforce_custom.h rename to paddle/phi/backends/custom/enforce_custom.h index ba92b4ac7d..c98d4580d3 100644 --- a/paddle/fluid/platform/device/custom/enforce_custom.h +++ b/paddle/phi/backends/custom/enforce_custom.h @@ -16,12 +16,10 @@ limitations under the License. */ #ifdef PADDLE_WITH_CUSTOM_DEVICE #include -#include "paddle/fluid/platform/enforce.h" #include "paddle/phi/backends/device_ext.h" +#include "paddle/phi/core/enforce.h" -namespace paddle { -namespace platform { -namespace details { +namespace phi { template struct CustomDeviceStatusType {}; @@ -33,7 +31,6 @@ struct CustomDeviceStatusType {}; } DEFINE_CUSTOM_DEVICE_STATUS_TYPE(C_Status, C_SUCCESS); -} // namespace details inline std::string build_custom_device_error_msg(C_Status stat) { std::ostringstream sout; @@ -41,19 +38,17 @@ inline std::string build_custom_device_error_msg(C_Status stat) { return sout.str(); } -#define PADDLE_ENFORCE_CUSTOM_DEVICE_SUCCESS(COND) \ - do { \ - auto __cond__ = (COND); \ - using __CUSTOM_DEVICE_STATUS_TYPE__ = decltype(__cond__); \ - constexpr auto __success_type__ = \ - ::paddle::platform::details::CustomDeviceStatusType< \ - __CUSTOM_DEVICE_STATUS_TYPE__>::kSuccess; \ - if (UNLIKELY(__cond__ != __success_type__)) { \ - auto __summary__ = ::paddle::platform::errors::External( \ - ::paddle::platform::build_custom_device_error_msg(__cond__)); \ - __THROW_ERROR_INTERNAL__(__summary__); \ - } \ +#define PADDLE_ENFORCE_CUSTOM_DEVICE_SUCCESS(COND) \ + do { \ + auto __cond__ = (COND); \ + using __CUSTOM_DEVICE_STATUS_TYPE__ = decltype(__cond__); \ + constexpr auto __success_type__ = ::phi::CustomDeviceStatusType< \ + __CUSTOM_DEVICE_STATUS_TYPE__>::kSuccess; \ + if (UNLIKELY(__cond__ != __success_type__)) { \ + auto __summary__ = ::phi::errors::External( \ + ::phi::build_custom_device_error_msg(__cond__)); \ + __THROW_ERROR_INTERNAL__(__summary__); \ + } \ } while (0) -} // namespace platform -} // namespace paddle +} // namespace phi #endif // PADDLE_WITH_CUSTOM_DEVICE -- GitLab