Devito: Symbolic Finite Difference Computation

Devito is a prototype Domain-specific Language (DSL) and code generation framework for the design of highly optimised finite difference kernels for use in inversion methods. Devito utilises SymPy to allow the definition of operators from high-level symbolic equations and generates optimised and automatically tuned code specific to a given target architecture.

Symbolic computation is a powerful tool that allows users to:

  • Build complex solvers from only a few lines of high-level code
  • Use automated performance optimisation for generated code
  • Adjust stencil discretisation at runtime as required
  • (Re-)development of solver code in hours rather than months


Documentation for Devito is available here, including installation instructions, a set of tutorials and API documentation. In addition, a paper outlining the use of symbolic Python to define finite difference operators in Devito can be found here.

from devito import TimeData, Operator
from import s, h

u = TimeData(name=ā€™uā€™, shape=(nx, ny),
             time_order=1, space_order=2)[0, :] = initial_data[:]

eqn = Eq(u.dt, a * (u.dx2 + u.dy2))
stencil = solve(eqn, u.forward)[0]
op = Operator(
   stencils=Eq(u.forward, stencil),
   subs={h: dx, s: dt}, nt=timesteps

Example code for a 2D diffusion operator from a symbolic definition. The full tutorial can be found here.

Seismic Inversion using Devito

Devito is primarily designed to create wave propagation kernels for use in seismic inversion problems. A tutorial for the generation of a modelling operator using an acoustic wave equation can be found here and a paper outlining the verification procedures of the acoustic operator can be found here.

True velocity model (Marmousi-ii)

Initial velocity model for FWI

FWI inverted velocity model


Optimisation and Performance

Devito provides a set of automated performance optimiza- tions during code generation that allow user applications to fully utilise the target hardware without changing the model specification:

  • Vectoriastion and shared-memory parallelism
  • Loop blocking and auto-tuning
  • Symbolic optimisations:
    • Common sub-expression elimination (CSE)
    • Loop re-writing and expression hoisting


Performance of acoustic wave modelling operator with different stencil sizes and auto-tuning on single-socket E5-2697 v4 CPU (Broadwell, 16 cores @ 2.3GHz).