diff --git a/cmake/external/lite.cmake b/cmake/external/lite.cmake index a39bb3b69955782f11d892639b4e1de6ea3799f8..274511e3d39df860b9012fe498277e3d74eec494 100644 --- a/cmake/external/lite.cmake +++ b/cmake/external/lite.cmake @@ -132,7 +132,11 @@ if (NOT LITE_SOURCE_DIR OR NOT LITE_BINARY_DIR) endif() if (WITH_ARM) - set(LITE_OUTPUT_BIN_DIR inference_lite_lib.armlinux.armv8) + if(LITE_WITH_XPU) + set(LITE_OUTPUT_BIN_DIR inference_lite_lib.armlinux.armv8.xpu) + else() + set(LITE_OUTPUT_BIN_DIR inference_lite_lib.armlinux.armv8) + endif() else() set(LITE_OUTPUT_BIN_DIR inference_lite_lib) endif() diff --git a/paddle/fluid/inference/tests/api/lite_resnet50_test.cc b/paddle/fluid/inference/tests/api/lite_resnet50_test.cc index b88f09ae6a6a8619cbad4e97c630b453c1a8aad1..da56a7978a2e4815e7fb9534dab8a9a41d91000c 100644 --- a/paddle/fluid/inference/tests/api/lite_resnet50_test.cc +++ b/paddle/fluid/inference/tests/api/lite_resnet50_test.cc @@ -26,11 +26,7 @@ namespace inference { TEST(AnalysisPredictor, use_gpu) { std::string model_dir = FLAGS_infer_model + "/" + "model"; AnalysisConfig config; -#if defined(PADDLE_WITH_CUDA) config.EnableUseGpu(100, 0); -#elif defined(LITE_SUBGRAPH_WITH_XPU) - config.EnableXpu(100); -#endif config.SetModel(model_dir + "/model", model_dir + "/params"); config.EnableLiteEngine(paddle::AnalysisConfig::Precision::kFloat32, true); @@ -73,6 +69,54 @@ TEST(AnalysisPredictor, use_gpu) { } } +#ifdef LITE_SUBGRAPH_WITH_XPU +TEST(AnalysisPredictor, use_xpu) { + std::string model_dir = FLAGS_infer_model + "/" + "model"; + AnalysisConfig config; + config.EnableLiteEngine(paddle::AnalysisConfig::Precision::kFloat32, true); + config.EnableXpu(100); + config.SetModel(model_dir + "/model", model_dir + "/params"); + + std::vector inputs; + auto predictor = CreatePaddlePredictor(config); + const int batch = 1; + const int channel = 3; + const int height = 318; + const int width = 318; + const int input_num = batch * channel * height * width; + std::vector input(input_num, 1); + + PaddleTensor in; + in.shape = {batch, channel, height, width}; + in.data = + PaddleBuf(static_cast(input.data()), input_num * sizeof(float)); + in.dtype = PaddleDType::FLOAT32; + inputs.emplace_back(in); + + std::vector outputs; + ASSERT_TRUE(predictor->Run(inputs, &outputs)); + + const std::vector truth_values = { + 127.84, 738.088, 1013.22, -438.055, 366.451, 927.585, 736.341, + -633.776, -329.904, -430.149, -633.082, -146.597, -1324.19, -1349.29, + -242.68, 117.541, -801.704, -391.428, -404.756, 453.995, 515.373, + -133.003, 69.3941, 590.056, -1434.66, -1070.81, 307.093, 400.463, + -316.094, -587.089, -161.033, 800.357, -96.4212, 748.706, 868.226, + -447.936, 112.782, 1127.24, 47.4587, 677.698, 593.126, -336.462, + 551.328, 397.816, 78.3572, -715.269, 406.002, 404.149, 246.067, + -8.4649, 131.345, -647.951, + }; + + const size_t expected_size = 1; + EXPECT_EQ(outputs.size(), expected_size); + float* data_o = static_cast(outputs[0].data.data()); + for (size_t j = 0; j < outputs[0].data.length() / sizeof(float); j += 10) { + EXPECT_NEAR((data_o[j] - truth_values[j / 10]) / truth_values[j / 10], 0., + 10e-5); + } +} +#endif + } // namespace inference } // namespace paddle diff --git a/paddle/scripts/paddle_build.sh b/paddle/scripts/paddle_build.sh index 21eedc6066b49ca42e5a12444f446a93401f1632..e555832ba09365b61f5f721523bd4b8d862930ae 100755 --- a/paddle/scripts/paddle_build.sh +++ b/paddle/scripts/paddle_build.sh @@ -288,6 +288,7 @@ EOF -DWITH_GLOO=${gloo_flag} \ -DLITE_GIT_TAG=develop \ -DWITH_XPU=${WITH_XPU:-OFF} \ + -DXPU_SDK_ROOT=${XPU_SDK_ROOT:-""} \ -DWITH_LITE=${WITH_LITE:-OFF} \ -DWITH_UNITY_BUILD=${WITH_UNITY_BUILD:-OFF};build_error=$? if [ "$build_error" != 0 ];then