onnxruntime
5003d932 - Fix CUDA build with contrib ops disabled (#28554)

Commit
170 days ago
Fix CUDA build with contrib ops disabled (#28554) ### Description The CUDA Attention kernel (`core/providers/cuda/llm/attention.cc`) depends on contrib_ops internals (flash attention, memory efficient attention, unfused attention helpers) but was compiled unconditionally. When building with `--disable_contrib_ops`, `GetAttentionKernelOptions()` is unavailable (guarded by `#ifndef DISABLE_CONTRIB_OPS` in `cuda_kernel.h`), causing a compile error. Changes: - **`cmake/onnxruntime_providers_cuda.cmake`** — When contrib ops are disabled (and not in CUDA minimal mode), include the `contrib_ops/cuda/bert/` attention infrastructure files (flash attention, memory efficient attention, unfused attention helpers, etc.) so the ONNX domain Attention kernel can compile and link. Uses `elseif(onnxruntime_DISABLE_CONTRIB_OPS AND NOT onnxruntime_CUDA_MINIMAL)` to avoid including these files in CUDA minimal builds where `llm/attention.cc` isn't compiled and `cudnn_frontend.h` isn't available. - **`onnxruntime/core/providers/cuda/cuda_execution_provider.h`** — Remove `#ifndef DISABLE_CONTRIB_OPS` guards from the `AttentionKernelOptions` include, `GetAttentionKernelOptions()` method, and `attention_kernel_options_` member variable - **`onnxruntime/core/providers/cuda/cuda_kernel.h`** — Remove `#ifndef DISABLE_CONTRIB_OPS` guard from `GetAttentionKernelOptions()` The CUDA Attention kernel and its underlying attention backends (flash, memory efficient, unfused) are now always available in full CUDA builds regardless of whether contrib ops are enabled. No changes are needed in `cuda_execution_provider.cc` since the Attention kernel registrations remain unconditional. ### Motivation and Context Building onnxruntime with CUDA enabled and `--disable_contrib_ops` fails: ``` error C2039: 'GetAttentionKernelOptions': is not a member of 'onnxruntime::cuda::Attention<float>' ``` This is a valid build configuration (useful for reducing compile time) that should be supported. Rather than excluding the CUDA Attention kernel when contrib ops are disabled, the necessary attention infrastructure from `contrib_ops/cuda/bert/` is included in the build so the ONNX domain Attention op retains full CUDA acceleration. The fix is scoped to non-minimal CUDA builds only, since CUDA minimal builds use a non-recursive glob that doesn't include `llm/attention.cc` and don't have `cudnn_frontend` available. --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: tianleiwu <30328909+tianleiwu@users.noreply.github.com> Co-authored-by: Tianlei Wu <tlwu@microsoft.com> Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Author
Parents
Loading