| 1 | include(FetchContent) |
| 2 | |
| 3 | # If DEEPSELECT_SRC_DIR is set, DeepSelect is built from that directory |
| 4 | # instead of downloading. |
| 5 | # It can be set as an environment variable or passed as a cmake argument. |
| 6 | # The environment variable takes precedence. |
| 7 | if (DEFINED ENV{DEEPSELECT_SRC_DIR}) |
| 8 | set(DEEPSELECT_SRC_DIR $ENV{DEEPSELECT_SRC_DIR}) |
| 9 | endif() |
| 10 | |
| 11 | if(DEEPSELECT_SRC_DIR) |
| 12 | FetchContent_Declare( |
| 13 | deepselect |
| 14 | SOURCE_DIR ${DEEPSELECT_SRC_DIR} |
| 15 | CONFIGURE_COMMAND "" |
| 16 | BUILD_COMMAND "" |
| 17 | ) |
| 18 | else() |
| 19 | FetchContent_Declare( |
| 20 | deepselect |
| 21 | GIT_REPOSITORY https://github.com/vllm-project/DeepSelect.git |
| 22 | GIT_TAG d96d33afe1fab0d6066da49cdc91e64c2bee65ea |
| 23 | GIT_PROGRESS TRUE |
| 24 | CONFIGURE_COMMAND "" |
| 25 | BUILD_COMMAND "" |
| 26 | ) |
| 27 | endif() |
| 28 | |
| 29 | FetchContent_MakeAvailable(deepselect) |
| 30 | message(STATUS "DeepSelect is available at ${deepselect_SOURCE_DIR}") |
| 31 | |
| 32 | # DeepSelect kernels require CUDA 12.9+; 10.0f (family) covers SM100 and SM103. |
| 33 | set(DEEPSELECT_SUPPORT_ARCHS) |
| 34 | if(${CMAKE_CUDA_COMPILER_VERSION} VERSION_GREATER_EQUAL 12.9) |
| 35 | list(APPEND DEEPSELECT_SUPPORT_ARCHS "10.0f") |
| 36 | endif() |
| 37 | |
| 38 | cuda_archs_loose_intersection(DEEPSELECT_ARCHS "${DEEPSELECT_SUPPORT_ARCHS}" "${CUDA_ARCHS}") |
| 39 | if(DEEPSELECT_ARCHS) |
| 40 | message(STATUS "DeepSelect CUDA architectures: ${DEEPSELECT_ARCHS}") |
| 41 | |
| 42 | # All explicit template instantiations must be compiled: api.cpp |
| 43 | # references every dispatch combination. |
| 44 | file(GLOB DeepSelect_SOURCES CONFIGURE_DEPENDS |
| 45 | ${deepselect_SOURCE_DIR}/csrc/cuda_kernels/v3/instantiations/*.cu |
| 46 | ${deepselect_SOURCE_DIR}/csrc/cuda_kernels/v3_fp32/instantiations/*.cu |
| 47 | ${deepselect_SOURCE_DIR}/csrc/cuda_kernels/v3_cluster/instantiations/*.cu |
| 48 | ) |
| 49 | list(PREPEND DeepSelect_SOURCES ${deepselect_SOURCE_DIR}/csrc/api.cpp) |
| 50 | |
| 51 | set(DeepSelect_INCLUDES |
| 52 | ${deepselect_SOURCE_DIR}/csrc |
| 53 | ${deepselect_SOURCE_DIR}/csrc/3rdparty/cutlass/include |
| 54 | ${deepselect_SOURCE_DIR}/csrc/3rdparty/kerutils/include |
| 55 | ) |
| 56 | |
| 57 | set_gencode_flags_for_srcs( |
| 58 | SRCS "${DeepSelect_SOURCES}" |
| 59 | CUDA_ARCHS "${DEEPSELECT_ARCHS}") |
| 60 | |
| 61 | set(VLLM_DEEPSELECT_GPU_FLAGS ${VLLM_GPU_FLAGS}) |
| 62 | list(APPEND VLLM_DEEPSELECT_GPU_FLAGS |
| 63 | "-O3" "--expt-relaxed-constexpr" "--expt-extended-lambda" |
| 64 | "--use_fast_math" "--ftz=false" |
| 65 | "-U__CUDA_NO_HALF_OPERATORS__" "-U__CUDA_NO_HALF_CONVERSIONS__" |
| 66 | "-U__CUDA_NO_HALF2_OPERATORS__" "-U__CUDA_NO_BFLOAT16_CONVERSIONS__") |
| 67 | |
| 68 | define_extension_target( |
| 69 | _deepselect_C |
| 70 | DESTINATION vllm |
| 71 | LANGUAGE ${VLLM_GPU_LANG} |
| 72 | SOURCES ${DeepSelect_SOURCES} |
| 73 | COMPILE_FLAGS ${VLLM_DEEPSELECT_GPU_FLAGS} |
| 74 | ARCHITECTURES ${VLLM_GPU_ARCHES} |
| 75 | INCLUDE_DIRECTORIES ${DeepSelect_INCLUDES} |
| 76 | USE_SABI 3 |
| 77 | WITH_SOABI) |
| 78 | |
| 79 | # Only use C-shim APIs available in PyTorch 2.10. |
| 80 | # _deepselect_C is abi compatible with PyTorch >= TORCH_TARGET_VERSION. |
| 81 | target_compile_definitions(_deepselect_C PRIVATE |
| 82 | TORCH_TARGET_VERSION=0x020A000000000000ULL) |
| 83 | |
| 84 | # Needed to use cuda APIs from C-shim |
| 85 | if(VLLM_GPU_LANG STREQUAL "CUDA") |
| 86 | target_compile_definitions(_deepselect_C PRIVATE USE_CUDA) |
| 87 | endif() |
| 88 | |
| 89 | # DeepSelect requires C++20 |
| 90 | target_compile_options(_deepselect_C PRIVATE |
| 91 | $<$<COMPILE_LANGUAGE:CXX>:-std=c++20> |
| 92 | $<$<COMPILE_LANGUAGE:CUDA>:-std=c++20>) |
| 93 | else() |
| 94 | message(STATUS "DeepSelect will not compile: unsupported CUDA architecture ${CUDA_ARCHS}") |
| 95 | # Create an empty target for setup.py on unsupported systems |
| 96 | add_custom_target(_deepselect_C) |
| 97 | endif() |