Repository: pytorch
Issue: Build failure when using CUDAGraph
Labels: module: docs,module: cpp,module: cuda,triaged,actionable

### 🐛 Describe the bug

If I follow the minimal C++ example (https://pytorch.org/cppdocs/installing.html#minimal-example), but use CUDA stream or graph functionality through ATen, the build fails:

```C++
#include <torch/torch.h>
#include <iostream>

// Only modification from example
#include <ATen/cuda/CUDAGraph.h>

int main() {
  torch::Tensor tensor = torch::rand({2, 3});
  std::cout << tensor << std::endl;
}
```

```
In file included from /home/adr/git/tmp/try-torch/libtorch/include/c10/cuda/CUDAGraphsC10Utils.h:3,
                 from /home/adr/git/tmp/try-torch/libtorch/include/ATen/cuda/CUDAGraph.h:5,
                 from /home/adr/git/tmp/try-torch/example-app.cpp:3:
/home/adr/git/tmp/try-torch/libtorch/include/c10/cuda/CUDAStream.h:3:10: fatal error: cuda_runtime_api.h: No such file or directory
    3 | #include <cuda_runtime_api.h>
      |          ^~~~~~~~~~~~~~~~~~~~
compilation terminated.
make[2]: *** [CMakeFiles/example-app.dir/build.make:76: CMakeFiles/example-app.dir/example-app.cpp.o] Error 1
make[1]: *** [CMakeFiles/Makefile2:83: CMakeFiles/example-app.dir/all] Error 2
make: *** [Makefile:91: all] Error 2
```

I hope I don't just misunderstand something, but shouldn't libtorch either provide this header file with the other dependencies or not refer to it in its public headers?

### Versions

Collecting environment information...
PyTorch version: N/A
Is debug build: N/A
CUDA used to build PyTorch: N/A
ROCM used to build PyTorch: N/A

OS: Arch Linux (x86_64)
GCC version: (GCC) 13.2.1 20240417
Clang version: 17.0.6
CMake version: version 3.29.2
Libc version: glibc-2.39

Python version: 3.12.3 (main, Apr 23 2024, 09:16:07) [GCC 13.2.1 20240417] (64-bit runtime)
Python platform: Linux-6.8.8-arch1-1-x86_64-with-glibc2.39
Is CUDA available: N/A
CUDA runtime version: Could not collect
CUDA_MODULE_LOADING set to: N/A
GPU models and configuration: GPU 0: NVIDIA GeForce GTX 1070 Ti
Nvidia driver version: 550.76
cuDNN version: Probably one of the following:
/usr/lib/libcudnn.so.8.9.7
/usr/lib/libcudnn_adv_infer.so.8.9.7
/usr/lib/libcudnn_adv_train.so.8.9.7
/usr/lib/libcudnn_cnn_infer.so.8.9.7
/usr/lib/libcudnn_cnn_train.so.8.9.7
/usr/lib/libcudnn_ops_infer.so.8.9.7
/usr/lib/libcudnn_ops_train.so.8.9.7
HIP runtime version: N/A
MIOpen runtime version: N/A
Is XNNPACK available: N/A

CPU:
Architecture:                         x86_64
CPU op-mode(s):                       32-bit, 64-bit
Address sizes:                        43 bits physical, 48 bits virtual
Byte Order:                           Little Endian
CPU(s):                               24
On-line CPU(s) list:                  0-23
Vendor ID:                            AuthenticAMD
Model name:                           AMD Ryzen Threadripper 1920X 12-Core Processor
CPU family:                           23
Model:                                1
Thread(s) per core:                   2
Core(s) per socket:                   12
Socket(s):                            1
Stepping:                             1
Frequency boost:                      enabled
CPU(s) scaling MHz:                   77%
CPU max MHz:                          3500,0000
CPU min MHz:                          2200,0000
BogoMIPS:                             6988,10
Flags:                                fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush mmx fxsr sse sse2 ht syscall nx mmxext fxsr_opt pdpe1gb rdtscp lm constant_tsc rep_good nopl nonstop_tsc cpuid extd_apicid amd_dcm aperfmperf rapl pni pclmulqdq monitor ssse3 fma cx16 sse4_1 sse4_2 movbe popcnt aes xsave avx f16c rdrand lahf_lm cmp_legacy svm extapic cr8_legacy abm sse4a misalignsse 3dnowprefetch osvw skinit wdt tce topoext perfctr_core perfctr_nb bpext perfctr_llc mwaitx cpb hw_pstate ssbd ibpb vmmcall fsgsbase bmi1 avx2 smep bmi2 rdseed adx smap clflushopt sha_ni xsaveopt xsavec xgetbv1 clzero irperf xsaveerptr arat npt lbrv svm_lock nrip_save tsc_scale vmcb_clean flushbyasid decodeassists pausefilter pfthreshold avic v_vmsave_vmload vgif overflow_recov succor smca sev
Virtualization:                       AMD-V
L1d cache:                            384 KiB (12 instances)
L1i cache:                            768 KiB (12 instances)
L2 cache:                             6 MiB (12 instances)
L3 cache:                             32 MiB (4 instances)
NUMA node(s):                         2
NUMA node0 CPU(s):                    0-5,12-17
NUMA node1 CPU(s):                    6-11,18-23
Vulnerability Gather data sampling:   Not affected
Vulnerability Itlb multihit:          Not affected
Vulnerability L1tf:                   Not affected
Vulnerability Mds:                    Not affected
Vulnerability Meltdown:               Not affected
Vulnerability Mmio stale data:        Not affected
Vulnerability Reg file data sampling: Not affected
Vulnerability Retbleed:               Mitigation; untrained return thunk; SMT vulnerable
Vulnerability Spec rstack overflow:   Mitigation; Safe RET
Vulnerability Spec store bypass:      Mitigation; Speculative Store Bypass disabled via prctl
Vulnerability Spectre v1:             Mitigation; usercopy/swapgs barriers and __user pointer sanitization
Vulnerability Spectre v2:             Mitigation; Retpolines; IBPB conditional; STIBP disabled; RSB filling; PBRSB-eIBRS Not affected; BHI Not affected
Vulnerability Srbds:                  Not affected
Vulnerability Tsx async abort:        Not affected

Versions of relevant libraries:
[None] No relevant packages
[conda] Could not collect


cc @svekars @brycebortree @jbschlosser @ptrblck @msaroufim