Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ set(CMAKE_SKIP_INSTALL_RPATH FALSE)
# Compiler flags - defined as lists for cleaner management
set(WARNING_FLAGS
"-Wall"
Copy link

Copilot AI Oct 3, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removing -Wextra reduces compiler warning coverage. This change appears unrelated to the HIP CMake infrastructure update and should be justified or reverted.

Suggested change
"-Wall"
"-Wall"
"-Wextra"

Copilot uses AI. Check for mistakes.
"-Wextra"
"-Winit-self"
"-Wno-switch-bool"
"-Wunused-function"
Expand Down Expand Up @@ -232,6 +231,10 @@ if(FLASHINFER_ENABLE_HIP)

endif()

if(FLASHINFER_UNITTESTS)
enable_testing()
endif()

# Add library subdirectories
add_subdirectory(libflashinfer)

Expand Down
12 changes: 3 additions & 9 deletions cmake/Dependencies.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,9 @@ endif()

# === Test Dependencies ===
if(FLASHINFER_UNITTESTS)
include(FetchContent)

# Google Test for unit testing
FetchContent_Declare(
googletest
GIT_REPOSITORY https://github.com/google/googletest.git
GIT_TAG 6910c9d9165801d8827d628cb72eb7ea9dd538c5 # release-1.16.0
FIND_PACKAGE_ARGS NAMES GTest)
FetchContent_MakeAvailable(googletest)
find_package(GTest REQUIRED)
include(GoogleTest)
message(STATUS "Found GoogleTest: ${GTEST_INCLUDE_DIRS}")
endif()

# === Benchmark Dependencies ===
Expand Down
36 changes: 19 additions & 17 deletions cmake/Options.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,10 @@ flashinfer_option(FLASHINFER_PY_LIMITED_API "Use Python's limited API for better
flashinfer_option(FLASHINFER_MIN_PYTHON_ABI "Minimum Python ABI version for limited API compatibility" "3.9")

# === CUDA OPTIONS ===
flashinfer_option(FLASHINFER_ENABLE_CUDA "Enable NVIDIA CUDA backend" ON)
flashinfer_option(FLASHINFER_ENABLE_CUDA "Enable NVIDIA CUDA backend" OFF)

# === HIP/ROCm OPTIONS ===
flashinfer_option(FLASHINFER_ENABLE_HIP "Enable AMD HIP/ROCm backend" OFF)
flashinfer_option(FLASHINFER_ENABLE_HIP "Enable AMD HIP/ROCm backend" ON)
Copy link

Copilot AI Oct 3, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changing the default HIP backend from OFF to ON may break existing builds that don't have HIP dependencies installed. Consider keeping the original default or documenting this breaking change.

Suggested change
flashinfer_option(FLASHINFER_ENABLE_HIP "Enable AMD HIP/ROCm backend" ON)
flashinfer_option(FLASHINFER_ENABLE_HIP "Enable AMD HIP/ROCm backend" OFF)

Copilot uses AI. Check for mistakes.
flashinfer_option(FLASHINFER_HIP_ARCHITECTURES "AMD GPU architectures to target" "")

# === AUTO-DERIVED OPTIONS ===
Expand Down Expand Up @@ -112,22 +112,24 @@ if(FLASHINFER_ENABLE_HIP AND FLASHINFER_ENABLE_CUDA)
endif()

# Handle CUDA architectures
if(FLASHINFER_CUDA_ARCHITECTURES)
message(STATUS "CMAKE_CUDA_ARCHITECTURES set to ${FLASHINFER_CUDA_ARCHITECTURES}.")
else()
# No user-provided architectures, try to detect the CUDA archs based on where
# the project is being built
set(detected_archs "")
detect_cuda_architectures(detected_archs)
if(detected_archs)
set(FLASHINFER_CUDA_ARCHITECTURES ${detected_archs} CACHE STRING
"CUDA architectures" FORCE)
message(STATUS "Setting FLASHINFER_CUDA_ARCHITECTURES to detected values: ${FLASHINFER_CUDA_ARCHITECTURES}")
if(FLASHINFER_ENABLE_CUDA)
if(FLASHINFER_CUDA_ARCHITECTURES)
message(STATUS "CMAKE_CUDA_ARCHITECTURES set to ${FLASHINFER_CUDA_ARCHITECTURES}.")
else()
# No architectures detected, use safe defaults
set(FLASHINFER_CUDA_ARCHITECTURES "75;80;86" CACHE STRING
"CUDA architectures to compile for" FORCE)
message(STATUS "No architectures detected, using defaults: ${FLASHINFER_CUDA_ARCHITECTURES}")
# No user-provided architectures, try to detect the CUDA archs based on where
# the project is being built
set(detected_archs "")
detect_cuda_architectures(detected_archs)
if(detected_archs)
set(FLASHINFER_CUDA_ARCHITECTURES ${detected_archs} CACHE STRING
"CUDA architectures" FORCE)
message(STATUS "Setting FLASHINFER_CUDA_ARCHITECTURES to detected values: ${FLASHINFER_CUDA_ARCHITECTURES}")
else()
# No architectures detected, use safe defaults
set(FLASHINFER_CUDA_ARCHITECTURES "75;80;86" CACHE STRING
"CUDA architectures to compile for" FORCE)
message(STATUS "No architectures detected, using defaults: ${FLASHINFER_CUDA_ARCHITECTURES}")
endif()
endif()
endif()

Expand Down
14 changes: 6 additions & 8 deletions cmake/utils/ConfigureTargets.cmake
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# cmake-format: off
# Common configuration function for tests and benchmarks
function(configure_flashinfer_target)
set(options IS_GTEST IS_BENCHMARK)
set(options IS_GTEST IS_BENCHMARK IS_HIP)
set(oneValueArgs TARGET_NAME)
set(multiValueArgs SOURCES LINK_LIBS COMPILE_FLAGS INCLUDE_DIRS)

Expand All @@ -27,6 +27,10 @@ function(configure_flashinfer_target)
# Create executable target
add_executable(${arg_TARGET_NAME} EXCLUDE_FROM_ALL ${arg_SOURCES})

if(arg_IS_HIP)
set_source_files_properties(${arg_SOURCES} PROPERTIES LANGUAGE HIP)
endif()

# Add all include directories
target_include_directories(
${arg_TARGET_NAME}
Expand All @@ -40,9 +44,6 @@ function(configure_flashinfer_target)
target_include_directories(${arg_TARGET_NAME} PRIVATE ${extra_include_dir})
endforeach()

# Add dispatch_inc dependency
add_dependencies(${arg_TARGET_NAME} dispatch_inc)

# Add benchmark-specific library for benchmarks
if(arg_IS_BENCHMARK)
target_link_libraries(${arg_TARGET_NAME} PRIVATE nvbench::main)
Expand All @@ -59,10 +60,7 @@ function(configure_flashinfer_target)

# Add Google Test libraries if required
if(arg_IS_GTEST)
target_include_directories(${arg_TARGET_NAME} PRIVATE
${gtest_SOURCE_DIR}/include
${gtest_SOURCE_DIR})
target_link_libraries(${arg_TARGET_NAME} PRIVATE gtest gtest_main)
target_link_libraries(${arg_TARGET_NAME} PRIVATE GTest::gtest GTest::gtest_main Threads::Threads)
endif()

# Register with CTest if it's a test
Expand Down
9 changes: 4 additions & 5 deletions libflashinfer/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,9 @@ message(STATUS "HEAD_DIMS_SM90=${HEAD_DIMS_SM90}")
# the DECODE_KERNELS_SRCS, PREFILL_KERNELS_SRCS, and DISPATCH_INC_FILE
# variables.
include(ConfigureKernelGeneration)
flashinfer_configure_kernel_generation()
if(FLASHINFER_BUILD_KERNELS)
flashinfer_configure_kernel_generation()
endif()
# ---------------------------------------------------------------------------#

# Set the install path for the libflashinfer headers based on whether the build
Expand Down Expand Up @@ -97,10 +99,7 @@ flashinfer_generate_config_header(
# ---------------------------------------------------------------------------#

# Build decode_kernels and prefill_kernels if needed
if(FLASHINFER_BUILD_KERNELS
OR FLASHINFER_UNITTESTS
OR FLASHINFER_CXX_BENCHMARKS)

if(FLASHINFER_BUILD_KERNELS)
set(FLASHINFER_KERNEL_TARGETS "")

add_library(decode_kernels STATIC ${DECODE_KERNELS_SRCS})
Expand Down
165 changes: 16 additions & 149 deletions libflashinfer/tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,151 +4,25 @@ set(ALL_TEST_TARGETS "")
# Include centralized config utilities
include(ConfigureTargets)

# Include GoogleTest to enable test discovery
include(GoogleTest)
find_package(Threads REQUIRED)

# cmake-format: off
# === Core Tests Configuration ===

# Single and batch decode tests
configure_flashinfer_target(
TARGET_NAME test_single_decode
SOURCES "test_single_decode.cu"
LINK_LIBS "decode_kernels"
IS_GTEST ON
)

configure_flashinfer_target(
TARGET_NAME test_batch_decode
SOURCES "test_batch_decode.cu"
LINK_LIBS "decode_kernels"
IS_GTEST ON
)

# Single and batch prefill tests
configure_flashinfer_target(
TARGET_NAME test_single_prefill
SOURCES "test_single_prefill.cu"
LINK_LIBS "prefill_kernels"
IS_GTEST ON
)

configure_flashinfer_target(
TARGET_NAME test_batch_prefill
SOURCES "test_batch_prefill.cu"
LINK_LIBS "prefill_kernels"
IS_GTEST ON
)

# Other core tests
configure_flashinfer_target(
TARGET_NAME test_page
SOURCES "test_page.cu"
IS_GTEST ON
)

configure_flashinfer_target(
TARGET_NAME test_cascade
SOURCES "test_cascade.cu"
LINK_LIBS "decode_kernels;prefill_kernels"
IS_GTEST ON
)

configure_flashinfer_target(
TARGET_NAME test_sampling
SOURCES "test_sampling.cu"
IS_GTEST ON
)

configure_flashinfer_target(
TARGET_NAME test_norm
SOURCES "test_norm.cu"
IS_GTEST ON
)

configure_flashinfer_target(
TARGET_NAME test_fastdiv
SOURCES "test_fastdiv.cu"
IS_GTEST ON
)

configure_flashinfer_target(
TARGET_NAME test_fast_dequant
SOURCES "test_fast_dequant.cu"
IS_GTEST ON
)

# === Distributed Test Configuration ===
if(FLASHINFER_DIST_UNITTESTS)
set(DIST_INCLUDE_DIRS
"${FLASHINFER_INCLUDE_DIR}"
"${mscclpp_SOURCE_DIR}/include"
)

# Add spdlog include directory if available
if(DEFINED SPDLOG_INCLUDE_DIR)
list(APPEND DIST_INCLUDE_DIRS "${SPDLOG_INCLUDE_DIR}")
elseif(TARGET spdlog::spdlog)
# If found via find_package
get_target_property(SPDLOG_INCLUDE_DIRS spdlog::spdlog INTERFACE_INCLUDE_DIRECTORIES)
list(APPEND DIST_INCLUDE_DIRS "${SPDLOG_INCLUDE_DIRS}")
endif()

configure_flashinfer_target(
TARGET_NAME test_sum_all_reduce
SOURCES "test_sum_all_reduce.cu"
LINK_LIBS "MPI::MPI_CXX;flashinfer::mscclpp"
COMPILE_FLAGS "-DENABLE_MPI"
INCLUDE_DIRS "${DIST_INCLUDE_DIRS}"
IS_GTEST OFF
)

configure_flashinfer_target(
TARGET_NAME test_attn_all_reduce
SOURCES "test_attn_all_reduce.cu"
LINK_LIBS "MPI::MPI_CXX;flashinfer::mscclpp"
COMPILE_FLAGS "-DENABLE_MPI"
IS_GTEST OFF
)
endif()

# === FP8 Test Configuration ===
if(FLASHINFER_FP8_TESTS)
# Set path to FP8 utilities
set(FP8_UTILS_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../utils/fp8)

# Define FP8-specific CUDA compile flags - one per line for readability
set(FP8_CUDA_FLAGS_LIST
--expt-extended-lambda
--use_fast_math
--generate-code=arch=compute_90a,code=sm_90a
)

# Combine the list into a generator expression for CUDA language only
string(JOIN ";" FP8_CUDA_FLAGS_JOINED "${FP8_CUDA_FLAGS_LIST}")
set(FP8_CUDA_FLAGS "$<$<COMPILE_LANGUAGE:CUDA>:${FP8_CUDA_FLAGS_JOINED}>")

# Define FP8-specific include directories
set(FP8_INCLUDE_DIRS
"${TORCH_INCLUDE_DIRS}"
"${CUDA_INCLUDE_DIRS}"
"${Python3_INCLUDE_DIRS}"
"${FA3_INCLUDE_DIR}"
"${CUTLASS_INCLUDE_DIRS}"
"${FP8_UTILS_DIR}"
)

# Add the FP8 test with improved readability
configure_flashinfer_target(
TARGET_NAME test_single_prefill_fa3_sm90
SOURCES "fp8/test_single_prefill_fa3_sm90.cu"
LINK_LIBS "FA3_LIB;${TORCH_LIBRARIES}"
COMPILE_FLAGS "${FP8_CUDA_FLAGS}"
INCLUDE_DIRS "${FP8_INCLUDE_DIRS}"
)
endif()

# === HIP C++ Unit Tests Configuration ===
if(FLASHINFER_ENABLE_HIP)
file(GLOB HIP_TEST_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/hip/*.cpp")

foreach(test_source IN LISTS HIP_TEST_SOURCES)
get_filename_component(test_name ${test_source} NAME_WE)
set(target_name "${test_name}_hip")
configure_flashinfer_target(
TARGET_NAME ${target_name}
SOURCES ${test_source}
IS_GTEST ON
IS_HIP ON
)
endforeach()

endif(FLASHINFER_ENABLE_HIP)
# cmake-format: on

# === Test Discovery and Targets ===
Expand All @@ -164,10 +38,3 @@ endforeach()
# Create target to build all tests
add_custom_target(build_tests)
add_dependencies(build_tests ${ALL_TEST_TARGETS})

# Setup "check" target similar to autotools
set(CMAKE_CTEST_COMMAND ctest --progress --output-on-failure)
add_custom_target(check COMMAND ${CMAKE_COMMAND} ${CMAKE_CTEST_COMMAND})
add_dependencies(check build_tests)

enable_testing()
Loading