LMS

Program Generation and
Embedded Compilers in Scala.

Get started now

Lightweight Modular Staging (LMS) is a runtime code generation approach. The framework provides a library of core components for building high performance code generators and embedded compilers in Scala.

LMS is used by several other projects, including:

News Flash

News:

We’re holding tutorials at major conferences:

Slides and additional materials are available from the links above.

Abstraction Without Regret

Turn nice high-level programs into fast low-level code. Strip abstraction overhead from generic programs. Add domain-specific optimizations.

class Vector[T:Numeric:Manifest](val data: Rep[Array[T]]) {
  def foreach(f: Rep[T] => Rep[Unit]): Rep[Unit] =
    for (i <- 0 until data.length) f(data(i))
  def sumIf(f: Rep[T] => Rep[Boolean]) = { 
    var n = zero[T]; foreach(x => if (f(x)) n += x); n }
}

val v: Vector[Double] = ...
println(v.sumIf(_ > 0))
var n: Double = 0.0
var i: Int = 0
val end = data.length
while (i < end) {
  val x = data(i)
  val c = x > 0
  if (c) n += x
}
println(n)

Running the snippet above will generate the program on the left: All functions are inlined, all generics specialized, all type class instances removed. All of this is guaranteed by the type system: Expressions of type Rep[T] become part of the generated program, everything else is evaluated when the original snippet is run.

Actually this is only half of the story: The output on the left is not produced directly, but going through an extensible intermediate representation (IR) that can be further transformed and optimized. Read more…

Run Scala Anywhere

Generate code for heterogenenous targets. Compile Scala to JavaScript, SQL, CUDA, C…

Getting Started

Clone the GitHub repo. It contains an extensive test suite with examples.

git clone git://github.com/TiarkRompf/virtualization-lms-core.git

Be sure to check out the docs!

Community

LMS is developed and used by researchers and practitioners from EPFL, Stanford, ETH, Purdue, University of Rennes, Oracle Labs, Huawei Labs, and other institutions.