Parallel Web Programming



Similar documents
Performance Optimization and Debug Tools for mobile games with PlayCanvas

WebCL for Hardware-Accelerated Web Applications. Won Jeon, Tasneem Brutch, and Simon Gibbs

Press Briefing. GDC, March Neil Trevett Vice President Mobile Ecosystem, NVIDIA President Khronos. Copyright Khronos Group Page 1

Enabling OpenCL Acceleration of Web Applications

Introduction GPU Hardware GPU Computing Today GPU Computing Example Outlook Summary. GPU Computing. Numerical Simulation - from Models to Software

Introduction to WebGL

PARALLEL JAVASCRIPT. Norm Rubin (NVIDIA) Jin Wang (Georgia School of Technology)

Computer Graphics on Mobile Devices VL SS ECTS

Geo-Scale Data Visualization in a Web Browser. Patrick Cozzi pcozzi@agi.com

Graphics Cards and Graphics Processing Units. Ben Johnstone Russ Martin November 15, 2011

A Hybrid Visualization System for Molecular Models

Web Based 3D Visualization for COMSOL Multiphysics

JavaFX Session Agenda

GPGPU Computing. Yong Cao

Web-Based Enterprise Data Visualization a 3D Approach. Oleg Kachirski, Black and Veatch

Development Techniques for Native/Hybrid Tizen Apps. Presented by Kirill Kruchinkin

Crosswalk: build world class hybrid mobile apps

Outline. 1.! Development Platforms for Multimedia Programming!

CSE 564: Visualization. GPU Programming (First Steps) GPU Generations. Klaus Mueller. Computer Science Department Stony Brook University

Introduction to Computer Graphics with WebGL

Chapter 2 - Graphics Programming with JOGL

Computer Graphics Hardware An Overview

The Evolution of Computer Graphics. SVP, Content & Technology, NVIDIA

Visualizing Data: Scalable Interactivity

Programming 3D Applications with HTML5 and WebGL

Open Source Open Possibilities. Vellamo. System Level Benchmarking October Open Source Open Possibilities PAGE 1

Introduction to GPU Programming Languages

Color correction in 3D environments Nicholas Blackhawk

Silverlight for Windows Embedded Graphics and Rendering Pipeline 1

L20: GPU Architecture and Models

How To Understand The Power Of Unity 3D (Pro) And The Power Behind It (Pro/Pro)

How To Teach Computer Graphics

Introducing PgOpenCL A New PostgreSQL Procedural Language Unlocking the Power of the GPU! By Tim Child

Research on HTML5 in Web Development

How to test OpenGL drivers with Free Software

Lets3D: A Collaborative 3D Editing Tool Based On Cloud Storage

USING RUST TO BUILD THE NEXT GENERATION WEB BROWSER

Rich Internet Applications

WebSocket Server. To understand the Wakanda Server side WebSocket support, it is important to identify the different parts and how they interact:

Some Issues on Ajax Invocation

Titolo del paragrafo. Titolo del documento - Sottotitolo documento The Benefits of Pushing Real-Time Market Data via a Web Infrastructure

Trends in HTML5. Matt Spencer UI & Browser Marketing Manager

Selenium WebDriver. Gianluca Carbone. Selenium WebDriver 1

An introduction to creating Web 2.0 applications in Rational Application Developer Version 8.0

2: Introducing image synthesis. Some orientation how did we get here? Graphics system architecture Overview of OpenGL / GLU / GLUT

NVPRO-PIPELINE A RESEARCH RENDERING PIPELINE MARKUS TAVENRATH MATAVENRATH@NVIDIA.COM SENIOR DEVELOPER TECHNOLOGY ENGINEER, NVIDIA

Programming in HTML5 with JavaScript and CSS3

Jenkins XML API and Mobile Devices

Making the Most of Existing Public Web Development Frameworks WEB04

How To Create A Flood Simulator For A Web Browser (For Free)

4 Understanding. Web Applications IN THIS CHAPTER. 4.1 Understand Web page development. 4.2 Understand Microsoft ASP.NET Web application development

Dynamic Web Programming BUILDING WEB APPLICATIONS USING ASP.NET, AJAX AND JAVASCRIPT

Step into the Future: HTML5 and its Impact on SSL VPNs

ANDROID PROGRAMMING - INTRODUCTION. Roberto Beraldi

Introduction to GPGPU. Tiziano Diamanti


1 How to Monitor Performance

A Pipeline From COLLADA to WebGL for Skeletal Animation

GR.jl Plotting for Julia based on GR

OpenGL Insights. Edited by. Patrick Cozzi and Christophe Riccio

Next Generation GPU Architecture Code-named Fermi

HTML5 the new. standard for Interactive Web

Writing Applications for the GPU Using the RapidMind Development Platform

Adding Panoramas to Google Maps Using Ajax

Recent Advances and Future Trends in Graphics Hardware. Michael Doggett Architect November 23, 2005

An evaluation of JavaFX as 2D game creation tool

Shader Model 3.0. Ashu Rege. NVIDIA Developer Technology Group

GPU(Graphics Processing Unit) with a Focus on Nvidia GeForce 6 Series. By: Binesh Tuladhar Clay Smith

Front-End Performance Testing and Optimization

Abstractions from Multimedia Hardware. Libraries. Abstraction Levels

Programmable Graphics Hardware

OpenGL ES Safety-Critical Profile Philosophy

Table of contents. HTML5 Data Bindings SEO DMXzone

Interactive visualization of big data

Learning HTML5 Game Programming

The Future Of Animation Is Games

Hardware design for ray tracing

Making Multicore Work and Measuring its Benefits. Markus Levy, president EEMBC and Multicore Association

Optimizing Unity Games for Mobile Platforms. Angelo Theodorou Software Engineer Unite 2013, 28 th -30 th August

Stream Processing on GPUs Using Distributed Multimedia Middleware

Lecture Notes, CEng 477

Web Development. Owen Sacco. ICS2205/ICS2230 Web Intelligence

SYCL for OpenCL. Andrew Richards, CEO Codeplay & Chair SYCL Working group GDC, March Copyright Khronos Group Page 1

DATA VISUALIZATION OF THE GRAPHICS PIPELINE: TRACKING STATE WITH THE STATEVIEWER

Introduction to Computer Graphics

Mobility Introduction Android. Duration 16 Working days Start Date 1 st Oct 2013

Client-side Web Engineering From HTML to AJAX

Getting more out of Matplotlib with GR

WebGL Massively Multiplayer Online Game

CLOUD GAMING WITH NVIDIA GRID TECHNOLOGIES Franck DIARD, Ph.D., SW Chief Software Architect GDC 2014

Software Requirements Specification For Real Estate Web Site

3D Graphics and Cameras

Image Processing and Computer Graphics. Rendering Pipeline. Matthias Teschner. Computer Science Department University of Freiburg

Game Development in Android Disgruntled Rats LLC. Sean Godinez Brian Morgan Michael Boldischar

1 How to Monitor Performance

Load Testing RIA using WebLOAD. Amir Shoval, VP Product Management

Transcription:

Parallel Web Programming Tobias Groß, Björn Meier Hardware/Software Co-Design, University of Erlangen-Nuremberg May 23, 2013

Outline WebGL OpenGL Rendering Pipeline Shader WebCL Motivation Development Design A portable javascript thread library for Ajax applications Ajax Multithread library Web Workers Motivation Programing with Web Workers Load distribution by using Web Workers for a real-time web aaplication May 23, 2013 Tobias Groß, Björn Meier Hardware/Software Co-Design Parallel Web Programming 2

WebGL cross-browser and cross-platform API to create 2D/3D graphics based on OpenGL ES 2.0 uses OpenGL shading language GLSL runs in HTML5 canvas elements low-level API can be simplified by WebGL libraries (three.js, GLGE,...) Matrix libraries May 23, 2013 Tobias Groß, Björn Meier Hardware/Software Co-Design Parallel Web Programming 3

Figure: OpenGL ES 2.0 rendering pipeline[1] May 23, 2013 Tobias Groß, Björn Meier Hardware/Software Co-Design Parallel Web Programming 4

Rendering Pipeline 1. Vertex Shader 2. Triangle assembly 3. Rasterization 4. Fragment Shader 1 2 3 4 Figure: Example for rendering an object. May 23, 2013 Tobias Groß, Björn Meier Hardware/Software Co-Design Parallel Web Programming 5

Shader Vertex Shader receives a single vertex composed of a series of Vertex Attributes produces an output vertex 1:1 mapping from input vertices to output vertices Fragment Shader processes a Fragment from the rasterization process into a set of colors and a single depth value < s c r i p t i d ="2d vertex shader " type ="x shader / x vertex " > a t t r i b u t e vec2 a _ p o s i t i o n ; void main ( ) { g l _ P o s i t i o n = vec4 ( a_position, 0, 1) ; } </ s c r i p t > Figure: vertex shader < s c r i p t i d ="2d fragment shader " type ="x shader / x fragment " > void main ( ) { gl_fragcolor = vec4 ( 0, 1, 0, 1 ) ; / / green } </ s c r i p t > Figure: fragment shader May 23, 2013 Tobias Groß, Björn Meier Hardware/Software Co-Design Parallel Web Programming 6

WebGL is gather system fast for a special purpose lack of flexibility gather read The program will write to a fixed position (like the target fragment position of a fragment shader), but has fast access to arbitrary data sources (textures, uniforms, etc.). scatter write The program receives a stream of input data which it cannot arbitarily address, but can do fast writes to arbitrary memory locations. May 23, 2013 Tobias Groß, Björn Meier Hardware/Software Co-Design Parallel Web Programming 7

Outline WebGL OpenGL Rendering Pipeline Shader WebCL Motivation Development Design A portable javascript thread library for Ajax applications Ajax Multithread library Web Workers Motivation Programing with Web Workers Load distribution by using Web Workers for a real-time web aaplication May 23, 2013 Tobias Groß, Björn Meier Hardware/Software Co-Design Parallel Web Programming 8

Motivation for WebCL increasing number of compute intensive browser applications complex image and audio processing scientific simulations games augmented reality... JavaScript is insufficient use of heterogeneous resources OpenCL kernel vs GLSL shader OpenCL has functionality not available in GLSL shaders Scattered writes Local memory Thread synchronization Atomic memory operations May 23, 2013 Tobias Groß, Björn Meier Hardware/Software Co-Design Parallel Web Programming 9

Development Specification of an JavaScript binding to the Khronos OpenCL standard is still in progress by the Khronos Group. Implementation prototypes Nokia (Firefox extension) Samsung (WebKit) Motorola (NodeJS) May 23, 2013 Tobias Groß, Björn Meier Hardware/Software Co-Design Parallel Web Programming 10

Design for Samsung implementation[2] (Nokia and Motorola are similar) interface above OpenCL (drivers with OpenCL support are required) single WebCL object Error handling: JavaScript-like exception handling mechanism Interoperability with HTML Canvas, Image and Video Elements kernel source code must be part of web page WebGL interoperability May 23, 2013 Tobias Groß, Björn Meier Hardware/Software Co-Design Parallel Web Programming 11

< s c r i p t i d =" square " type ="x k e r nel " > kernel void square ( global f l o a t input, global f l o a t output, const unsigned i n t count ) { i n t i = g e t _ g l o b a l _ i d ( 0 ) ; i f ( i < count ) output [ i ] = i n p u t [ i ] i n p u t [ i ] ; } </ s c r i p t > < s c r i p t > f u n c t i o n getkernel ( i d ) { var k e r n e l S c r i p t = document. getelementbyid ( i d ) ; i f ( k e r n e l S c r i p t === n u l l k e r n e l S c r i p t. type!== " x kernel " ) r e t u r n n u l l ; r e t u r n k e r n e l S c r i p t. f i r s t C h i l d. textcontent ; } </ s c r i p t > < s c r i p t >... var kernelsource = getkernel ( " square " ) ;... program = context. createprogram ( kernelsource ) ; / / B u i l d the program executable program. b u i l d ( device ) ; / / Create the compute k e r n e l i n the program we wish to run kernel = program. createkernel ( " square " ) ;... / / Set the arguments to our compute kernel kernel. setarg ( 0, i n p u t ) ;... queue. enqueuendrangekernel ( kernel, n u l l, globalworksize, localworksize ) ;... </ s c r i p t > May 23, 2013 Tobias Groß, Björn Meier Hardware/Software Co-Design Parallel Web Programming 12

Outline WebGL OpenGL Rendering Pipeline Shader WebCL Motivation Development Design A portable javascript thread library for Ajax applications Ajax Multithread library Web Workers Motivation Programing with Web Workers Load distribution by using Web Workers for a real-time web aaplication May 23, 2013 Tobias Groß, Björn Meier Hardware/Software Co-Design Parallel Web Programming 13

Ajax (Asynchronous JavaScript and XML) asynchronous web applications dynamicly changing web pages Figure: classic web application[7] Figure: Ajax web application[7] Problem: event driven asynchronous programs on a single thread May 23, 2013 Tobias Groß, Björn Meier Hardware/Software Co-Design Parallel Web Programming 14

Multithread library[4][3] Features: JavaScript library concurrent programming with threads preemptive scheduler object-oriented API portability May 23, 2013 Tobias Groß, Björn Meier Hardware/Software Co-Design Parallel Web Programming 15

API Public methods: create stop sleep yield kill Http.get Http.post... f u n c t i o n load ( u r l ) { var th = Thread. create ( nowloading ) ; t r y { var res = Thread. Http. get ( u r l ) ; document. w r i t e ( res. responsetext ) ; } catch ( e ) { document. w r i t e ( "ERROR: " + e ) ; } th. k i l l ( ) ; } f u n c t i o n nowloading ( ) { var bar = [ " ", " / ", " ", " \ " ] ; var i = 0; while ( t r u e ) { window. s t a t u s = "Now loading... " + bar [ i =( i +1) %4]; Thread. sleep (125) ; } } Thread. create ( load, " h t t p : / /... " ) ; Figure: example for the multithread library[3] May 23, 2013 Tobias Groß, Björn Meier Hardware/Software Co-Design Parallel Web Programming 16

Design timesharing the UI-thread for pseudo multithreading program break-up into basic blocks continuation-based multithreading f u n c t i o n f ( ) { var c = getc ( ) ; / / ( ) document. w r i t e ( c, " \ n " ) ; } f u n c t i o n f ( ) { var c = getc ( ) ; f u n c t i o n r e s t ( ) { document. w r i t e ( c, " \ n " ) ; } r e s t ( ) ; } Figure: Original program[7] Figure: Rewriting result[7] trampolined style do { t r y { context = context. c o n t i n u a t i o n. procedure. c a l l ( context. c o n t i n u a t i o n. t h i s _ v a l, context. r e t _ v a l ) ; } catch ( e ) { exception handling } } while ( context. timeout == undefined && time s l i c e remains ) ; Figure: trampoline[7] May 23, 2013 Tobias Groß, Björn Meier Hardware/Software Co-Design Parallel Web Programming 17

Outline WebGL OpenGL Rendering Pipeline Shader WebCL Motivation Development Design A portable javascript thread library for Ajax applications Ajax Multithread library Web Workers Motivation Programing with Web Workers Load distribution by using Web Workers for a real-time web aaplication May 23, 2013 Tobias Groß, Björn Meier Hardware/Software Co-Design Parallel Web Programming 18

Motivation What are Web Workers? extension for JavaScript available in all modern browsers allows to run scripts in the background are relatively heavy-weight high start-up performance cost high per-instance memory cost Why using Web Workers? they allow to write client-side code, that utilize threads, which run in background this threads don t block the frontend (keeps the webpage responsive) you can relocate computing power from server-side to client-side May 23, 2013 Tobias Groß, Björn Meier Hardware/Software Co-Design Parallel Web Programming 19

Example using Web Workers < s c r i p t > var worker = new Worker ( worker. js ) ; worker. onmessage = f u n c t i o n ( event ) { document. getelementbyid ( r e s u l t ). textcontent = event. data ; } ; </ s c r i p t > Figure: compute prime numbers 1 [6] var n = 1; search : while ( t r u e ) { n += 1; f o r ( var i = 2; i <= Math. s q r t ( n ) ; i += 1) i f ( n % i == 0) continue search ; / / found a prime! postmessage ( n ) ; } Figure: compute prime numbers 2 [6] May 23, 2013 Tobias Groß, Björn Meier Hardware/Software Co-Design Parallel Web Programming 20

Web Workers API (extract) Constructors Worker( script.js ) Communication main thread uses postmessage method to communicate with the worker worker handle messages with a onmessage function, which must be implemented communication in other direction uses function postmessage and a messagehandler as well May 23, 2013 Tobias Groß, Björn Meier Hardware/Software Co-Design Parallel Web Programming 21

The web application Initial situation it s a web-based multiplayer online role-playing game every user operates an avatar the avatars interact with other avatars or NPCs to interact, avatars have to move arround the movement is computed depending on forces which affect the avatar Problem Server has to compute forces of all avatars and NPCs the latency has to be smaller than 500 ms this limits the number of avatars a server can handle at once Solution Load distribution from server to client using Web Workers May 23, 2013 Tobias Groß, Björn Meier Hardware/Software Co-Design Parallel Web Programming 22

Program flow with Web Worker Figure: System with Web Worker[5] May 23, 2013 Tobias Groß, Björn Meier Hardware/Software Co-Design Parallel Web Programming 23

Evaluation Figure: Web Worker performance based on browser implementation[5] May 23, 2013 Tobias Groß, Björn Meier Hardware/Software Co-Design Parallel Web Programming 24

Evaluation Figure: CPU Usage of server[5] May 23, 2013 Tobias Groß, Björn Meier Hardware/Software Co-Design Parallel Web Programming 25

Evaluation Figure: Data transfer rate[5] May 23, 2013 Tobias Groß, Björn Meier Hardware/Software Co-Design Parallel Web Programming 26

References I [1] Khronos Group. The standard for embedded accelerated 3d graphics, 2013. [Online; accessed 23-Mai-2013]. [2] Won Jeon, Tasneem Brutch, and Simon Gibbs. Webcl for hardware-accelerated web applications. 2012. [3] Daisuke Maki and Hideya Iwasaki. Javascript multithread framework for asynchronous processing. IPSJ Transactions on Programming, 48:1 18. [4] Daisuke Maki and Hideya Iwasaki. A portable javascript thread library for ajax applications. In Companion to the 22nd ACM SIGPLAN conference on Object-oriented programming systems and applications companion, OOPSLA 07, pages 817 818, New York, NY, USA, 2007. ACM. May 23, 2013 Tobias Groß, Björn Meier Hardware/Software Co-Design Parallel Web Programming 27

References II [5] Shusuke Okamoto and Masaki Kohana. Load distribution by using web workers for a real-time web application. In International Journal of Web Information Systems, pages 381 395, 2011. [6] W3C. Web workers, 2012. [Online; accessed 20-Mai-2013]. [7] Wikipedia. Ajax (programmierung), 2013. [Online; accessed 20-Mai-2013]. May 23, 2013 Tobias Groß, Björn Meier Hardware/Software Co-Design Parallel Web Programming 28