mirror of
https://github.com/PaddlePaddle/FastDeploy.git
synced 2025-10-23 16:44:22 +08:00
Merge branch 'develop' into encrypt_model
This commit is contained in:
@@ -122,4 +122,4 @@ int main(int argc, char* argv[]) {
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@@ -20,8 +20,8 @@
|
|||||||
DEFINE_string(model, "", "Directory of the inference model.");
|
DEFINE_string(model, "", "Directory of the inference model.");
|
||||||
DEFINE_string(image, "", "Path of the image file.");
|
DEFINE_string(image, "", "Path of the image file.");
|
||||||
DEFINE_string(device, "cpu",
|
DEFINE_string(device, "cpu",
|
||||||
"Type of inference device, support 'cpu' or 'gpu'.");
|
"Type of inference device, support 'cpu/gpu/xpu'.");
|
||||||
DEFINE_int32(device_id, 0, "device(gpu) id.");
|
DEFINE_int32(device_id, 0, "device(gpu/xpu/...) id.");
|
||||||
DEFINE_int32(warmup, 200, "Number of warmup for profiling.");
|
DEFINE_int32(warmup, 200, "Number of warmup for profiling.");
|
||||||
DEFINE_int32(repeat, 1000, "Number of repeats for profiling.");
|
DEFINE_int32(repeat, 1000, "Number of repeats for profiling.");
|
||||||
DEFINE_string(profile_mode, "runtime", "runtime or end2end.");
|
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() {
|
void PrintUsage() {
|
||||||
std::cout << "Usage: infer_demo --model model_path --image img_path --device "
|
std::cout << "Usage: infer_demo --model model_path --image img_path --device "
|
||||||
"[cpu|gpu] --backend "
|
"[cpu|gpu|xpu] --backend "
|
||||||
"[default|ort|paddle|ov|trt|paddle_trt] "
|
"[default|ort|paddle|ov|trt|paddle_trt|lite] "
|
||||||
"--use_fp16 false"
|
"--use_fp16 false"
|
||||||
<< std::endl;
|
<< std::endl;
|
||||||
std::cout << "Default value of device: cpu" << std::endl;
|
std::cout << "Default value of device: cpu" << std::endl;
|
||||||
@@ -52,7 +52,7 @@ void PrintUsage() {
|
|||||||
|
|
||||||
bool CreateRuntimeOption(fastdeploy::RuntimeOption* option) {
|
bool CreateRuntimeOption(fastdeploy::RuntimeOption* option) {
|
||||||
if (FLAGS_device == "gpu") {
|
if (FLAGS_device == "gpu") {
|
||||||
option->UseGpu();
|
option->UseGpu(FLAGS_device_id);
|
||||||
if (FLAGS_backend == "ort") {
|
if (FLAGS_backend == "ort") {
|
||||||
option->UseOrtBackend();
|
option->UseOrtBackend();
|
||||||
} else if (FLAGS_backend == "paddle") {
|
} else if (FLAGS_backend == "paddle") {
|
||||||
@@ -94,8 +94,27 @@ bool CreateRuntimeOption(fastdeploy::RuntimeOption* option) {
|
|||||||
<< FLAGS_backend << " is not supported." << std::endl;
|
<< FLAGS_backend << " is not supported." << std::endl;
|
||||||
return false;
|
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 {
|
} 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;
|
<< " is not supported." << std::endl;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@@ -10,7 +10,7 @@
|
|||||||
- [IPU部署环境编译安装](cn/build_and_install/ipu.md)
|
- [IPU部署环境编译安装](cn/build_and_install/ipu.md)
|
||||||
- [昆仑芯XPU部署环境编译安装](cn/build_and_install/kunlunxin.md)
|
- [昆仑芯XPU部署环境编译安装](cn/build_and_install/kunlunxin.md)
|
||||||
- [瑞芯微RV1126部署环境编译安装](cn/build_and_install/rv1126.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)
|
- [晶晨A311D部署环境编译安装](cn/build_and_install/a311d.md)
|
||||||
- [华为昇腾部署环境编译安装](cn/build_and_install/huawei_ascend.md)
|
- [华为昇腾部署环境编译安装](cn/build_and_install/huawei_ascend.md)
|
||||||
- [Jetson部署环境编译安装](cn/build_and_install/jetson.md)
|
- [Jetson部署环境编译安装](cn/build_and_install/jetson.md)
|
||||||
|
@@ -51,8 +51,9 @@ void LiteBackend::ConfigureCpu(const LiteBackendOption& option) {
|
|||||||
|
|
||||||
void LiteBackend::ConfigureKunlunXin(const LiteBackendOption& option) {
|
void LiteBackend::ConfigureKunlunXin(const LiteBackendOption& option) {
|
||||||
std::vector<paddle::lite_api::Place> valid_places;
|
std::vector<paddle::lite_api::Place> valid_places;
|
||||||
valid_places.push_back(
|
// TODO(yeliang): Placing kInt8 first may cause accuracy issues of some model
|
||||||
paddle::lite_api::Place{TARGET(kXPU), PRECISION(kInt8)});
|
// valid_places.push_back(
|
||||||
|
// paddle::lite_api::Place{TARGET(kXPU), PRECISION(kInt8)});
|
||||||
if (option.enable_fp16) {
|
if (option.enable_fp16) {
|
||||||
valid_places.push_back(
|
valid_places.push_back(
|
||||||
paddle::lite_api::Place{TARGET(kXPU), PRECISION(kFP16)});
|
paddle::lite_api::Place{TARGET(kXPU), PRECISION(kFP16)});
|
||||||
|
@@ -44,6 +44,10 @@ void PaddleBackend::BuildOption(const PaddleBackendOption& option) {
|
|||||||
"file will save to the directory where paddle model saved."
|
"file will save to the directory where paddle model saved."
|
||||||
<< std::endl;
|
<< std::endl;
|
||||||
use_static = true;
|
use_static = true;
|
||||||
|
std::string opt_cache_dir =
|
||||||
|
GetDirFromPath(option.trt_option.serialize_file);
|
||||||
|
|
||||||
|
config_.SetOptimCacheDir(opt_cache_dir);
|
||||||
}
|
}
|
||||||
config_.EnableTensorRtEngine(option.trt_option.max_workspace_size,
|
config_.EnableTensorRtEngine(option.trt_option.max_workspace_size,
|
||||||
option.trt_option.max_batch_size, 3,
|
option.trt_option.max_batch_size, 3,
|
||||||
|
61
scripts/android/bundle_android_cpp_with_text_api_only.sh
Executable file
61
scripts/android/bundle_android_cpp_with_text_api_only.sh
Executable file
@@ -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
|
79
scripts/linux/build_linux_x86_64_cpp_xpu_with_benchmark.sh
Executable file
79
scripts/linux/build_linux_x86_64_cpp_xpu_with_benchmark.sh
Executable file
@@ -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
|
Reference in New Issue
Block a user