Arquitectura de GPUs

Presenter Notes

Resumen

  • Motivación.
  • Pipeline de gráficos.
  • Evolución del pipeline programable.
  • Unified shaders ¿NV60?
  • Arquitectura NVIDIA Fermi.

Nicolás Wolovick, $Date: 2012-05-22 20:57:01 -0300 (Tue, 22 May 2012) $, $Revision: 3536 $

Presenter Notes

Motivación

Presenter Notes

BITBLT

Rutina de Bit Block Transfer, Xerox Alto, 1973.
Opera en un "rectángulo" de la memoria, operando Destination, boolean function, Source, Texture.
Usualmente la función se conocía como ROP Raster OPeration.

  • D ← f(D,S,T)

Bitblt para sprites

A mediados de los 80s aparecen las Commodode Amiga con BITBLT implementado en hardware. Atari ST rápidamente copia el blitter.
La placa VGA original no incorporaba blitter. Pero por ejemplo en 1993 la CL-GD5426 incorpora un blitter.

(Rob Pike, Leo Guibas and Dan Ingalls, SIGGRAPH'84 Course Notes: Bitmap Graphics , AT&T Bell Laboratories 1984.)

Presenter Notes

BITBLT y HPC

Idea

Usar el BITBLT de las placas para efectuar operaciones booleanas sobre memoria muy rápidamente.

O_O

Este tipo de ideas se mantiene a lo largo de todo el recorrido de hardware-assisted graphics.

Los gráficos de commodity computers pasaron de 2D en los 80s a 3D en los 2000.
Veamos como funciona un graphic pipeline típico para 3D real-time rendering (juegos, fps>=60).

Presenter Notes

Graphics Pipeline

Presenter Notes

Graphics Pipeline

¿Cómo cada uno de los triángulos contribuye a la imagen final?

Teapot rendeing

(CMU 15-869, Graphics and Imaging Architectures)

Queremos 60 fps en 1920x1080 con colores de 24bit. Tenemos 16.6ms para transformar, iluminar, cortar, proyectar, pegar texturas y generar los píxeles de:

  • ~1M polígonos (triángulos).
  • Dibujar 6MB en el framebuffer.

(Rick Stirling, Yes, but how many polygons?, 2007)

Sería bueno poder calcular esto un poco mejor.

Presenter Notes

Tipos de datos que maneja el pipeline

Pipeline entities

(CMU 15-869, Graphics and Imaging Architectures)

Presenter Notes

Real-time graphics pipeline

Real-time graphics pipeline

(CMU 15-869, Graphics and Imaging Architectures)

Presenter Notes

Vértices

Un vertex es una tupla con attributes.
Cada attribute tiene components.

Vertex data structure

1 struct vertex {
2     float3 pos; // screen pixel coordinates (sample point location)
3     float3 normal;
4     float2 texcoord;
5 }

(Penn CIS565)

Presenter Notes

Vértices y su ensamblado

Como un MPI_GatherV, pero de información 3D.

Vertex assembly

Vertex assembly

(Penn CIS565)

Presenter Notes

Vertex shader

Función que procesa cada vértice. Mapeo de todo el arreglo de vértices por una función.
También conocido como T&Ltransform and lightning—.

Aplica una matriz de 4x4 que es composición de cuatro matrices:

Wikipedia camera analogy

  1. Posicionar el modelo — modeling transformation.
  2. Posicionar la cámara — viewing transformation.
  3. Ajustar el zoom — projection transformation.
  4. Recortar la imagen — viewport transformation.

(Wikibooks, GLSL Programming, Vertex Transformations.)

Presenter Notes

Vertex Shader, lightning

A partir de:

  • La posición de la(s) fuente(s) de luz.
  • La normal a cada vértice respecto a las fuentes

Se calcula la intensidad de luz que recibe el vértice.

Per vertex lightning

(CMU 15-869, Graphics and Imaging Architectures)

Presenter Notes

Vertex Shader, processing

Transformaciones que modifican (ligeramente) la posición de los vértices.

Ejemplo: pulsing

Vertex pulsing

(Penn CIS565)

Presenter Notes

Vertex Shader, texturas

Texturas pueden ser mapas de altura para desplazamientos de vértices.

Vertex Texure Demo

(Simon Green GeForce 6 Series OpenGL Extensions, 2004?)

Presenter Notes

¿Qué es una textura?

Presenter Notes

Rasterizing

Rasterization

(Wikibooks, GLSL Programming, Rasterization.)

Presenter Notes

O Rasterizing?

Visual Pipeline

(GLSL Tutorial von Lighthouse3D.)

¿Convierte los vértices o también todos los puntos intermedios?

Presenter Notes

Fragment Shader

Asigna color y textura a cada fragmento o pre-pixel.

Ejemplo: Phong shading

Phong Components

Phong equation

(Wikipedia, Phong reflection model.)

Sumas, productos punto, potencias fraccionarias, multiplicación por constantes.
Un fragment shader puede ser computacionalmente intensivo.

1 float diffuse = max(dot(N, L), 0.0);
2 float specular = max(pow(dot(H, N), u_shininess), 0.0);

Presenter Notes

Fragment Shader: luz y textura

Fragment shader, light and texture

(Penn CIS565)

Presenter Notes

Fragment shader: entrada y salida

1 struct fragment {
2     float x,y; // screen pixel coordinates (sample point location)
3     float z; // depth of triangle at sample point
4     float3 normal;
5     float2 texcoord;
6     // interpolated application-defined attribs
7     // (e.g., texture coordinates, surface normal)
8 }

Después de procesar

1 struct output_fragment {
2     int x,y; // pixel
3     float z;
4     float4 color;
5 }

Presenter Notes

Operaciones en el FrameBuffer

Frame buffer operations

(CMU 15-869, Graphics and Imaging Architectures)

Presenter Notes

Ejemplo de Operaciones en el FB

1 if (fragment.z < zbuffer[fragment.x][fragment.y]) {
2     zbuffer[fragment.x][fragment.y] = fragment.z;
3     colorbuffer[fragment.x][fragment.y] =
4     blend(colorbuffer[fragment.x][fragment.y], fragment.color);
5 }

z-buffer example

Además del depth test hay otros: alpha test, stencil test, etc.

(CMU 15-869, Graphics and Imaging Architectures)

Presenter Notes

Parametrización de las operaciones

The graphics pipeline

Uniforms: funciones aridad 0 (constantes).
Textures: funciones aridad 2.

Presenter Notes

RenderMonkey

  • Prototipado de shaders.
  • Defunct.
  • Windows, up to DX 9.1.

FullScreen-Hebe_lrg.jpg

Presenter Notes

Evolución del pipeline programable

Presenter Notes

Evolución del pipeline programable

  • Pre GPU.
  • GPU de funciones fijas.
  • GPU de funciones programables.
  • Shader Processors unificados.
  • GPU Computing.

Presenter Notes

90's

Pre-GPU: Wolfenstein 3D (1992), Doom (1993).

pregpu

Código de CPU optimizado artesanalmente.

Michael Abrash, Graphics Programming Black Book, 1997.

Presenter Notes

3dfx Voodoo (1996)

3dfx Voodoo 1996

(Penn CIS565)

Presenter Notes

NVIDIA GeForce 256 (1999)

NVIDIA GeForce 256 1999

(Penn CIS565)

Presenter Notes

NVIDIA GeForce 3 (2001)

NVIDIA GeForce 3 2001

(Penn CIS565)

Presenter Notes

NVIDIA GeForce 6 (2004)

NVIDIA GeForce 6 2004

(Penn CIS565)

6 vertex shader processors, 16 fragment shader processors, 40 GFLOP pico.

Presenter Notes

Shader Model 3 (NV40, 2004)

  • Shaders manejan fp32.
  • Vertex shader lee texturas.
  • Programas largos y flujo dinámico de control
  • Se puede dirigir el rendering a los texture buffers.

The modern graphics hardware pipeline

La cena está servida: ¡a computar!

No me interesan: sombras condicionales, mapas de desplazamientos, etc. Yo quiero: GPU particle systems, GPU navier-stokes, etc.

(Mark Harris, Mapping Computational Concepts to GPUs, ACM SIGGRAPH 2005.)
(Ashu Rege, Shader Model 3.0, NVIDIA, 2004.)

Presenter Notes

GPGPU, un paso intermedio

  • OpenGL 2/DirectX 9, tenían todos los ingredientes para computar.
  • El crecimiento de la potencia de cálculo por año interesó a los científicos.
  • Complicado de programar: entender muy bien el pipeline gráfico, usar texture displacements, usar render to texture.

Programable floating point performance

(J. Owens, et.al, A Survey of General-Purpose Computation on Graphics Hardware, Computer Graphics Forum, 26(1), 2007)

Presenter Notes

Shader Model 3, comparación

Complete Native Shader Model 3.0 Support

Presenter Notes

Phong Shader, una fuente de luz

¿Como es un programa en GLSL?

Vertex shader

1 varying vec3 N;
2 varying vec3 v;
3 void main(void)
4 {
5    v = vec3(gl_ModelViewMatrix * gl_Vertex);
6    N = normalize(gl_NormalMatrix * gl_Normal);
7    gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;
8 }

(Clockworkcoders Tutorials, Per Fragment Lightning.)

Presenter Notes

Phong Shader, una fuente de luz

Fragment shader

 1 varying vec3 N;
 2 varying vec3 v;
 3 void main (void)
 4 {
 5    vec3 L = normalize(gl_LightSource[0].position.xyz - v);
 6    vec3 E = normalize(-v); // we are in Eye Coordinates, so EyePos is (0,0,0)
 7    vec3 R = normalize(-reflect(L,N));
 8 
 9    //calculate Ambient Term:
10    vec4 Iamb = gl_FrontLightProduct[0].ambient;
11 
12    //calculate Diffuse Term:  
13    vec4 Idiff = gl_FrontLightProduct[0].diffuse * max(dot(N,L), 0.0);
14    Idiff = clamp(Idiff, 0.0, 1.0);
15 
16    // calculate Specular Term:
17    vec4 Ispec = gl_FrontLightProduct[0].specular 
18                 * pow(max(dot(R,E),0.0),0.3*gl_FrontMaterial.shininess);
19    Ispec = clamp(Ispec, 0.0, 1.0);
20 
21    // write Total Color:
22    gl_FragColor = gl_FrontLightModelProduct.sceneColor + Iamb + Idiff + Ispec;
23 }

(Clockworkcoders Tutorials, Per Fragment Lightning.)

Presenter Notes

OpenGL-ES 2.0 y mobile

Cualquier dispositivo móvil de rango medio-alto incorpora algún acelerador 3D.

Todos soportan GLESv2.

  • Programable vertex&pixel shaders.
  • Vertex textures.
  • Conditional branches.
  • Render to texture.

Básicamente: programables, bajo consumo, gran paralelismo.

(Varun Sampath, Mobile GPUs, UPenn, CIS565, 2011)

Presenter Notes

Ejemplo: NVIDIA Tegra 3 (Kal-El)

  • 4 vertex shaders.
  • 8 pixel shaders.

¡Un par de estos chips ya son OpenCL-capable!

Mobile SoC GPU Comparison

(Anandtech, NVIDIA's Tegra 3 Launched: Architecture Revealed, Sep 2011.)

Presenter Notes

Unified shaders, GeForce 8800 (G80)

DirectX 10, incorpora geometry shaders (quitar o agregar vértices), luego del vertex shader.
NVIDIA, en vez de agregar más unidades específicas, cambia la arquitectura.

  • Unified general shaders.
  • Recircular información para emular el pipeline.
  • Agregar instrucciones de manejo de enteros.
  • Agregar instrucciones load & store.
  • Organizar los hilos en blocks of threads y grids of blocks.
    • Sincronización de barrera dentro de un bloque.

Presenter Notes

Unified shaders, mejoran los fps

Why Unify 1 Why Unify 2

(NVIDIA, NVIDIA GeForce 8800 GPU Architecture Overview, 2006.)

Presenter Notes

Unified shaders reemplazan el pipeline

8800 replaces pileline model

(NVIDIA, NVIDIA GeForce 8800 GPU Architecture Overview, 2006.)

Presenter Notes

Unified shaders permiten computar

G80 thread unified compute

(NVIDIA, NVIDIA GeForce 8800 GPU Architecture Overview, 2006.)

Presenter Notes

Evolución del pipeline programable

Interactive rendering returns to software?

(Mike Houston, Beyond Programmable Shading Retrospective, AMD, SIGGRAPH 2009.)

Presenter Notes

GPU Computing

Presenter Notes

Arquitectura Fermi

Fermi 16 SM

Presenter Notes

Arquitectura Fermi

  • 550mm2 die size.
  • 3000M transitores.
  • 512 cores.
    • 32 cores por SM (streaming multiprocessor).
    • 16 SM.
  • Full IEEE-754-2008 fp32 y fp64.
  • Direcciones 64 bit.
  • Espacio unificado de direcciones CPU-GPU.
  • Memoria ECC.
  • Caché L2 y L1 (configurable con la shared).
  • Operaciones atómicas rápidas y en fp32.
  • Hasta 6GB DDR5, 6x1GB, 6 puertos, ancho 384 bits (6x64 bits).
  • Dual-issue warp scheduler.

Presenter Notes

Streaming Multiprocessor

Fermi Streaming Multiprocessor

Presenter Notes

CUDA Core

Presenter Notes

Espacio de memoria unificado 64 bits

Unified Address Space

Presenter Notes

Jerarquía de memoria

Presenter Notes

Ejecución Concurrente de Kernels

Presenter Notes

Evolución de las arquitecturas

Fermi, Summary Table

Presenter Notes

Jerarquía de hilos, bloques, grillas

CUDA hierarchy of threads, blocks, grids

(NVIDIA’s Next Generation CUDA Compute Architecture: Fermi™, NVIDIA, 2009.)

Presenter Notes

Formato de instrucciones PTX

opcode.type d, a, b, c;

PTX types

(Hennessy, Patterson, CAAQA5, p.298)

Presenter Notes

PTX ISA

CAAQA5 Fig-4.17

(Hennessy, Patterson, CAAQA5, Fig-4.17)

Presenter Notes

PTX ISA

CAAQA5 Fig-4.17

(Hennessy, Patterson, CAAQA5, Fig-4.17)

Presenter Notes

PTX ISA

CAAQA5 Fig-4.17

(Hennessy, Patterson, CAAQA5, Fig-4.17)

Presenter Notes

PTX es intermedio!

A demostration of the value of the PTX is that the Fermi architecture radically changed the hardware instruction set -- from being memory-oriented like x86 to being register-oriented like MIPS as well as doubling the address size to 64 bits -- without disrupting the NVIDIA software stack.

(Hennessy, Patterson, CAAQA5, p.330)

Presenter Notes

Bibliografía

Presenter Notes

La clase que viene

  • CUDA básico.

Presenter Notes