07-ispc-bps2011-pharr

Upload: yurymik

Post on 03-Apr-2018

217 views

Category:

Documents


0 download

TRANSCRIPT

  • 7/29/2019 07-ISPC-BPS2011-pharr

    1/10

    Beyond Programmable Shading Cours

    High Performance GraphicOn The CPU Using ispc

    Matt Pharr

    Intel

    Beyond Programmable Shading Cours

  • 7/29/2019 07-ISPC-BPS2011-pharr

    2/10

    Beyond Programmable Shading Cours

    ispc: Goals

    Deliver excellent performance to programmers

    want to run SPMD programs on the CPU

    Provide a thin abstraction layer: programmer c

    cleanly reason about what the compiler will do

    Allow close-coupling and fine-grained interactiobetween C/C++ code and ispc code

  • 7/29/2019 07-ISPC-BPS2011-pharr

    3/10

  • 7/29/2019 07-ISPC-BPS2011-pharr

    4/10

    Beyond Programmable Shading Cours

    ispc: Key Features

    C-based syntax

    Pointers, data structures shared with C/C++ code

    (no driver/data reformatting)

    Only a function call boundary between C/C++ and is

    Recursion, externally-defined functions just work

    Rich standard library: vectorized transcendentals, a

  • 7/29/2019 07-ISPC-BPS2011-pharr

    5/10

    Beyond Programmable Shading Cours

    Building Applications with ispc

    ispc SourceC/C++ Source

    ispc Compiler C/C++ Compiler

    Object File Object File

    Linker

    ispc Source C/C++ Source

    Executable

  • 7/29/2019 07-ISPC-BPS2011-pharr

    6/10

    Beyond Programmable Shading Cours

    Hello ispcHello ispc

    int nVertices = ...;float *x = new float[nVertices];

    float *y = new float[nVertices];

    float *z = new float[nVertices];

    // fill in x[], y[], z[]

    float matrix[3][3] = { { ... }, ... };

    transform3x3(x, y, z, matrix, nVertices);

    export void

    transform3x3(uniform float xarray[], uni

    uniform float zarray[], uni

    uniform int nVertices) {

    uniform int i;

    for (i = 0; i < nVertices; i +=prog

    float x = xarray[i +programInde

    float y = yarray[i +programInde

    float z = zarray[i +programInde

    float xt = m[0][0]*x + m[0][1]*y

    float yt = m[1][0]*x + m[1][1]*y

    float zt = m[2][0]*x + m[2][1]*y

    xarray[i +programIndex] = xt;

    yarray[i +programIndex] = yt;

    zarray[i +programIndex] = zt;

    }

    }

    ispc CodeC++ Application Code

  • 7/29/2019 07-ISPC-BPS2011-pharr

    7/10

    Beyond Programmable Shading Cours

    A Ray Tracer in ispc

    int width = ..., height = ...;

    const float raster2camera[4][4] = { ... };const float camera2world[4][4] = { ... };

    float *image = new float[width*height];

    Triangle *triangles = new Triangle[nTris];

    LinearBVHNode *nodes = new LinearBVHNode[nNodes];

    // init triangles and nodes

    raytrace(width, height, raster2camera,

    camera2world, image, nodes, triangles);

    export voidraytrace(uniform int width, uniform in

    const uniform float raster2ca

    const uniform float camera2wo

    uniform float image[],

    const LinearBVHNode nodes[],

    const Triangle triangles[])

    // ...

    // map program instances to rays

    // ...

    for (y = 0; y < height; y += yStep

    for (x = 0; x < width; x += xS

    Ray ray;

    generateRay(raster2camera

    x+dx, y+dy, ra

    BVHIntersect(nodes, triangl

    int offset = (y + idy) * wi

    image[offset] = ray.maxt;

    id[offset] = ray.hitId;

    }

    }

    }

    ispc CodC++ Application Code

  • 7/29/2019 07-ISPC-BPS2011-pharr

    8/10

    Beyond Programmable Shading Cours

    PerformanceDual Xeon X5680 (12 cores)

    Serial C

    ispc

    SPMD +tasks

    Ray Tracer 1x 102.25x

    SHRadiance

    Probe Gen.

    1x 65.71x

    Deferred

    Shading1x 39.40x

  • 7/29/2019 07-ISPC-BPS2011-pharr

    9/10

    Beyond Programmable Shading Cours

    Integration WithRegular Debuggers

  • 7/29/2019 07-ISPC-BPS2011-pharr

    10/10

    Beyond Programmable Shading Cours

    Try It Yourself!

    ispc is available in open-source from

    http://ispc.github.com

    Codegen uses the (excellent) LLVM compiler

    Supports Linux, Windows, Mac OS X

    x86 and x86-64 targets, SSE2 and SSE4

    (AVX soon)

    http://ispc.github.com/http://ispc.github.com/