← All tasks
cppmicrosoft/onnxruntime #32570Not a task: not reproduced

[Build] onnxruntime_USE_FLASH_ATTENTION=OFF still compiles all 48 Flash Attention .cu files (dead code)

envgap__microsoft__onnxruntime-32570

01 / FAILURE SIGNATURE

As reported upstream

### Error / output
Not a benchmark task.
  • In a clean container the reported failure did not reproduce, or the known fix did not make the project run.

02 / ENVIRONMENT RECIPE

Base commit
4d95047dfb2c9395388dd17bdb87f3dda561b091
Manifest
cmake/CMakeLists.txt
Reproduce
Awaiting issue-specific recipe
Run under trace
Awaiting a meaningful runtime command

03 / ORIGINAL ISSUE TEXT

microsoft/onnxruntime #32570 · read the original issue
### Describe the issue

When configuring ONNX Runtime with `-Donnxruntime_USE_FLASH_ATTENTION=OFF`, CMake correctly unsets the C++ preprocessor definition `USE_FLASH_ATTENTION`. 

However, the CMake build system does not filter out the Flash Attention CUDA source files. As a result, CMake still creates the `onnxruntime_providers_cuda_flash_attention` target and compiles all **48 `flash_fwd_*.cu` kernel files** for all SM80+ architectures (`sm_80`, `sm_86`, `sm_89`, `sm_90`, `sm_120`), even though:
1. `contrib_ops/cuda/bert/flash_attention/flash_api.cc` is entirely `#if USE_FLASH_ATTENTION ... #endif`, so it compiles into an empty object file with no callers.
2. `core/providers/cuda/llm/attention.cc` `#if USE_FLASH_ATTENTION` branch is disabled.
3. Every single compiled Flash Attention kernel is 100% dead code in the resulting shared library.

On multi-architecture builds, compiling these 48 CUTLASS template files can add 1 to 2+ hours of build time and consume significant memory for code that is completely unused.

### Urgency

_No response_

### Target platform

Windows/Linux

### Build script

```bash
cmake -S cmake -B build \
  -Donnxruntime_USE_CUDA=ON \
  -Donnxruntime_USE_FLASH_ATTENTION=OFF \
  -DCMAKE_CUDA_ARCHITECTURES="80;86;89"
```

### Error / output

```bash
ninja -C build -t targets | grep flash_fwd
```

All 48 `flash_fwd_*.cu` files are still generated as build targets for `onnxruntime_providers_cuda_flash_attention`.  

### Visual Studio Version

2026

### GCC / Compiler Version

14
Continue on GitHub ↗

04 / LABELS

Labels from the report text only; not yet run

No supported category has been assigned.

Label rules and the text that matched
[]