[RFC] Redesigned CMake build infrastructure for C++ API #944
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Overview
This PR improves the CMake build system for the C++ API of flashinfer, making it more modular, easier to configure, and overall easier to integrate into downstream projects. The changes introduce a proper component-based installation for different usage scenarios for the C++ API, adds CMake-based dependency management, and generally offers a cleaner build organization.
Key Changes
Directory Structure Changes
The C++ sources, tests, and benchmarks are now reorganized inside a
libflashinfer
directory.BEFORE
flashinfer/
├── CMakeLists.txt
├── include/
│ └── flashinfer/
└── src/
AFTER
flashinfer/
├── CMakeLists.txt
├── cmake/
│ └── utils/
│ │ └── ConfigureTargets.cmake
│ ├── Config.cmake.in
│ ├── Dependencies.cmake
│ ├── Options.cmake
├── libflashinfer/
│ ├── CMakeLists.txt
│ ├── include/
│ │ └── flashinfer/
│ │ ├── attention/
│ │ └── distributed/
│ │ └── gemm/
│ ├── tests/
│ │ ├── CMakeLists.txt # Consistent test configuration
│ │ └── fp8/ # FP8-specific tests
│ ├── utils/
│ │ └── fp8/ # FP8 utility files
│ └── benchmarks/
│ ├── CMakeLists.txt # Standardized benchmark setup
│ └── fp8/ # FP8-specific benchmarks
High-level CMake changes
find_package(flashinfer)
in their CMake scripts.CMake configuration and build improvements
The C++ API is broken down into multiple components: Headers, Kernels, TVMBinding, Distributed.
Components can be configured and built separately
cmake .. -GNinja -DFLASHINFER_CUDA_ARCHITECTURES=80 -DFLASHINFER_BUILD_KERNELS=ON -DFLASHINFER_UNITTESTS=ON -DFLASHINFER_CXX_BENCHMARKS=ON -DFLASHINFER_CUTLASS_DIR=../3rdparty/cutlass -DCMAKE_INSTALL_PREFIX=~/devel/install
cmake --build . --target install
Added CMake targets to generate sources based on the same logic as in the current
setup.py
. Generated sources are now placed under theCMAKE_CURRENT_BINARY_DIR
cmake --build . --target generate_kernels
These changes are primarily meant to streamline the changes to add new CMake config options for a proposed HIP back end. However, it is foreseeable to build upon these changes to convert the build system to a fully unified CMake-based using
scikit-build
and use a single configuration system for both C++ and Python APIs. In my experience, using a unified system makes it easier to package and do integration testing.