33
DevCon 2013: Dec 9th11th 2013, Monte Carlo Boosting HTML Apps with WebCL Janakiram Raghumandala December 10, 2013

Boosting your HTML Apps – Overview of OpenCL and Hello World of WebCL

Embed Size (px)

DESCRIPTION

WebCL enables you boost the performance of select HTML application where lots of computation is involved. For example, fluid simulation, image manipulation, video manipulation. Since, OpenCL is the underlying platform, the same has been introduced in the beginning and then WebCL. Contents: Motivation Introduction to OpenCL Introduction to WebCL Hello World Program of WebCL

Citation preview

Page 1: Boosting your HTML Apps – Overview of OpenCL and Hello World of WebCL

DevCon 2013: Dec 9th–11th 2013,

Monte Carlo

Boosting HTML Apps with WebCL

Janakiram Raghumandala

December 10, 2013

Page 2: Boosting your HTML Apps – Overview of OpenCL and Hello World of WebCL

2 | © 2013 Cisco and/or its affiliates. All rights reserved.

Source Name Placement

• WebCL is an open API to achieve heterogeneous parallel computing in HTML5 web browsers.

• It is a JavaScript binding to OpenCL

• Generally used with Canvas element, SIMD computing, particle simulation

• WebCL enables of compute-intensive web applications.

What is WebCL?

Page 3: Boosting your HTML Apps – Overview of OpenCL and Hello World of WebCL

3 | © 2013 Cisco and/or its affiliates. All rights reserved.

Contents

– Motivation

– OpenCL, The Underlying Concept

– WebCL

– Performance Comparison & Demos

– Summary, current status and References

Page 4: Boosting your HTML Apps – Overview of OpenCL and Hello World of WebCL

4 | © 2013 Cisco and/or its affiliates. All rights reserved.

Contents

– Motivation

– OpenCL, The Underlying Concept

– WebCL

– Performance Comparison & Demos

– Summary, current status and References

Page 5: Boosting your HTML Apps – Overview of OpenCL and Hello World of WebCL

5 | © 2013 Cisco and/or its affiliates. All rights reserved.

Motivation

• New mobile apps with high-computing demands

– Augmented Reality

– Video Processing

– 3D Games – lots of calculations and physics

– Computational photography

Page 6: Boosting your HTML Apps – Overview of OpenCL and Hello World of WebCL

6 | © 2013 Cisco and/or its affiliates. All rights reserved.

Motivation…

• GPU delivers

improved FLOPS

• 100 times faster

Page 7: Boosting your HTML Apps – Overview of OpenCL and Hello World of WebCL

7 | © 2013 Cisco and/or its affiliates. All rights reserved.

Motivation…

• Higher FLOPS per WATT• RED – CPUs

• ORANGE – APUs

• Light BLUE – ARM

• GREEN – Grid Processors

• YELLO – GPUs

• Top-left is the preferred zone

Page 8: Boosting your HTML Apps – Overview of OpenCL and Hello World of WebCL

8 | © 2013 Cisco and/or its affiliates. All rights reserved.

Webcentric Applications

WebcentricApplications

Page 9: Boosting your HTML Apps – Overview of OpenCL and Hello World of WebCL

9 | © 2013 Cisco and/or its affiliates. All rights reserved.

Motivation… growing web centric applications

Page 10: Boosting your HTML Apps – Overview of OpenCL and Hello World of WebCL

10 | © 2013 Cisco and/or its affiliates. All rights reserved.

Contents

– Motivation

– OpenCL, The Underlying Concept

– WebCL

– Performance Comparison & Demos

– Summary, current status and References

Page 11: Boosting your HTML Apps – Overview of OpenCL and Hello World of WebCL

11 | © 2013 Cisco and/or its affiliates. All rights reserved.

OpenCL

• C-based cross-platform programming interface

• Kernels

• Run-time or build-time compilation

• Rich set of built-in functions, cross, dot, sin, cos, log …

Page 12: Boosting your HTML Apps – Overview of OpenCL and Hello World of WebCL

12 | © 2013 Cisco and/or its affiliates. All rights reserved.

OpenCL…

• Host contains one or

more OpenCL Devices

(aka Compute Devices)

• A Computer Device

contains one or more

Compute Units ~ Cores

Page 13: Boosting your HTML Apps – Overview of OpenCL and Hello World of WebCL

13 | © 2013 Cisco and/or its affiliates. All rights reserved.

OpenCL…

• A Compute Unit

contains one or more

processing elements

~ Intel’s hyper threads

• Processing elements

execute code as SIMD

Page 14: Boosting your HTML Apps – Overview of OpenCL and Hello World of WebCL

14 | © 2013 Cisco and/or its affiliates. All rights reserved.

OpenCL… Work Items & Work Groups

Page 15: Boosting your HTML Apps – Overview of OpenCL and Hello World of WebCL

15 | © 2013 Cisco and/or its affiliates. All rights reserved.

OpenCL… Execution Model

• Kernel

– Basic unit of executable code, similar to a C function

• Program

– Collection of kernels and functions called by kernels

– Analogous to a dynamic library (run-time linking)

• Command Queue

– Applications queue kernels and data transfers

– Performed in-order or out-of-order

• Work-item ~ Processing Element ~ Thread– An execution of a kernel by a processing element (~ thread)

• Work-group ~ Compute Unit ~ Core– A collection of related work-items that execute on a single compute unit (~ core)

Page 16: Boosting your HTML Apps – Overview of OpenCL and Hello World of WebCL

16 | © 2013 Cisco and/or its affiliates. All rights reserved.

OpenCL… Execution Model

• Kernel

– Basic program element, similar to a C function

• Program

– Collection of kernels and functions called by kernels

– Analogous to a dynamic library (run-time linking)

• Command Queue

– Applications queue kernels and data transfers

– Performed in-order or out-of-order

• Work-item ~ Processing Element ~ Thread– An execution of a kernel by a processing element (~ thread)

• Work-group ~ Compute Unit ~ Core– A collection of related work-items that execute on a single compute unit (~ core)

Page 17: Boosting your HTML Apps – Overview of OpenCL and Hello World of WebCL

17 | © 2013 Cisco and/or its affiliates. All rights reserved.

OpenCL… Memory Model

• Private Memory per PE

• Local Memory per Compute Unit

• Global Memory per Device

• Host Memory per Host System

Page 18: Boosting your HTML Apps – Overview of OpenCL and Hello World of WebCL

18 | © 2013 Cisco and/or its affiliates. All rights reserved.

OpenCL:Kernels

OpenCL: Kernels• OpenCL kernel– Defined on an N-dimensional computation domain– Execute a kernel at each point of the computation domain

Traditional Loop

void vectorMult(

const float* a,

const float* b,

float* c,

const unsigned int count)

{

for(int i=0; i<count; i++)

c[i] = a[i] * b[i];

}

Data Parallel OpenCL Kernel

kernel void vectorMult(

global const float* a,

global const float* b,

global float* c)

{

int id = get_global_id(0);

c[id] = a[id] * b[id];

}

Page 19: Boosting your HTML Apps – Overview of OpenCL and Hello World of WebCL

19 | © 2013 Cisco and/or its affiliates. All rights reserved.

OpenCL:Execution of Programs - Steps

1. Query host for OpenCL devices. 2. Create a context to associate OpenCL devices. 3. Create programs for execution on one or more

associated devices. 4. From the programs, select kernels to execute. 5. Create memory objects accessible from the host

and/or the device. 6. Copy memory data to the device as needed. 7. Provide kernels to the command queue for

execution. 8. Copy results from the device to the host.

Page 20: Boosting your HTML Apps – Overview of OpenCL and Hello World of WebCL

20 | © 2013 Cisco and/or its affiliates. All rights reserved.

Contents

– Motivation

– OpenCL, The Underlying Concept

– WebCL

– Performance Comparison & Demos

– Summary, current status and References

Page 21: Boosting your HTML Apps – Overview of OpenCL and Hello World of WebCL

21 | © 2013 Cisco and/or its affiliates. All rights reserved.

WebCL

• WebCL concepts were deliberately made similar to the OpenCL model

– Programs

– Kernels

– Linking

– Memory Transfers

Page 22: Boosting your HTML Apps – Overview of OpenCL and Hello World of WebCL

22 | © 2013 Cisco and/or its affiliates. All rights reserved.

WebCL:Programming

• Initialization

• Create kernel

• Run kernel

• WebCL image object creation

– From Uint8Array

– From <img>, <canvas>, or <video>

– From WebGL vertex buffer

– From WebGL texture

• WebGL vertex animation

• WebGL texture animation

Page 23: Boosting your HTML Apps – Overview of OpenCL and Hello World of WebCL

23 | © 2013 Cisco and/or its affiliates. All rights reserved.

WebCL:Initialization

<script> var platforms = WebCL.getPlatforms();

var devices = platforms[0].getDevices(WebCL.DEVICE_TYPE_GPU);

var context = WebCL.createContext({ WebCLDevice: devices[0] } );

var queue = context.createCommandQueue();

</script>

Page 24: Boosting your HTML Apps – Overview of OpenCL and Hello World of WebCL

24 | © 2013 Cisco and/or its affiliates. All rights reserved.

WebCL:Creating a kernel

<script id="squareProgram" type="x-kernel">

__kernel square(

__global float* input,

__global float* output,

const unsigned int count)

{

int i = get_global_id(0);

if(i < count)

output[i] = input[i] * input[i];

}

</script>

<script> var programSource = getProgramSource("squareProgram");

var program = context.createProgram(programSource);

program.build();

var kernel = program.createKernel("square");

</script>

Page 25: Boosting your HTML Apps – Overview of OpenCL and Hello World of WebCL

25 | © 2013 Cisco and/or its affiliates. All rights reserved.

WebCL:Running WebCL Kernes

<script> ...

var inputBuf context.createBuffer(WebCL.MEM_READ_ONLY, Float32Array.BYTES_PER_ELEMENT * count);var outputBuf =

context.createBuffer(WebCL.MEM_WRITE_ONLY, Float32Array.BYTES_PER_ELEMENT * count);

var data = new Float32Array(count); // populate data ...

queue.enqueueWriteBuffer(inputBuf, data, true); //Last arg indicates blocking API

kernel.setKernelArg(0, inputBuf);

kernel.setKernelArg(1, outputBuf);

kernel.setKernelArg(2, count, WebCL.KERNEL_ARG_INT);

var workGroupSize = kernel.getWorkGroupInfo(devices[0], WebCL.KERNEL_WORK_GROUP_SIZE);

queue.enqueueNDRangeKernel(kernel, [count], [workGroupSize]);

queue.finish(); //This API blocks

queue.enqueueReadBuffer(outputBuf, data, true); //Last arg indicates blocking API

</script>

Page 26: Boosting your HTML Apps – Overview of OpenCL and Hello World of WebCL

26 | © 2013 Cisco and/or its affiliates. All rights reserved.

Contents

– Motivation

– OpenCL, The Underlying Concept

– WebCL

– Performance Comparison & Demos

– Summary, current status and References

Page 27: Boosting your HTML Apps – Overview of OpenCL and Hello World of WebCL

DevCon 2013: Dec 9th–11th 2013,

Monte Carlo

Page 28: Boosting your HTML Apps – Overview of OpenCL and Hello World of WebCL

28 | © 2013 Cisco and/or its affiliates. All rights reserved.

Contents

– Motivation

– OpenCL, The Underlying Concept

– WebCL

– Performance Comparison & Demos

– Summary, current status and References

Page 29: Boosting your HTML Apps – Overview of OpenCL and Hello World of WebCL

29 | © 2013 Cisco and/or its affiliates. All rights reserved.

WebCL:Summary

JavaScript binding for OpenCL

Provides high performance parallel processing on multicore CPU & GPGPU

– Portable and efficient access to heterogeneous multicore devices

– Provides a single coherent standard across desktop and mobile devices

WebCL HW and SW requirements

– Need a modified browser with WebCL support

– Hardware, driver, and runtime support for OpenCL

WebCL stays close to the OpenCL standard

– Preserves developer familiarity and facilitates adoption

– Allows developers to translate their OpenCL knowledge to the web environment

– Easier to keep OpenCL and WebCL in sync, as the two evolve

Intended to be an interface above OpenCL

Facilitates layering of higher level abstractions on top of WebCL API

Page 30: Boosting your HTML Apps – Overview of OpenCL and Hello World of WebCL

30 | © 2013 Cisco and/or its affiliates. All rights reserved.

WebCL:Goals

• Compute intensive web applications

– High Performance

– Platform independent – Standards-compliant

– Ease of application development

Page 31: Boosting your HTML Apps – Overview of OpenCL and Hello World of WebCL

31 | © 2013 Cisco and/or its affiliates. All rights reserved.

WebCL Standardization – Current Status

• Work in progress

• Working-draft is available

Page 32: Boosting your HTML Apps – Overview of OpenCL and Hello World of WebCL

32 | © 2013 Cisco and/or its affiliates. All rights reserved.

References

• OpenCL 2.0 Tutorial• https://cvs.khronos.org/svn/repos/registry/trunk/public/webcl/spec/latest/index.html - WebCL Working draft • http://www.khronos.org/registry/cl/specs/opencl-1.1.pdf- OpenCL 1.1 Specification• http://streamcomputing.eu/blog/2012-08-27/processors-that-can-do-20-gflops-watt/

Page 33: Boosting your HTML Apps – Overview of OpenCL and Hello World of WebCL

Thank you.