Skip to content

Commit de99059

Browse files
authored
Fix build pipeline for CUDA 13.0 (microsoft#26983)
This PR fixes the build pipeline failures observed with CUDA 13.0. ### Changes: 1. **Compiler Flags**: Fixed check_nvcc_compiler_flag macro in adjust_global_compile_flags.cmake to correctly pass flags to the host compiler using -Xcompiler, preventing 'nvcc fatal' errors. Added cmake/empty.c for this check. 2. **Node.js Bindings**: Fixed warn_unused_result warnings in session_options_helper.cc by wrapping CreateCUDAProviderOptions calls with Ort::ThrowOnError. 3. **CCCL Header Location**: Updated `onnxruntime_providers_cuda.cmake` to handle the relocation of CCCL headers in CUDA 13.0. It now adds the `cccl` subdirectory to include paths when detected, ensuring headers like `<cuda/std/utility>` are correctly found. 4. Update nuget pipeline to pass cudnn home to build command line for cuda 13. See "cudnn not found" issue below. 5. Diable a step 'Test C API application for GPU package' in nuget pipeline, since "Onnxruntime-Linux-GPU-A10" pool has old cuda driver which cannot run cuda 13. This is a temporary walkaround to unblock the pipeline before we have a pool with new cuda driver. #### Issue: cuda/std/utility not found See microsoft#26362. I tried two ways to fix it, one is to change CMAKE_CUDA_COMPILER_FRONTEND_VARIANT, another is to add include cccl path for cuda 13. Both can fix the error in build pipeline. Since the second approach more straightforward, it is kept. #### Issue: cudnn not found The Windows packaging builds ("Windows_Packaging_CUDA" and "Windows_Packaging_TensorRT") were failing for CUDA 13.0 because the --cudnn_home argument was missing from the build.py command line. Note that CUDA 12.8 build has no such problem, since we put cudnn with cuda togother. For cuda 13, we separate cuda and cudnn to two directories, so we need add --cudnn_home in build commands for CUDA 13. Fix: * Defined win_cudnn_home in c-api-noopenmp-packaging-pipelines.yml and cuda-packaging-pipeline.yml (set to $(Agent.TempDirectory)\9.14.0.64_cuda13 for CUDA 13.0). * Propagated this variable through nuget-combine-cuda-stage.yml to nuget-win-cuda-packaging-stage.yml * Updated nuget-win-cuda-packaging-stage.yml to conditionally add --cudnn_home=${{ parameters.win_cudnn_home }} to the build parameters when the variable is set.
1 parent 081633e commit de99059

9 files changed

Lines changed: 45 additions & 8 deletions

cmake/adjust_global_compile_flags.cmake

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -208,10 +208,8 @@ endif()
208208

209209

210210
macro(check_nvcc_compiler_flag _FLAG _RESULT)
211-
execute_process(COMMAND ${CUDAToolkit_BIN_DIR}/nvcc "${_FLAG}" RESULT_VARIABLE NVCC_OUT ERROR_VARIABLE NVCC_ERROR)
212-
message("NVCC_ERROR = ${NVCC_ERROR}")
213-
message("NVCC_OUT = ${NVCC_OUT}")
214-
if ("${NVCC_OUT}" MATCHES "0")
211+
execute_process(COMMAND ${CMAKE_CUDA_COMPILER} --compiler-options "${_FLAG}" -c ${REPO_ROOT}/cmake/empty.c -o ${CMAKE_CURRENT_BINARY_DIR}/empty.o RESULT_VARIABLE NVCC_OUT ERROR_QUIET OUTPUT_QUIET)
212+
if (NVCC_OUT EQUAL 0)
215213
set(${_RESULT} 1)
216214
else()
217215
set(${_RESULT} 0)

cmake/empty.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
// This file is used by the check_nvcc_compiler_flag macro in adjust_global_compile_flags.cmake to test nvcc compiler flags.
2+
void empty() {}

cmake/onnxruntime_providers_cuda.cmake

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,17 @@
257257
target_include_directories(${target} PRIVATE ${cutlass_SOURCE_DIR}/include ${cutlass_SOURCE_DIR}/examples ${cutlass_SOURCE_DIR}/tools/util/include)
258258
target_link_libraries(${target} PRIVATE Eigen3::Eigen)
259259
target_include_directories(${target} PRIVATE ${ONNXRUNTIME_ROOT} ${CMAKE_CURRENT_BINARY_DIR} PUBLIC ${CUDAToolkit_INCLUDE_DIRS})
260+
261+
# Handle CUDA 13.0 CCCL header directory move
262+
if (CMAKE_CUDA_COMPILER_VERSION VERSION_GREATER_EQUAL 13.0)
263+
foreach(inc_dir ${CUDAToolkit_INCLUDE_DIRS})
264+
if (EXISTS "${inc_dir}/cccl")
265+
# Add the cccl subdirectory to the include path so <cuda/std/utility> can be found
266+
target_include_directories(${target} PRIVATE "${inc_dir}/cccl")
267+
endif()
268+
endforeach()
269+
endif()
270+
260271
# ${CMAKE_CURRENT_BINARY_DIR} is so that #include "onnxruntime_config.h" inside tensor_shape.h is found
261272
set_target_properties(${target} PROPERTIES LINKER_LANGUAGE CUDA)
262273
set_target_properties(${target} PROPERTIES FOLDER "ONNXRuntime")

js/node/src/session_options_helper.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,15 +143,15 @@ void ParseExecutionProviders(const Napi::Array epList, Ort::SessionOptions& sess
143143
#ifdef USE_CUDA
144144
} else if (name == "cuda") {
145145
OrtCUDAProviderOptionsV2* options;
146-
Ort::GetApi().CreateCUDAProviderOptions(&options);
146+
Ort::ThrowOnError(Ort::GetApi().CreateCUDAProviderOptions(&options));
147147
options->device_id = deviceId;
148148
sessionOptions.AppendExecutionProvider_CUDA_V2(*options);
149149
Ort::GetApi().ReleaseCUDAProviderOptions(options);
150150
#endif
151151
#ifdef USE_TENSORRT
152152
} else if (name == "tensorrt") {
153153
OrtTensorRTProviderOptionsV2* options;
154-
Ort::GetApi().CreateTensorRTProviderOptions(&options);
154+
Ort::ThrowOnError(Ort::GetApi().CreateTensorRTProviderOptions(&options));
155155
options->device_id = deviceId;
156156
sessionOptions.AppendExecutionProvider_TensorRT_V2(*options);
157157
Ort::GetApi().ReleaseTensorRTProviderOptions(options);

tools/ci_build/github/azure-pipelines/c-api-noopenmp-packaging-pipelines.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,11 @@ variables:
8888
value: $(Agent.TempDirectory)\v12.8
8989
${{ if eq(parameters.CudaVersion, '13.0') }}:
9090
value: $(Agent.TempDirectory)\v13.0
91+
- name: win_cudnn_home
92+
${{ if eq(parameters.CudaVersion, '12.8') }}:
93+
value: ''
94+
${{ if eq(parameters.CudaVersion, '13.0') }}:
95+
value: $(Agent.TempDirectory)\9.14.0.64_cuda13
9196
- name: CudaArchs
9297
${{ if eq(parameters.CudaVersion, '12.8') }}:
9398
value: '75-real;86-real;89-real;90-virtual'
@@ -171,6 +176,7 @@ extends:
171176
PreReleaseVersionSuffixString: ${{ parameters.PreReleaseVersionSuffixString }}
172177
PreReleaseVersionSuffixNumber: ${{ parameters.PreReleaseVersionSuffixNumber }}
173178
CudaArchs: ${{ variables.CudaArchs }}
179+
win_cudnn_home: ${{ variables.win_cudnn_home }}
174180

175181
- template: stages/nodejs-win-packaging-stage.yml
176182
parameters:

tools/ci_build/github/azure-pipelines/cuda-packaging-pipeline.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,11 @@ variables:
6767
value: $(Agent.TempDirectory)\v12.8
6868
${{ if eq(parameters.CudaVersion, '13.0') }}:
6969
value: $(Agent.TempDirectory)\v13.0
70+
- name: win_cudnn_home
71+
${{ if eq(parameters.CudaVersion, '12.8') }}:
72+
value: ''
73+
${{ if eq(parameters.CudaVersion, '13.0') }}:
74+
value: $(Agent.TempDirectory)\9.14.0.64_cuda13
7075
# CMAKE_CUDA_ARCHITECTURES for Windows nuget packaging
7176
- name: CudaArchs
7277
${{ if eq(parameters.CudaVersion, '12.8') }}:
@@ -133,6 +138,7 @@ extends:
133138
PreReleaseVersionSuffixString: ${{ parameters.PreReleaseVersionSuffixString }}
134139
PreReleaseVersionSuffixNumber: ${{ parameters.PreReleaseVersionSuffixNumber }}
135140
CudaArchs: ${{ variables.CudaArchs }}
141+
win_cudnn_home: ${{ variables.win_cudnn_home }}
136142

137143
- template: stages/download-java-tools-stage.yml
138144

tools/ci_build/github/azure-pipelines/stages/nuget-combine-cuda-stage.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,9 @@ parameters:
4747

4848
- name: CudaArchs
4949
type: string
50+
- name: win_cudnn_home
51+
type: string
52+
default: ''
5053

5154
stages:
5255
- template: nuget-linux-cuda-packaging-stage.yml
@@ -71,6 +74,7 @@ stages:
7174
PreReleaseVersionSuffixString: ${{ parameters.PreReleaseVersionSuffixString }}
7275
PreReleaseVersionSuffixNumber: ${{ parameters.PreReleaseVersionSuffixNumber }}
7376
CudaArchs: ${{ parameters.CudaArchs }}
77+
win_cudnn_home: ${{ parameters.win_cudnn_home }}
7478

7579
- template: nuget-cuda-packaging-stage.yml
7680
parameters:

tools/ci_build/github/azure-pipelines/stages/nuget-linux-cuda-packaging-stage.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,7 @@ stages:
207207

208208
- task: CmdLine@2
209209
displayName: 'Test C API application for GPU package'
210+
condition: and(succeeded(), ne(variables['CUDA_VERSION_MAJOR'], '13'))
210211
inputs:
211212
script: |
212213
docker run -e SYSTEM_COLLECTIONURI --gpus all -e CFLAGS="-Wp,-D_FORTIFY_SOURCE=2 -Wp,-D_GLIBCXX_ASSERTIONS -fstack-protector-strong -fstack-clash-protection -fcf-protection -O3 -Wl,--strip-all" -e CXXFLAGS="-Wp,-D_FORTIFY_SOURCE=2 -Wp,-D_GLIBCXX_ASSERTIONS -fstack-protector-strong -fstack-clash-protection -fcf-protection -O3 -Wl,--strip-all" -e NVIDIA_VISIBLE_DEVICES=all --rm --volume /data/models:/data/models --volume $(Build.SourcesDirectory):/src_dir \

tools/ci_build/github/azure-pipelines/stages/nuget-win-cuda-packaging-stage.yml

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,9 @@ parameters:
5252

5353
- name: CudaArchs
5454
type: string
55+
- name: win_cudnn_home
56+
type: string
57+
default: ''
5558

5659
stages:
5760
# Windows CUDA without TensorRT Packaging
@@ -66,7 +69,10 @@ stages:
6669
msbuildPlatform: x64
6770
packageName: x64-cuda
6871
CudaVersion: ${{ parameters.CudaVersion }}
69-
buildparameter: --use_cuda --cuda_home=${{ parameters.win_cuda_home }} --enable_onnx_tests --enable_wcos --parallel 4 --nvcc_threads 1 --cmake_extra_defines "CMAKE_CUDA_ARCHITECTURES=${{ parameters.CudaArchs }}"
72+
${{ if ne(parameters.win_cudnn_home, '') }}:
73+
buildparameter: --use_cuda --cuda_home=${{ parameters.win_cuda_home }} --cudnn_home=${{ parameters.win_cudnn_home }} --enable_onnx_tests --enable_wcos --parallel 4 --nvcc_threads 1 --cmake_extra_defines "CMAKE_CUDA_ARCHITECTURES=${{ parameters.CudaArchs }}"
74+
${{ else }}:
75+
buildparameter: --use_cuda --cuda_home=${{ parameters.win_cuda_home }} --enable_onnx_tests --enable_wcos --parallel 4 --nvcc_threads 1 --cmake_extra_defines "CMAKE_CUDA_ARCHITECTURES=${{ parameters.CudaArchs }}"
7076
runTests: ${{ parameters.RunOnnxRuntimeTests }}
7177
buildJava: ${{ parameters.buildJava }}
7278
java_artifact_id: onnxruntime_gpu
@@ -86,7 +92,10 @@ stages:
8692
msbuildPlatform: x64
8793
CudaVersion: ${{ parameters.CudaVersion }}
8894
packageName: x64-tensorrt
89-
buildparameter: --use_tensorrt --tensorrt_home=${{ parameters.win_trt_home }} --cuda_home=${{ parameters.win_cuda_home }} --enable_onnx_tests --enable_wcos --parallel 4 --nvcc_threads 1 --cmake_extra_defines "CMAKE_CUDA_ARCHITECTURES=${{ parameters.CudaArchs }}"
95+
${{ if ne(parameters.win_cudnn_home, '') }}:
96+
buildparameter: --use_tensorrt --tensorrt_home=${{ parameters.win_trt_home }} --cuda_home=${{ parameters.win_cuda_home }} --cudnn_home=${{ parameters.win_cudnn_home }} --enable_onnx_tests --enable_wcos --parallel 4 --nvcc_threads 1 --cmake_extra_defines "CMAKE_CUDA_ARCHITECTURES=${{ parameters.CudaArchs }}"
97+
${{ else }}:
98+
buildparameter: --use_tensorrt --tensorrt_home=${{ parameters.win_trt_home }} --cuda_home=${{ parameters.win_cuda_home }} --enable_onnx_tests --enable_wcos --parallel 4 --nvcc_threads 1 --cmake_extra_defines "CMAKE_CUDA_ARCHITECTURES=${{ parameters.CudaArchs }}"
9099
runTests: ${{ parameters.RunOnnxRuntimeTests }}
91100
buildJava: ${{ parameters.buildJava }}
92101
java_artifact_id: onnxruntime_gpu

0 commit comments

Comments
 (0)