In this presentation from 2012, AMD details the potential benefits that developers could take advantage of to leverage additional performance efficiency boosts and parallellism in gaming via utilizing the HSA capabilities of selected silicon.
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Â
AMD 2012: HSA in Gaming
1. GPGPU ALGORITHMS IN GAMES
How Heterogeneous Systems Architecture can be
leveraged to optimize algorithms in video games
Matthijs De Smedt
Nixxes Software B.V.
Lead Graphics Programmer
2. | HSA Algorithms in Games | June 13th, 2012
CONTENTS
ï§ A short introduction
ï§ Current usage of GPGPU in games
ï§ Heterogeneous Systems Architecture
ï§ Examples made possible by HSA
4. | HSA Algorithms in Games | June 13th, 2012
VIDEOGAMES
ï§ Games are near real-time simulations
ï§ Response time is key
ï§ Most systems run in sync with the output frequency
â Rendering 60 frames per second
â Allows for 16ms of processing time
ï§ Framerate is limited either by:
â GPU
â CPU
â Display (VSync)
CPU
GPU
Input
Simulate
Render
Render
5. | HSA Algorithms in Games | June 13th, 2012
HARDWARE
ï§ Typical hardware target for PC games:
â One multicore CPU
â One GPU
ï§ Multiple GPUs: CrossFire
â Transparent to the application
â Driver alternates frames between GPUs
ï§ GPUs are becoming more general purpose:
â General Purpose GPU algorithms (GPGPU)
CrossFire
7. | HSA Algorithms in Games | June 13th, 2012
INTRODUCTION TO GPGPU
ï§ Rendering is a sequence of parallel algorithms
ï§ GPUs are great at parallel computation
ï§ Evolution of hardware and software to general purpose
ï§ First GPGPU was accomplished with programmable rendering
â DirectX
â OpenGL
ï§ Second generation using dedicated GPGPU APIs:
â CUDA
â OpenCL
â DirectCompute
ï§ Third generation of GPGPU on the way:
â Heterogeneous Systems Architecture
8. | HSA Algorithms in Games | June 13th, 2012
GPGPU IN GAMES
ï§ Some GPGPU algorithms are being used in
games right now. For example:
â Physics
ï§ Particles
ï§ Fluid simulation
ï§ Destruction
â Specialized graphics algorithms
ï§ Post-processing
ï§ All these algorithms drive visual effects
GPU particle system by Fairlight
9. | HSA Algorithms in Games | June 13th, 2012
CURRENT PHYSICS EXAMPLE
ï§ GPGPU particle simulation using DirectCompute
ï§ Great for simulating thousands of visible particles
ï§ Results of simulation are never copied back to CPU
â Can not interfere with gameplay
â Not synced in networked games
ï§ Example: Smoke particles that affect game AI
CPU
GPU
Call GPU
Simulate
particles
Render
particles
10. | HSA Algorithms in Games | June 13th, 2012
GPGPU LIMITATIONS
ï§ Why isnât GPGPU used more for non-graphics?
ï§ Latency
â DirectX has many layers and buffers
â DirectX commands are buffered up to multiple frames
â Actual execution on the GPU is delayed
ï§ Copy overhead
â GPU cannot directly access application memory
â Must copy all data from and to the application
ï§ Functionality
â Constrained programming models
12. | HSA Algorithms in Games | June 13th, 2012
HETEROGENEOUS SYSTEMS ARCHITECTURE
Hardware Software
ï§ "Drivers"
â HSA provides a new, thin Compute API
â Very low latency
â Unified Address Space
â Exposes more hardware capabilities
ï§ HSA Intermediate Language
â Virtual ISA
â Introduces CPU programming features to the GPU
ï§ New features on discrete GPUs
ï§ Accelerated Processing Unit
â Next generation processor
â Multiple CPU and GPU cores on
the same die
â Shared memory access
â Soon to be as widespread as
multicore CPUs
ï§ New hardware and software
13. | HSA Algorithms in Games | June 13th, 2012
USING THE APU
ï§ Distinction between two hardware configurations
ï§ APU without discrete GPU
â Found in many laptops, soon in many desktops
â Use the on-die GPU for rendering
ï§ APU with discrete GPU:
â Hard-core gamers will still use discrete GPUs
â Asymmetrical CrossFire
â Or: Dedicate the on-die GPU to Compute algorithms
ï§ Could result in massive speedup of algorithms
ï§ Using SIMD co-processors to offload the CPU is familiar to PS3 developers
14. | HSA Algorithms in Games | June 13th, 2012
COPY OVERHEAD
ï§ Current Compute APIs require the application to explicitly copy all input and output memory
â Copying can easily takes longer than processing on CPU!
â Only small datasets or very expensive computations benefit from GPGPU
ï§ HSA introduces a Unified Address Space for CPU and GPU memory
â CPU pointers on the GPU
â Virtual memory on the GPU
ï§ Paging over PCI-Express (discrete) or shared memory controller (APU)
â Fully coherent
â Will make GPGPU an option for many more algorithms
15. | HSA Algorithms in Games | June 13th, 2012
LATENCY
ï§ DirectX commands are buffered
ï§ When the GPU is fully loaded this buffer is saturated
ï§ Delay between scheduling and executing a GPGPU program on a busy GPU can take multiple frames
â Results will be several frames behind
â Game simulation needs all objects to be in sync
ï§ GPGPU is currently impractical to use for anything but visual effects
20. | HSA Algorithms in Games | June 13th, 2012
LATENCY
ï§ HSAâs new Compute API will reduce latency
ï§ How to deal with a saturated GPU?
ï§ A second GPU
â Dedicate the APU to Compute
â Virtually no latency
ï§ HSA feature: Graphics pre-emption
â Context switching on the GPU
ï§ Interrupt a graphics task (typically a large command list)
ï§ Execute Compute algorithm
ï§ Switch back to graphics
â Can be used both on discrete GPUs or on the APU
ï§ Choose the solution best suited to your needs
21. | HSA Algorithms in Games | June 13th, 2012
APU USAGE EXAMPLE
GPU
CPU
HSA
Frame
Schedule
DirectCompute
Execute
Execute
22. | HSA Algorithms in Games | June 13th, 2012
PROGRAMMING MODEL
ï§ HSA Intermediate Language: HSAIL
ï§ Designed for parallel algorithms
ï§ JIT compiles your algorithm to CPU or GPU hardware
â Also makes multi-core SIMD programming easy!
ï§ High level language features
â Object-oriented programming
â Virtual functions
â Exceptions
ï§ Debugging
ï§ SysCall support
â I/O
24. | HSA Algorithms in Games | June 13th, 2012
PHYSICS
ï§ Current GPGPU physics solutions only output to
the renderer
ï§ With HSA you can simulate physics on the GPU
and get the results back in the same frame
ï§ Use hardware acceleration to compute physics for
gameplay objects
ï§ Reduced CPU load
ï§ More objects, higher fidelity
25. | HSA Algorithms in Games | June 13th, 2012
FRUSTUM CULLING
ï§ Videogames tend to be GPU-bound
ï§ Avoid rendering what cannot be seen
ï§ Cull objects outside the camera viewport
â Test the bounding box of every object against
the camera frustum
â Currently done on the CPU
â Lots of vector math
â Can be computed completely in parallel!
ï§ CPU needs the results immediately
â HSA will allow low-latency execution
26. | HSA Algorithms in Games | June 13th, 2012
OCCLUSION CULLING
ï§ Objects may be hidden behind others: Occlusion
ï§ Final per-pixel occlusion is only known after
rendering the scene
ï§ Approximate occlusion by rendering low-detail
geometry
â This kind of occlusion culling is currently being
done on CPU or on SPUs
â Rendering is better suited to GPUs
ï§ HSA solution:
â Software rasterization in Compute on the GPU
â HSA does not yet expose graphics pipeline ï
â Still much faster than a multicore CPU
Software occlusion culling in Battlefield 3
27. | HSA Algorithms in Games | June 13th, 2012
SORTING
ï§ Typically several long lists per frame need sorting
ï§ Sorting on the GPU using a parallel sort algorithm
â Ken Batcher: Bitonic or Odd-even mergesort
ï§ Copy overhead currently negates the performance
advantage of using a GPU sorting algorithm
ï§ HSA solution:
â Unified Address Space
â GPU can sort in-place in system memory
28. | HSA Algorithms in Games | June 13th, 2012
ASSET DECOMPRESSION
ï§ Game assets are stored compressed on disk
ï§ Decompression is expensive
ï§ The usage of some compression algorithms is
prevented by CPU speed
ï§ Games are moving away from loading screens
ï§ An APU with Unified Address Space
â Can be used to decompress new assets
without taxing the CPU or discrete GPU
â Perhaps even use HSAIL I/O to read from disk
â A better streaming experience for gamers
29. | HSA Algorithms in Games | June 13th, 2012
PATHFINDING
ï§ Some strategy games simulate thousands of units
ï§ Pathfinding over complex terrain with thousands of
moving units is very expensive
ï§ Clever approximate solutions are often used
â Supreme Commander 2 âFlow fieldâ
ï§ GPGPU pathfinding with HSA
â Use one GPU thread per unit to do a deep
search for an optimal path
â With HSA such an algorithm can page all
requisite data from system memory and write
back found paths
â APU could be fully saturated with pathfinding
without impacting framerate
30. | HSA Algorithms in Games | June 13th, 2012
CONCLUSION
ï§ Many algorithms in games are suitable for offloading to the GPU
ï§ Heterogeneous Systems Architecture solves two major obstacles
â Latency
â Memory access
ï§ HSAIL allows for entirely new kinds of GPGPU programs
ï§ APUs can be used to offload the CPU
ï§ HSA will finally make GPUs available to developers as full-featured co-processors
31. | HSA Algorithms in Games | June 13th, 2012
THANK YOU
ï§ Any questions?
32.
33. | HSA Algorithms in Games | June 13th, 2012
Disclaimer & Attribution
The information presented in this document is for informational purposes only and may contain technical inaccuracies, omissions
and typographical errors.
The information contained herein is subject to change and may be rendered inaccurate for many reasons, including but not limited
to product and roadmap changes, component and motherboard version changes, new model and/or product releases, product
differences between differing manufacturers, software changes, BIOS flashes, firmware upgrades, or the like. There is no
obligation to update or otherwise correct or revise this information. However, we reserve the right to revise this information and to
make changes from time to time to the content hereof without obligation to notify any person of such revisions or changes.
NO REPRESENTATIONS OR WARRANTIES ARE MADE WITH RESPECT TO THE CONTENTS HEREOF AND NO
RESPONSIBILITY IS ASSUMED FOR ANY INACCURACIES, ERRORS OR OMISSIONS THAT MAY APPEAR IN THIS
INFORMATION.
ALL IMPLIED WARRANTIES OF MERCHANTABILITY OR FITNESS FOR ANY PARTICULAR PURPOSE ARE EXPRESSLY
DISCLAIMED. IN NO EVENT WILL ANY LIABILITY TO ANY PERSON BE INCURRED FOR ANY DIRECT, INDIRECT, SPECIAL
OR OTHER CONSEQUENTIAL DAMAGES ARISING FROM THE USE OF ANY INFORMATION CONTAINED HEREIN, EVEN IF
EXPRESSLY ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
AMD, the AMD arrow logo, and combinations thereof are trademarks of Advanced Micro Devices, Inc. All other names used in
this presentation are for informational purposes only and may be trademarks of their respective owners.
The contents of this presentation were provided by individual(s) and/or company listed on the title page. The information and
opinions presented in this presentation may not represent AMDâs positions, strategies or opinions. Unless explicitly stated, AMD is
not responsible for the content herein and no endorsements are implied.