Giter Site home page Giter Site logo

parakeet's Introduction

Parakeet

Parakeet is a runtime accelerator for an array-oriented subset of Python. If you're doing a lot of number crunching in Python, Parakeet may be able to significantly speed up your code.

To accelerate a function, wrap it with Parakeet's @jit decorator:

import numpy as np 
from parakeet import jit 

alpha = 0.5
beta = 0.3
x = np.array([1,2,3])
y = np.tanh(x * alpha) + beta
   
@jit
def fast(x, alpha = 0.5, beta = 0.3):
  return np.tanh(x * alpha) + beta 
   
@jit 
def loopy(x, alpha = 0.5, beta = 0.3):
  y = np.empty_like(x, dtype = float)
  for i in xrange(len(x)):
    y[i] = np.tanh(x[i] * alpha) + beta
  return y
     
@jit
def comprehension(x, alpha = 0.5, beta = 0.3):
  return np.array([np.tanh(xi*alpha) + beta for xi in x])
  
assert np.allclose(fast(x), y)
assert np.allclose(loopy(x), y)
assert np.allclose(comprehension(x), y)

Install

You should be able to install Parakeet from its PyPI package by running:

pip install parakeet

Dependencies

Parakeet is written for Python 2.7 (sorry internet) and depends on:

The default backend (which uses OpenMP) requires gcc 4.4+.

Windows: If you have a 32-bit Windows install, your compiler should come from Cygwin or MinGW. Getting Parakeet working on 64-bit Windows is non-trivial and seems to require colossal hacks.

Mac OS X: By default, your machine probably either has only clang or an outdated version of gcc. You can get a more recent version using HomeBrew

If you want to use the CUDA backend, you need to have an NVIDIA graphics card and install both the CUDA Toolkit and PyCUDA.

How does it work?

Your untyped function gets used as a template from which multiple type specializations are 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 information

Supported language features

Parakeet 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 lambdas
  • Tuples
  • Slices
  • NumPy array expressions (i.e. x[1:, :] + 2 * y[:-1, ::2])
  • Some NumPy library functions like np.ones and np.sin (look at the mappings module for a full list)
  • List literals (interpreted as array construction)
  • List comprehensions (interpreted as array comprehensions)
  • Parakeet's higher order array operations like parakeet.imap, parakeet.scan, and parakeet.allpairs

Backends

Parakeet currently supports compilation to sequential C, multi-core C with OpenMP (default), or LLVM (deprecated). To switch between these options change parakeet.config.backend to 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

parakeet's People

Contributors

iskandr avatar hielscher avatar kylestev avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.