Repository: pytorch
Issue: On UMA systems, pytorch fails to reserve memory exceeding the initial memory size
Labels: module: rocm,module: memory usage,triaged

### 🐛 Describe the bug

When using pytorch with ROCm / HIP on systems with unified memory, eg. AMD APUs, pytorch seems to stick to the inital reported GPU memory (which is 512 MB on my system for example), even if plenty of system RAM (and so candidate VRAM) is available.  It seems the available memory is only polled once (or with an unreliable method), and after using up this memory, torch bails out like:

"HIP out of memory. Tried to allocate 2.00 MiB (GPU 0; 512.00 MiB total capacity; 455.97 MiB already allocated; 42.00 MiB free; 470.00 MiB reserved in total by PyTorch) If reserved memory is >> allocated memory try setting max_split_size_mb to avoid fragmentation.  See documentation for Memory Management and PYTORCH_HIP_ALLOC_CONF"

Other applications on my system (eg. OpenGL) manage to use 4GB+ of GPU memory. So it seems pytorch is stuck to the initial reported "free" GPU memory forever. 

### Versions

PyTorch version: 2.0.0+rocm5.4.2
Is debug build: False
CUDA used to build PyTorch: N/A
ROCM used to build PyTorch: 5.4.22803-474e8620

OS: Ubuntu 22.10 (x86_64)
GCC version: (Ubuntu 12.2.0-3ubuntu1) 12.2.0
Clang version: Could not collect
CMake version: version 3.26.3
Libc version: glibc-2.36

Python version: 3.10.7 (main, Mar 10 2023, 10:47:39) [GCC 12.2.0] (64-bit runtime)
Python platform: Linux-6.2.0-060200-generic-x86_64-with-glibc2.36
Is CUDA available: True
CUDA runtime version: Could not collect
CUDA_MODULE_LOADING set to: LAZY
GPU models and configuration: AMD Radeon Graphics
Nvidia driver version: Could not collect
cuDNN version: Could not collect
HIP runtime version: 5.4.22803
MIOpen runtime version: 2.19.0
Is XNNPACK available: True

CPU:
Architektur:                     x86_64
CPU Operationsmodus:             32-bit, 64-bit
Adressgrößen:                    48 bits physical, 48 bits virtual
Byte-Reihenfolge:                Little Endian
CPU(s):                          16
Liste der Online-CPU(s):         0-15
Anbieterkennung:                 AuthenticAMD
Modellname:                      AMD Ryzen 9 6900HX with Radeon Graphics
Prozessorfamilie:                25
Modell:                          68
Thread(s) pro Kern:              2
Kern(e) pro Socket:              8
Sockel:                          1
Stepping:                        1
BogoMIPS:                        6587.65
Markierungen:                    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 aperfmperf rapl pni pclmulqdq monitor ssse3 fma cx16 sse4_1 sse4_2 x2apic movbe popcnt aes xsave avx f16c rdrand lahf_lm cmp_legacy svm extapic cr8_legacy abm sse4a misalignsse 3dnowprefetch osvw ibs skinit wdt tce topoext perfctr_core perfctr_nb bpext perfctr_llc mwaitx cpb cat_l3 cdp_l3 hw_pstate ssbd mba ibrs ibpb stibp vmmcall fsgsbase bmi1 avx2 smep bmi2 erms invpcid cqm rdt_a rdseed adx smap clflushopt clwb sha_ni xsaveopt xsavec xgetbv1 xsaves cqm_llc cqm_occup_llc cqm_mbm_total cqm_mbm_local clzero irperf xsaveerptr rdpru wbnoinvd cppc arat npt lbrv svm_lock nrip_save tsc_scale vmcb_clean flushbyasid decodeassists pausefilter pfthreshold avic v_vmsave_vmload vgif v_spec_ctrl umip pku ospke vaes vpclmulqdq rdpid overflow_recov succor smca fsrm
Virtualisierung:                 AMD-V
L1d Cache:                       256 KiB (8 instances)
L1i Cache:                       256 KiB (8 instances)
L2 Cache:                        4 MiB (8 instances)
L3 Cache:                        16 MiB (1 instance)
NUMA-Knoten:                     1
NUMA-Knoten0 CPU(s):             0-15
Vulnerability Itlb multihit:     Not affected
Vulnerability L1tf:              Not affected
Vulnerability Mds:               Not affected
Vulnerability Meltdown:          Not affected
Vulnerability Mmio stale data:   Not affected
Vulnerability Retbleed:          Not affected
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, IBRS_FW, STIBP always-on, RSB filling, PBRSB-eIBRS Not affected
Vulnerability Srbds:             Not affected
Vulnerability Tsx async abort:   Not affected

Versions of relevant libraries:
[pip3] clip-anytorch==2.5.2
[pip3] mypy-extensions==1.0.0
[pip3] numpy==1.23.5
[pip3] open-clip-torch==2.16.0
[pip3] pytorch-lightning==1.7.7
[pip3] pytorch-triton-rocm==2.0.2
[pip3] torch==2.0.0+rocm5.4.2
[pip3] torch-fidelity==0.3.0
[pip3] torchaudio==2.0.0+rocm5.4.2
[pip3] torchcontrib==0.0.2
[pip3] torchdiffeq==0.2.3
[pip3] torchlibrosa==0.0.9
[pip3] torchmetrics==0.11.4
[pip3] torchsde==0.2.5
[pip3] torchvision==0.15.1+rocm5.4.2
[conda] No relevant packages


cc @jeffdaily @sunway513 @jithunnair-amd @pruthvistony @ROCmSupport