Giter Site home page Giter Site logo

petalisp's Introduction

Petalisp

Petalisp is an attempt to generate high performance code for parallel computers by JIT-compiling array definitions. It is not a full blown programming language, but rather a carefully crafted extension of Common Lisp that allows for extreme optimization and parallelization.

Getting Started

  1. Install Lisp and a suitable IDE. If unsure, pick Portacle.
  2. Download Petalisp via Quicklisp.
  3. Check out some of the examples.

Showcases

Petalisp is still under development, so the following examples may still change slightly. Nevertheless they give a good glimpse on what programming with Petalisp will be like.

Example 1: transposing a matrix

(defun transpose (A)
  (reshape A (τ (m n) (n m))))

Example 2: matrix-matrix multiplication

(defun matrix-multiplication (A B)
  (β #'+#'*
        (reshape A (τ (m n) (n m 1)))
        (reshape B (τ (n k) (n 1 k))))))

Example 3: the numerical Jacobi scheme in two dimensions

(defun jacobi-2d (grid iterations)
  (let ((interior (interior grid)))
    (if (zerop iterations) grid
        (jacobi-2d
         (fuse x
               (α #'* 0.25#'+
                     (reshape x (τ (i0 i1) ((+ i0 1) i1)) interior)
                     (reshape x (τ (i0 i1) ((- i0 1) i1)) interior)
                     (reshape x (τ (i0 i1) (i0 (+ i1 1))) interior)
                     (reshape x (τ (i0 i1) (i0 (- i1 1))) interior))))
         (- iterations 1)))))

Performance

Coming soon!

Frequently Asked Questions

Is Petalisp similar to NumPy?

NumPy is a widely used Python library for scientific computing on arrays. It provides powerful N-dimensional arrays and a variety of functions for working with these arrays.

Petalisp works on a more fundamental level. It provides even more powerful N-dimensional arrays, but just a few building blocks for working on them - element-wise function application, reduction, reshaping and array fusion.

So Petalisp is not a substitute for NumPy. However, it could be used to write a library that behaves like NumPy, but that is much faster and fully parallelized. In fact, writing such a library is one of my future goals.

Do I have to program Lisp to use Petalisp?

Not necessarily. Not everyone has the time to learn Common Lisp. That is why I am also working on some convenient Python bindings for Petalisp.

But: If you ever have time to learn Lisp, do it! It is an enlightening experience.

Why the Greek letters?

There are several reasons:

  1. It underlines the beautiful, mathematical nature of this programming model.
  2. The α and β functions are a tribute to Connection Machine Lisp.
  3. Compared to programming a computer with billions of transistors and terabytes of memory, typing Greek letters is easy. Right?

Note: Following community feedback, it is now also possible to write a instead of α and b instead of β. But as a convention, please use the ASCII aliases only as a shortcut for scripting. If I ever see a and b being called in a Quicklisp project, I will remove them from the API :)

Why is Petalisp licensed under AGPL?

I am aware that this license prevents some people from using or contributing to this piece of software, which is a shame. But unfortunately the majority of software developers have not yet understood that

  1. In a digital world, free software is a necessary prerequisite for a free society.
  2. When developing software, open collaboration is way more efficient than competition.

So as long as distribution of non-free software is socially accepted, copyleft licenses like the AGPL seem to be the lesser evil.

That being said, I am willing to discuss relicensing on an individual basis.

Why is Petalisp written in Common Lisp?

I couldn’t wish for a better tool for the job. Common Lisp is extremely rich in features, standardized, fast, safe and mature. The Lisp community is amazing and there are excellent libraries for almost every imaginable task.

To illustrate why Lisp is particularly well suited for a project like Petalisp, consider the following implementation of a JIT-compiler for mapping a function over a vector of a certain element type:

(defun vector-mapper (element-type)
  (compile nil `(lambda (fn vec)
                  (declare (function fn)
                           (type (simple-array ,element-type (*)) vec)
                           (optimize (speed 3) (safety 0)))
                  (loop for index below (length vec) do
                    (symbol-macrolet ((elt (aref vec index)))
                      (setf elt (funcall fn elt)))))))

Not only is this JIT-compiler just 8 lines of code, it is also 20 times faster than invoking GCC or Clang on a roughly equivalent piece of C code.

petalisp's People

Contributors

marcoheisig avatar

Watchers

James Cloos 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.