Monadic C nadic Compos mpositio ition for or De Deter ermini - - PowerPoint PPT Presentation

monadic c nadic compos mpositio ition
SMART_READER_LITE
LIVE PREVIEW

Monadic C nadic Compos mpositio ition for or De Deter ermini - - PowerPoint PPT Presentation

Monadic C nadic Compos mpositio ition for or De Deter ermini inistic, P c, Par aral allel el Bat Batch ch Pr Proc oces essing ng Ryan Scott 1 Omar Navarro Leija 2 Ryan Newton 1 Joe Devietti 2 1 Indiana University 2 University of


slide-1
SLIDE 1

Monadic C nadic Compos mpositio ition

for

  • r De

Deter ermini inistic, P c, Par aral allel el Bat Batch ch Pr Proc

  • ces

essing ng

rgscott@indiana.edu github.com/RyanGlScott

Ryan Scott1 Omar Navarro Leija2 Ryan Newton1 Joe Devietti2

1Indiana University 2University of Pennsylvania

slide-2
SLIDE 2

Non Nondet deter ermini inism

Ideal Program Ideal Program

Arguments Input fjles Output fjles

slide-3
SLIDE 3

Non Nondet deter ermini inism

Nondeterministic Program Nondeterministic Program

Arguments Input fjles Output fjles v1 Output fjles v2 ...

slide-4
SLIDE 4

Non Nondet deter ermini inism

Nondeterministic Program Nondeterministic Program

Arguments Input fjles Output fjles v1 Output fjles v2 ... Thread scheduling

slide-5
SLIDE 5

Non Nondet deter ermini inism

Nondeterministic Program Nondeterministic Program

Arguments Input fjles Output fjles v1 Output fjles v2 ... Thread scheduling Environment leaks

slide-6
SLIDE 6

Non Nondet deter ermini inism

Nondeterministic Program Nondeterministic Program

Arguments Input fjles Output fjles v1 Output fjles v2 ... Thread scheduling Environment leaks

  • Nondet. system calls/CPU instructions
slide-7
SLIDE 7

Wh Where nondet nondetermi minism nism hur hurts

slide-8
SLIDE 8

Wh Where nondet nondetermi minism nism hur hurts

Continuous integration

slide-9
SLIDE 9

Wh Where nondet nondetermi minism nism hur hurts

all: a b c a b c: @for n in 1 2 ; do \ echo $@-$$n && sleep 1 ; \ done

Parallel workfmows

slide-10
SLIDE 10

Serial execution

$ make a-1 a-2 b-1 b-2 c-1 c-2

Parallel execution

slide-11
SLIDE 11

Serial execution

$ make a-1 a-2 b-1 b-2 c-1 c-2 $ make -j2 a-1 a-2 b-1 b-2 c-1 c-2

Parallel execution

slide-12
SLIDE 12

Serial execution

$ make a-1 a-2 b-1 b-2 c-1 c-2 $ make -j2 a-1 b-1 b-2 a-2 c-1 c-2

Parallel execution

slide-13
SLIDE 13

Serial execution

$ make a-1 a-2 b-1 b-2 c-1 c-2 $ make -j2 a-1 b-1 a-2 b-2 c-1 c-2

Parallel execution

slide-14
SLIDE 14

detflow detflow

Static determinism enforcement Dynamic runtime sandboxing Low

  • verall
  • verhead
slide-15
SLIDE 15

detflow detflow

Static determinism enforcement Dynamic runtime sandboxing Low

  • verall
  • verhead
slide-16
SLIDE 16

Entrypoi Entrypoints ts

main :: IO ()

slide-17
SLIDE 17

Entrypoi Entrypoints ts

main :: IO () main = do Parallel.mapM_ putStrLn [1..10]

slide-18
SLIDE 18

Entrypoi Entrypoints ts

main :: IO () main = do Parallel.mapM_ putStrLn [1..10]

  • - Already nondeterministic!
slide-19
SLIDE 19

DetIO DetIO

newtype DetIO a = MkDetIO (IO a)

slide-20
SLIDE 20

DetIO DetIO

newtype DetIO a = MkDetIO (IO a)

  • - Expose only deterministic API calls

getLine :: DetIO String putStrLn :: String -> DetIO ()

  • - etc.
slide-21
SLIDE 21

DetIO DetIO

newtype DetIO a = MkDetIO (IO a)

  • - Expose only deterministic API calls

getLine :: DetIO String putStrLn :: String -> DetIO ()

  • - etc.

Key idea: Only expose deterministic operations that can be composed in a deterministic fashion

slide-22
SLIDE 22

DetIO DetIO

newtype DetIO a = MkDetIO (IO a)

  • - Expose only deterministic API calls

getLine :: DetIO String putStrLn :: String -> DetIO ()

  • - etc.

main :: DetIO () main = do x <- getLine putStrLn x

slide-23
SLIDE 23

Par arall lleli lism

  • detflow uses the fjlesystem for shared-memory

parallelism

  • Should this be allowed?

readFile :: FilePath -> DetIO String writeFile :: FilePath -> String

  • > DetIO String
slide-24
SLIDE 24

Par arall lleli lism Thread 1

do writeFile “foo.txt” “Hello, World” do foo <- readFile “foo.txt” if foo == “Hello, World” then ... else ...

Thread 2

slide-25
SLIDE 25

Par arall lleli lism Thread 1

do writeFile “foo.txt” “Hello, World” do foo <- readFile “foo.txt” if foo == “Hello, World” then ... else ...

Thread 2

slide-26
SLIDE 26

Solu Solution: per tion: permis issions

  • ns
  • Every thread holds separate permissions on

system fjlepaths

slide-27
SLIDE 27

Solu Solution: per tion: permis issions

  • ns
  • Every thread holds separate permissions on

system fjlepaths

/abcdef/ghijkl/mnopqr

Thread 1 Thread 2 R 0.5 R 0.5 R 0.5 R 0.5 RW 1.0

slide-28
SLIDE 28

Par arall lleli lism, r , revi visited

data Perm -- (R/RW) + path + fraction forkWPerms :: [PathPerm] -> DetIO a

  • > DetIO (Thread a)

joinThread :: Thread a -> DetIO ()

  • readFile and writeFile must respect the

permissions in a thread’s local state

slide-29
SLIDE 29

Perm rmissions chec ions checkout ut

pgm :: DetIO () pgm :: do -- Assume parent starts with R 1.0 on /a th1 <- forkWPerms [R “/a”] computation1 th2 <- forkWPerms [R “/b”] computation2 joinThread t1 joinThread t2

slide-30
SLIDE 30

Perm rmissions chec ions checkout ut

pgm :: DetIO () pgm :: do -- Assume parent starts with R 1.0 on /a th1 <- forkWPerms [R “/a”] computation1

  • - Parent has R 0.5 on /a

th2 <- forkWPerms [R “/a”] computation2 joinThread t1 joinThread t2

slide-31
SLIDE 31

Perm rmissions chec ions checkout ut

pgm :: DetIO () pgm :: do -- Assume parent starts with R 1.0 on /a th1 <- forkWPerms [R “/a”] computation1

  • - Parent has R 0.5 on /a

th2 <- forkWPerms [R “/a”] computation2

  • - Parent has R 0.25 on /a

joinThread t1 joinThread t2

slide-32
SLIDE 32

Perm rmissions chec ions checkout ut

pgm :: DetIO () pgm :: do -- Assume parent starts with R 1.0 on /a th1 <- forkWPerms [R “/a”] computation1

  • - Parent has R 0.5 on /a

th2 <- forkWPerms [R “/a”] computation2

  • - Parent has R 0.25 on /a

joinThread t1

  • - Parent has R 0.75 on /a

joinThread t2

slide-33
SLIDE 33

Perm rmissions chec ions checkout ut

pgm :: DetIO () pgm :: do -- Assume parent starts with R 1.0 on /a th1 <- forkWPerms [R “/a”] computation1

  • - Parent has R 0.5 on /a

th2 <- forkWPerms [R “/a”] computation2

  • - Parent has R 0.25 on /a

joinThread t1

  • - Parent has R 0.75 on /a

joinThread t2

  • - Parent has R 1.0 on /a
slide-34
SLIDE 34

Mor

  • re

e detflow detflow

  • Replace nondeterministic IO operations with

deterministic alternatives

  • Reading system time
  • putStrLn
  • Full lattice of permissions, and formalization of

permission checkout (see paper)

slide-35
SLIDE 35

detflow detflow

Low

  • verall
  • verhead

Dynamic runtime sandboxing Static determinism enforcement

slide-36
SLIDE 36

system system cal calls ls

system :: String -> DetIO () main :: DetIO () main = system “gcc foo.c -o foo”

slide-37
SLIDE 37

system system cal calls ls

system :: String -> DetIO () main :: DetIO () main = system “gcc foo.c -o foo”

  • How can we make shelling out to arbitrary programs (not written

in DetIO) deterministic?

slide-38
SLIDE 38

system system cal calls ls

system :: String -> DetIO () main :: DetIO () main = system “gcc foo.c -o foo”

  • How can we make shelling out to arbitrary programs (not written

in DetIO) deterministic?

  • Answer: run them in a deterministic runtime.
slide-39
SLIDE 39

libdet libdet

slide-40
SLIDE 40

libdet libdet

libdet must intercept potential sources of nondeterminism at runtime.

slide-41
SLIDE 41

libdet libdet

libdet must intercept potential sources of nondeterminism at runtime.

Reading from “banned” directories

  • /dev/urandom
  • /proc
slide-42
SLIDE 42

libdet libdet

Reading from “banned” directories

  • /dev/urandom
  • /proc

Solution

  • Intercept calls to fopen() (with

LD_PRELOAD), error if they read anything blacklisted

libdet must intercept potential sources of nondeterminism at runtime.

slide-43
SLIDE 43

libdet libdet

Uncontrolled concurrency

  • e.g., with pthreads

libdet must intercept potential sources of nondeterminism at runtime.

slide-44
SLIDE 44

libdet libdet

Uncontrolled concurrency

  • e.g., with pthreads

libdet must intercept potential sources of nondeterminism at runtime.

Solution

  • Intercept calls to

pthread_create() (with LD_PRELOAD) to run everything sequentially

slide-45
SLIDE 45

libdet libdet

Nondeterministic OS properties

  • e.g., reading addresses

returned by mmap()

libdet must intercept potential sources of nondeterminism at runtime.

slide-46
SLIDE 46

libdet libdet

Nondeterministic OS properties

  • e.g., reading addresses

returned by mmap()

libdet must intercept potential sources of nondeterminism at runtime.

Solution

  • Disable address-space layout

randomization (ASLR)

slide-47
SLIDE 47

detflow detflow

Static determinism enforcement Dynamic runtime sandboxing Low

  • verall
  • verhead
slide-48
SLIDE 48

Case Case studies es

  • Ran a deterministic version of make against SPLASH2

benchmarks

  • Performance is essentially identical to that of GNU make
  • Ported various bioinformatics scripts to defmow and measured

parallel speedup

  • Overall performance overhead for determinism enforcement is

less than 1%

slide-49
SLIDE 49

1 2 3 4 5 6 2 4 6 8 10 12 14 16 Median time in seconds Threads raytrace DetIO-Det GNU make DetIO-NonDet 0.6 0.8 1 1.2 1.4 1.6 1.8 2 2.2 2.4 2 4 6 8 10 12 14 16 Median time in seconds Threads barnes DetIO-Det GNU make DetIO-NonDet

Sel Select ected SPL ed SPLASH ASH2 benchma benchmark rks

(Lower is better)

slide-50
SLIDE 50

Bioi Bioinf nfor

  • rmat

atics apps cs apps, par parall llel el spee peedup

(Higher is better)

2 4 6 8 10 12 14 16 2 4 6 8 10 12 14 16 Parallel speedup over sequential NonDet Threads bwa-Det bwa-NonDet clustal-Det clustal-NonDet mothur-Det mothur-NonDet raxml-Det raxml-NonDet

2 4 6 8 10 12 14 16 2 4 6 8 10 12 14 16 Parallel speedup over sequential NonDet Threads bwa-Det bwa-NonDet clustal-Det clustal-NonDet mothur-Det mothur-NonDet raxml-Det raxml-NonDet

slide-51
SLIDE 51

Futur ture e wor

  • rk
  • Reach closer to catching all sources of

nondeterminism in runtime

  • Dynamic (at-runtime) checkout of permissions
  • Make more programs feasible to determinize
slide-52
SLIDE 52

An Any ques y questio tions? s?

detflow development: https://github.com/iu-parfunc/detmonad https://github.com/iu-parfunc/detmonad

slide-53
SLIDE 53

“Hello, World!” Hello, World!” thr hroughp

  • ughput

(Higher is better)

10000 100000 1x106 1x107 2 4 6 8 10 12 14 16 Print line, throughput per second Threads DetIO-Det DetIO-NonDet Native

10000 100000 1x106 1x107 2 4 6 8 10 12 14 16 Print line, throughput per second Threads DetIO-Det DetIO-NonDet Native