General Purpose computation on GPUs. Liangjun Zhang 2/23/2005

Similar documents
Dynamic Texturing. Mark Harris NVIDIA Corporation

Texture Mapping. CS 537 Interactive Computer Graphics Prof. David E. Breen Department of Computer Science

CISC 3620 Lecture 7 Lighting and shading. Topics: Exam results Buffers Texture mapping intro Texture mapping basics WebGL texture mapping

Lighting and Texturing

Buffers. Angel and Shreiner: Interactive Computer Graphics 7E Addison-Wesley 2015

CS 432 Interactive Computer Graphics

Lecture 19: OpenGL Texture Mapping. CITS3003 Graphics & Animation

CS452/552; EE465/505. Texture Mapping in WebGL

Computer Graphics. Bing-Yu Chen National Taiwan University

Discussion 3. PPM loading Texture rendering in OpenGL

CS4621/5621 Fall Basics of OpenGL/GLSL Textures Basics

Texture Mapping. Mike Bailey.

Lecture 07: Buffers and Textures

CSE 167: Introduction to Computer Graphics Lecture #7: Textures. Jürgen P. Schulze, Ph.D. University of California, San Diego Fall Quarter 2018

Graphics. Texture Mapping 고려대학교컴퓨터그래픽스연구실.

Texturing. Slides done bytomas Akenine-Möller and Ulf Assarsson Department of Computer Engineering Chalmers University of Technology

CT5510: Computer Graphics. Texture Mapping

CS452/552; EE465/505. Image Processing Frame Buffer Objects

Computergraphics Exercise 15/ Shading & Texturing

-=Catmull's Texturing=1974. Part I of Texturing

Lecture 2. Shaders, GLSL and GPGPU

CSC Graphics Programming. Budditha Hettige Department of Statistics and Computer Science

CS335 Graphics and Multimedia. Slides adopted from OpenGL Tutorial

The Problem: Difficult To Use. Motivation: The Potential of GPGPU CGC & FXC. GPGPU Languages

Texture Mapping. Computer Graphics, 2015 Lecture 9. Johan Nysjö Centre for Image analysis Uppsala University

Shaders. Slide credit to Prof. Zwicker

CS179: GPU Programming

CS GPU and GPGPU Programming Lecture 7: Shading and Compute APIs 1. Markus Hadwiger, KAUST

X. GPU Programming. Jacobs University Visualization and Computer Graphics Lab : Advanced Graphics - Chapter X 1

CSE 167: Introduction to Computer Graphics Lecture #8: Textures. Jürgen P. Schulze, Ph.D. University of California, San Diego Fall Quarter 2017

SUMMARY. CS380: Introduction to Computer Graphics Texture Mapping Chapter 15. Min H. Kim KAIST School of Computing 18/05/03.

GPGPU IGAD 2014/2015. Lecture 4. Jacco Bikker

CSE 167: Introduction to Computer Graphics Lecture #8: Textures. Jürgen P. Schulze, Ph.D. University of California, San Diego Spring Quarter 2016

Today. Texture mapping in OpenGL. Texture mapping. Basic shaders for texturing. Today. Computergrafik

GPU Memory Model Overview

MULTI-PASS VS SINGLE-PASS CUBEMAP

Introduction to Computer Graphics with WebGL

OpenGL Texture Mapping. Objectives Introduce the OpenGL texture functions and options

INF3320 Computer Graphics and Discrete Geometry

Textures. Texture Mapping. Bitmap Textures. Basic Texture Techniques

CSE 167: Introduction to Computer Graphics Lecture #6: Lights. Jürgen P. Schulze, Ph.D. University of California, San Diego Fall Quarter 2014

Computergrafik. Matthias Zwicker Universität Bern Herbst 2016

Programmable Graphics Hardware

last time put back pipeline figure today will be very codey OpenGL API library of routines to control graphics calls to compile and load shaders

Applying Textures. Lecture 27. Robb T. Koether. Hampden-Sydney College. Fri, Nov 3, 2017

Rendering Objects. Need to transform all geometry then

CS212. OpenGL Texture Mapping and Related

GPU Memory Model. Adapted from:

Imaging and Raster Primitives

Graphics Hardware. Instructor Stephen J. Guy

TSBK 07! Computer Graphics! Ingemar Ragnemalm, ISY

General Purpose Computation (CAD/CAM/CAE) on the GPU (a.k.a. Topics in Manufacturing)

CSE 167: Lecture #17: Volume Rendering. Jürgen P. Schulze, Ph.D. University of California, San Diego Fall Quarter 2012

CS 179 GPU Programming

Steiner- Wallner- Podaras

Texturing. Slides done by Tomas Akenine-Möller and Ulf Assarsson Department of Computer Engineering Chalmers University of Technology

Tutorial on GPU Programming #2. Joong-Youn Lee Supercomputing Center, KISTI

Fast Third-Order Texture Filtering

Copyright Khronos Group 2012 Page 1. Teaching GL. Dave Shreiner Director, Graphics and GPU Computing, ARM 1 December 2012

Shaders (some slides taken from David M. course)

Today. Rendering - III. Outline. Texturing: The 10,000m View. Texture Coordinates. Specifying Texture Coordinates in GL

General Purpose Computation (CAD/CAM/CAE) on the GPU (a.k.a. Topics in Manufacturing)

Pipeline Operations. CS 4620 Lecture Steve Marschner. Cornell CS4620 Spring 2018 Lecture 11

Real - Time Rendering. Graphics pipeline. Michal Červeňanský Juraj Starinský

Rationale for Non-Programmable Additions to OpenGL 2.0

GPGPU. Peter Laurens 1st-year PhD Student, NSC

Objectives. Texture Mapping and NURBS Week 7. The Limits of Geometric Modeling. Modeling an Orange. Three Types of Mapping. Modeling an Orange (2)

printf Debugging Examples

Lecture 22 Sections 8.8, 8.9, Wed, Oct 28, 2009

General Purpose Computation (CAD/CAM/CAE) on the GPU (a.k.a. Topics in Manufacturing)

Fog example. Fog is atmospheric effect. Better realism, helps determine distances

GPGPU: Parallel Reduction and Scan

Pipeline Operations. CS 4620 Lecture 14

The Graphics Pipeline

Shadow Rendering. CS7GV3 Real-time Rendering

Real-Time Rendering (Echtzeitgraphik) Michael Wimmer

UberFlow: A GPU-Based Particle Engine

Sign up for crits! Announcments

How to Work on Next Gen Effects Now: Bridging DX10 and DX9. Guennadi Riguer ATI Technologies

COMP371 COMPUTER GRAPHICS

CPSC 436D Video Game Programming

Real-time Graphics 9. GPGPU

Texture Mapping CSCI 4229/5229 Computer Graphics Fall 2016

OUTLINE. Implementing Texturing What Can Go Wrong and How to Fix It Mipmapping Filtering Perspective Correction

Graphics Hardware. Graphics Processing Unit (GPU) is a Subsidiary hardware. With massively multi-threaded many-core. Dedicated to 2D and 3D graphics

CS GPU and GPGPU Programming Lecture 2: Introduction; GPU Architecture 1. Markus Hadwiger, KAUST

Graphics Hardware, Graphics APIs, and Computation on GPUs. Mark Segal

frame buffer depth buffer stencil buffer

Real-time Graphics 9. GPGPU

Information Coding / Computer Graphics, ISY, LiTH GLSL. OpenGL Shading Language. Language with syntax similar to C

General Purpose Computation (CAD/CAM/CAE) on the GPU (a.k.a. Topics in Manufacturing)

Motivation Hardware Overview Programming model. GPU computing. Part 1: General introduction. Ch. Hoelbling. Wuppertal University

The Application Stage. The Game Loop, Resource Management and Renderer Design

Best practices for effective OpenGL programming. Dan Omachi OpenGL Development Engineer

Methodology for Lecture. Importance of Lighting. Outline. Shading Models. Brief primer on Color. Foundations of Computer Graphics (Spring 2010)

Programmable GPUS. Last Time? Reading for Today. Homework 4. Planar Shadows Projective Texture Shadows Shadow Maps Shadow Volumes

OPENGL RENDERING PIPELINE

Programmable GPUs. Real Time Graphics 11/13/2013. Nalu 2004 (NVIDIA Corporation) GeForce 6. Virtua Fighter 1995 (SEGA Corporation) NV1

Methodology for Lecture

Overview. Goals. MipMapping. P5 MipMap Texturing. What are MipMaps. MipMapping in OpenGL. Generating MipMaps Filtering.

Transcription:

General Purpose computation on GPUs Liangjun Zhang 2/23/2005

Outline Interpretation of GPGPU GPU Programmable interfaces GPU programming sample: Hello, GPGPU More complex programming GPU essentials, opportunity

Interpretation of GPGPU

GPU: Graphics Hardware From Stream Programming Environments Hanrahan, 2004.

What is GPGPU? General Purpose Computation on GPUs The GPU is a graphics-specific processor Useful for general computation Parallel processor 32-bit float support, even better Flexible programming

GPU Programmable interfaces

GPU Pipeline Fixed Pipeline -- > Programmable Vertex Shader, Kernel Pixel Shader ( Fragment Processor, Kernel)

Programmable Stream Model Kernel Parallel Stream Model Pixel Shader Input Stream (Framebuffer, Texture) Output Stream (Framebuffer, Texture)

The input of pixel shader Input: Fragment Input: Texture Image Attributes Color R G B A Position X Y Z W Texture coordinates X Y [Z] - Interpolated from vertex information Texture coordinates X Y [Z] - X Y Z W Each element of texture is 4D vector 32 bits = float Textures can be square or rectangular (power-of-two or not) 16 bits = half From http://www.cis.upenn.edu/~suvenkat/700

The output of pixel shader updated Color

GPU programming sample - Hello GPGPU

GPU programming sample - Hello GPGPU silhouette

Algorithm A simple post-process edge detection filter. -1/8-1/8-1/8-1/8 1-1/8-1/8-1/8-1/8

Pixel Shader (Image -> Texture) static const char *edgefragsource = "half4 edges(half2 coords : TEX0, \n" " uniform sampler2d texture) : COLOR \n" "{ \n" " static const half offset = 1.0 / 512.0; \n" " half4 c = tex2d(texture, coords); \n" " half4 bl = tex2d(texture, coords + half2(-offset, -offset)); \n" " half4 l = tex2d(texture, coords + half2(-offset, 0)); \n" " half4 tl = tex2d(texture, coords + half2(-offset, offset)); \n" " half4 t = tex2d(texture, coords + half2( 0, offset)); \n" " half4 ur = tex2d(texture, coords + half2( offset, offset)); \n" " half4 r = tex2d(texture, coords + half2( offset, 0)); \n" " half4 br = tex2d(texture, coords + half2( offset, -offset)); \n" " half4 b = tex2d(texture, coords + half2( 0, -offset)); \n" " // scale by 8 to brighten the edges \n" " return 8 * (c + -0.125 * (bl + l + tl + t + ur + r + br + b)); \n" "}

Details of Hello, GPGPU Draw A Teapot to frame buffer Why move the data from FB to texture? Copy the results from FB to the texture Bind Pixel Shading Program Draw a Viewport-Sized Quad Trigger Pixel Shader (Kernel) Fetch the filtered result from FB to the texture for rendering

GPGPU Programming Concepts 1. Texture = Array 2. Fragment Program = Computational Kernel. 3. One-to-one Pixel to Texel Mapping: a) Data-Dimensioned Viewport, and b) Orthographic Projection. 4. Viewport-Sized Quad = Data Stream Generator. 5. Copy To Texture = feedback.

Source Code Want to take a look at the source code? hellogpgpu.cpp

GPGPU programming Environments High Level Programming VS Assemble DirectX9 + HLSL High Level Shading Language OpenGL + GLSL OpenGL Shading Language OpenGL + cgtoolkit Some useful extensions Glew, glee

More complex programming Multipass Rendering Render to Texture Floating point texture/pbuffer

Streaming Model Kernel 1 Kernel 2 Input Stream (Framebuffer, Texture) Intermediate stream Output Stream (Framebuffer, Texture)

A streaming ray tracer Streams Ray Tracer on Programmable Graphics Hardware, Purcell, Hanrahan, Stanford

Multi pass rendering First Pass Second Pass Kernel 1 Kernel 2 Input Stream (Framebuffer, Texture) Intermediate stream Performance Bottlenecks Intermediate stream (Framebuffer) Texture glcopytexsubimage*()

Render To Texture - PBuffer From GDC2002 -- OpenGL Render-to-Texture, NVidia

What is Dynamic Texturing? The creation of texture maps on the fly for use in real time. Simplified view: Loop: 1. Render an image. 2. Create a texture from that image. 3. Use the texture as you would a static texture.

Challenge of Dynamic Texturing Performance Bottlenecks Simplified view: Loop: 1. Render an image. 2. Create a texture from that image. 3. Use the texture as you would a static texture. *Step 2 is primary bottleneck but 1 and 3 can be relevant as well.

Methods for Creating the Texture How to get rendered image into a texture? glreadpixels() glteximage*()? Slow. glcopyteximage*() Better. glcopytexsubimage*() Even Better. Render Directly to Texture Eliminates texture copy potentially optimal

Rendering Directly to a Texture Not a core part of OpenGL 1.3, but ARB extensions make this possible on most GPUs. Required Extensions: WGL_ARB_extensions_string WGL_ARB_render_texture WGL_ARG_pbuffer WGL_ARB_pixel_format

Rendering to a Texture: overview Basic Idea: Allow a p-buffer to be bound as a texture 1. Create a texture object 2. Create a Render Texture (i.e. the pbuffer) 3. Loop as necessary: Make the pbuffer the current rendering target Render an image Make the window the current rendering target Bind the pbuffer to the texture object Use the texture object as you would any other Release the pbuffer from the texture object 4. Clean Up

Creating the Texture Object Just as you would for a regular texture -- no need to specify the actual texture data // Create a render texture object glgentextures( 1, &render_texture ); glbindtexture( GL_TEXTURE_2D, render_texture ); gltexparameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR ); gltexparameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR ); gltexparameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE ); gltexparameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE );

Creating the Pbuffer Get a valid device context HDC hdc = wglgetcurrentdc(); Choose a pixel format wglchoosepixelformat() Create the pbuffer HPBUFFER hbuf = wglcreatepbufferarb( hdc, fid, width, height, pfattr ); Get a rendering context for the pbuffer hpbufglrc = wglcreatecontext( hpbufdc );

Rendering to the Texture Can be done anytime once the creation of the pbuffer is complete Initialization function, display loop, every 10 frames, etc. Must make the rendering context for the pbuffer current using wglmakecurrent: wglmakecurrent( hpbufdc, hpbufglrc ); Issue OpenGL drawing commands wglmakecurrent( hwindc, hwinglrc );

Binding the pbuffer to the texture object Call wglbindteximagearb to bind the pbuffer to the texture object. After binding the texture object

Floating Point Texture / PBuffer Numerical Computation High Accuracy Requirements

Floating Point Texture glteximage2d(gl_texture_2d,, GL_RGB, GL_FLOAT, texdata);

Floating Point Pbuffer HPBUFFER hbuf = wglcreatepbufferarb( hdc, fid, width, height, pfattr ); if (WGLEW_NV_float_buffer) { pfattribs.push_back(wgl_pixel_type_arb); pfattribs.push_back(wgl_type_rgba_arb); pfattribs.push_back(wgl_float_components_nv); pfattribs.push_back(true); } else { pfattribs.push_back(wgl_pixel_type_arb); pfattribs.push_back(wgl_type_rgba_float_ati); }

Quiz 1 Vector + Vector

Solution: Vector + Vector Input: How to represent the input data Floating Point Pbuffer Kernel? Output: Render to Texture Vector 2D Texture

Quiz 2 Matrix * Vector

Matrix Representations http://www15.in.tum.de/research/publications/linalg

Solution: Matrix * Vector Input: How to represent the input data Floating Point Rendering Multipass rendering Making use of Vector + Vector Output: Render to Texture

GPU essentials SIMD model, Parallelism Single instruction multiple data PS can process 16 pixels simultaneously Limitation Hardware not optimal Software environment immature

Wealth of applications Already Motion Planning Data Analysis Voronoi Diagrams Geometric Optimization Particle Systems Force-field simulation Molecular Dynamics Graph Drawing Physical Simulation Conjugate Gradient Matrix Multiplication Database queries Sorting and Searching Range queries Signal Processing From http://www.cis.upenn.edu/~suvenkat/700 and graphics too!!

From Stream Programming Environments Hanrahan, 2004.

Acknowledge Thanks for all the materials I used in this presentation.

Question? Thanks!