CUDA: fix replacment of bad archs in CMake (llama/18457)
This commit is contained in:
parent
d6cb2407b7
commit
5765c5b04e
|
|
@ -51,35 +51,35 @@ if (CUDAToolkit_FOUND)
|
||||||
endif()
|
endif()
|
||||||
endif()
|
endif()
|
||||||
endif()
|
endif()
|
||||||
message(STATUS "Using CUDA architectures: ${CMAKE_CUDA_ARCHITECTURES}")
|
|
||||||
|
|
||||||
enable_language(CUDA)
|
enable_language(CUDA)
|
||||||
|
|
||||||
# Replace any 12x-real architectures with 12x{a}-real. FP4 ptx instructions are not available in just 12x
|
# Replace any plain 12X CUDA architectures with their "architecture-specific" equivalents 12Xa.
|
||||||
if (GGML_NATIVE)
|
# 12X is forwards-compatible, 12Xa is not.
|
||||||
set(PROCESSED_ARCHITECTURES "")
|
# Notably the Blackwell FP4 tensor core instructions are not forwards compatible and therefore need 12Xa.
|
||||||
if (CMAKE_CUDA_ARCHITECTURES_NATIVE)
|
# But while 12X vs. 12Xa can be checked in device code there is (to my knowledge) no easy way to do the same check in host code.
|
||||||
set(ARCH_LIST ${CMAKE_CUDA_ARCHITECTURES_NATIVE})
|
# So for now just replace all instances of 12X with 12Xa, this should be fine until Rubin is released.
|
||||||
else()
|
foreach(ARCHS IN ITEMS CMAKE_CUDA_ARCHITECTURES CMAKE_CUDA_ARCHITECTURES_NATIVE)
|
||||||
set(ARCH_LIST ${CMAKE_CUDA_ARCHITECTURES})
|
set(FIXED_ARCHS "")
|
||||||
endif()
|
foreach(ARCH IN LISTS ${ARCHS})
|
||||||
foreach(ARCH ${ARCH_LIST})
|
|
||||||
if (ARCH MATCHES "^12[0-9](-real|-virtual)?$")
|
if (ARCH MATCHES "^12[0-9](-real|-virtual)?$")
|
||||||
string(REGEX REPLACE "^(12[0-9]).*$" "\\1" BASE_ARCH ${ARCH})
|
string(REGEX REPLACE "^(12[0-9])((-real|-virtual)?)$" "\\1a\\2" FIXED_ARCH ${ARCH})
|
||||||
message(STATUS "Replacing ${ARCH} with ${BASE_ARCH}a-real")
|
message(STATUS "Replacing ${ARCH} in ${ARCHS} with ${FIXED_ARCH}")
|
||||||
list(APPEND PROCESSED_ARCHITECTURES "${BASE_ARCH}a-real")
|
list(APPEND FIXED_ARCHS "${FIXED_ARCH}")
|
||||||
else()
|
else()
|
||||||
list(APPEND PROCESSED_ARCHITECTURES ${ARCH})
|
list(APPEND FIXED_ARCHS "${ARCH}")
|
||||||
endif()
|
|
||||||
endforeach()
|
|
||||||
set(CMAKE_CUDA_ARCHITECTURES ${PROCESSED_ARCHITECTURES})
|
|
||||||
else()
|
|
||||||
foreach(ARCH ${CMAKE_CUDA_ARCHITECTURES})
|
|
||||||
if(ARCH MATCHES "^12[0-9](-real|-virtual)?$")
|
|
||||||
message(FATAL_ERROR "Compute capability ${ARCH} used, use ${ARCH}a or ${ARCH}f for Blackwell-specific optimizations")
|
|
||||||
endif()
|
endif()
|
||||||
endforeach()
|
endforeach()
|
||||||
|
set(${ARCHS} ${FIXED_ARCHS})
|
||||||
|
endforeach()
|
||||||
|
|
||||||
|
# If we try to compile a "native" build it will use the 12X architectures and fail.
|
||||||
|
# So we should instead use the native architectures as determined by CMake after replacing 12X with 12Xa.
|
||||||
|
# But if at the time of the build no GPUs are connected at all CMAKE_CUDA_ARCHITECTURES will contain garbage that we should not use.
|
||||||
|
if (CMAKE_CUDA_ARCHITECTURES STREQUAL "native" AND CMAKE_CUDA_ARCHITECTURES_NATIVE MATCHES "^[0-9]+(a|f)?(-real|-virtual)?(;[0-9]+(a|f)?(-real|-virtual)?|;)*$")
|
||||||
|
set(CMAKE_CUDA_ARCHITECTURES ${CMAKE_CUDA_ARCHITECTURES_NATIVE})
|
||||||
endif()
|
endif()
|
||||||
|
message(STATUS "Using CMAKE_CUDA_ARCHITECTURES=${CMAKE_CUDA_ARCHITECTURES} CMAKE_CUDA_ARCHITECTURES_NATIVE=${CMAKE_CUDA_ARCHITECTURES_NATIVE}")
|
||||||
|
|
||||||
file(GLOB GGML_HEADERS_CUDA "*.cuh")
|
file(GLOB GGML_HEADERS_CUDA "*.cuh")
|
||||||
list(APPEND GGML_HEADERS_CUDA "../../include/ggml-cuda.h")
|
list(APPEND GGML_HEADERS_CUDA "../../include/ggml-cuda.h")
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue