Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[RFC] Redesigned CMake build infrastructure for C++ API #944

Open
wants to merge 8 commits into
base: main
Choose a base branch
from

Conversation

diptorupd
Copy link
Contributor

@diptorupd diptorupd commented Mar 14, 2025

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

  • Separated flashinfer CMake option definitions into distinct files for better organization
  • Created utility modules for configuring tests and benchmarks consistently
  • Consolidated dependency management in a single location
  • Added a flashinferconfig for downstream projects to be able to do 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

    • Ex1. Configuring the C++ API to build AOT kernels, C++ unit tests and benchmarks
        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
    • Ex2. Build various components as needed
        # Build the test_single_decode unit tests
        cmake --build . --target test_single_decode 
        # Build all unit tests (broken right now)
        cmake --build . --target build_tests
        # Build bench_single_decode 
        cmake --build . --target bench_single_decode 
        # Build all benchmarks (broken right now)
        cmake --build . --target build_benchmarks
    • Ex3. Install components
          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 the CMAKE_CURRENT_BINARY_DIR

    • Ex4. Install components
          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.

@diptorupd diptorupd force-pushed the feature/libflashinfer branch 2 times, most recently from 927f643 to 2fa7a24 Compare March 14, 2025 05:11
diptorupd added a commit to diptorupd/flashinfer that referenced this pull request Mar 20, 2025
@diptorupd diptorupd force-pushed the feature/libflashinfer branch 3 times, most recently from 5159f40 to 2335b2f Compare March 25, 2025 17:44
@diptorupd diptorupd changed the title [RFC] Feature/libflashinfer [RFC] Redesigned CMake build infrastructure for C++ API Mar 25, 2025
@diptorupd diptorupd force-pushed the feature/libflashinfer branch from 2335b2f to 10d67e1 Compare March 25, 2025 19:57
@diptorupd diptorupd marked this pull request as ready for review March 25, 2025 21:02
@diptorupd
Copy link
Contributor Author

diptorupd commented Mar 25, 2025

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant