Sign in to follow this  
Chris_F

OpenGL OpenGL and unified address space

Recommended Posts

Chris_F    3030
Supposedly new and upcoming hardware supports a feature refereed to as "unified address space" whereby the GPU and CPU can share the same address space, which should allow you to transfer data back and forth with nothing but a memory pointer.

I haven't managed to find much practical information on this. How exactly can this be used? Are there OpenGL extensions for this?

Share this post


Link to post
Share on other sites
swiftcoder    18437
[quote name='Chris_F' timestamp='1348602202' post='4983697']
Supposedly new and upcoming hardware supports a feature refereed to as "unified address space" whereby the GPU and CPU can share the same address space, which should allow you to transfer data back and forth with nothing but a memory pointer.[/quote]
As an aside, integrated GPUs have done this for years.

It's especially easy in the integrated case, because the GPU is actually using a portion of main memory as its video memory. This has the odd effect of sometimes making CPU->GPU data transfer much cheaper for integrated GPUs than for faster, dedicated GPUs.

[quote name='Chris_F' timestamp='1348602202' post='4983697']
I haven't managed to find much practical information on this. How exactly can this be used? Are there OpenGL extensions for this?[/quote]
No, and I doubt that there will be, in the near future. Unified address space is much more the domain of OpenCL and CUDA computations - I would expect to see support for unified addressing in both of those. Edited by swiftcoder

Share this post


Link to post
Share on other sites
_the_phantom_    11250
[quote name='swiftcoder' timestamp='1348607470' post='4983747']
As an aside, integrated GPUs have done this for years.
[/quote]

In fact they haven't; CPUs and GPUs, even integrated ones, use their own address spaces to access the physical memory. What 0x00F4567380 refers to as far as the CPU is concerned is different to what the GPU sees.

AMD's Trinity APUs are, afaik, the first CPU+GPU combo where both parts can access the same memory without requiring a driver to do address translation in any form but it won't be until 2013 that they will be using the same memory controller.

As for the second part of the question; AMD do have some extensions which allow you to 'pin' memory so that it can't be swapped out (GPUs currently can't handle paging in/out of memory so any pages shared must be resident) and thus freely accessed by both CPU and GPU parts - however this is really only useful in the context of an APU otherwise the GPU would be accessing via the PCIe bus which would be a tad on the slow side.

Now, once both the CPU and GPU share the MMU and can respond to page faults accordingly such pinning won't be required, but that's not due until the 2013 time frame from AMD.

Share this post


Link to post
Share on other sites
swiftcoder    18437
[quote name='phantom' timestamp='1348610824' post='4983767']
In fact they haven't; CPUs and GPUs, even integrated ones, use their own address spaces to access the physical memory. What 0x00F4567380 refers to as far as the CPU is concerned is different to what the GPU sees.[/quote]
That isn't what I meant. Yes, the address space is different, but don't they still have the ability to transfer control of hardware pages back-and-forth?

Share this post


Link to post
Share on other sites
_the_phantom_    11250
Until recently I'm 99.999999% sure that isn't the case; on system start up a chunk of memory was reserved for the integrated GPUs and that was all they could see.

If you wanted to copy something to GPU controlled memory then it was copied across from 'system' ram to 'graphics' ram.

That's why AMD's pinning extensions is a pretty big deal as it allows for that zero-copy stuff to work but the GPU doesn't 'own' it, the memory is just locked so it can't be paged out from the physical address; the GPU itself is still just seeing a physical address, all be it one outside of its normal address range.

Share this post


Link to post
Share on other sites
Hodgman    51328
Most games consoles use a unified address space from system RAM / GPU RAM ([i]regardless of whether these are physically the same, or separate chips[/i]), which sounds pretty cool, but isn't that much of a game changer.
Some random observations:

* Loading of assets is more straightforward. Typically to load a texture, I read it from disk into some malloc'ed memory, then create a GPU texture resource, then copy my malloc'ed memory into the texture resource ([i]map/unmap/update/etc[/i]), then free my temporary memory.
On consoles, I can "malloc" some "GPU RAM" directly, and then stream the texture from disk straight into it.

* CPU read-back is still not a good idea, unless CPU/GPU RAM are physically unified as well. Dereferencing a pointer to GPU RAM may be very slow. In my experiences on systems where GPU/CPU RAM are physically seperate, despite being unified in address space, the CPU can [i]write[/i] to GPU RAM very quickly, but [i]reads[/i] from it ~10 times slower.

* Even if you do want to have to CPU/GPU communicate via shared memory, it's not straightforward. The GPU buffers commands, and is often an entire frame behind the CPU ([i]on PC, it can be even worse, with some drivers buffering up to half a dozen frames of commands at high frame-rates![/i]).
So, say for example that the GPU is producing some data for us, and the CPU wants to consume that data once it's complete -- then as well as having a (unified address space) pointer to the data to read, you also need to use GPU fence/[url="http://msdn.microsoft.com/en-us/library/windows/desktop/ff476191(v=vs.85).aspx#D3D11_QUERY_EVENT"]event[/url] system, so you can be notified once the GPU has completed that workload.
Or the converse of the above, where the CPU is producing data for the GPU to consume -- if that's some mutable resource, like changing a single pixel in a texture, then you need to insert GPU fences/events so you can tell when the GPU has finished using the previous version of that texture, then perform your modifications after the GPU has passed that fence/completed that event.

To expand on that last one -- on consoles you can work at a level where you've got a lot of synchronisation between the two processors to get the most out of your extremely limited resources ([i]keep in mind the PS3 has a [/i][i]256MiB [/i][i]GeForce7 and the 360 isn't much better!![/i]).
e.g. we've got 3 objects with procedural textures, but only enough ram for 2 at a time:
You can send off a whole stream of GPU commands in one go, which tells it to draw the 3 objects, but with some important notify/wait points
[font=courier new,courier,monospace]DrawA using Tex0, Notify DrawA complete, DrawB using Tex1, Infinite Loop C, DrawC using Tex0[/font]

You can then prime the CPU so that upon receiving "[i]Notify DrawA complete[/i]", it will immediately execute the function that writes out the appropriate texture data for DrawC into [font=courier new,courier,monospace]Tex0[/font] ([i]which is safe because DrawA is no longer using [font=courier new,courier,monospace]Tex0[/font][/i]).
Meanwhile the GPU continues on with DrawB, and if it completes it before the CPU has done this job, then it goes into an infinite loop ([i]lots of careful hand scheduling work will be done to try and ensure this doesn't happen for efficiency's sake[/i]).
When the CPU finishes writing out the new data to [font=courier new,courier,monospace]Tex0[/font], it overwrites "[font=courier new,courier,monospace]Infinite Loop C[/font]" with "[font=courier new,courier,monospace]goto next[/font]" -- if the GPU hasn't yet reached this command, then when it gets up to it, it will do nothing and move on to the next command ([i]to Draw C using the new [font=courier new,courier,monospace]Tex0[/font][/i]), or, if the GPU has reached the infinite loop, then this will break it out of it so that it can continue to Draw C.

I wouldn't dare try to implement something with such fine-grained CPU/GPU synchronisation via D3D/GL!!

So as you can see, unified address space, plus great event/notification between the two processors, plus explicit knowledge of how CPU->GPU latency and command buffering is implemented, allows you to make the most of both processors... however, this is advanced stuff that's really only done out of desperation on consoles to get by with old hardware. Ideally the above example would be scheduled in such a way that the CPU update job is quicker than the GPU's [font=courier new,courier,monospace]Draw B[/font] job ([i]so that the busy loop isn't executed at all by the GPU[/i]), but if your users can upgrade their GPU, then this busy-wait will occur for some users, and they'll get bottlenecked by their CPUs instead. Edited by Hodgman

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this  

  • Similar Content

    • By pseudomarvin
      I assumed that if a shader is computationally expensive then the execution is just slower. But running the following GLSL FS instead just crashes
      void main() { float x = 0; float y = 0; int sum = 0; for (float x = 0; x < 10; x += 0.00005) { for (float y = 0; y < 10; y += 0.00005) { sum++; } } fragColor = vec4(1, 1, 1 , 1.0); } with unhandled exception in nvoglv32.dll. Are there any hard limits on the number of steps/time that a shader can take before it is shut down? I was thinking about implementing some time intensive computation in shaders where it would take on the order of seconds to compute a frame, is that possible? Thanks.
    • By Arulbabu Donbosco
      There are studios selling applications which is just copying any 3Dgraphic content and regenerating into another new window. especially for CAVE Virtual reality experience. so that the user opens REvite or CAD or any other 3D applications and opens a model. then when the user selects the rendered window the VR application copies the 3D model information from the OpenGL window. 
      I got the clue that the VR application replaces the windows opengl32.dll file. how this is possible ... how can we copy the 3d content from the current OpenGL window.
      anyone, please help me .. how to go further... to create an application like VR CAVE. 
       
      Thanks
    • By cebugdev
      hi all,

      i am trying to build an OpenGL 2D GUI system, (yeah yeah, i know i should not be re inventing the wheel, but this is for educational and some other purpose only),
      i have built GUI system before using 2D systems such as that of HTML/JS canvas, but in 2D system, i can directly match a mouse coordinates to the actual graphic coordinates with additional computation for screen size/ratio/scale ofcourse.
      now i want to port it to OpenGL, i know that to render a 2D object in OpenGL we specify coordiantes in Clip space or use the orthographic projection, now heres what i need help about.
      1. what is the right way of rendering the GUI? is it thru drawing in clip space or switching to ortho projection?
      2. from screen coordinates (top left is 0,0 nd bottom right is width height), how can i map the mouse coordinates to OpenGL 2D so that mouse events such as button click works? In consideration ofcourse to the current screen/size dimension.
      3. when let say if the screen size/dimension is different, how to handle this? in my previous javascript 2D engine using canvas, i just have my working coordinates and then just perform the bitblk or copying my working canvas to screen canvas and scale the mouse coordinates from there, in OpenGL how to work on a multiple screen sizes (more like an OpenGL ES question).
      lastly, if you guys know any books, resources, links or tutorials that handle or discuss this, i found one with marekknows opengl game engine website but its not free,
      Just let me know. Did not have any luck finding resource in google for writing our own OpenGL GUI framework.
      IF there are no any available online, just let me know, what things do i need to look into for OpenGL and i will study them one by one to make it work.
      thank you, and looking forward to positive replies.
    • By fllwr0491
      I have a few beginner questions about tesselation that I really have no clue.
      The opengl wiki doesn't seem to talk anything about the details.
       
      What is the relationship between TCS layout out and TES layout in?
      How does the tesselator know how control points are organized?
          e.g. If TES input requests triangles, but TCS can output N vertices.
             What happens in this case?
      In this article,
      http://www.informit.com/articles/article.aspx?p=2120983
      the isoline example TCS out=4, but TES in=isoline.
      And gl_TessCoord is only a single one.
      So which ones are the control points?
      How are tesselator building primitives?
    • By Orella
      I've been developing a 2D Engine using SFML + ImGui.
      Here you can see an image
      The editor is rendered using ImGui and the scene window is a sf::RenderTexture where I draw the GameObjects and then is converted to ImGui::Image to render it in the editor.
      Now I need to create a 3D Engine during this year in my Bachelor Degree but using SDL2 + ImGui and I want to recreate what I did with the 2D Engine. 
      I've managed to render the editor like I did in the 2D Engine using this example that comes with ImGui. 
      3D Editor preview
      But I don't know how to create an equivalent of sf::RenderTexture in SDL2, so I can draw the 3D scene there and convert it to ImGui::Image to show it in the editor.
      If you can provide code will be better. And if you want me to provide any specific code tell me.
      Thanks!
  • Popular Now