Julia: compiler and community

24
compiler and community Jiahao Chen MIT Computer Science and Artificial Intelligence Laboratory julialang.org Alan Edelman Jeff Bezanson Stefan Karpinski Viral B. Shah

description

A very short tour through the Julia community and how key features of the language interact to produce an expressive syntax that users like without sacrificing performance

Transcript of Julia: compiler and community

Page 1: Julia: compiler and community

compiler and communityJiahao Chen

MIT Computer Science and Artificial Intelligence Laboratory julialang.org

Alan EdelmanJeff Bezanson Stefan Karpinski Viral B. Shah

Page 2: Julia: compiler and community

433 code contributors as of 2014-06-30

The faces of Julia

Page 3: Julia: compiler and community

as of 2014-06-30

The world of181 package-only developers

252 contributors to julia repo3,906 stargazers321 watchers

Page 4: Julia: compiler and community

What’s the big deal about Julia ?

julialang.org/benchmarks

Page 5: Julia: compiler and community

What’s the big deal about Julia ?

Julia isn’t designed for performance using all means necessary.

“FFTW (FFTs) and BLAS libraries (matrix multiplication) take ~100,000 lines [of code] to solve problems that can be implemented in ~15 lines of (slow) code… It usually

isn’t worth it to get the last factor of two in speed” !

- Steven Johnson, author of FFTW (emphases his)

Page 6: Julia: compiler and community

What’s the big deal about Julia ?

Julia isn’t designed for performance using all means necessary. Instead, performance comes from designing a language that is easy for both humans and compilers to understand. !Multimethods (multiple dispatch) is one of the key mechanisms.

Page 7: Julia: compiler and community

Object-oriented programming with classes

What can I do with/to a thing?

Page 8: Julia: compiler and community

Object-oriented programming with classes

What can I do with/to a thing?

Page 9: Julia: compiler and community

Object-oriented programming with classes

What can I do with/to a thing?

top uppay fare

lose

buy

Page 10: Julia: compiler and community

Object-oriented programming with classes

What can I do with/to a thing?

top uppay fare

lose

buy

top uppay fare

lose

buy

Page 11: Julia: compiler and community

Object-oriented programming with classes

What can I do with/to a thing?

top uppay fare

lose

buy

top uppay fare

lose

buy

Page 12: Julia: compiler and community

Object-oriented programming with classes

What can I do with/to a thing?

top uppay fare

lose

buy

top uppay fare

lose

buy

pay farelose

buy

Page 13: Julia: compiler and community

methods objects

Object-oriented programming with classes

What can I do with/to a thing?

top uppay fare

lose

buy

top uppay fare

lose

buy

pay farelose

buy

Page 14: Julia: compiler and community

methods objects

Object-oriented programming with classes

What can I do with/to a thing?

top uppay fare

lose

buy

top uppay fare

lose

buy

pay farelose

buy

class-based OO !classes are more fundamental than methods

Page 15: Julia: compiler and community

generic function

objectsmethods

rechargeable subway pass

single-use subway ticket

is a subtype of

subway ticket

top up

pay fare

lose

buy

abstract object

Multi-methods with type hierarchy

Page 16: Julia: compiler and community

generic function

objectsmethods

rechargeable subway pass

single-use subway ticket

is a subtype of

subway ticket

top up

pay farelose

buy

abstract object

Multi-methods with type hierarchy

Page 17: Julia: compiler and community

Multi-methods for linear algebra

What can I do with/to a thing?

find eigenvalues and eigenvectors

find singular values

find singular values and vectors

find eigenvalues

generic function

objectsmethods

general matrix

symmetric tridiagonal matrix

bidiagonal matrix

Methods can take advantage of special matrix structures

eigvals

eigfact

svdvals

svdfact

Matrix

SymTridiagonal

Bidiagonal

Page 18: Julia: compiler and community

So how does this help us with linear algebra?

Multi-method dispatch on special matrix types

Page 19: Julia: compiler and community

So how does this help us with linear algebra?

Multi-method dispatch on special matrix types

Page 20: Julia: compiler and community

So how does this help us with linear algebra?

Multi-method dispatch on special matrix types

stev!{T<:BlasFloat} calls sgestvdgestvcgestvzgestv

and handles workspace memory allocation

Page 21: Julia: compiler and community

What’s the big deal about Julia ?

Julia isn’t designed for performance using all means necessary. Instead, performance comes from designing a language that is easy for both humans and compilers to understand. !!

Page 22: Julia: compiler and community

from the programmer’s point of view: !- dynamic language semantics: faster to prototype code - dynamic types: compiler does not hinder experimentation - multiple dispatch allows both methods for general

functionality and methods for specialized performance - low-cost software abstractions allow code to retain

structure of mathematical abstractions - metaprogramming (with macros) allows code generation:

takes software experimentation to the next level with less lines of actual code

- flexible syntax, Unicode operators, great community…

Page 23: Julia: compiler and community

Pure-­‐Julia  FFT  performance

2 4 8 16 32 64 128

256

512

1024

2048

4096

8192

16384

32768

65536

131072

262144

0

1000

2000

3000

4000

5000

6000

7000

8000

9000

10000

11000

12000

13000

14000

spee

d (m

flops

)

intel-mkl-dfti in-placeintel-mkl-dfti out-of-placefftw3 out-of-placefftw3 in-placefftw3-no-simd out-of-placefftw3-no-simd in-placedfftpackemayerjuliabloodworthcrosscwplibesrfft

double-precision complex, 1d transformspowers of two

already  comparable  to  FFTPACK  ![  actually  was  even  a  bit  better;        some  recent  inlining        regressions  in  Julia  snapshots  ]

Steven Johnson, 2014-06 Presented at NAIS Codegen workshop

Page 24: Julia: compiler and community

from the compiler’s point of view: !- dynamic semantics with static analysis: when possible,

offload runtime checks to JIT compile stage - multiple dispatch requires function signatures that expose

type information - rich type system allows for detailed type inference - inlining passes reduce abstraction cost - automatic code specialization generates many performant

methods - macros allow further fine-grained tradeoffs between

performance and correctness, e.g. @inbounds, @simd,…