Installing using conda

PIQP can be directly installed via anaconda/miniconda:

conda install -c conda-forge piqp

Building and Installing from Source

To build PIQP it is required to have CMake, Eigen 3.3.4+ and a compatible compiler like GCC, Clang, or Visual Studio with C++ extensions on Windows installed. CMake and a compatible compiler should already be installed on most systems. The (optional) KKT solver backend sparse_multistage needs the additional dependency Blasfeo.

Installing Eigen

on macOS via Homebrew

brew install eigen

on Ubuntu

sudo apt install libeigen3-dev

on Windows via Chocolatey

choco install eigen

via conda

conda install -c conda-forge eigen

building from source

# clone Eigen
git clone https://gitlab.com/libeigen/eigen.git eigen
cd eigen
git checkout 3.4.0

# build Eigen
mkdir build
cd build
cmake .. -DCMAKE_BUILD_TYPE=Release
cmake --build .

# install Eigen
cmake --install .

Installing Blasfeo (optional)

via conda

conda install -c conda-forge blasfeo

Blasfeo installed via conda is a dynamic library and not static. Additionally, it is never build with the X64_INTEL_SKYLAKE_X target. This means if you care about static linkage or running an x86-64 CPU with AVX512 support, you might lose some performance, and building from source is recommended.

building from source (unix only)

# clone Blasfeo
git clone https://github.com/giaf/blasfeo.git blasfeo
cd blasfeo

# build Blasfeo
mkdir build
cd build
# -DTARGET=X64_INTEL_SKYLAKE_X    on x86_64 CPUs with AVX512 support (Intel Skylake / AMD Zen5 or later)
# -DTARGET=X64_INTEL_HASWELL      on x86_64 CPUs with AVX2 support (Intel Haswell / AMD Zen or later)
# -DTARGET=X64_INTEL_SANDY_BRIDGE on x86_64 CPUs with AVX support (Intel Sandy-Bridge or later)
# -DTARGET=X64_INTEL_CORE         on x86_64 CPUs with SSE3 support (Intel Core or later)
# -DTARGET=X64_AMD_BULLDOZER      on x86_64 CPUs with AVX and FMA support (AMD Bulldozer or later)
# -DTARGET=ARMV8A_APPLE_M1        on ARMv8A CPUs optimized for Apple M1 or later
# -DTARGET=ARMV8A_ARM_CORTEX_A76  on ARMv8A CPUs optimized for ARM Cortex A76 (e.g. Raspberry Pi 5) 
# -DTARGET=ARMV8A_ARM_CORTEX_A73  on ARMv8A CPUs optimized for ARM Cortex A73
# for more targets see https://github.com/giaf/blasfeo/blob/master/CMakeLists.txt#L55
cmake .. -DCMAKE_BUILD_TYPE=Release -DTARGET=X64_INTEL_HASWELL
cmake --build .

# install Blasfeo
cmake --install .

Building and Installing PIQP

  • Clone PIQP from Github
    git clone https://github.com/PREDICT-EPFL/piqp.git
    
  • Build PIQP in a build folder
    cd piqp
    mkdir build
    cd build
    # add -DBUILD_WITH_BLASFEO=ON to build with Blasfeo (needed for sparse_multistage backend)
    cmake .. -DCMAKE_CXX_FLAGS="-march=native" -DBUILD_TESTS=OFF -DBUILD_BENCHMARKS=OFF
    cmake --build . --config Release
    

    Note that by setting -march=native, we allow the compiler to optimize for the full available instruction set on the machine compiling the code.

When compiling with -march=native and you are on a modern x86 architecture (which you are very very likely are), Eigen will align vectors to 32 (AVX2) or 64 (AVX512) bytes. Hence, when consuming the precompiled PIQP library, your target needs to be built with the same architecture flags (e.g. -march=native) otherwise there will be ABI incompatibilities with Eigen. Alternatively, by setting the CMake flag -DBUILD_WITH_EIGEN_MAX_ALIGN_BYTES=ON, PIQP will be built with EIGEN_MAX_ALIGN_BYTES=64 ensuring maximal Eigen compatibility and export it as well to the linked target. Note that this might conflict with other libraries and has to be used cautiously. For more information see the Alignment section in the Eigen docs.

  • Install libraries and header files (requires CMake 3.15+)
    cmake --install . --config Release
    

    This will install the C++ and C headers and shared libraries.

If you want to build static libraries instead, you can pass -DBUILD_SHARED_LIBS=OFF when configuring cmake.

Using PIQP in CMake Projects

PIQP has first class support for CMake project. The C++ library is header-only. For the C interface we provide a shared as well as a static library which can be linked against.

# Find PIQP package
find_package(piqp REQUIRED)

# PIQP requires at least C++14
set(CMAKE_CXX_STANDARD 14)

# Link the PIQP C++ library with precompiled template instantiations
target_link_libraries(yourTarget PRIVATE piqp::piqp)

# Link the PIQP C++ header-only library
target_link_libraries(yourTarget PRIVATE piqp::piqp_header_only)

# Link the PIQP C library
target_link_libraries(yourTarget PRIVATE piqp::piqp_c)