• Stars
    star
    402
  • Rank 107,380 (Top 3 %)
  • Language
    Common Lisp
  • License
    GNU Affero Genera...
  • Created over 8 years ago
  • Updated about 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Elegant High Performance Computing

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 lazy-transpose (A)
  (lazy-reshape A (transform m n to n m)))

Example 2: matrix-matrix multiplication

(defun matrix-multiplication (A B)
  (lazy-reduce #'+
   (lazy #'*
    (lazy-reshape A (transform m n to n m 1))
    (lazy-reshape B (transform n k to n 1 k)))))

Example 3: the numerical Jacobi scheme in two dimensions

(defun lazy-jacobi-2d (grid iterations)
  (let ((interior (interior grid)))
    (if (zerop iterations) grid
        (lazy-jacobi-2d
         (lazy-fuse
          x
          (lazy #'* 0.25
           (lazy #'+
            (lazy-reshape x (transform i0 i1 to (+ i0 1) i1) interior)
            (lazy-reshape x (transform i0 i1 to (- i0 1) i1) interior)
            (lazy-reshape x (transform i0 i1 to i0 (+ i1 1)) interior)
            (lazy-reshape x (transform i0 i1 to 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.

How can I get Emacs to indent Petalisp code nicely?

Put the following code in your initialization file:

(put 'lazy 'common-lisp-indent-function '(1 &rest 1))
(put 'lazy-reduce 'common-lisp-indent-function '(1 &rest 1))
(put 'lazy-multireduce 'common-lisp-indent-function '(1 1 &rest 1))
(put 'lazy-multiple-value 'common-lisp-indent-function '(1 1 &rest 1))
(put 'lazy-reshape 'common-lisp-indent-function '(1 &rest 1))

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.

More Repositories

1

fast-generic-functions

Seal your generic functions for an extra boost in performance.
Common Lisp
91
star
2

cl4py

Common Lisp for Python
Python
83
star
3

sb-simd

A convenient SIMD interface for SBCL.
Common Lisp
77
star
4

cl-mpi

MPI bindings for Common Lisp with many useful extras
Common Lisp
63
star
5

the-cost-of-nothing

Determine the cost of things in Common Lisp.
Common Lisp
60
star
6

Loopus

A portable loop optimization framework for Common Lisp
Common Lisp
40
star
7

common-lisp-tweaks

A collection of various tweaks for working with Common Lisp.
35
star
8

sealable-metaobjects

A CLOSsy way to trade genericity for performance.
Common Lisp
33
star
9

Typo

A portable type inference library for Common Lisp
Common Lisp
31
star
10

bitfield

Efficiently represent several finite sets or small integers as a single non-negative integer.
Common Lisp
22
star
11

numpy-file-format

Read and write Numpy .npy and .npz files.
Common Lisp
13
star
12

petalisp-for-python

Petalisp for Python - a replacement for Numpy.
Python
11
star
13

restricted-functions

Reasoning about functions with restricted argument types.
Common Lisp
10
star
14

julia-functions

A prototype implementation for having Julia-like functions in Common Lisp.
Common Lisp
9
star
15

ucons

Unique conses.
Common Lisp
8
star
16

Cleavir-Development

Developer utilities for the Cleavir Common Lisp compiler framework
Common Lisp
8
star
17

simplified-types

Simplification of Common Lisp type specifiers.
Common Lisp
7
star
18

adventofcode

Common Lisp solutions for https://adventofcode.com/
Common Lisp
6
star
19

Petalisp.linear-algebra

A Numpy replacement, written in Petalisp.
Common Lisp
5
star
20

cl-isl

A Common Lisp Interface for the Integer Set Library (ISL)
Common Lisp
5
star
21

simplify-mesh

Very scalable tool to coarsen gigantic meshes that may be distributed across several computers.
C++
5
star
22

Petalisp.starpu-backend

A StarPU Backend for Petalisp
Common Lisp
3
star
23

jacob-berwalt

A simple tool to convert MediaWiki articles and books to beautiful TeX.
Ruby
3
star
24

.emacs.d

Marco Heisig's Emacs configuration
Emacs Lisp
2
star
25

cl-starpu

A Common Lisp Interface for StarPU
Common Lisp
2
star
26

mscheme

A Scheme interpreter in Matlab
MATLAB
2
star
27

maxima

A fork of Maxima with better CL integration, with the goal of upstreaming it eventually.
Common Lisp
2
star
28

monitoring

A proposal for a metering library for Common Lisp
TeX
1
star
29

Leibniz

A Computer Algebra System for Common Lisp
Common Lisp
1
star
30

numerical-cxx-abstraction-benchmark

A benchmark measuring the cost of different C++ abstractions on various compilers. The focus lies on numerical codes.
C++
1
star