diff --git a/benchmark/cpp/benchmark_ppyolov8.cc b/benchmark/cpp/benchmark_ppyolov8.cc index 4bd6e0df4..cff374200 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 c9a8e8d91..6ecf9b33e 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 000000000..e098883ea --- /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