From 6064c2f49c057ba401385e8cefe1de73e687b395 Mon Sep 17 00:00:00 2001 From: hong19860320 <9973393+hong19860320@users.noreply.github.com> Date: Tue, 16 Jun 2020 14:40:13 +0800 Subject: [PATCH] [XPU] Enable XPU CI (#3796) --- lite/CMakeLists.txt | 4 +++- lite/tests/api/CMakeLists.txt | 7 +++++-- lite/tests/api/test_bert_lite_xpu.cc | 2 +- lite/tests/api/test_ernie_lite_xpu.cc | 2 +- lite/tests/kernels/activation_compute_test.cc | 6 +++--- lite/tests/kernels/batch_norm_compute_test.cc | 2 +- lite/tests/kernels/cast_compute_test.cc | 2 +- lite/tests/kernels/dropout_compute_test.cc | 2 +- lite/tests/kernels/elementwise_compute_test.cc | 2 +- lite/tests/kernels/gather_compute_test.cc | 2 +- lite/tests/kernels/layer_norm_compute_test.cc | 2 +- lite/tests/kernels/lookup_table_compute_test.cc | 5 +++-- lite/tests/kernels/matmul_compute_test.cc | 4 ++-- lite/tests/kernels/mul_compute_test.cc | 2 +- lite/tests/kernels/multiclass_nms_compute_test.cc | 2 +- lite/tests/kernels/pool_compute_test.cc | 2 +- lite/tests/kernels/reshape_compute_test.cc | 2 +- lite/tests/kernels/scale_compute_test.cc | 2 +- lite/tests/kernels/slice_compute_test.cc | 2 +- lite/tests/kernels/softmax_compute_test.cc | 2 +- lite/tests/kernels/stack_compute_test.cc | 2 +- lite/tests/kernels/transpose_compute_test.cc | 2 +- lite/tests/kernels/yolo_box_compute_test.cc | 2 +- lite/tools/ci_build.sh | 2 +- 24 files changed, 35 insertions(+), 29 deletions(-) diff --git a/lite/CMakeLists.txt b/lite/CMakeLists.txt index ff4d00dbb1..e534fdd9f9 100644 --- a/lite/CMakeLists.txt +++ b/lite/CMakeLists.txt @@ -48,11 +48,13 @@ if (WITH_TESTING) endif() if(NOT LITE_WITH_LIGHT_WEIGHT_FRAMEWORK) lite_download_and_uncompress(${LITE_MODEL_DIR} ${LITE_URL} "GoogleNet_inference.tar.gz") - lite_download_and_uncompress(${LITE_MODEL_DIR} ${LITE_URL} "mobilenet_v1.tar.gz") + lite_download_and_uncompress(${LITE_MODEL_DIR} ${LITE_URL} "mobilenet_v1.tar.gz") lite_download_and_uncompress(${LITE_MODEL_DIR} ${LITE_URL} "mobilenet_v2_relu.tar.gz") lite_download_and_uncompress(${LITE_MODEL_DIR} ${LITE_URL} "resnet50.tar.gz") lite_download_and_uncompress(${LITE_MODEL_DIR} ${LITE_URL} "inception_v4_simple.tar.gz") lite_download_and_uncompress(${LITE_MODEL_DIR} ${LITE_URL} "step_rnn.tar.gz") + lite_download_and_uncompress(${LITE_MODEL_DIR} ${LITE_URL} "bert.tar.gz") + lite_download_and_uncompress(${LITE_MODEL_DIR} ${LITE_URL} "ernie.tar.gz") endif() endif() diff --git a/lite/tests/api/CMakeLists.txt b/lite/tests/api/CMakeLists.txt index 810a20abbc..0acc54c270 100644 --- a/lite/tests/api/CMakeLists.txt +++ b/lite/tests/api/CMakeLists.txt @@ -3,14 +3,17 @@ if(LITE_WITH_XPU) DEPS mir_passes lite_api_test_helper paddle_api_full paddle_api_light gflags utils ${ops} ${host_kernels} ${x86_kernels} ${xpu_kernels} ARGS --model_dir=${LITE_MODEL_DIR}/resnet50) + add_dependencies(test_resnet50_lite_xpu extern_lite_download_resnet50_tar_gz) lite_cc_test(test_ernie_lite_xpu SRCS test_ernie_lite_xpu.cc DEPS mir_passes lite_api_test_helper paddle_api_full paddle_api_light gflags utils ${ops} ${host_kernels} ${x86_kernels} ${xpu_kernels} - ARGS --model_dir=${LITE_MODEL_DIR}/resnet50) + ARGS --model_dir=${LITE_MODEL_DIR}/ernie) + add_dependencies(test_ernie_lite_xpu extern_lite_download_ernie_tar_gz) lite_cc_test(test_bert_lite_xpu SRCS test_bert_lite_xpu.cc DEPS mir_passes lite_api_test_helper paddle_api_full paddle_api_light gflags utils ${ops} ${host_kernels} ${x86_kernels} ${xpu_kernels} - ARGS --model_dir=${LITE_MODEL_DIR}/resnet50) + ARGS --model_dir=${LITE_MODEL_DIR}/bert) + add_dependencies(test_bert_lite_xpu extern_lite_download_bert_tar_gz) endif() if(LITE_WITH_RKNPU) diff --git a/lite/tests/api/test_bert_lite_xpu.cc b/lite/tests/api/test_bert_lite_xpu.cc index b3ee9febb3..5d66fd0d54 100644 --- a/lite/tests/api/test_bert_lite_xpu.cc +++ b/lite/tests/api/test_bert_lite_xpu.cc @@ -93,7 +93,7 @@ TEST(Ernie, test_ernie_lite_xpu) { for (size_t i = 0; i < results.size(); ++i) { for (size_t j = 0; j < results[i].size(); ++j) { EXPECT_NEAR( - out->data()[j + (out->shape()[1] * i)], results[i][j], 1e-5); + out->data()[j + (out->shape()[1] * i)], results[i][j], 3e-5); } } } diff --git a/lite/tests/api/test_ernie_lite_xpu.cc b/lite/tests/api/test_ernie_lite_xpu.cc index 0b614fec96..b1db9f3536 100644 --- a/lite/tests/api/test_ernie_lite_xpu.cc +++ b/lite/tests/api/test_ernie_lite_xpu.cc @@ -93,7 +93,7 @@ TEST(Ernie, test_ernie_lite_xpu) { for (size_t i = 0; i < results.size(); ++i) { for (size_t j = 0; j < results[i].size(); ++j) { EXPECT_NEAR( - out->data()[j + (out->shape()[1] * i)], results[i][j], 1e-5); + out->data()[j + (out->shape()[1] * i)], results[i][j], 2e-5); } } } diff --git a/lite/tests/kernels/activation_compute_test.cc b/lite/tests/kernels/activation_compute_test.cc index 5824ba91c2..a62c698f83 100644 --- a/lite/tests/kernels/activation_compute_test.cc +++ b/lite/tests/kernels/activation_compute_test.cc @@ -300,7 +300,7 @@ TEST(Activation_relu, precision) { abs_error = 1e-2; // Using fp16 in NPU #elif defined(LITE_WITH_ARM) place = TARGET(kARM); -#elif defined(LITE_WITH_XPU) +#elif defined(LITE_WITH_XPU) && defined(LITE_WITH_XTCL) place = TARGET(kXPU); #else return; @@ -426,7 +426,7 @@ TEST(Activation_tanh, precision) { abs_error = 1e-2; // Using fp16 in NPU #elif defined(LITE_WITH_ARM) place = TARGET(kARM); -#elif defined(LITE_WITH_XPU) +#elif defined(LITE_WITH_XPU) && defined(LITE_WITH_XTCL) place = TARGET(kXPU); #else return; @@ -572,7 +572,7 @@ TEST(Activation_gelu, precision) { LOG(INFO) << "test gelu op"; Place place; float abs_error = 2e-5; -#if defined(LITE_WITH_XPU) +#if defined(LITE_WITH_XPU) && defined(LITE_WITH_XTCL) place = TARGET(kXPU); #else return; diff --git a/lite/tests/kernels/batch_norm_compute_test.cc b/lite/tests/kernels/batch_norm_compute_test.cc index ae65e0e3c3..9674f95d0b 100644 --- a/lite/tests/kernels/batch_norm_compute_test.cc +++ b/lite/tests/kernels/batch_norm_compute_test.cc @@ -157,7 +157,7 @@ TEST(BatchNorm, precision) { LOG(INFO) << "test BatchNorm op"; float abs_error = 2e-5; Place place; -#if defined(LITE_WITH_XPU) +#if defined(LITE_WITH_XPU) && defined(LITE_WITH_XTCL) place = TARGET(kXPU); #elif defined(LITE_WITH_NPU) place = TARGET(kNPU); diff --git a/lite/tests/kernels/cast_compute_test.cc b/lite/tests/kernels/cast_compute_test.cc index 86331bb8a1..34038dfdc7 100644 --- a/lite/tests/kernels/cast_compute_test.cc +++ b/lite/tests/kernels/cast_compute_test.cc @@ -135,7 +135,7 @@ TEST(Cast, precision) { float abs_error = 2e-5; #if defined(LITE_WITH_ARM) place = TARGET(kARM); -#elif defined(LITE_WITH_XPU) +#elif defined(LITE_WITH_XPU) && defined(LITE_WITH_XTCL) place = TARGET(kXPU); #else return; diff --git a/lite/tests/kernels/dropout_compute_test.cc b/lite/tests/kernels/dropout_compute_test.cc index 025f02ce31..c4ecc0cf01 100644 --- a/lite/tests/kernels/dropout_compute_test.cc +++ b/lite/tests/kernels/dropout_compute_test.cc @@ -94,7 +94,7 @@ TEST(Dropout, precision) { #if defined(LITE_WITH_NPU) place = TARGET(kNPU); abs_error = 1e-2; // Using fp16 in NPU -#elif defined(LITE_WITH_XPU) +#elif defined(LITE_WITH_XPU) && defined(LITE_WITH_XTCL) place = TARGET(kXPU); #else return; diff --git a/lite/tests/kernels/elementwise_compute_test.cc b/lite/tests/kernels/elementwise_compute_test.cc index 505ab72dc1..d91c304ef7 100644 --- a/lite/tests/kernels/elementwise_compute_test.cc +++ b/lite/tests/kernels/elementwise_compute_test.cc @@ -228,7 +228,7 @@ TEST(Elementwise, precision) { abs_error = 1e-2; // use fp16 in npu #elif defined(LITE_WITH_ARM) place = TARGET(kARM); -#elif defined(LITE_WITH_XPU) +#elif defined(LITE_WITH_XPU) && defined(LITE_WITH_XTCL) place = TARGET(kXPU); #else return; diff --git a/lite/tests/kernels/gather_compute_test.cc b/lite/tests/kernels/gather_compute_test.cc index 4d0ad1ab47..c023a12b0f 100644 --- a/lite/tests/kernels/gather_compute_test.cc +++ b/lite/tests/kernels/gather_compute_test.cc @@ -98,7 +98,7 @@ TEST(Gather, precision) { abs_error = 1e-2; // use fp16 in npu #elif defined(LITE_WITH_ARM) place = TARGET(kARM); -#elif defined(LITE_WITH_XPU) +#elif defined(LITE_WITH_XPU) && defined(LITE_WITH_XTCL) place = TARGET(kXPU); #else return; diff --git a/lite/tests/kernels/layer_norm_compute_test.cc b/lite/tests/kernels/layer_norm_compute_test.cc index 5ea01a6cca..bd4480b612 100644 --- a/lite/tests/kernels/layer_norm_compute_test.cc +++ b/lite/tests/kernels/layer_norm_compute_test.cc @@ -147,7 +147,7 @@ TEST(LayerNorm, precision) { LOG(INFO) << "test layer_norm op"; float abs_error = 2e-5; Place place; -#if defined(LITE_WITH_XPU) +#if defined(LITE_WITH_XPU) && defined(LITE_WITH_XTCL) place = TARGET(kXPU); #elif defined(LITE_WITH_NPU) place = TARGET(kNPU); diff --git a/lite/tests/kernels/lookup_table_compute_test.cc b/lite/tests/kernels/lookup_table_compute_test.cc index 988077c6c3..ae39abf1db 100644 --- a/lite/tests/kernels/lookup_table_compute_test.cc +++ b/lite/tests/kernels/lookup_table_compute_test.cc @@ -116,7 +116,7 @@ TEST(LookupTable, precision) { abs_error = 1e-2; #elif defined(LITE_WITH_ARM) place = TARGET(kARM); -#elif defined(LITE_WITH_XPU) +#elif defined(LITE_WITH_XPU) && defined(LITE_WITH_XTCL) place = TARGET(kXPU); #else return; @@ -132,7 +132,8 @@ TEST(LookupTable, precision) { std::vector>{{5, 2, 3, 1}, {2, 3, 1}, {3, 1}}) { for (auto w_dims : std::vector>{{4, 2}, {6, 8}, {12, 15}}) { -#if defined(LITE_WITH_XPU) && defined(LITE_WITH_NPU) +#if (defined(LITE_WITH_XPU) && defined(LITE_WITH_XTCL)) || \ + defined(LITE_WITH_NPU) for (auto padding_idx : std::vector{-1}) { // Only -1 is supported by XPU or NPU #else diff --git a/lite/tests/kernels/matmul_compute_test.cc b/lite/tests/kernels/matmul_compute_test.cc index 59b0fde8fd..9799c15622 100644 --- a/lite/tests/kernels/matmul_compute_test.cc +++ b/lite/tests/kernels/matmul_compute_test.cc @@ -457,7 +457,7 @@ TEST(Matmul2x2, precision) { abs_error = 1e-2; // use fp16 in npu #elif defined(LITE_WITH_ARM) place = TARGET(kARM); -#elif defined(LITE_WITH_XPU) +#elif defined(LITE_WITH_XPU) && defined(LITE_WITH_XTCL) place = TARGET(kXPU); #else return; @@ -489,7 +489,7 @@ TEST(Matmul2x2_y_transpose, precision) { abs_error = 1e-2; // use fp16 in npu #elif defined(LITE_WITH_ARM) place = TARGET(kARM); -#elif defined(LITE_WITH_XPU) +#elif defined(LITE_WITH_XPU) && defined(LITE_WITH_XTCL) place = TARGET(kXPU); #else return; diff --git a/lite/tests/kernels/mul_compute_test.cc b/lite/tests/kernels/mul_compute_test.cc index d070292332..d89b356935 100644 --- a/lite/tests/kernels/mul_compute_test.cc +++ b/lite/tests/kernels/mul_compute_test.cc @@ -127,7 +127,7 @@ TEST(Mul, precision) { #if defined(LITE_WITH_NPU) place = TARGET(kNPU); abs_error = 1e-2; // use fp16 in npu -#elif defined(LITE_WITH_XPU) +#elif defined(LITE_WITH_XPU) && defined(LITE_WITH_XTCL) place = TARGET(kXPU); #else return; diff --git a/lite/tests/kernels/multiclass_nms_compute_test.cc b/lite/tests/kernels/multiclass_nms_compute_test.cc index a1190197bf..dd16730ef5 100644 --- a/lite/tests/kernels/multiclass_nms_compute_test.cc +++ b/lite/tests/kernels/multiclass_nms_compute_test.cc @@ -478,7 +478,7 @@ TEST(multiclass_nms, precision) { Place place; #if defined(LITE_WITH_ARM) place = TARGET(kHost); -#elif defined(LITE_WITH_XPU) +#elif defined(LITE_WITH_XPU) && defined(LITE_WITH_XTCL) place = TARGET(kXPU); #else return; diff --git a/lite/tests/kernels/pool_compute_test.cc b/lite/tests/kernels/pool_compute_test.cc index 04894188b0..fc4d004e55 100644 --- a/lite/tests/kernels/pool_compute_test.cc +++ b/lite/tests/kernels/pool_compute_test.cc @@ -381,7 +381,7 @@ TEST(Pool, precision) { #if defined(LITE_WITH_NPU) place = TARGET(kNPU); abs_error = 1e-2; // Using fp16 in NPU -#elif defined(LITE_WITH_XPU) +#elif defined(LITE_WITH_XPU) && defined(LITE_WITH_XTCL) place = TARGET(kXPU); #else return; diff --git a/lite/tests/kernels/reshape_compute_test.cc b/lite/tests/kernels/reshape_compute_test.cc index 3a866b6cf2..f3fcc0bad5 100644 --- a/lite/tests/kernels/reshape_compute_test.cc +++ b/lite/tests/kernels/reshape_compute_test.cc @@ -206,7 +206,7 @@ TEST(Reshape, precision) { abs_error = 1e-2; // Using fp16 in NPU #elif defined(LITE_WITH_ARM) place = TARGET(kHost); -#elif defined(LITE_WITH_XPU) +#elif defined(LITE_WITH_XPU) && defined(LITE_WITH_XTCL) place = TARGET(kXPU); #else return; diff --git a/lite/tests/kernels/scale_compute_test.cc b/lite/tests/kernels/scale_compute_test.cc index efd0497002..9d1f4403dc 100644 --- a/lite/tests/kernels/scale_compute_test.cc +++ b/lite/tests/kernels/scale_compute_test.cc @@ -165,7 +165,7 @@ TEST(Scale, precision) { abs_error = 4e-3; // Using fp16 in NPU #elif defined(LITE_WITH_ARM) place = TARGET(kARM); -#elif defined(LITE_WITH_XPU) +#elif defined(LITE_WITH_XPU) && defined(LITE_WITH_XTCL) place = TARGET(kXPU); abs_error = 3e-4; // Some operations use fp16 in XPU #elif defined(LITE_WITH_X86) diff --git a/lite/tests/kernels/slice_compute_test.cc b/lite/tests/kernels/slice_compute_test.cc index fc96b39f01..8d5d2c089e 100644 --- a/lite/tests/kernels/slice_compute_test.cc +++ b/lite/tests/kernels/slice_compute_test.cc @@ -273,7 +273,7 @@ TEST(Slice, precision) { test_slice(place); test_slice_tensor(place); test_slice_tensor_list(place); -#elif defined(LITE_WITH_XPU) +#elif defined(LITE_WITH_XPU) && defined(LITE_WITH_XTCL) Place place(TARGET(kXPU)); test_slice(place); #endif diff --git a/lite/tests/kernels/softmax_compute_test.cc b/lite/tests/kernels/softmax_compute_test.cc index a91f6534ff..e0f708f3a7 100644 --- a/lite/tests/kernels/softmax_compute_test.cc +++ b/lite/tests/kernels/softmax_compute_test.cc @@ -103,7 +103,7 @@ TEST(Softmax, precision) { #if defined(LITE_WITH_NPU) place = TARGET(kNPU); abs_error = 4e-3; // Using fp16 in NPU -#elif defined(LITE_WITH_XPU) +#elif defined(LITE_WITH_XPU) && defined(LITE_WITH_XTCL) place = TARGET(kXPU); #else return; diff --git a/lite/tests/kernels/stack_compute_test.cc b/lite/tests/kernels/stack_compute_test.cc index 10b289e419..72529cac51 100644 --- a/lite/tests/kernels/stack_compute_test.cc +++ b/lite/tests/kernels/stack_compute_test.cc @@ -106,7 +106,7 @@ TEST(Stack, precision) { Place place; #ifdef LITE_WITH_ARM place = TARGET(kARM); -#elif defined(LITE_WITH_XPU) +#elif defined(LITE_WITH_XPU) && defined(LITE_WITH_XTCL) place = TARGET(kXPU); #else return; diff --git a/lite/tests/kernels/transpose_compute_test.cc b/lite/tests/kernels/transpose_compute_test.cc index 0ec010e47f..933e9f8ec5 100644 --- a/lite/tests/kernels/transpose_compute_test.cc +++ b/lite/tests/kernels/transpose_compute_test.cc @@ -164,7 +164,7 @@ TEST(Transpose, precision) { LOG(INFO) << "test Transpose op"; float abs_error = 2e-5; Place place; -#ifdef LITE_WITH_XPU +#if defined(LITE_WITH_XPU) && defined(LITE_WITH_XTCL) place = TARGET(kXPU); #elif defined(LITE_WITH_NPU) place = TARGET(kNPU); diff --git a/lite/tests/kernels/yolo_box_compute_test.cc b/lite/tests/kernels/yolo_box_compute_test.cc index c41c89608f..b88f25e1e0 100644 --- a/lite/tests/kernels/yolo_box_compute_test.cc +++ b/lite/tests/kernels/yolo_box_compute_test.cc @@ -247,7 +247,7 @@ TEST(YoloBox, precision) { Place place; #if defined(LITE_WITH_ARM) place = TARGET(kARM); -#elif defined(LITE_WITH_XPU) +#elif defined(LITE_WITH_XPU) && defined(LITE_WITH_XTCL) place = TARGET(kXPU); #else return; diff --git a/lite/tools/ci_build.sh b/lite/tools/ci_build.sh index 29ed9100f9..fde4ea6faa 100755 --- a/lite/tools/ci_build.sh +++ b/lite/tools/ci_build.sh @@ -353,7 +353,7 @@ function cmake_xpu { -DWITH_MKL=ON \ -DLITE_BUILD_EXTRA=ON \ -DLITE_WITH_XPU=ON \ - -DXPU_SDK_ROOT="$(pwd)/../../XPU_SDK" + -DXPU_SDK_ROOT="/opt/output" } function build_xpu { -- GitLab