shader-school

Getting Your (GPU) Feet Wet

Martin Andrews / @redcatlabs

27 August 2014

Who Am I?

  • PhD in Machine Learning
    • Genetic Algorithms, Trees, etc
    • Early 90s, Cambs, UK
  • Went over to the "Dark Side"
    • Quant-Finance in London / NYC
  • Moved from NYC to SG in Sept-2013
    • ~ Sabbatical

Intro : Node-School

  • Learn modern Javascript
  • Has pre-built exercises
  • Weekends 'teach-ins' around the world

NodeSchool

Shader-School

  • Learn WebGL : "JS" for infrastructure

Shader-School

Download and Install

  • Best to run from GitHub
  • First, need to install nodejs & npm (YMMV)
  • Then...

mkdir TEMPDIR
cd TEMPDIR

git clone https://github.com/stackgl/shader-school.git

cd shader-school
npm install
# ( tons of web downloads within TEMPDIR/shader-school )
cd ..

node shader-school
# ( creates base work-files with TEMPDIR and launches browser )
 

What to Expect : 01

Hello "x+y"

01 Hello x+y

What to Expect : 09

Fragment shader (with texture)

09 Fragment shader

What to Expect : 11

Vertex shader (with interpolation)

11 Vertex shader

What to Expect : 15

Mathematics - reflection in plane

15 Reflection

What to Expect : 19

Graphics - Phuong shading

19 Phuong

What to Expect : 26

GPGPU - Wave equation

26 Wave equation

What to Expect : 29

GPGPU - Flocking playground

29 Flocking playground

Live Demo !

  • ( Cross-fingers )

Live Demo !

  • Obviously didn't work
05 Mandelbrot

Just Do It!

  • A nice, productive few hours...
  • Code is there to cheat from (if essential)
  • Real problems : Submit issue on GitHub

Future Work

  • Deep Learning : OCR
  • Spark ("in-memory Hadoop")
    • MLlib is still a work-in-progress
    • Scala / OpenCL

OCR for Name Cards

Leading to Deep-Learning ASAP

Name Card Problem

OCR Tasks

Image Processing

OCR processing

Currently server-side

OCR Tasks

Text Extraction

OCR result

Currently server-side

OCR into Phone

  • GPU training on the server
  • Recognition on the phone

ConvNet

Spark -> Scala -> OpenCL

  • Apache (OSS) cluster computing framework
  • In-memory algorithms : "10x - 100x" Hadoop
  • Written in Scala (JVM), also Python interface
  • Machine Learning library "MLlib"
    • Currently a work-in-progress
    • Lots of room for innovation

iSpark (Scala) Notebook

  • Backend for iPython Notebook
  • Can use whole cluster
  • Visualization ("Bohek") coming soon

iSpark

Scala & OpenCL

  • Write code using higher-level language
  • Dynamically generates GPU kernels

import scalacl._

case class Matrix(data: CLArray[Float], rows: Int, columns: Int)(implicit context: Context) {
  def this(rows: Int, columns: Int) =
    this(new CLArray[Float](rows * columns), rows, columns)
    
  def this(n: Int) = this(n, n)

  def putProduct(a: Matrix, b: Matrix): Unit = {
    assert(a.columns == b.rows)
    assert(a.rows == rows)
    assert(b.columns == columns)

    kernel {
      // This block will either be converted to an 
      // OpenCL kernel or cause compilation error
      for (i <- 0 until rows; j <- 0 until columns) {
        data(i * columns + j) = (0 until a.columns).map(k => {
          a.data(i * a.columns + k) * b.data(k * b.columns + j)
        }).sum
      }
    }
  }

  def putSum(a: Matrix, b: Matrix): Unit = {
    assert(a.columns == b.columns && a.columns == columns)
    assert(a.rows == b.rows && a.rows == rows)

    kernel {
      for (i <- 0 until rows; j <- 0 until columns) {
        val offset = i * columns + j
        data(offset) = a.data(offset) + b.data(offset)
      }
    }
  }
}

implicit val context = Context.best

val n = 10
val a = new Matrix(n)
val b = new Matrix(n)
val out = new Matrix(n)

out.putProduct(a, b)

println(out.data)
  

Shader-School (recap)

  • GPU action in your browser

05 Mandelbrot

Questions ?

 

Martin.Andrews @
RedCatLabs.com

 

 

Name Card pics for OCR to ::

ocr @ RedCatLabs.com

OCR Interactive Demo

  • PLEASE send an image of a Business Card to :
    • ocr@redcatlabs.com
Fill Required

TIPS : No flash; Fill middle third;
Landscape; Dark background

Demo : Terms of Service (v0.01)

  • Won't sell your email to anyone else
  • Won't sell your card photos to anyone else
  • Won't put your card photos up on-screen
  • Send you one response now
  • Send you another response soon, once the OCR thing works better
  • Hopefully, there'll be an update at a Talk.js night