Portable Parallel Programming on Cloud and HPC: Scientific Applications of Twister4Azure
Views, Programming Language Research, and HPC
-
Upload
patrick-lam -
Category
Documents
-
view
218 -
download
0
Transcript of Views, Programming Language Research, and HPC
8/3/2019 Views, Programming Language Research, and HPC
http://slidepdf.com/reader/full/views-programming-language-research-and-hpc 1/52
Introduction Views Example PL Research Views Technical Details Conclusions
Views, Programming Languages Research,
and HPC
Patrick Lam
http://patricklam.ca
Joint work with Brian Demsky
January 2012
8/3/2019 Views, Programming Language Research, and HPC
http://slidepdf.com/reader/full/views-programming-language-research-and-hpc 2/52
Introduction Views Example PL Research Views Technical Details Conclusions
Context
1.2 5.8 2.2 3.5 8.1
7.
3 9.
1 2.
3 0.
9 2.
28.3 1.1 0.8 3.5 2.9
1.8 3.4 2.8 6.5 9.3
0.8 3.2 3.3 8.2 4.3
8/3/2019 Views, Programming Language Research, and HPC
http://slidepdf.com/reader/full/views-programming-language-research-and-hpc 3/52
Introduction Views Example PL Research Views Technical Details Conclusions
Context
1.2 5.8 2.2 3.5 8.1
7.
3 9.
1 2.
3 0.
9 2.
28.3 1.1 0.8 3.5 2.9
1.8 3.4 2.8 6.5 9.3
0.8 3.2 3.3 8.2 4.3
8/3/2019 Views, Programming Language Research, and HPC
http://slidepdf.com/reader/full/views-programming-language-research-and-hpc 4/52
Introduction Views Example PL Research Views Technical Details Conclusions
Context
8/3/2019 Views, Programming Language Research, and HPC
http://slidepdf.com/reader/full/views-programming-language-research-and-hpc 5/52
Introduction Views Example PL Research Views Technical Details Conclusions
Roadmap
Views: mutual exclusion via policy-basedlocks
Programming languages and HPC
Technical details on views
D C
8/3/2019 Views, Programming Language Research, and HPC
http://slidepdf.com/reader/full/views-programming-language-research-and-hpc 6/52
Introduction Views Example PL Research Views Technical Details Conclusions
Problem
Current lockingmechanisms are
hard to use.
I t d ti Vi E l PL R h Vi T h i l D t il C l i
8/3/2019 Views, Programming Language Research, and HPC
http://slidepdf.com/reader/full/views-programming-language-research-and-hpc 7/52
Introduction Views Example PL Research Views Technical Details Conclusions
Problems
no guarantee that locks are consistentlyapplied;
no way to express fine-grained locking;
can’t express why locks exist.
Introduction Views Example PL Research Views Technical Details Conclusions
8/3/2019 Views, Programming Language Research, and HPC
http://slidepdf.com/reader/full/views-programming-language-research-and-hpc 8/52
Introduction Views Example PL Research Views Technical Details Conclusions
Goal
Raise abstraction level ofconcurrency control
primitives.
Introduction Views Example PL Research Views Technical Details Conclusions
8/3/2019 Views, Programming Language Research, and HPC
http://slidepdf.com/reader/full/views-programming-language-research-and-hpc 9/52
Introduction Views Example PL Research Views Technical Details Conclusions
Subgoals
Support object-oriented design principles.
Support fine-grained locking at language level.
Support static checking to help catch
concurrency bugs.
Introduction Views Example PL Research Views Technical Details Conclusions
8/3/2019 Views, Programming Language Research, and HPC
http://slidepdf.com/reader/full/views-programming-language-research-and-hpc 10/52
Introduction Views Example PL Research Views Technical Details Conclusions
Array-Based Vector Implementation
2 5 3 1 7 9
sizecapacity
array
Introduction Views Example PL Research Views Technical Details Conclusions
8/3/2019 Views, Programming Language Research, and HPC
http://slidepdf.com/reader/full/views-programming-language-research-and-hpc 11/52
Introduction Views Example PL Research Views Technical Details Conclusions
Vector class definition
Vector
size : intcapacity : int
array : int[]
Rule: must hold owning lock to access “size”.
Introduction Views Example PL Research Views Technical Details Conclusions
8/3/2019 Views, Programming Language Research, and HPC
http://slidepdf.com/reader/full/views-programming-language-research-and-hpc 12/52
Introduction Views Example PL Research Views Technical Details Conclusions
Basic Approach
Vector
size : int
capacity : intarray : int[]
Declare a view which protects the field.
Must hold the view to access the field—checked by
compiler.
Compiler uses annotations to create efficient lock-based
code.
Introduction Views Example PL Research Views Technical Details Conclusions
8/3/2019 Views, Programming Language Research, and HPC
http://slidepdf.com/reader/full/views-programming-language-research-and-hpc 13/52
p
Concrete Example of Views
1 view read {
2 size, capacity, array: readonly;
3
4 incompatible write, resize;
5
6 get(int i) preferred;
7 capacity();
8 }
Introduction Views Example PL Research Views Technical Details Conclusions
8/3/2019 Views, Programming Language Research, and HPC
http://slidepdf.com/reader/full/views-programming-language-research-and-hpc 14/52
p
Concrete Example of Views
1 view read {
2 size, capacity, array: readonly;
3
4 incompatible write, resize;
5
6 get(int i) preferred;
7 capacity();
8 }
Provides read-only access to fields “size”, “capacity” and“array”.
Introduction Views Example PL Research Views Technical Details Conclusions
8/3/2019 Views, Programming Language Research, and HPC
http://slidepdf.com/reader/full/views-programming-language-research-and-hpc 15/52
Concrete Example of Views
1 view read {
2 size, capacity, array: readonly;
3
4 incompatible write, resize;
5
6 get(int i) preferred;
7 capacity();
8 }
Provides read-only access to fields “size”, “capacity” and“array”.
A thread cannot hold this view on some object while some
other thread holds view “write” or “resize” on that object.
Introduction Views Example PL Research Views Technical Details Conclusions
8/3/2019 Views, Programming Language Research, and HPC
http://slidepdf.com/reader/full/views-programming-language-research-and-hpc 16/52
Concrete Example of Views
1 view read {
2 size, capacity, array: readonly;
3
4 incompatible write, resize;
5
6 get(int i) preferred;
7 capacity();
8 }
Provides read-only access to fields “size”, “capacity” and“array”.
A thread cannot hold this view on some object while some
other thread holds view “write” or “resize” on that object.
Methods “get” and “capacity” belong to this view.
Introduction Views Example PL Research Views Technical Details Conclusions
8/3/2019 Views, Programming Language Research, and HPC
http://slidepdf.com/reader/full/views-programming-language-research-and-hpc 17/52
Concrete Example of Views
1 view read {
2 size, capacity, array: readonly;
3
4 incompatible write, resize;
5
6 get(int i) preferred;
7 capacity();
8 }
Provides read-only access to fields “size”, “capacity” and“array”.
A thread cannot hold this view on some object while some
other thread holds view “write” or “resize” on that object.
Methods “get” and “capacity” belong to this view.
Calling method “get” will auto-acquire this view.
Introduction Views Example PL Research Views Technical Details Conclusions
8/3/2019 Views, Programming Language Research, and HPC
http://slidepdf.com/reader/full/views-programming-language-research-and-hpc 18/52
Interface of Vector Example
Our Vector provides the following methods:
get()
set()
capacity(): queries current Vector capacity.
resize(): changes Vector capacity, re-copying items.
Introduction Views Example PL Research Views Technical Details Conclusions
8/3/2019 Views, Programming Language Research, and HPC
http://slidepdf.com/reader/full/views-programming-language-research-and-hpc 19/52
Views for Vector Example
capacity: provides read access to capacity field
All other views provide read access to Vectormetadata (size, capacity) and:read: read access to Vector contents (“get”).
write: write access to Vector contents (“set”).
xclRead: read access to Vector contents; only one threadcan hold xclRead.
resize: write access to Vector contents and metadata.
Introduction Views Example PL Research Views Technical Details Conclusions
8/3/2019 Views, Programming Language Research, and HPC
http://slidepdf.com/reader/full/views-programming-language-research-and-hpc 20/52
Resizing the Vector
1 public void resize(int newcapacity) {
2 Object[] newarray = new Object[newcapacity];
3 for(int i=0; i < newcapacity && i < size; i++) {
4 newarray[i] = array[i];
5 }6
7 acquire (this@resize) {
8 array = newarray; capacity = newcapacity;
9 size = (size<newcapacity) ? size : newcapacity;
10 }11 }
1 Copy existing Vector’s contents, holding xclRead view.2 Switch over the Vector to point to the new copy, holding
resize view.
Introduction Views Example PL Research Views Technical Details Conclusions
8/3/2019 Views, Programming Language Research, and HPC
http://slidepdf.com/reader/full/views-programming-language-research-and-hpc 21/52
Views Ensure Mutual Exclusion
Calling resize() auto-acquires xclRead view.
No other thread may write while xclRead view held(xclRead incompatible with write, xclRead, resize).
During the critical switchover phase, no other thread may
access the Vector: all views incompatible with resize view.
Introduction Views Example PL Research Views Technical Details Conclusions
8/3/2019 Views, Programming Language Research, and HPC
http://slidepdf.com/reader/full/views-programming-language-research-and-hpc 22/52
Workflow for using Views
source
code
w/views
view
declarations
compiler
lock
allocation
Java
source
code
Introduction Views Example PL Research Views Technical Details Conclusions
8/3/2019 Views, Programming Language Research, and HPC
http://slidepdf.com/reader/full/views-programming-language-research-and-hpc 23/52
Results
No speedups.
1 Microbenchmarks: views are fast enough.
2 Case studies: views are useful.
Introduction Views Example PL Research Views Technical Details Conclusions
8/3/2019 Views, Programming Language Research, and HPC
http://slidepdf.com/reader/full/views-programming-language-research-and-hpc 24/52
Microbenchmarks
Investigate performance of views, compared to naı̈ve locks and
hand-coded implementations.
Two benchmarks:
Red-black tree
Concurrent hash map
Hardware: dual-processor quad-core Intel Xeon E5520.
Introduction Views Example PL Research Views Technical Details Conclusions
8/3/2019 Views, Programming Language Research, and HPC
http://slidepdf.com/reader/full/views-programming-language-research-and-hpc 25/52
Red-black tree performance
% Writes
T i m e ( m s )
2000
4000
6000
8000
10000
0 5 10 15 20
Java LocksRead-Write LocksViews
Introduction Views Example PL Research Views Technical Details Conclusions
8/3/2019 Views, Programming Language Research, and HPC
http://slidepdf.com/reader/full/views-programming-language-research-and-hpc 26/52
Concurrent hash map performance (vs. % writes)
% Writes
T i m e ( m s )
1000
2000
3000
4000
5000
6000
0 5 10 15 20
java.util.Hashtable (built-in synchronization)ConcurrentHashMap with manual locksConcurrentHashMap with views java.util.concurrent.ConcurrentHashMap
Introduction Views Example PL Research Views Technical Details Conclusions
8/3/2019 Views, Programming Language Research, and HPC
http://slidepdf.com/reader/full/views-programming-language-research-and-hpc 27/52
Concurrent hash map performance (vs. # cores)
Cores
T i m e ( m s )
1000
2000
3000
4000
5000
1 2 4 8
java.util.Hashtable (built-in synchronization)ConcurrentHashMap with manual locksConcurrentHashMap with views java.util.concurrent.ConcurrentHashMap
Introduction Views Example PL Research Views Technical Details Conclusions
8/3/2019 Views, Programming Language Research, and HPC
http://slidepdf.com/reader/full/views-programming-language-research-and-hpc 28/52
Case study results
Implemented Views as a Polyglot (extensible compiler
framework) extension.
Views compiler available for download at
http://demsky.eecs.uci.edu/software.php .
Acquired and ported 4 multi-threaded Java applications:
Vuze file-sharing client
Mailpuccino mail clientTupleSoup database library
jPhoneLite voIP softphone
Introduction Views Example PL Research Views Technical Details Conclusions
8/3/2019 Views, Programming Language Research, and HPC
http://slidepdf.com/reader/full/views-programming-language-research-and-hpc 29/52
Vuze file-sharing client case study
194,000 lines of code total
We modified the buddy plugin for Vuze, 13,500 lines of code
Changed two classes:
BuddyPlugin, 4 views
BuddyTracker, 9 views
Introduction Views Example PL Research Views Technical Details Conclusions
8/3/2019 Views, Programming Language Research, and HPC
http://slidepdf.com/reader/full/views-programming-language-research-and-hpc 30/52
Vuze: BuddyPlugin class
Added 4 views:
read state: provides read access to 11 fields, incompatible
with write statewrite state: provides write access to 11 field, incompatible
with read state and write state
pd queue, publish write contents: lock-like, provide
read/write access to 1 field, incompatible with self
Note how views protect part of the class’s state and ensure
appropriate locks are held.
Introduction Views Example PL Research Views Technical Details Conclusions
8/3/2019 Views, Programming Language Research, and HPC
http://slidepdf.com/reader/full/views-programming-language-research-and-hpc 31/52
Vuze: BuddyPluginTracker class
Most interesting locking structure in buddy plugin.
Converted 5 locks into 6 views:
“this” lock maps to 2 views, “read internal state” and
“write internal state”
other locks generally map to 1 view
For instance:
view “online buddies” provides read/write access to fields
“online buddies”, “online buddy ips”.
view “read internal state” provides read access to 12 fields,
incompatible with “write internal state” and “buddy peers”.
Introduction Views Example PL Research Views Technical Details Conclusions
8/3/2019 Views, Programming Language Research, and HPC
http://slidepdf.com/reader/full/views-programming-language-research-and-hpc 32/52
Mailpuccino graphical mail client
Contains 14,000 lines of code.
Ported the mail folder cache to use views, allowing multiple
threads to simultaneously read the message cache.
Created 4 views in all: 2 sets of 2 views each.
1 lookup and modify views: protect the “KeyValues” field
(which stores the cache) and its accessor methods.
2
file and indexfile views: protect the cache file and its index.Only one
Only one thread may access a file at a time.
Compiler synthesizes 3 locks: 2 normal plus 1 read/write lock.
Introduction Views Example PL Research Views Technical Details Conclusions
8/3/2019 Views, Programming Language Research, and HPC
http://slidepdf.com/reader/full/views-programming-language-research-and-hpc 33/52
Mailpuccino graphical mail client: bad code
Benchmark also contains a class MonitoredInputStream.
Tried to replace two synchronized methods with views.Compiler warned that a third unsynchronized method
accessed a view protected method.
Discovery: MonitorInputStream was not thread safe and
the synchronized methods were never actually called
Introduction Views Example PL Research Views Technical Details Conclusions
8/3/2019 Views, Programming Language Research, and HPC
http://slidepdf.com/reader/full/views-programming-language-research-and-hpc 34/52
jPhoneLite VoIP softphone
Contains 20,000 lines of code.
Annotated the RTP and RTPChannel classes.
readSamples, writeSamples: protect a circular buffer
containing incoming data.
readSamples writes to the buffer metadata.
readHostPort, writeHostPort: protect destination
information (remoteip, remoteport fields)
Compiler produces 1 read-write lock (host port) and 1 normallock (samples) for RTP, plus 1 normal lock for RTPChannel.
Also kept the original lock on RTP to protect remaining state.
Introduction Views Example PL Research Views Technical Details Conclusions
8/3/2019 Views, Programming Language Research, and HPC
http://slidepdf.com/reader/full/views-programming-language-research-and-hpc 35/52
TupleSoup database library
Contains 6,000 lines of code.
Three index classes: MemoryIndex, PageIndex, FlatIndex.
Original implementation used one lock to protect all indexes.
Created 2 views per index class: access and modifying.
multiple threads may hold an access view;
only one thread may hold modifying view, and no other
thread may access or modify concurrently.
Compiler uses read-write locks to implement these views.
Also converted a cached table (5 locks) to use views.
one lock was unnecessary; views made this obvious.
Introduction Views Example PL Research Views Technical Details Conclusions
8/3/2019 Views, Programming Language Research, and HPC
http://slidepdf.com/reader/full/views-programming-language-research-and-hpc 36/52
Goals of PL Research
Make programs go faster
(“program optimization”).
Make programs less buggy.
Make developers more productive.
Introduction Views Example PL Research Views Technical Details Conclusions
8/3/2019 Views, Programming Language Research, and HPC
http://slidepdf.com/reader/full/views-programming-language-research-and-hpc 37/52
Optimizing Compilers
Two basic ideas:
1 eliminate redundant work or
unnecessary waiting
2 enable automatic or guided parallelization
Introduction Views Example PL Research Views Technical Details Conclusions
8/3/2019 Views, Programming Language Research, and HPC
http://slidepdf.com/reader/full/views-programming-language-research-and-hpc 38/52
How Compilers Optimize
Static analysis: estimate program behaviour
ahead-of-time.Dynamic analysis: observe program
behaviour on actual inputs.
In either case, the compiler rewrites the programto make it faster.
Introduction Views Example PL Research Views Technical Details Conclusions
8/3/2019 Views, Programming Language Research, and HPC
http://slidepdf.com/reader/full/views-programming-language-research-and-hpc 39/52
Static Analysis Examples
Views implement some static analyses, including:
one to ensure that views held at field accesses;
one to ensure that array references don’t escape.
Example of a standard static analysis for optimization:
1 a = x * y + 3 ;
2 b = c - x * y;⇒
1 t = x * y;
2 a = t + 3;
3 b = c - t;
Common subexpression elimination finds that x * y is evaluated
needlessly.
Introduction Views Example PL Research Views Technical Details Conclusions
8/3/2019 Views, Programming Language Research, and HPC
http://slidepdf.com/reader/full/views-programming-language-research-and-hpc 40/52
Static Analysis for Parallelization
Establishing the absence of cycles enables parallelization oftree operations.
Can use a second-order logic formula to summarize the
reachable heap objects.
Introduction Views Example PL Research Views Technical Details Conclusions
8/3/2019 Views, Programming Language Research, and HPC
http://slidepdf.com/reader/full/views-programming-language-research-and-hpc 41/52
Dynamic Analysis Example: Specialization
1 f(3);
2 f(5);
3 f(3);
4 f(3);
5 f(3);
If the run-time system observes that f is always
called with parameter 3, it can create a
specialized, faster version of f.
Introduction Views Example PL Research Views Technical Details Conclusions
8/3/2019 Views, Programming Language Research, and HPC
http://slidepdf.com/reader/full/views-programming-language-research-and-hpc 42/52
Establishing Program Correctness
Goal: verify that the program meets some specifications.
Implicit: programs are never supposed to dereferencenull pointers;
Lightweight: selected domain-specificproperties/invariants, e.g. conservation of energy;
Full: program does exactly what it is supposed to.
Introduction Views Example PL Research Views Technical Details Conclusions
8/3/2019 Views, Programming Language Research, and HPC
http://slidepdf.com/reader/full/views-programming-language-research-and-hpc 43/52
Techniques for Program Verification
Ad-hoc techniques specialized for a
particular abstraction;
Exhaustive search using model checking;
Automatic theorem proving.
Introduction Views Example PL Research Views Technical Details Conclusions
8/3/2019 Views, Programming Language Research, and HPC
http://slidepdf.com/reader/full/views-programming-language-research-and-hpc 44/52
Improving Programmer Productivity: Beyond
Libraries
Language extensions
Domain-specific languages
Program synthesis
Introduction Views Example PL Research Views Technical Details Conclusions
8/3/2019 Views, Programming Language Research, and HPC
http://slidepdf.com/reader/full/views-programming-language-research-and-hpc 45/52
Language Extensions
Views are one example of a language
extension. Some others:
Type systems: e.g. augmenting types with
units (inches, cm);
Tracematches: specify safety properties
using finite-state machines.
Introduction Views Example PL Research Views Technical Details Conclusions
8/3/2019 Views, Programming Language Research, and HPC
http://slidepdf.com/reader/full/views-programming-language-research-and-hpc 46/52
Domain-Specific Languages
MATLABCan also define e.g. DSLs for numerical
kernels.
Introduction Views Example PL Research Views Technical Details Conclusions
8/3/2019 Views, Programming Language Research, and HPC
http://slidepdf.com/reader/full/views-programming-language-research-and-hpc 47/52
Program Synthesis
Idea: specify some description of the program
without all of the implementation details.
One example: program sketching.
Provide the structure of the implementation;
Provide sample inputs and outputs.
Compiler then synthesizes correct code meeting
the requirements.
Introduction Views Example PL Research Views Technical Details Conclusions
8/3/2019 Views, Programming Language Research, and HPC
http://slidepdf.com/reader/full/views-programming-language-research-and-hpc 48/52
Views: Behind the scenes
source
code
w/views
view
declarations
compiler
lock
allocation
Java
source
code
Introduction Views Example PL Research Views Technical Details Conclusions
8/3/2019 Views, Programming Language Research, and HPC
http://slidepdf.com/reader/full/views-programming-language-research-and-hpc 49/52
Compiler Checks
read/write hazards (on view declarations)
assignment checks
method call checks
inheritance checks
Introduction Views Example PL Research Views Technical Details Conclusions
8/3/2019 Views, Programming Language Research, and HPC
http://slidepdf.com/reader/full/views-programming-language-research-and-hpc 50/52
Lock Synthesis
Compile incompatibility graphs into locks
Locks implement edges in graph
Write lock implements conflict edges in a clique in which allvertices have self edges
Read-write lock implements conflict edges in a clique in
which all vertices but one have self edges
Lock synthesis problem is simply minimum clique coveringUse greedy algorithm
Introduction Views Example PL Research Views Technical Details Conclusions
8/3/2019 Views, Programming Language Research, and HPC
http://slidepdf.com/reader/full/views-programming-language-research-and-hpc 51/52
Related Work: Views
Type systems to ensure absence of data races (Boyapati
et al; Abadi et al; Bacon et al)Race detection tools (Eraser; Choi et al; Marino et al;
RacerX; Warlock; Sema)
Automatic generation of locking schemes for critical
regions (Halpert et al; Emmi et al; Hicks et al; Zhang et al)
Introduction Views Example PL Research Views Technical Details Conclusions
8/3/2019 Views, Programming Language Research, and HPC
http://slidepdf.com/reader/full/views-programming-language-research-and-hpc 52/52
Conclusion
Presented the views concurrency control mechanism:
raise the abstraction level of concurrency control
enable static checking that can help catch concurrency
bugs
Experience indicates that views are:
simple to program with;
support sophisticated fine-grained access control; and
can detect concurrency bugs
Also presented some thoughts about programming languages
and HPC.