|
| 1 | +# === Required Dependencies for Core Functionality === |
| 2 | +find_package(CUDAToolkit REQUIRED) |
| 3 | +find_package(Python3 REQUIRED) |
| 4 | +if(NOT Python3_FOUND) |
| 5 | + message( |
| 6 | + FATAL_ERROR |
| 7 | + "Python3 not found it is required to generate the kernel sources.") |
| 8 | +endif() |
| 9 | + |
| 10 | +find_package(Thrust REQUIRED) |
| 11 | + |
| 12 | +# === Test Dependencies === |
| 13 | +if(FLASHINFER_UNITTESTS) |
| 14 | + include(FetchContent) |
| 15 | + |
| 16 | + # Google Test for unit testing |
| 17 | + FetchContent_Declare( |
| 18 | + googletest |
| 19 | + GIT_REPOSITORY https://github.com/google/googletest.git |
| 20 | + GIT_TAG 6910c9d9165801d8827d628cb72eb7ea9dd538c5 # release-1.16.0 |
| 21 | + FIND_PACKAGE_ARGS NAMES GTest) |
| 22 | + FetchContent_MakeAvailable(googletest) |
| 23 | +endif() |
| 24 | + |
| 25 | +# === Benchmark Dependencies === |
| 26 | +if(FLASHINFER_CXX_BENCHMARKS) |
| 27 | + include(FetchContent) |
| 28 | + |
| 29 | + # NVBench for GPU benchmarking |
| 30 | + FetchContent_Declare( |
| 31 | + nvbench |
| 32 | + GIT_REPOSITORY https://github.com/NVIDIA/nvbench.git |
| 33 | + GIT_TAG c03033b50e46748207b27685b1cdfcbe4a2fec59) |
| 34 | + FetchContent_MakeAvailable(nvbench) |
| 35 | +endif() |
| 36 | + |
| 37 | +# === Boost Dependency for FP16 QK Reductions === |
| 38 | +if(FLASHINFER_GEN_USE_FP16_QK_REDUCTIONS) |
| 39 | + include(FetchContent) |
| 40 | + set(BOOST_ENABLE_CMAKE ON) |
| 41 | + FetchContent_Declare(boost_math |
| 42 | + GIT_REPOSITORY https://github.com/boostorg/math.git) |
| 43 | + FetchContent_MakeAvailable(boost_math) |
| 44 | + |
| 45 | + set(USE_FP16_QK_REDUCTIONS "true") |
| 46 | + message(STATUS "USE_FP16_QK_REDUCTIONS=${USE_FP16_QK_REDUCTIONS}") |
| 47 | +else() |
| 48 | + set(USE_FP16_QK_REDUCTIONS "false") |
| 49 | + message(STATUS "USE_FP16_QK_REDUCTIONS=${USE_FP16_QK_REDUCTIONS}") |
| 50 | +endif() |
| 51 | + |
| 52 | +# === Distributed component dependencies === |
| 53 | +if(FLASHINFER_DISTRIBUTED OR FLASHINFER_DIST_UNITTESTS) |
| 54 | + include(FetchContent) |
| 55 | + FetchContent_Declare( |
| 56 | + mscclpp |
| 57 | + GIT_REPOSITORY https://github.com/microsoft/mscclpp.git |
| 58 | + GIT_TAG 11e62024d3eb190e005b4689f8c8443d91a6c82e) |
| 59 | + FetchContent_MakeAvailable(mscclpp) |
| 60 | + |
| 61 | + # Create alias for distributed component |
| 62 | + if(NOT TARGET flashinfer::mscclpp) |
| 63 | + add_library(flashinfer::mscclpp ALIAS mscclpp) |
| 64 | + endif() |
| 65 | + |
| 66 | + # Fetch spdlog for distributed tests (header-only usage) |
| 67 | + FetchContent_Declare( |
| 68 | + spdlog |
| 69 | + GIT_REPOSITORY https://github.com/gabime/spdlog.git |
| 70 | + GIT_TAG f355b3d58f7067eee1706ff3c801c2361011f3d5 # release-1.15.1 |
| 71 | + FIND_PACKAGE_ARGS NAMES spdlog) |
| 72 | + |
| 73 | + # Use Populate instead of MakeAvailable since we only need the headers |
| 74 | + FetchContent_Populate(spdlog) |
| 75 | + |
| 76 | + # Set the include directory for later use |
| 77 | + set(SPDLOG_INCLUDE_DIR "${spdlog_SOURCE_DIR}/include") |
| 78 | + message(STATUS "Using spdlog from ${SPDLOG_INCLUDE_DIR}") |
| 79 | + |
| 80 | + find_package(MPI REQUIRED) |
| 81 | +endif() |
| 82 | + |
| 83 | +# === FP8 Dependencies === |
| 84 | +if(FLASHINFER_FP8_TESTS OR FLASHINFER_FP8_BENCHMARKS) |
| 85 | + # Verify CUDA architecture is SM90 or higher |
| 86 | + if(NOT CMAKE_CUDA_ARCHITECTURES STREQUAL "90" |
| 87 | + AND NOT CMAKE_CUDA_ARCHITECTURES STREQUAL "90a") |
| 88 | + message( |
| 89 | + FATAL_ERROR "FP8 tests/benchmarks require SM90 or higher architecture") |
| 90 | + endif() |
| 91 | + |
| 92 | + # Find PyTorch which is required for FP8 features |
| 93 | + find_package(Torch REQUIRED) |
| 94 | + if(NOT Torch_FOUND) |
| 95 | + message( |
| 96 | + FATAL_ERROR "PyTorch is required for FP8 tests/benchmarks but not found") |
| 97 | + endif() |
| 98 | + message(STATUS "Found PyTorch: ${TORCH_INCLUDE_DIRS}") |
| 99 | + |
| 100 | + # Fetch Flash Attention repository with specific commit |
| 101 | + include(FetchContent) |
| 102 | + FetchContent_Declare( |
| 103 | + flash_attention |
| 104 | + GIT_REPOSITORY https://github.com/Dao-AILab/flash-attention.git |
| 105 | + GIT_TAG 29ef580560761838c0e9e82bc0e98d04ba75f949) |
| 106 | + FetchContent_Populate(flash_attention) |
| 107 | + |
| 108 | + # Set Flash Attention 3 include directory |
| 109 | + set(FA3_INCLUDE_DIR "${flash_attention_SOURCE_DIR}/csrc/flash_attn/hopper") |
| 110 | + message(STATUS "Flash Attention 3 source directory: ${FA3_INCLUDE_DIR}") |
| 111 | + |
| 112 | + # Compile Flash Attention 3 kernel library |
| 113 | + file(GLOB FA3_IMPL_FILES "${FA3_INCLUDE_DIR}/flash_fwd_*.cu") |
| 114 | +endif() |
| 115 | + |
| 116 | +# === TVM Binding dependencies === |
| 117 | +if(FLASHINFER_TVM_BINDING) |
| 118 | + # Resolve TVM source directory |
| 119 | + if(NOT FLASHINFER_TVM_SOURCE_DIR STREQUAL "") |
| 120 | + set(TVM_SOURCE_DIR_SET ${FLASHINFER_TVM_SOURCE_DIR}) |
| 121 | + elseif(DEFINED ENV{TVM_SOURCE_DIR}) |
| 122 | + set(TVM_SOURCE_DIR_SET $ENV{TVM_SOURCE_DIR}) |
| 123 | + elseif(DEFINED ENV{TVM_HOME}) |
| 124 | + set(TVM_SOURCE_DIR_SET $ENV{TVM_HOME}) |
| 125 | + else() |
| 126 | + message( |
| 127 | + FATAL_ERROR |
| 128 | + "TVM source directory not found. Set FLASHINFER_TVM_SOURCE_DIR.") |
| 129 | + endif() |
| 130 | +endif() |
| 131 | + |
| 132 | +# === CUTLASS Configuration === |
| 133 | +if(FLASHINFER_CUTLASS_DIR) |
| 134 | + list(APPEND CMAKE_PREFIX_PATH ${FLASHINFER_CUTLASS_DIR}) |
| 135 | +endif() |
| 136 | + |
| 137 | +if(FLASHINFER_CUTLASS_DIR) |
| 138 | + # Add CUTLASS include directories directly |
| 139 | + include_directories(${FLASHINFER_CUTLASS_DIR}/include) |
| 140 | + include_directories(${FLASHINFER_CUTLASS_DIR}/tools/util/include) |
| 141 | + |
| 142 | + message(STATUS "Using CUTLASS from ${FLASHINFER_CUTLASS_DIR}") |
| 143 | +else() |
| 144 | + message( |
| 145 | + FATAL_ERROR "FLASHINFER_CUTLASS_DIR must be set to the path of CUTLASS") |
| 146 | +endif() |
0 commit comments