mirror of
https://github.com/PaddlePaddle/FastDeploy.git
synced 2025-10-03 07:46:50 +08:00
[XPU] Add XPU option for benchmark example (#1287)
* [XPU] Add xpu option for benchmark example * [XPU] Add fp16 flags
This commit is contained in:
@@ -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;
|
||||||
}
|
}
|
||||||
|
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