未验证 提交 9e74211f 编写于 作者: Z zhangxiaoci 提交者: GitHub

add macro control in enforce_xpu.h, test=kunlun (#45022)

* add macro control in enforce_xpu.h, test=kunlun

* minor bugfix

* minor bugfix
上级 01d05bc0
......@@ -21,7 +21,7 @@
#include "paddle/fluid/imperative/parallel_context.h"
#include "paddle/fluid/operators/math/concat_and_split.h"
#include "paddle/fluid/operators/strided_memcpy.h"
#ifdef PADDLE_WITH_XPU_BKCL
#ifdef PADDLE_WITH_XPU
#include "paddle/fluid/platform/device/xpu/enforce_xpu.h"
#endif
#include "paddle/fluid/string/string_helper.h"
......
......@@ -25,10 +25,6 @@ inline const char* xpuGetErrorString(int stat) {
return phi::backends::xpu::xpuGetErrorString(stat);
}
inline const char* bkclGetErrorString(BKCLResult_t stat) {
return phi::backends::xpu::bkclGetErrorString(stat);
}
inline const char* xdnnGetErrorString(int stat) {
return phi::backends::xpu::xdnnGetErrorString(stat);
}
......@@ -37,10 +33,16 @@ inline std::string build_xpu_error_msg(int stat) {
return phi::backends::xpu::build_xpu_error_msg(stat);
}
#ifdef PADDLE_WITH_XPU_BKCL
inline std::string build_xpu_error_msg(BKCLResult_t stat) {
return phi::backends::xpu::build_xpu_error_msg(stat);
}
inline const char* bkclGetErrorString(BKCLResult_t stat) {
return phi::backends::xpu::bkclGetErrorString(stat);
}
#endif
inline std::string build_xpu_xdnn_error_msg(int stat, std::string msg) {
return phi::backends::xpu::build_xpu_xdnn_error_msg(stat, msg);
}
......
......@@ -124,6 +124,7 @@ TEST(enforce, xpu_status) {
"Execution interrupted by user"));
}
#ifdef PADDLE_WITH_XPU_BKCL
TEST(enforce, bkcl_status) {
EXPECT_TRUE(CheckXPUStatusSuccess(BKCL_SUCCESS));
EXPECT_TRUE(
......@@ -133,6 +134,7 @@ TEST(enforce, bkcl_status) {
EXPECT_TRUE(
CheckXPUStatusFailure(BKCL_INTERNAL_ERROR, "BKCL_INTERNAL_ERROR"));
}
#endif
TEST(enforce, xdnn_status) {
EXPECT_TRUE(CheckXDNNStatusSuccess(xpu::Error_t::SUCCESS));
......
......@@ -16,7 +16,9 @@ limitations under the License. */
#include "paddle/fluid/platform/enforce.h"
#include "paddle/phi/backends/xpu/xpu_header.h"
#ifdef PADDLE_WITH_XPU_BKCL
#include "xpu/bkcl.h"
#endif
namespace phi {
namespace backends {
......@@ -97,6 +99,7 @@ inline const char* xpuGetErrorString(int stat) {
}
}
#ifdef PADDLE_WITH_XPU_BKCL
inline const char* bkclGetErrorString(BKCLResult_t stat) {
switch (stat) {
case BKCL_SUCCESS:
......@@ -113,6 +116,7 @@ inline const char* bkclGetErrorString(BKCLResult_t stat) {
return "Unknown BKCL status";
}
}
#endif
inline const char* xdnnGetErrorString(int stat) {
switch (stat) {
......@@ -136,10 +140,12 @@ inline std::string build_xpu_error_msg(int stat) {
return msg + xpuGetErrorString(stat) + " ";
}
#ifdef PADDLE_WITH_XPU_BKCL
inline std::string build_xpu_error_msg(BKCLResult_t stat) {
std::string msg("BKCL Error, ");
return msg + bkclGetErrorString(stat) + " ";
}
#endif
inline std::string build_xpu_xdnn_error_msg(int stat, std::string msg) {
return msg + " XDNN Error, " + xdnnGetErrorString(stat) + " ";
......@@ -158,7 +164,9 @@ struct ExternalApiType {};
}
DEFINE_EXTERNAL_API_TYPE(int, XPU_SUCCESS);
#ifdef PADDLE_WITH_XPU_BKCL
DEFINE_EXTERNAL_API_TYPE(BKCLResult_t, BKCL_SUCCESS);
#endif
#undef DEFINE_EXTERNAL_API_TYPE
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册