26

Since graphics cards provide large amounts of RAM (0.5GiB to 2GiB) and API access to the GPU is not that difficult with CUDA, Stream and more portable OpenCL I wondered if it is possible to use graphics memory as RAM. Grahics RAM might have a larger latency (from CPU) than real RAM but its definitively faster than HDD so it could be optimal for caching.

Is it possible to access graphics memory directly or at least with a thin memory management layer within own applications (rather than free usable for the OS)? If so, what the the preferred way to do this?

mbx
  • 6,292
  • 6
  • 58
  • 91
  • 2
    See footy's answer, which is a Linux specific hack. Apart from that you are without luck. OpenCL and similar APIs will not let you use graphics memory as additional RAM or swap space. Contrarily, any amount of RAM that you allocate on the graphics card with these is _also_ maintained as a copy in system RAM, i.e. you effectively "lose" RAM instead of "gaining some". – Damon Jun 12 '11 at 11:34
  • None of the APIs you mentioned support calls from kernel space, they are user space only. So if you were to try and do this, it would require a user space driver or daemon via a separate kernel space process (Linux FUSE springs to mind). I voted to close this because it really is off topic for stackoverflow. – talonmies Jun 12 '11 at 11:38
  • @Damon, that's only the case if you explicitly keep a Shadow Copy in main memory though. – Jasper Bekkers Jun 12 '11 at 12:24
  • 1
    @Jasper Bekkers: No need, the driver already does that. OpenCL, like OpenGL gives you the guarantee that data which you pass to it, e.g. into a buffer object will not magically disappear if something unexpected happens. Your CL context competes for the memory on the graphics card with an unknown number of other CL and/or GL contexts, the framebuffer, and whatnot. A resolution switch (and a dozen other events) can mean that your data is invalidated. The driver can only keep its integrity promise if it keeps at least one copy of all data you hand to it at all times. – Damon Jun 12 '11 at 17:29
  • 1
    @talonmies It would be fine to use the graphics RAM in own applications. It should use some kind of placement new. Perhaps one could write an allocator and then use map with that allocator. – mbx Jun 12 '11 at 20:15
  • Instead of RAM, you could also use it as swap space: https://wiki.archlinux.org/title/Swap_on_video_RAM – mbx Nov 03 '22 at 08:31

1 Answers1

17

Yes, you can use it as swap memory on Linux. Refer to the link here for more details.

With Linux, it's possible to use it as swap space, or even as RAM disk.

Be warned

It's nice to have fast swap or RAM disk on your home computer but be warned, if a binary driver is loaded for X, it may freeze the whole system or create graphical glitches. Usually there is no way to tell the driver how much memory could be used, so it won't know the upper limit. However, the VESA driver can be used because it provides the possibility to set the video RAM size.

So, Direct Rendering or fast swap. Your choice.

Unlike motherboard RAM and hard drives, there aren't any known video cards that have ECC memory. This may not be a big deal for graphics rendering, but you definitely don't want to put critical data in it or use this feature on servers.

Sam Sirry
  • 631
  • 5
  • 22
footy
  • 5,803
  • 13
  • 48
  • 96
  • 8
    Certain NVIDIA graphics cards in the Quadro and Tesla lines that are based on the Fermi architecture support ECC. For example, the Tesla C2050 and C2070 (see http://www.nvidia.com/object/personal-supercomputing.html), and the Quadro 5000 (see http://www.nvidia.com/docs/IO/40049/NV-DS-QUADRO-5000-Jul10-LR-final.pdf) – njuffa Jun 12 '11 at 16:26
  • is it possible in windows? – RaviSam Mar 18 '21 at 12:22
  • @RaviSam no - MS only allows page file on disk. – Andreas Hartmann May 30 '22 at 05:23