Presentation is loading. Please wait.

Presentation is loading. Please wait.

Light Hearted Look At GPU Programming And Linear Algebra Operators.

Similar presentations


Presentation on theme: "Light Hearted Look At GPU Programming And Linear Algebra Operators."— Presentation transcript:

1 Light Hearted Look At GPU Programming And Linear Algebra Operators

2 Pass Out (3) Papers And GPUGems Book Book Has Some Nice Graphics

3 Demos

4 Pyramids Demo Blackbox

5 Codecreatures Demo Benchmarks!

6 What Are The Differences Between These Demos?

7 Food For Thought Science/Education Versus Entertainment? “Edutainment”? Is “User Friendliness” The Same? To Me, The Codecreatures Demo Was State Of The Art! Probably To Some Video Gamers, It’s Old Hat! I Assume This Code Is Really Taking Advantage Of The GPU

8 “The Continuum” Assembly Programming  “GPU Programming”  Monitor Programming  4GL, 5GL, …? User Friendliness small medium large What, Exactly, Is Happening On The GPU? Probably Don’t Know Exactly SDKS e.g. Visual Studio

9 My Continuum GPU Knowledge small medium large Me Prof Bailey (and Prof Zhang and Jacob)

10 ;-) :-)

11 What’s On the GPU, What’s on the CPU? “Don’t Ask Me!”

12 Is the GPU Synonymous With the Graphics Card? “Yes, close enough. The GPU is actually the processor chip that lives on the graphics card. The "graphics card" has a bunch of other stuff on it to support the GPU and its operations, plus memory, bus interaction, etc.” Mike Bailey

13 Gonna Wear This One Out!

14 GPU/ Graphics Card ?

15 CPU, Bus, VP, FP, bunch of other stuff

16 Benchmarking (CPU) (BUS)

17 Benchmarking (VP) (FP) Science? Entertainment?

18 Benchmarking glFinish(); int t0 = glutGet( GLUT_ELAPSED_TIME ); > glFinish(); int t1 = glutGet( GLUT_ELAPSED_TIME ); glutSwapBuffers(); fprintf( stderr, "One display frame took %d milliseconds\n", t1 - t0 );

19 What’s On the GPU, What’s On the CPU? How Well Do We Know The Hardware/Software Boundary?

20 // minimal vertex shader // void main() { // the following three lines provide the same result //gl_Position = gl_ProjectionMatrix * gl_ModelViewMatrix * gl_Vertex; //gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex; gl_Position = ftransform(); } The end result is of course the same. Does this guarantee the same transformation as in the fixed functionality? Well in theory yes, but in practice the process of transforming the vertices may not follow the same order as in here. This is normally a highly optimized task in a graphic card, and a special function is provided to take advantage of that optimization. Another reason for this function is due to the limit in the precision of the float data type. When calculus is done in different orders, different results may be obtained due to this limited precision. Hence the GLSL provides a function that guarantees that not only the best performance is obtained but also that the result is always the same as when using the fixed functionality. This magical function is: vec4 ftransform(void); This function returns the transformed incoming vertex, following the same steps as the fixed functionality does. Jumping Ahead: Specific Code, But Takeaway Is Some Uncertainty In Implementation Simplest Shader Program You Will Ever See!

21 GPU Overview

22 What is the GPU? “Graphical Processing Unit”

23 How We Gonna Dive In?

24 GLSL - (Relatively) User Friendly GLman - User Friendly Good Demos Available (e.g. Pyramids) GLSL/GLman Orientation (Simple, Less Powerful, Less User Friendly Visual Studio Demos/Prototypes Do Exist And Will Be Overviewed

25 GLSL/GLman Orientation

26 “GLman is written in OpenGL. It is meant to be a scripting system to make it easy to explore GPU programming, so internally it takes care of a lot of the boilerplate of writing GPU-based programs, leaving you just to write the GPU code. So, the.glib files are the script, and the.vert and.frag files are the vertex and fragment GPU code.” Mike Bailey

27 Glman Lets You Concentrate On: Vertex Processor -.vert file // text file Fragment Processor -.frag file // text file GLSL/GLman Orientation

28 Glman makes this part easy

29 GLSL/GLman Orientation Simple/ Standalone Visual Studio Demo Apps Available, And Will Be Looked At

30 Why Use the GPU?

31 “The rasterizer is a part of the GPU, but its functionality can't be customized by the user, other than sending user-defined variables through it to be interpolated.” Mike Bailey

32 Rasterizer In The “Bunch Of Other Stuff” Category ?

33

34

35 GPU versus CPU “The distinction is becoming more and more blurred, but the basic difference is that GPUs have certain architectural changes that appeal more to graphics, such as more cores, less cache, and special texture fetching hardware.” Mike Bailey Can’t Do Recursion On The GPU!!!

36 GPU versus CPU Can’t Do Recursion On The GPU!!! CPU – double oriented GPU – float oriented

37 Multi Cores  Parallelism Less Cache  Streaming Texture (Local) Memory  Reduced Bus Activity

38 GPU versus CPU

39 [Chiang, Hsueh, Liu]

40 GPU versus CPU

41 We’ll take a quick look at these (mostly linear operator) terms shortly

42 ?tp=&isnumber=&arnumber= [Gong, Langille, Gong]

43 GPU Typical Programming Environment GLSL - OpenGL Shading Language HLSL - DirectX's high-level shading language Cg – C For Graphics …

44 Vertex Shader Program(ming) Fragment Shader Program(ming) each with a main() examples shortly

45 Specific Linear Operators Matrices for Multiplication Matrices for Differentiation – e.g. Sobel Filter

46 Specific Linear Operators vec2 texcoord1, texcoord2; vec3 position; vec4 myRGBA; ivec2 textureLookup; bvec3 less; Data Types

47 Specific Linear Operators mat2 mat2D; mat3 optMatrix; mat4 view, projection; mat4x4 view; // an alternate way of declaring a mat4 mat3x2 m; // a matrix with 3 columns and 2 rows Data Types

48 Specific Linear Operators vec3(float) // initializes each component of with the float vec4(ivec4) // makes a vec4 with component-wise conversion vec2(float, float) // initializes a vec2 with 2 floats ivec3(int, int, int) // initializes an ivec3 with 3 ints bvec4(int, int, float, float) // uses 4 Boolean conversions vec2(vec3) // drops the third component of a vec3 vec3(vec4) // drops the fourth component of a vec4 vec3(vec2, float) // vec3.x = vec2.x, vec3.y = vec2.y, vec3.z = float vec3(float, vec2) // vec3.x = float, vec3.y = vec2.x, vec3.z = vec2.y vec4(vec3, float) // We’’ll See An Application Of One Of These vec4(float, vec3) // Or Something Similar vec4(vec2, vec2) Constructors

49 Specific Linear Operators

50 Specific Linear Operators Testing/ Benchmarking

51 Specific Linear Operators Testing/ Benchmarking

52 Specific Linear Operators Non Linear Testing/ Benchmarking

53 Specific Linear Operators SWIZZLING!

54 Specific Linear Operators // different denominator forms

55 Specific Linear Operators

56

57 [Kruger,Westermann] Specific Linear Operators

58 Basic Architecture View Input Is (C/C++ Program),.vert file,.frag file (,.glib file) Output Is Image(s)

59 More Complex Architecture Views

60 Another Pipeline Overview MC – Model Coordinates SC – Screen Coordinates Complete Colored Screen Coordinates

61

62

63 Another Pipeline Overview “Programmable Unit”

64 Over Simplified?

65 MC – Model Coordinates SC – Screen Coordinates Colored Screen Coordinates

66 Snazzy Examples

67

68

69

70 Getting Started GLSL/GLman

71 Demos Start -> Programs -> Shaders -> Glman has multiple sets of input files (.glib,.vert, and.frag) (In e.g. CGEL)

72 Pyramids - pyramids.glib - pyramids.vert - pyramids.frag

73 GLSL/Glman Specialization

74

75 ##OpenGL GLIB Perspective 70 Vertex pyramids.vert Fragment pyramids.frag Program BumpMapTest\ LightX \ LightY \ LightZ \ SurfaceColor { }\ Ang \ BumpDensity \ Ambient \ Height Sphere #Obj cow.obj #Teapot pyramids.glib

76 ##OpenGL GLIB Perspective 70 Vertex pyramids.vert Fragment pyramids.frag Program BumpMapTest\ LightX \ LightY \ LightZ \ SurfaceColor { }\ Ang \ BumpDensity \ Ambient \ Height Sphere #Obj cow.obj #Teapot “one to one” Pyramids.glib vert file frag file “one to one”

77 Getting Started has VS Project (glutglsl) that compiles (e.g. in CGEL) (needs glew32.lib which can be copied from the local hard drive) Another Approach

78 void setShaders() { char *vs = NULL,*fs = NULL,*fs2 = NULL; v = glCreateShader(GL_VERTEX_SHADER); f = glCreateShader(GL_FRAGMENT_SHADER); f2 = glCreateShader(GL_FRAGMENT_SHADER); vs = textFileRead("minimal.vert"); fs = textFileRead("minimal.frag"); const char * vv = vs; const char * ff = fs; glShaderSource(v, 1, &vv,NULL); glShaderSource(f, 1, &ff,NULL); free(vs);free(fs); glCompileShader(v); glCompileShader(f); printShaderInfoLog(v); printShaderInfoLog(f); printShaderInfoLog(f2); p = glCreateProgram(); glAttachShader(p,v); glAttachShader(p,f); glLinkProgram(p); printProgramInfoLog(p); glUseProgram(p); } “THE CODE !!!” (“THE SYNTAX”?)

79 // minimal vertex shader // void main() { // the following three lines provide the same result //gl_Position = gl_ProjectionMatrix * gl_ModelViewMatrix * gl_Vertex; //gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex; gl_Position = ftransform(); } The end result is of course the same. Does this guarantee the same transformation as in the fixed functionality? Well in theory yes, but in practice the process of transforming the vertices may not follow the same order as in here. This is normally a highly optimized task in a graphic card, and a special function is provided to take advantage of that optimization. Another reason for this function is due to the limit in the precision of the float data type. When calculus is done in different orders, different results may be obtained due to this limited precision. Hence the GLSL provides a function that guarantees that not only the best performance is obtained but also that the result is always the same as when using the fixed functionality. This magical function is: vec4 ftransform(void); This function returns the transformed incoming vertex, following the same steps as the fixed functionality does.

80 // minimal fragment shader // void main() { gl_FragColor = vec4(0.4,0.4,0.8,1.0); What Color Is This? } // minimal vertex shader // void main() { // the following three lines provide the same result //gl_Position = gl_ProjectionMatrix * gl_ModelViewMatrix * gl_Vertex; //gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex; gl_Position = ftransform(); }

81

82 CTRL-ALT-PRINT_SCREEN PASTE INTO PAINT SAVE AS 24 BIT BMP RIGHT CLICK FILE OPEN WITH PHOTOSHOP TEARDROPPER TOOL DOUBLE CLICK 102 =.4 * =.8 * 255

83 // minimal fragment shader // void main() { gl_FragColor = gl_Color ; // varying vec4 gl_Color; } // minimal vector shader // void main() { gl_FrontColor = gl_Color; // attribute vec4 gl_Color; gl_Position = ftransform(); }

84

85 // “near” minimal vertex shader // varying vec3 lightDir,normal; void main() { lightDir = normalize(vec3(gl_LightSource[0].position)); normal = gl_NormalMatrix * gl_Normal; gl_Position = ftransform(); } // “near” minimal fragment shader // varying vec3 lightDir,normal; void main() { float intensity; vec4 color; // normalizing the lights position to be on the safe side vec3 l = normalize(vec3(gl_LightSource[0].position)); vec3 n = normalize(normal); intensity = dot(l,n); if (intensity > 0.95) color = vec4(1.0,0.5,0.5,1.0); else if (intensity > 0.5) color = vec4(0.6,0.3,0.3,1.0); else if (intensity > 0.25) color = vec4(0.4,0.2,0.2,1.0); else color = vec4(0.2,0.1,0.1,1.0); gl_FragColor = color; }

86 Shader Pseudo Lighting

87 Real Utility? Exploiting (Living With) Existing Architecture/ Hardware That’s Beyond Programmatic Control // Special Constructor

88 Context

89 Exploiting (Living With) Existing Architecture/ Hardware That’s Beyond Programmatic Control

90 Context // We Saw An // Example

91 Context

92 Miscellaneous “Programmable Unit”

93 Miscellaneous “Programmable Unit”

94 Did You See All 3 Papers And The Book?

95 Questions?

96 GLUTGLSL Demo z:\Windows.Documents\Desktop\colorglut_2.0\Debug>glutglsl


Download ppt "Light Hearted Look At GPU Programming And Linear Algebra Operators."

Similar presentations


Ads by Google