Compilation Optimization
In inference service scenarios, compiling and installing Python with the BiSheng compiler can significantly enhance inference performance.
Currently, the link-time optimization (LTO) and profile-guided optimization (PGO) capabilities of the BiSheng compiler are used. For details, see BiSheng Compiler Optimization and Programming Guide.
Prerequisites
The BiSheng compiler has been installed, and environment variables have been configured. For details, see BiSheng Compiler User Guide.
Compiling and Installing Python
- Install the dependencies required for compiling Python.Debian, Ubuntu, veLinux:
1sudo apt-get install -y make cmake libsqlite3-dev libbz2-dev zlib1g-dev libssl-dev libffi-dev
openEuler, CentOS, Kylin, BCLinux, UOS V20, AntOS, AliOS, CTyunOS, CULinux, Tlinux, MTOS, vesselOS:1sudo yum install -y make cmake sqlite-devel bzip2-devel zlib-devel openssl-devel libffi-devel
- Configure environment variables and specify the BiSheng compiler for compilation.
1 2
export CC=clang export CXX=clang++
- Download the Python source package using wget. The following uses Python 3.7.5 as an example. Download the package to any directory in the installation environment.
1wget https://www.python.org/ftp/python/3.7.5/Python-3.7.5.tgz - Decompress the source package.
1tar -zxvf Python-3.7.5.tgz
- Use the BiSheng compiler to compile Python. Go to the decompressed folder and run the following configuration, compilation, and installation commands:
1 2 3
cd Python-3.7.5 ./configure --prefix=/usr/local/python3.7.5_bisheng --enable-loadable-sqlite-extensions --enable-shared --with-lto --enable-optimizations make -j32 && make install
- Configure the Python environment variables. The following uses the installation path /usr/local/python3.7.5_bisheng as an example. Replace it with the actual Python installation path.
1 2
export LD_LIBRARY_PATH=/usr/local/python3.7.5_bisheng/lib:$LD_LIBRARY_PATH export PATH=/usr/local/python3.7.5_bisheng/bin:$PATH
Parent topic: High-Performance Configuration