C/C++/Fortran and “wrapping” with • SWIG • ctypes • Cython • f2py (or fwrap) • hand-coded wrappers • Writing new code in Cython directly • Cython is “modiﬁed Python” with type information everywhere. • It produces a C-extension module which is then compiled Saturday, March 16, 13
with regular storage and access patterns. There is plenty of information to optimize the code if we either: • Provide type information for function inputs (jit) • Create a “call-site” for each function that compiles and caches the result the ﬁrst time it gets called with new types. Saturday, March 16, 13
full scientiﬁc Python stack!) • Minimal modiﬁcations to code (use type inference) • Programmer control over what and when to “jit” • Ability to build static extensions (for libraries) • Fall back to Python C-API for “object” types. Saturday, March 16, 13
(maybe even Fortran) • Support NumPy array-expressions and be able to produce universal functions (e.g. y = sin(x)) • Provide a tool that could adapt to provide parallelism and produce code for modern vector hardware (GPUs, accelerators, and many-core machines) Saturday, March 16, 13
call at run-time) • autojit --- detects input types, infers output, generates code if needed, and dispatches (a little more run-time call overhead) #@jit('void(double[:,:], double, double)') @autojit def numba_update(u, dx2, dy2): nx, ny = u.shape for i in xrange(1,nx-1): for j in xrange(1, ny-1): u[i,j] = ((u[i+1,j] + u[i-1,j]) * dy2 + (u[i,j+1] + u[i,j-1]) * dx2) / (2*(dx2+dy2)) Comment out one of jit or autojit (don’t use together) Saturday, March 16, 13
image.shape m, n = filt.shape for i in range(m//2, M-m//2): for j in range(n//2, N-n//2): result = 0.0 for k in range(m): for l in range(n): result += image[i+k-m//2,j+l-n//2]*filt[k, l] output[i,j] = result ~1500x speed-up Saturday, March 16, 13
element-by-element over entire arrays Write kernels in Python! from numba.vectorize import vectorize from math import sin @vectorize([‘f8(f8)’, ‘f4(f4)’]) def sinc(x): if x==0.0: return 1.0 else: return sin(x*pi)/(pi*x) Saturday, March 16, 13
the ﬁrst libraries I wrote • extended “umath” module by adding new “universal functions” to compute many scientiﬁc functions by wrapping C and Fortran libs. • Bessel functions are solutions to a differential equation: x 2 d 2 y dx 2 + x dy dx + ( x 2 ↵ 2) y = 0 y = J↵ ( x ) Jn (x) = 1 ⇡ Z ⇡ 0 cos (n⌧ x sin (⌧)) d⌧ Saturday, March 16, 13
10000 loops, best of 3: 75 us per loop In [7]: from scipy.special import j0 In [8]: %timeit j0(x) 10000 loops, best of 3: 75.3 us per loop But! Now code is in Python and can be experimented with more easily (and moved to the GPU / accelerator more easily)! Saturday, March 16, 13
--- autojit coming soon!) • Struct support (NumPy arrays can be structs) • SSA --- can refer to local variables as different types • Typed lists and typed dictionaries and sets coming soon! • pointer support • calling ctypes and CFFI functions natively • pycc (create stand-alone dynamic library and executable) • pycc --python (create static extension module for Python) Saturday, March 16, 13
Architectures (GPUs and multi-core machines) • Create parallel-for loops • Parallel execution of ufuncs • Run ufuncs on the GPU • Write CUDA directly in Python! • Free for Academics fast development and fast execution! Currently premium features will be contributed to open- source over time! Saturday, March 16, 13
Kwan Lam 110 Travis E. Oliphant 30 Dag Sverre Seljebotn 28 Hernan Grecco 19 Ilan Schnell 11 Mark Wiebe 8 James Bergstra 4 Alberto Valverde 3 Thomas Kluyver 2 Maggie Mari 2 Dan Yamins 2 Dan Christensen 1 timo 1 Yaroslav Halchenko 1 Phillip Cloud 1 Ondřej Čertík 1 Martin Spacek 1 Lars Buitinck 1 Juan Luis Cano Rodríguez git log --format=format:%an | sort | uniq -c | sort -r Siu Mark Jon Saturday, March 16, 13
bugs -- needs users! • Version 0.7 end of Feb. • Version 0.8 in April • Version 0.9 June • Version 1.0 by end of August • Stable API (jit, autojit) easy to use • Should be able to write equivalent of NumPy and SciPy with Numba and memory-views. http://numba.pydata.org http://llvmpy.org http://compilers.pydata.org We need you: • your use-cases • your tests • developer help Saturday, March 16, 13
l (4 lines are blank or instructions) l Github https://github.com/numba/numba l Mailing list --- numba-users@continuum.io l Sprints --- contact Jon Riehl l Examples: l Hernan Grecco just contributed Python 3 support (Yeah!) l Dag collaborating on autojit classes with Mark F. l We need you to show off your amazing demo! Saturday, March 16, 13