Aaron Lefohn University of California, Davis GPU Memory Model Overview.

45
Aaron Lefohn Aaron Lefohn University of California, University of California, Davis Davis GPU Memory Model Overview GPU Memory Model Overview

Transcript of Aaron Lefohn University of California, Davis GPU Memory Model Overview.

Page 1: Aaron Lefohn University of California, Davis GPU Memory Model Overview.

Aaron LefohnAaron Lefohn

University of California, University of California, DavisDavis

GPU Memory Model GPU Memory Model OverviewOverview

Page 2: Aaron Lefohn University of California, Davis GPU Memory Model Overview.

OverviewOverview

• GPU Memory Model• GPU Data Structure Basics• Introduction to Framebuffer Objects

Page 3: Aaron Lefohn University of California, Davis GPU Memory Model Overview.

3

Memory HierarchyMemory Hierarchy

• CPU and GPU Memory Hierarchy

Disk

CPU Main Memory

GPU Video Memory

CPU Caches

CPU Registers GPU Caches

GPU Temporary Registers

GPU Constant Registers

Page 4: Aaron Lefohn University of California, Davis GPU Memory Model Overview.

4

CPU Memory ModelCPU Memory Model

• At any program point– Allocate/free local or global memory– Random memory access

• Registers– Read/write

• Local memory– Read/write to stack

• Global memory– Read/write to heap

• Disk– Read/write to disk

Page 5: Aaron Lefohn University of California, Davis GPU Memory Model Overview.

5

GPU Memory ModelGPU Memory Model

• Much more restricted memory access– Allocate/free memory only before computation– Limited memory access during computation

(kernel)• Registers

– Read/write

• Local memory– Does not exist

• Global memory– Read-only during computation– Write-only at end of computation (pre-computed

address)

• Disk access– Does not exist

Page 6: Aaron Lefohn University of California, Davis GPU Memory Model Overview.

GPU Memory ModelGPU Memory Model

• Where is GPU Data Stored?– Vertex buffer– Frame buffer– Texture

Vertex BufferVertex

ProcessorRasterizer

FragmentProcessor

Texture

Frame Buffer(s)

VS 3.0 GPUs

Page 7: Aaron Lefohn University of California, Davis GPU Memory Model Overview.

7

GPU Memory APIGPU Memory API

• Each GPU memory type supports subset of the following operations– CPU interface– GPU interface

Page 8: Aaron Lefohn University of California, Davis GPU Memory Model Overview.

8

GPU Memory APIGPU Memory API

• CPU interface– Allocate– Free– Copy CPU GPU– Copy GPU CPU– Copy GPU GPU– Bind for read-only vertex stream access– Bind for read-only random access– Bind for write-only framebuffer access

Page 9: Aaron Lefohn University of California, Davis GPU Memory Model Overview.

9

GPU Memory APIGPU Memory API

• GPU (shader/kernel) interface– Random-access read– Stream read

Page 10: Aaron Lefohn University of California, Davis GPU Memory Model Overview.

Vertex BuffersVertex Buffers

• GPU memory for vertex data• Vertex data required to initiate

render pass

Vertex BufferVertex

ProcessorRasterizer

FragmentProcessor

Texture

Frame Buffer(s)

VS 3.0 GPUs

Page 11: Aaron Lefohn University of California, Davis GPU Memory Model Overview.

11

Vertex BuffersVertex Buffers

• Supported Operations– CPU interface

• Allocate• Free• Copy CPU GPU• Copy GPU GPU (Render-to-vertex-array)• Bind for read-only vertex stream access

– GPU interface• Stream read (vertex program only)

Page 12: Aaron Lefohn University of California, Davis GPU Memory Model Overview.

12

Vertex BuffersVertex Buffers

• Limitations– CPU

• No copy GPU CPU• No bind for read-only random access• No bind for write-only framebuffer access

– ATI supported this in uberbuffers. Perhaps we’ll see this as an OpenGL extension?

– GPU• No random-access reads• No access from fragment programs

Page 13: Aaron Lefohn University of California, Davis GPU Memory Model Overview.

TexturesTextures

• Random-access GPU memory

Vertex BufferVertex

ProcessorRasterizer

FragmentProcessor

Texture

Frame Buffer(s)

VS 3.0 GPUs

Page 14: Aaron Lefohn University of California, Davis GPU Memory Model Overview.

14

TexturesTextures

• Supported Operations– CPU interface

• Allocate• Free• Copy CPU GPU• Copy GPU CPU• Copy GPU GPU (Render-to-texture)• Bind for read-only random access (vertex or

fragment)• Bind for write-only framebuffer access

– GPU interface• Random read

Page 15: Aaron Lefohn University of California, Davis GPU Memory Model Overview.

15

TexturesTextures

• Limitations– No bind for vertex stream access

Page 16: Aaron Lefohn University of California, Davis GPU Memory Model Overview.

FramebufferFramebuffer

• Memory written by fragment processor

• Write-only GPU memory

Vertex BufferVertex

ProcessorRasterizer

FragmentProcessor

Texture

Frame Buffer(s)

VS 3.0 GPUs

Page 17: Aaron Lefohn University of California, Davis GPU Memory Model Overview.

17

OpenGL Framebuffer ObjectsOpenGL Framebuffer Objects

• General idea– Framebuffer object is lightweight struct of

pointers– Bind GPU memory to framebuffer as write-only– Memory cannot be read while bound to

framebuffer

• Which memory? – Texture– Renderbuffer– Vertex buffer??

Texture(RGBA)

Renderbuffer(Depth)

FramebufferObject

Page 18: Aaron Lefohn University of California, Davis GPU Memory Model Overview.

18

Framebuffer ObjectFramebuffer Object

• New OpenGL extension– Enables true render-to-texture in OpenGL– Mix-and-match depth/stencil buffers– Replaces pbuffers!– More details coming later in talk…

http://oss.sgi.com/projects/ogl-sample/registry/EXT/framebuffer_object.txt

Page 19: Aaron Lefohn University of California, Davis GPU Memory Model Overview.

19

What is a Renderbuffer?What is a Renderbuffer?

• “Traditional” framebuffer memory – Write-only GPU memory

• Color buffer• Depth buffer• Stencil buffer

• New OpenGL memory object– Part of Framebuffer Object extension

Page 20: Aaron Lefohn University of California, Davis GPU Memory Model Overview.

20

RenderbufferRenderbuffer

• Supported Operations– CPU interface

• Allocate• Free• Copy GPU CPU• Bind for write-only framebuffer access

Page 21: Aaron Lefohn University of California, Davis GPU Memory Model Overview.

21

Pixel Buffer ObjectsPixel Buffer Objects

• Mechanism to efficiently transfer pixel data– API nearly identical to vertex buffer objects

Vertex BufferVertex

ProcessorRasterizer

FragmentProcessor

Texture

Frame Buffer(s)

VS 3.0 GPUs

Page 22: Aaron Lefohn University of California, Davis GPU Memory Model Overview.

22

Pixel Buffer ObjectsPixel Buffer Objects

• Uses– Render-to-vertex-array

• glReadPixels into GPU-based pixel buffer• Use pixel buffer as vertex buffer

– Fast streaming textures• Map PBO into CPU memory space• Write directly to PBO• Reduces one or more copies

Page 23: Aaron Lefohn University of California, Davis GPU Memory Model Overview.

23

Pixel Buffer ObjectsPixel Buffer Objects

• Uses (continued)– Asynchronous readback

• Non-blocking GPU CPU data copy• glReadPixels into PBO does not block• Blocks when PBO is mapped into CPU memory

Page 24: Aaron Lefohn University of California, Davis GPU Memory Model Overview.

Summary : Render-to-Summary : Render-to-TextureTexture

• Basic operation in GPGPU apps

• OpenGL Support– Save up to 16, 32-bit floating values per pixel

• Multiple Render Targets (MRTs) on ATI and NVIDIA

1. Copy-to-texture• glCopyTexSubImage

2. Render-to-texture• GL_EXT_framebuffer_object

Page 25: Aaron Lefohn University of California, Davis GPU Memory Model Overview.

25

Summary : Render-To-Vertex-Summary : Render-To-Vertex-ArrayArray• Enable top-of-pipe feedback loop

• OpenGL Support– Copy-to-vertex-array

• GL_ARB_pixel_buffer_object• NVIDIA and ATI

– Render-to-vertex-array• Maybe future extension to framebuffer objects

Page 26: Aaron Lefohn University of California, Davis GPU Memory Model Overview.

26

OverviewOverview

• GPU Memory Model• GPU Data Structure Basics• Introduction to Framebuffer Objects

Page 27: Aaron Lefohn University of California, Davis GPU Memory Model Overview.

27

GPU Data Structure GPU Data Structure BasicsBasics• Summary of “Implementing Efficient

Parallel Data Structures on GPUs”– Chapter 33, GPU Gems II

• Low-level details– See the “Glift” talk for high-level view of GPU

data structures

• Now for the gory details…

Page 28: Aaron Lefohn University of California, Davis GPU Memory Model Overview.

28

GPU ArraysGPU Arrays

• Large 1D Arrays– Current GPUs limit 1D array sizes to 2048 or

4096– Pack into 2D memory– 1D-to-2D address translation

Page 29: Aaron Lefohn University of California, Davis GPU Memory Model Overview.

29

GPU ArraysGPU Arrays

• 3D Arrays– Problem

• GPUs do not have 3D frame buffers• No render-to-slice-of-3D-texture yet (coming

soon?)

– Solutions1. Stack of 2D slices2. Multiple slices per 2D buffer

Page 30: Aaron Lefohn University of California, Davis GPU Memory Model Overview.

30

GPU ArraysGPU Arrays

• Problems With 3D Arrays for GPGPU– Cannot read stack of 2D slices as 3D texture– Must know which slices are needed in advance– Visualization of 3D data difficult

• Solutions– Flat 3D textures– Need render-to-slice-of-3D-texture

– Maybe with GL_EXT_framebuffer_object

– Volume rendering of flattened 3D data– “Deferred Filtering: Rendering from Difficult Data

Formats,” GPU Gems 2, Ch. 41, p. 667

Page 31: Aaron Lefohn University of California, Davis GPU Memory Model Overview.

31

GPU ArraysGPU Arrays

• Higher Dimensional Arrays– Pack into 2D buffers– N-D to 2D address translation– Same problems as 3D arrays if data does not

fit in a single 2D texture

Page 32: Aaron Lefohn University of California, Davis GPU Memory Model Overview.

32

Sparse/Adaptive Data Sparse/Adaptive Data StructuresStructures• Why?

– Reduce memory pressure– Reduce computational workload

• Examples– Sparse matrices

• Krueger et al., Siggraph 2003• Bolz et al., Siggraph 2003

– Deformable implicit surfaces (sparse volumes/PDEs)• Lefohn et al., IEEE Visualization 2003 / TVCG 2004

– Adaptive radiosity solution (Coombe et al.)

Premoze et al.Eurographics 2003

Page 33: Aaron Lefohn University of California, Davis GPU Memory Model Overview.

33

Sparse/Adaptive Data Sparse/Adaptive Data StructuresStructures• Basic Idea

– Pack “active” data elements into GPU memory– For more information

• Linear algebra section in this course : Static structures• Adaptive grid case study in this course : Dynamic

structures

Page 34: Aaron Lefohn University of California, Davis GPU Memory Model Overview.

34

GPU Data StructuresGPU Data Structures

• Conclusions– Fundamental GPU memory primitive is a fixed-

size 2D array

– GPGPU needs more general memory model

– Building and modifying complex GPU-based data structures is an open research topic…

Page 35: Aaron Lefohn University of California, Davis GPU Memory Model Overview.

35

OverviewOverview

• GPU Memory Model• GPU-Based Data Structures• Introduction to Framebuffer Objects

Page 36: Aaron Lefohn University of California, Davis GPU Memory Model Overview.

36

Introduction to Framebuffer Introduction to Framebuffer ObjectsObjects• Where is the “Pbuffer Survival

Guide”?– Gone!!!– Framebuffer objects replace pbuffers– Simple, intuitive, fast render-to-texture in

OpenGL

http://oss.sgi.com/projects/ogl-sample/registry/EXT/framebuffer_object.txt

Page 37: Aaron Lefohn University of California, Davis GPU Memory Model Overview.

37

Framebuffer ObjectsFramebuffer Objects

• What is an FBO?– A struct that holds pointers to memory

objects– Each bound memory object can be a

framebuffer rendering surface– Platform-independent

Texture(RGBA)

Renderbuffer(Depth)

FramebufferObject

Page 38: Aaron Lefohn University of California, Davis GPU Memory Model Overview.

38

Framebuffer ObjectsFramebuffer Objects

• Which memory can be bound to an FBO?– Textures– Renderbuffers

• Depth, stencil, color• Traditional write-only framebuffer surfaces

Page 39: Aaron Lefohn University of California, Davis GPU Memory Model Overview.

39

Framebuffer ObjectsFramebuffer Objects

• Usage models– Keep N textures bound to one FBO (up to 16)

• Change render targets with glDrawBuffers

– Keep one FBO for each size/format• Change render targets with attach/unattach textures

– Keep several FBOs with textures attached• Change render targets by binding FBO

Page 40: Aaron Lefohn University of California, Davis GPU Memory Model Overview.

40

Framebuffer ObjectsFramebuffer Objects

• Performance– Render-to-texture

• glDrawBuffers is fastest on NVIDIA/ATI– As-fast or faster than pbuffers

• Attach/unattach textures same as changing FBOs

– Slightly slower than glDrawBuffers but faster than wglMakeCurrent

• Keep format/size identical for all attached memory

– Current driver limitation, not part of spec

– Readback• Same as pbuffers for NVIDIA and ATI

Page 41: Aaron Lefohn University of California, Davis GPU Memory Model Overview.

41

Framebuffer ObjectsFramebuffer Objects

• Driver support still evolving– GPUBench FBO tests coming soon…

• “fbocheck” evalulates completeness• Other tests…

Page 42: Aaron Lefohn University of California, Davis GPU Memory Model Overview.

42

Framebuffer ObjectFramebuffer Object

• Code examples– Simple C++ FBO and Renderbuffer classes

• HelloWorld example• http://gpgpu.sourceforge.net/

– OpenGL Spechttp://oss.sgi.com/projects/ogl-sample/registry/EXT/

framebuffer_object.txt

Page 43: Aaron Lefohn University of California, Davis GPU Memory Model Overview.

43

ConclusionsConclusions

• GPU Memory Model Evolving– Writable GPU memory forms loop-back in an

otherwise feed-forward pipeline– Memory model will continue to evolve as GPUs

become more general data-parallel processors

• GPGPU Data Structures– Basic memory primitive is limited-size, 2D texture– Use address translation to fit all array dimensions

into 2D– See “Glift” talk for higher-level GPU data structures

Page 44: Aaron Lefohn University of California, Davis GPU Memory Model Overview.

44

AcknowledgementsAcknowledgements

• Adam Moerschell, Shubho Sengupta UCDavis• Mike Houston Stanford

University• John Owens, Ph.D. advisor UC Davis

• National Science Foundation Graduate Fellowship

Page 45: Aaron Lefohn University of California, Davis GPU Memory Model Overview.

45

Questions?Questions?

• Google “Lefohn GPU”– http://graphics.cs.ucdavis.edu/~lefohn/