From e7f4e915ac73840eee7545050b3f1806d504a4b2 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sun, 16 Aug 2026 18:30:44 +0000 Subject: [PATCH 1/2] Initial plan From 118890c2e639d196f03960495a9eef188915be66 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sun, 16 Aug 2026 18:40:59 +0000 Subject: [PATCH 2/2] Fix CUDA 12.9 SM120 build on Windows Co-authored-by: tianleiwu <30328909+tianleiwu@users.noreply.github.com> --- cmake/CMakeLists.txt | 20 ++++++++++++++++++++ cmake/external/cuda_configuration.cmake | 17 +++++++++++++++++ 2 files changed, 37 insertions(+) diff --git a/cmake/CMakeLists.txt b/cmake/CMakeLists.txt index 2572b1657d1cf..87574eab17ff0 100644 --- a/cmake/CMakeLists.txt +++ b/cmake/CMakeLists.txt @@ -1516,6 +1516,26 @@ if (onnxruntime_USE_CUDA) endif() find_package(CUDAToolkit REQUIRED) + if(MSVC AND CMAKE_CUDA_COMPILER_VERSION VERSION_GREATER_EQUAL 12.9 + AND CMAKE_CUDA_COMPILER_VERSION VERSION_LESS 13.0) + foreach(_cuda_include_dir IN LISTS CUDAToolkit_INCLUDE_DIRS) + set(_clusterlaunchcontrol_header + "${_cuda_include_dir}/cuda/__ptx/instructions/generated/clusterlaunchcontrol.h") + if(EXISTS "${_clusterlaunchcontrol_header}") + # CUDA 12.9 uses Windows's 32-bit long for PTX 64-bit operands. Shadow the toolkit + # header with the longlong2 correction shipped by newer CCCL releases. + set(_cuda_12_9_fix_dir "${CMAKE_CURRENT_BINARY_DIR}/cuda_12_9_fix") + ort_patch_cuda_12_9_clusterlaunchcontrol_header( + "${_clusterlaunchcontrol_header}" + "${_cuda_12_9_fix_dir}/cuda/__ptx/instructions/generated/clusterlaunchcontrol.h") + if(EXISTS "${_cuda_12_9_fix_dir}/cuda/__ptx/instructions/generated/clusterlaunchcontrol.h") + include_directories(BEFORE "${_cuda_12_9_fix_dir}") + endif() + break() + endif() + endforeach() + endif() + # Note: The minimum required CUDA version is greater than 11.8. add_definitions("-DENABLE_BF16") message(STATUS "CUDA Toolkit version is greater or equal than 11.8, enable -DENABLE_BF16 flag") diff --git a/cmake/external/cuda_configuration.cmake b/cmake/external/cuda_configuration.cmake index ff8b1a00aaea1..47d6eef45302c 100644 --- a/cmake/external/cuda_configuration.cmake +++ b/cmake/external/cuda_configuration.cmake @@ -73,6 +73,23 @@ macro(setup_cuda_compiler) endif() endmacro() +function(ort_patch_cuda_12_9_clusterlaunchcontrol_header src dst) + if(NOT EXISTS "${src}") + return() + endif() + + file(READ "${src}" _content) + set(_orig "${_content}") + string(REPLACE "reinterpret_cast" "reinterpret_cast" _content "${_content}") + if(NOT _content STREQUAL _orig) + get_filename_component(_dst_dir "${dst}" DIRECTORY) + file(MAKE_DIRECTORY "${_dst_dir}") + file(WRITE "${dst}" "${_content}") + elseif(EXISTS "${dst}") + file(REMOVE "${dst}") + endif() +endfunction() + macro(setup_cuda_architectures) # cmake-format: off # Initialize and normalize CMAKE_CUDA_ARCHITECTURES before enabling CUDA.