Source Code Compilation and Build
Build Paddle Inference from the PaddlePaddle source code tree. After the build is complete, configure the GPU-oriented inference path and complete the compilation.
- Obtain the PaddlePaddle 3.3.1 source code.Build Paddle Inference from the PaddlePaddle source code tree.
1 2 3
git clone --branch v3.3.1 --depth 1 https://github.com/PaddlePaddle/Paddle.git cd Paddle git submodule sync --recursive
If OpenVINO is not enabled, you can skip the third_party/openvino submodule to avoid downloading unused dependencies.
1 2 3
git config -f .gitmodules --get-regexp path | awk '{print $2}' \ | grep -v '^third_party/openvino$' \ | xargs -r git submodule update --init --recursive --
- Configure CMake.
The following configuration is for the GPU inference path and generates CUDA code based on the single Ampere architecture.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
mkdir -p build-inference-cuda13 cd build-inference-cuda13 cmake .. \ -GNinja \ -DCMAKE_BUILD_TYPE=Release \ -DWITH_GPU=ON \ -DWITH_ARM=ON \ -DWITH_TESTING=OFF \ -DWITH_DISTRIBUTE=OFF \ -DWITH_NCCL=OFF \ -DWITH_OPENVINO=OFF \ -DWITH_CUDNN=ON \ -DWITH_CUDNN_FRONTEND=OFF \ -DWITH_PYTHON=OFF \ -DON_INFER=ON \ -DWITH_INFERENCE_API_TEST=OFF \ -DWITH_TP_CACHE=ON \ -DTHIRD_PARTY_CACHE_PATH="$(pwd)/third_party_cache" \ -DCUDA_ARCH_NAME=Ampere \ -DCMAKE_CUDA_FLAGS='-DEIGEN_DONT_VECTORIZE -UPADDLE_WITH_SLEEF'
Table 1 Key parameter description Parameter
Description
-DPY_VERSION=3.11
Generate a Python 3.11 ABI wheel.
-DWITH_GPU=ON
Build PaddlePaddle for the GPU version.
-DWITH_ARM=ON
Enable the Arm architecture for building.
-DWITH_TESTING=OFF
Disable the construction of test targets to reduce the construction time and dependency scale.
-DWITH_DISTRIBUTE=OFF
Disable the distributed training capability.
-DWITH_NCCL=OFF
Disable NCCL. Multi-device communication is not included in the minimum verification path.
-DWITH_OPENVINO=OFF
Disable the construction of the OpenVINO backend.
-DCUDA_ARCH_NAME=Ampere
Generate CUDA code for the A100/Ampere architecture.
-DCMAKE_CUDA_FLAGS=...
Used by the CUDA compilation unit to prevent the NVCC from parsing the Arm NEON header file in AArch64.
- Perform the compilation.
1 2 3
export MAX_JOBS=8 export CMAKE_BUILD_PARALLEL_LEVEL=8 ninja -j8
You are advised to use 8 concurrent jobs to balance the build speed and system load.
After the build is complete, the product directories are build-inference-cuda13/paddle_inference_install_dir/ and build-inference-cuda13/paddle_inference_c_install_dir/.
- Example of the C++ API product:
1 2 3 4
paddle_inference_install_dir/paddle/include/paddle_inference_api.h paddle_inference_install_dir/paddle/lib/libpaddle_inference.so paddle_inference_install_dir/paddle/lib/libpaddle_inference.a paddle_inference_install_dir/version.txt
- Example of the C API product:
1 2 3
paddle_inference_c_install_dir/paddle/include/pd_inference_api.h paddle_inference_c_install_dir/paddle/lib/libpaddle_inference_c.so paddle_inference_c_install_dir/paddle/lib/libpaddle_inference_c.a
- Example of the C++ API product: