From ea46586953e4bd0c96103dd0e62ad3036146d6f4 Mon Sep 17 00:00:00 2001 From: leiqing <54695910+leiqing1@users.noreply.github.com> Date: Thu, 9 Feb 2023 19:55:06 +0800 Subject: [PATCH 1/6] Update README_CN.md --- docs/README_CN.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/README_CN.md b/docs/README_CN.md index da0c7b8a9b..227db0407c 100755 --- a/docs/README_CN.md +++ b/docs/README_CN.md @@ -10,7 +10,7 @@ - [IPU部署环境编译安装](cn/build_and_install/ipu.md) - [昆仑芯XPU部署环境编译安装](cn/build_and_install/kunlunxin.md) - [瑞芯微RV1126部署环境编译安装](cn/build_and_install/rv1126.md) -- [瑞芯微RK3588部署环境编译安装](cn/build_and_install/rknpu2.md) +- [瑞芯微RK3588、RK356X部署环境编译安装](cn/build_and_install/rknpu2.md) - [晶晨A311D部署环境编译安装](cn/build_and_install/a311d.md) - [华为昇腾部署环境编译安装](cn/build_and_install/huawei_ascend.md) - [Jetson部署环境编译安装](cn/build_and_install/jetson.md) From 4742f97819ccb4f6084a877fb653788344732a82 Mon Sep 17 00:00:00 2001 From: yeliang2258 <30516196+yeliang2258@users.noreply.github.com> Date: Thu, 9 Feb 2023 20:39:44 +0800 Subject: [PATCH 2/6] [Bug Fix] Fix KunlunXin valid_places (#1285) fix KunlunXin valid_places --- fastdeploy/runtime/backends/lite/configure_hardware.cc | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/fastdeploy/runtime/backends/lite/configure_hardware.cc b/fastdeploy/runtime/backends/lite/configure_hardware.cc index 7ac60383fe..cf8a958fe6 100644 --- a/fastdeploy/runtime/backends/lite/configure_hardware.cc +++ b/fastdeploy/runtime/backends/lite/configure_hardware.cc @@ -51,8 +51,9 @@ void LiteBackend::ConfigureCpu(const LiteBackendOption& option) { void LiteBackend::ConfigureKunlunXin(const LiteBackendOption& option) { std::vector valid_places; - valid_places.push_back( - paddle::lite_api::Place{TARGET(kXPU), PRECISION(kInt8)}); + // TODO(yeliang): Placing kInt8 first may cause accuracy issues of some model + // valid_places.push_back( + // paddle::lite_api::Place{TARGET(kXPU), PRECISION(kInt8)}); if (option.enable_fp16) { valid_places.push_back( paddle::lite_api::Place{TARGET(kXPU), PRECISION(kFP16)}); From c2e5f6317eae57f30db2627f93ae68b628338785 Mon Sep 17 00:00:00 2001 From: wwbitejotunn Date: Thu, 9 Feb 2023 05:51:30 +0000 Subject: [PATCH 3/6] fix paddle backend --- fastdeploy/runtime/backends/paddle/paddle_backend.cc | 1 + 1 file changed, 1 insertion(+) diff --git a/fastdeploy/runtime/backends/paddle/paddle_backend.cc b/fastdeploy/runtime/backends/paddle/paddle_backend.cc index e0e908c368..19493f90b2 100644 --- a/fastdeploy/runtime/backends/paddle/paddle_backend.cc +++ b/fastdeploy/runtime/backends/paddle/paddle_backend.cc @@ -44,6 +44,7 @@ void PaddleBackend::BuildOption(const PaddleBackendOption& option) { "file will save to the directory where paddle model saved." << std::endl; use_static = true; + config_.SetOptimCacheDir(option.trt_option.serialize_file); } config_.EnableTensorRtEngine(option.trt_option.max_workspace_size, option.trt_option.max_batch_size, 3, From 898b0632161e8384ba7178598dfb2225549d586b Mon Sep 17 00:00:00 2001 From: wwbitejotunn Date: Thu, 9 Feb 2023 12:55:05 +0000 Subject: [PATCH 4/6] get cache dir --- fastdeploy/runtime/backends/paddle/paddle_backend.cc | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/fastdeploy/runtime/backends/paddle/paddle_backend.cc b/fastdeploy/runtime/backends/paddle/paddle_backend.cc index 19493f90b2..4df109991a 100644 --- a/fastdeploy/runtime/backends/paddle/paddle_backend.cc +++ b/fastdeploy/runtime/backends/paddle/paddle_backend.cc @@ -44,7 +44,10 @@ void PaddleBackend::BuildOption(const PaddleBackendOption& option) { "file will save to the directory where paddle model saved." << std::endl; use_static = true; - config_.SetOptimCacheDir(option.trt_option.serialize_file); + std::string opt_cache_dir = + GetDirFromPath(option.trt_option.serialize_file); + + config_.SetOptimCacheDir(opt_cache_dir); } config_.EnableTensorRtEngine(option.trt_option.max_workspace_size, option.trt_option.max_batch_size, 3, From ce424c313e3c2d7ad1cd9c44e711400c2ceb313c Mon Sep 17 00:00:00 2001 From: DefTruth <31974251+DefTruth@users.noreply.github.com> Date: Fri, 10 Feb 2023 11:24:40 +0800 Subject: [PATCH 5/6] [XPU] Add XPU option for benchmark example (#1287) * [XPU] Add xpu option for benchmark example * [XPU] Add fp16 flags --- benchmark/cpp/benchmark_ppyolov8.cc | 2 +- benchmark/cpp/flags.h | 31 ++++++-- ...ild_linux_x86_64_cpp_xpu_with_benchmark.sh | 79 +++++++++++++++++++ 3 files changed, 105 insertions(+), 7 deletions(-) create mode 100755 scripts/linux/build_linux_x86_64_cpp_xpu_with_benchmark.sh diff --git a/benchmark/cpp/benchmark_ppyolov8.cc b/benchmark/cpp/benchmark_ppyolov8.cc index 4bd6e0df45..cff3742004 100644 --- a/benchmark/cpp/benchmark_ppyolov8.cc +++ b/benchmark/cpp/benchmark_ppyolov8.cc @@ -122,4 +122,4 @@ int main(int argc, char* argv[]) { #endif } return 0; -} \ No newline at end of file +} diff --git a/benchmark/cpp/flags.h b/benchmark/cpp/flags.h index c9a8e8d91f..6ecf9b33ee 100755 --- a/benchmark/cpp/flags.h +++ b/benchmark/cpp/flags.h @@ -20,8 +20,8 @@ DEFINE_string(model, "", "Directory of the inference model."); DEFINE_string(image, "", "Path of the image file."); DEFINE_string(device, "cpu", - "Type of inference device, support 'cpu' or 'gpu'."); -DEFINE_int32(device_id, 0, "device(gpu) id."); + "Type of inference device, support 'cpu/gpu/xpu'."); +DEFINE_int32(device_id, 0, "device(gpu/xpu/...) id."); DEFINE_int32(warmup, 200, "Number of warmup for profiling."); DEFINE_int32(repeat, 1000, "Number of repeats for profiling."); DEFINE_string(profile_mode, "runtime", "runtime or end2end."); @@ -41,8 +41,8 @@ DEFINE_int32(dump_period, 100, "How often to collect memory info."); void PrintUsage() { std::cout << "Usage: infer_demo --model model_path --image img_path --device " - "[cpu|gpu] --backend " - "[default|ort|paddle|ov|trt|paddle_trt] " + "[cpu|gpu|xpu] --backend " + "[default|ort|paddle|ov|trt|paddle_trt|lite] " "--use_fp16 false" << std::endl; std::cout << "Default value of device: cpu" << std::endl; @@ -52,7 +52,7 @@ void PrintUsage() { bool CreateRuntimeOption(fastdeploy::RuntimeOption* option) { if (FLAGS_device == "gpu") { - option->UseGpu(); + option->UseGpu(FLAGS_device_id); if (FLAGS_backend == "ort") { option->UseOrtBackend(); } else if (FLAGS_backend == "paddle") { @@ -94,8 +94,27 @@ bool CreateRuntimeOption(fastdeploy::RuntimeOption* option) { << FLAGS_backend << " is not supported." << std::endl; return false; } + } else if (FLAGS_device == "xpu") { + option->UseKunlunXin(FLAGS_device_id); + if (FLAGS_backend == "ort") { + option->UseOrtBackend(); + } else if (FLAGS_backend == "paddle") { + option->UsePaddleInferBackend(); + } else if (FLAGS_backend == "lite") { + option->UsePaddleLiteBackend(); + if (FLAGS_use_fp16) { + option->EnableLiteFP16(); + } + } else if (FLAGS_backend == "default") { + return true; + } else { + std::cout << "While inference with XPU, only support " + "default/ort/paddle/lite now, " + << FLAGS_backend << " is not supported." << std::endl; + return false; + } } else { - std::cerr << "Only support device CPU/GPU now, " << FLAGS_device + std::cerr << "Only support device CPU/GPU/XPU now, " << FLAGS_device << " is not supported." << std::endl; return false; } diff --git a/scripts/linux/build_linux_x86_64_cpp_xpu_with_benchmark.sh b/scripts/linux/build_linux_x86_64_cpp_xpu_with_benchmark.sh new file mode 100755 index 0000000000..e098883ead --- /dev/null +++ b/scripts/linux/build_linux_x86_64_cpp_xpu_with_benchmark.sh @@ -0,0 +1,79 @@ +#!/bin/bash +set -e +set +x + +# ------------------------------------------------------------------------------- +# readonly global variables +# ------------------------------------------------------------------------------- +readonly ROOT_PATH=$(pwd) +readonly BUILD_ROOT=build/Linux +readonly BUILD_DIR="${BUILD_ROOT}/x86_64_xpu" + +# ------------------------------------------------------------------------------- +# tasks +# ------------------------------------------------------------------------------- +__make_build_dir() { + if [ ! -d "${BUILD_DIR}" ]; then + echo "-- [INFO] BUILD_DIR: ${BUILD_DIR} not exists, setup manually ..." + if [ ! -d "${BUILD_ROOT}" ]; then + mkdir -p "${BUILD_ROOT}" && echo "-- [INFO] Created ${BUILD_ROOT} !" + fi + mkdir -p "${BUILD_DIR}" && echo "-- [INFO] Created ${BUILD_DIR} !" + else + echo "-- [INFO] Found BUILD_DIR: ${BUILD_DIR}" + fi +} + +__check_cxx_envs() { + if [ $LDFLAGS ]; then + echo "-- [INFO] Found LDFLAGS: ${LDFLAGS}, \c" + echo "unset it before crossing compiling ${BUILD_DIR}" + unset LDFLAGS + fi + if [ $CPPFLAGS ]; then + echo "-- [INFO] Found CPPFLAGS: ${CPPFLAGS}, \c" + echo "unset it before crossing compiling ${BUILD_DIR}" + unset CPPFLAGS + fi + if [ $CPLUS_INCLUDE_PATH ]; then + echo "-- [INFO] Found CPLUS_INCLUDE_PATH: ${CPLUS_INCLUDE_PATH}, \c" + echo "unset it before crossing compiling ${BUILD_DIR}" + unset CPLUS_INCLUDE_PATH + fi + if [ $C_INCLUDE_PATH ]; then + echo "-- [INFO] Found C_INCLUDE_PATH: ${C_INCLUDE_PATH}, \c" + echo "unset it before crossing compiling ${BUILD_DIR}" + unset C_INCLUDE_PATH + fi +} + +__build_fastdeploy_linux_x86_64_xpu_shared() { + + local FASDEPLOY_INSTALL_DIR="${ROOT_PATH}/${BUILD_DIR}/install" + cd "${BUILD_DIR}" && echo "-- [INFO] Working Dir: ${PWD}" + + cmake -DWITH_KUNLUNXIN=ON \ + -DCMAKE_BUILD_TYPE=Release \ + -DWITH_GPU=OFF \ + -DENABLE_ORT_BACKEND=ON \ + -DENABLE_PADDLE_BACKEND=ON \ + -DENABLE_VISION=ON \ + -DENABLE_BENCHMARK=ON \ + -DBUILD_EXAMPLES=OFF \ + -DCMAKE_INSTALL_PREFIX=${FASDEPLOY_INSTALL_DIR} \ + -Wno-dev ../../.. && make -j8 && make install + + echo "-- [INFO][built][x86_64_xpu}][${BUILD_DIR}/install]" +} + +main() { + __make_build_dir + __check_cxx_envs + __build_fastdeploy_linux_x86_64_xpu_shared + exit 0 +} + +main + +# Usage: +# ./scripts/linux/build_linux_x86_64_cpp_gpu.sh From b732e4c711fdbad4979eabc203423309fabe8ba1 Mon Sep 17 00:00:00 2001 From: DefTruth <31974251+DefTruth@users.noreply.github.com> Date: Fri, 10 Feb 2023 12:00:43 +0800 Subject: [PATCH 6/6] [Bug Fix] Add bundle script for text api only pkg (#1295) [Android] Add bundle script for text api only pkg --- .../bundle_android_cpp_with_text_api_only.sh | 61 +++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100755 scripts/android/bundle_android_cpp_with_text_api_only.sh diff --git a/scripts/android/bundle_android_cpp_with_text_api_only.sh b/scripts/android/bundle_android_cpp_with_text_api_only.sh new file mode 100755 index 0000000000..a7c26f4175 --- /dev/null +++ b/scripts/android/bundle_android_cpp_with_text_api_only.sh @@ -0,0 +1,61 @@ +#!/bin/bash +set -e +set +x + +FASTDEPLOY_DIR=$(pwd) +BUILT_PACKAGE_DIR=build/Android +CXX_PACKAGE_PREFIX=fastdeploy-android-latest-shared-dev +CXX_PACKAGE_NAME=${BUILT_PACKAGE_DIR}/${CXX_PACKAGE_PREFIX} +ARMV8_CXX_PACKAGE_NAME=${BUILT_PACKAGE_DIR}/arm64-v8a-api-21/install +ARMV7_CXX_PACKAGE_NAME=${BUILT_PACKAGE_DIR}/armeabi-v7a-api-21/install + +# check package name +echo "[INFO] --- FASTDEPLOY_DIR: ${FASTDEPLOY_DIR}" + +# check arm v7 & v8 c++ sdk +if [ ! -d "${BUILT_PACKAGE_DIR}" ]; then + echo "[ERROR] --- ${BUILT_PACKAGE_DIR} not exist, please build c++ sdk first!" + exit 0 +fi +if [ ! -d "${ARMV8_CXX_PACKAGE_NAME}" ]; then + echo "[ERROR] --- ${ARMV8_CXX_PACKAGE_NAME} not exist, please build c++ sdk first!" + exit 0 +fi +if [ ! -d "${ARMV7_CXX_PACKAGE_NAME}" ]; then + echo "[ERROR] --- ${ARMV7_CXX_PACKAGE_NAME} not exist, please build c++ sdk first!" + exit 0 +fi + +# remove old package +echo "[INFO] --- Packing ${CXX_PACKAGE_NAME} package ..." +if [ -d "${CXX_PACKAGE_NAME}" ]; then + rm -rf ${CXX_PACKAGE_NAME} + echo "[INFO] --- Removed old ${CXX_PACKAGE_NAME} done !" + if [ -f "${CXX_PACKAGE_NAME}.tgz" ]; then + rm ${CXX_PACKAGE_NAME}.tgz + echo "[INFO] --- Removed old ${CXX_PACKAGE_NAME} done !" + fi +fi + +# package latest c++ sdk +mkdir ${CXX_PACKAGE_NAME} +echo "[INFO] --- Collecting package contents ..." +cp -r ${ARMV7_CXX_PACKAGE_NAME}/* ${CXX_PACKAGE_NAME}/ +cp -r ${ARMV8_CXX_PACKAGE_NAME}/* ${CXX_PACKAGE_NAME}/ +if [ -d "${CXX_PACKAGE_NAME}/examples" ]; then + rm -rf ${CXX_PACKAGE_NAME}/examples +fi +echo "[INFO] --- Removed examples files ..." +echo "[INFO] --- Removing static .a files: " +static_files=$(find ${CXX_PACKAGE_NAME}/third_libs/install/ -name "*.a") +if [ ${#static_files[@]} -gt 10 ]; then + echo "${#static_files[@]}: ${static_files}" + rm $(find ${CXX_PACKAGE_NAME}/third_libs/install/ -name "*.a") +fi +echo "[INFO] --- Taring ${CXX_PACKAGE_NAME}.tgz package ..." +tar -zcvf ${CXX_PACKAGE_NAME}.tgz ${CXX_PACKAGE_NAME}/* >> ${BUILT_PACKAGE_DIR}/pkg.log 2>&1 +echo "[INFO] --- Package ${CXX_PACKAGE_NAME}.tgz done ! Package size info: " +du -sh ${BUILT_PACKAGE_DIR}/* | grep ${CXX_PACKAGE_PREFIX} + +# Usage: +# ./scripts/android/bundle_android_cpp_with_text_api_only.sh