960 likes | 1.07k Views
Light Hearted Look At GPU Programming And Linear Algebra Operators. Pass Out (3) Papers And GPUGems Book Book Has Some Nice Graphics. Demos. Pyramids Demo Blackbox. Codecreatures Demo. Benchmarks!. What Are The Differences Between These Demos?. Food For Thought
E N D
Light Hearted Look AtGPU Programming And Linear Algebra Operators
Pass Out (3) PapersAnd GPUGems BookBook Has Some Nice Graphics
Codecreatures Demo Benchmarks!
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
“The Continuum” User Friendliness small medium large Assembly Programming “GPU Programming” Monitor Programming 4GL, 5GL, …? What, Exactly, Is Happening On The GPU? Probably Don’t Know Exactly SDKS e.g. Visual Studio
My Continuum GPU Knowledge small medium large Prof Bailey (and Prof Zhang and Jacob) Me
;-) :-)
What’s On the GPU,What’s on the CPU? “Don’t Ask Me!”
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
Gonna Wear This One Out!
GPU/ Graphics Card ?
CPU, Bus, VP, FP, bunch of other stuff
Benchmarking (CPU) (BUS)
Benchmarking (VP) (FP) Science? Entertainment?
Benchmarking glFinish(); int t0 = glutGet( GLUT_ELAPSED_TIME ); << All Graphics Calls That You Are Testing The Speed Of >> glFinish(); int t1 = glutGet( GLUT_ELAPSED_TIME ); glutSwapBuffers(); fprintf( stderr, "One display frame took %d milliseconds\n", t1 - t0 );
What’s On the GPU,What’s On the CPU? How Well Do We Know The Hardware/Software Boundary?
// minimal vertex shader // www.lighthouse3d.com 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(); } Simplest Shader Program You Will Ever See! 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. http://www.lighthouse3d.com/opengl/glsl/index.php?minimal Jumping Ahead: Specific Code, But Takeaway Is Some Uncertainty In Implementation
What is the GPU? “Graphical Processing Unit”
How We Gonna Dive In?
GLSL/GLman Orientation GLSL - (Relatively) User Friendly GLman - User Friendly Good Demos Available (e.g. Pyramids) (Simple, Less Powerful, Less User Friendly Visual Studio Demos/Prototypes Do Exist And Will Be Overviewed
“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 http://web.engr.oregonstate.edu/~mjb/cs519/Handouts/Glman/glman.pdf
GLSL/GLman Orientation Glman Lets You Concentrate On: Vertex Processor - .vert file // text file Fragment Processor - .frag file // text file
GLSL/GLman Orientation Glman makes this part easy
GLSL/GLman Orientation Simple/ Standalone Visual Studio Demo Apps Available, And Will Be Looked At
“The rasterizer is a part of the GPU, but its functionality can't becustomized by the user, other than sending user-defined variablesthrough it to be interpolated.” Mike Bailey
Rasterizer In The “Bunch Of Other Stuff” Category ?
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!!!
GPU versus CPU Can’t Do Recursion On The GPU!!! CPU – double oriented GPU – float oriented
Multi Cores Parallelism Less Cache Streaming Texture (Local) Memory Reduced Bus Activity
http://www.springerlink.com/content/eupfj7euk0jvj98u/fulltext.pdfhttp://www.springerlink.com/content/eupfj7euk0jvj98u/fulltext.pdf [Chiang, Hsueh, Liu]
GPU versus CPU We’ll take a quick look at these (mostly linear operator) terms shortly
http://ieeexplore.ieee.org/iel5/4221378/4221379/04221459.pdf ?tp=&isnumber=&arnumber=4221459 [Gong, Langille, Gong]
GPU Typical Programming Environment GLSL - OpenGL Shading Language HLSL - DirectX's high-level shading language Cg – C For Graphics …
Vertex Shader Program(ming) Fragment Shader Program(ming) each with a main() examples shortly
Specific Linear Operators Matrices for Multiplication Matrices for Differentiation – e.g. Sobel Filter
Specific Linear Operators Data Types vec2 texcoord1, texcoord2; vec3 position; vec4 myRGBA; ivec2 textureLookup; bvec3 less;
Specific Linear Operators Data Types 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
Specific Linear Operators Constructors 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)
Specific Linear Operators http://www.opengl.org/registry/doc/GLSLangSpec.Full.1.20.8.pdf
Specific Linear Operators Testing/ Benchmarking