# Why GPU still OOM when using CUDA unified memory?

**URL:** https://discourse.julialang.org/t/why-gpu-still-oom-when-using-cuda-unified-memory/111543
**Category:** GPU
**Created:** [March 12, 2024, 9:46pm UTC](https://discourse.julialang.org/t/why-gpu-still-oom-when-using-cuda-unified-memory/111543 "2024-03-12T21:46:16Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![pxshen](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pxshen/32/38776_2.png) [@pxshen](https://discourse.julialang.org/u/pxshen)
#### Post date: [March 12, 2024, 9:46pm UTC](https://discourse.julialang.org/t/why-gpu-still-oom-when-using-cuda-unified-memory/111543/1 "2024-03-12T21:46:16Z")

</div>

I’ve way more RAM than VRAM. Code runs fine on CPU. I thought using CUDA unified memory lets GPU tap system RAM but it still OOM.

I’m asking bc I’m getting a new laptop for ML work. Does unified memory mean VRAM is no longer a hard ceiling and as important of a spec? (I know having GPU tap system RAM is way slower but at least it runs)

---

<div class="post-metadata">

### Author: ![Benny](https://avatars.discourse-cdn.com/v4/letter/b/49beb7/32.png) [@Benny](https://discourse.julialang.org/u/Benny)
#### Post date: [March 12, 2024, 10:10pm UTC](https://discourse.julialang.org/t/why-gpu-still-oom-when-using-cuda-unified-memory/111543/2 "2024-03-12T22:10:16Z")

</div>

What you’re describing sounds more like an integrated GPU sharing memory with the CPU. Apple has a [Unified Memory Architecture](https://appleinsider.com/articles/23/06/28/why-apple-uses-integrated-memory-in-apple-silicon----and-why-its-both-good-and-bad) that does this in small part. CUDA’s [Unified Memory](https://developer.nvidia.com/blog/unified-memory-in-cuda-6/) is an unrelated software abstraction that lets the GPU and CPU code access data with the same pointer, even when the data is actually being migrated between the CPU’s and GPU’s memory.

---

<div class="post-metadata">

### Author: ![xgdgsc](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/xgdgsc/32/608_2.png) [@xgdgsc](https://discourse.julialang.org/u/xgdgsc)
#### Post date: [March 13, 2024, 6:13am UTC](https://discourse.julialang.org/t/why-gpu-still-oom-when-using-cuda-unified-memory/111543/3 "2024-03-13T06:13:32Z")

</div>

Depends on your OS. Windows might have this [Can PyTorch GPU Use Shared GPU Memory (from RAM, shows in Windows Task Manage)? - Stack Overflow](https://stackoverflow.com/a/77606583/1136027)

---

<div class="post-metadata">

### Author: ![photor](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/photor/32/14343_2.png) [@photor](https://discourse.julialang.org/u/photor)
#### Post date: [March 13, 2024, 2:43pm UTC](https://discourse.julialang.org/t/why-gpu-still-oom-when-using-cuda-unified-memory/111543/4 "2024-03-13T14:43:44Z")

</div>

interesting

---

<div class="post-metadata">

### Author: ![maleadt](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/maleadt/32/10097_2.png) [@maleadt](https://discourse.julialang.org/u/maleadt)
#### Post date: [March 13, 2024, 3:08pm UTC](https://discourse.julialang.org/t/why-gpu-still-oom-when-using-cuda-unified-memory/111543/5 "2024-03-13T15:08:43Z")

</div>

> [@pxshen](#):
>
> I thought using CUDA unified memory lets GPU tap system RAM

Works here:

```julia
julia> Sys.free_memory() |> Base.format_bytes
"55.165 GiB"

julia> CUDA.available_memory() |> Base.format_bytes
"46.865 GiB"

julia> a = CuVector{UInt8,Mem.Unified}(undef, 50*2^30);

julia> sizeof(a) |> Base.format_bytes
"50.000 GiB"

julia> a .= 1;

julia> Sys.free_memory() |> Base.format_bytes
"7.322 GiB"

julia> CUDA.available_memory() |> Base.format_bytes
"2.000 MiB"

```

What platform are you on?

---

<div class="post-metadata">

### Author: ![pxshen](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pxshen/32/38776_2.png) [@pxshen](https://discourse.julialang.org/u/pxshen)
#### Post date: [March 14, 2024, 5:01pm UTC](https://discourse.julialang.org/t/why-gpu-still-oom-when-using-cuda-unified-memory/111543/6 "2024-03-14T17:01:30Z")

</div>

Cool didn’t know it can split a single variable. I’m on Windows cuda 12 but a really old gpu so prob not bother debugging. for otherfolks: you can let cuda.jl alloc unified buffer by default by adding LocalPreferences.toml to your env folder w/ lines of  
[CUDA]  
default\_memory =“unified”

---

<div class="post-metadata">

### Author: ![maleadt](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/maleadt/32/10097_2.png) [@maleadt](https://discourse.julialang.org/u/maleadt)
#### Post date: [March 14, 2024, 6:44pm UTC](https://discourse.julialang.org/t/why-gpu-still-oom-when-using-cuda-unified-memory/111543/7 "2024-03-14T18:44:30Z")

</div>

> [@pxshen](#):
>
> I’m on Windows cuda 12 but a really old gpu

From [CUDA C++ Programming Guide](https://docs.nvidia.com/cuda/cuda-c-programming-guide/index.html#um-legacy-devices:)

> Devices of compute capability lower than 6.0 cannot allocate more managed memory than the physical size of GPU memory.
