Package: parakeet
ParakeetThis project is no longer being maintained.Parakeet was a runtime accelerator for an array-oriented subset of
Python. In retrospect, I don’t think that whole-function type
specialization at the AST level is a scalable approach to speeding up a
sufficiently large subset of Python. General-purpose Python code should
probably be accelerated using a bytecode JIT, whereas high-performance
numerical code should use a DSL with explicit parallel operators.ExampleTo accelerate a function, wrap it with Parakeet’s@jitdecorator:importnumpyasnpfromparakeetimportjitalpha=0.5beta=0.3x=np.array([1,2,3])y=np.tanh(x*alpha)+beta@jitdeffast(x,alpha=0.5,beta=0.3):returnnp.tanh(x*alpha)+beta@jitdefloopy(x,alpha=0.5,beta=0.3):y=np.empty_like(x,dtype=float)foriinxrange(len(x)):y[i]=np.tanh(x[i]*alpha)+betareturny@jitdefcomprehension(x,alpha=0.5,beta=0.3):returnnp.array([np.tanh(xi*alpha)+betaforxiinx])assertnp.allclose(fast(x),y)assertnp.allclose(loopy(x),y)assertnp.allclose(comprehension(x),y)InstallYou should be able to install Parakeet from itsPyPI
packageby running:pip install parakeetDependenciesParakeet is written for Python 2.7 (sorry internet) and depends on:dsltoolsnosefor unit testsNumPyappdirsThe default backend (which uses OpenMP) requiresgcc4.4+.Windows: If you have a 32-bit Windows install, your compiler should
come fromCygwinorMinGW. Getting Parakeet working on 64-bit
Windows is non-trivial and seems to requirecolossal
hacks.Mac OS X: By default, your machine probably either has onlyclangor an outdated version ofgcc.
You can get a more recent version usingHomeBrewIf you want to use the CUDA backend, you need to have an NVIDIA graphics
card and install both theCUDA
ToolkitandPyCUDA.How does it work?Your untyped function gets used as a template from which multipletype
specializationsare generated (for each distinct set of input types).
These typed functions are then churned through many optimizations before
finally getting translated into native code.More informationAsk questions on thediscussion
groupWatch theParakeet presentationfrom
this year’sPyData Boston, look at
theHotPar
slidesfrom last yearContact themain developerdirectlySupported language featuresParakeet cannot accelerate arbitrary Python code, it only supports a
limited subset of the language:Scalar operations (i.e.x + 3 * y)Control flow (if-statements, loops, etc…)Nested functions and lambdasTuplesSlicesNumPy array expressions (i.e.x[1:, :] + 2 *y[:-1,::2])Some NumPy library functions likenp.onesandnp.sin(look at
themappingsmodule for a full list)List literals (interpreted as array construction)List comprehensions (interpreted as array comprehensions)Parakeet’s higher order array operations likeparakeet.imap,parakeet.scan, andparakeet.allpairsBackendsParakeet currently supports compilation to sequential C, multi-core C
with OpenMP (default), or LLVM (deprecated). To switch between these
options changeparakeet.config.backendto one of:“openmp”: compiles with gcc, parallel operators run across multiple
cores (default)“c”: lowers all parallel operators to loops, compile sequential
code with gcc“cuda”: launch parallel operations on the GPU (experimental)“llvm”: older backend, has fallen behind and some programs may not
work“interp”: pure Python intepreter used for debugging optimizations,
only try this if you think CPython is about 10,000x too fast for your
taste