Opt: A Domain Specific Language for Non-Linear Least Squares Optimization in Graphics and Imaging

Zachary DeVito, Michael Mara, Michael Zollhöfer, Gilbert Bernstein, Jonathan Ragan-Kelley, Christian Theobalt, Pat Hanrahan, Matthew Fisher, Matthias Nießner

TL;DR

This paper introduces "Opt," a domain-specific language (DSL) that allows graphics and vision researchers to express complex non-linear least squares optimization problems at a high level. Opt's compiler automatically generates highly optimized GPU solvers, significantly outperforming existing general-purpose solvers and even hand-tuned custom solutions in terms of speed and ease of implementation.

What Problem Does This Paper Address?

Many problems in computer graphics and vision, such as image editing, shape reconstruction, and optical flow estimation, can be elegantly formulated as non-linear least squares optimization problems. While the mathematical descriptions of these problems are often concise, translating them into efficient, high-performance code, especially for real-time GPU execution, is a tedious and complex undertaking. Existing approaches either require extensive manual coding of complex derivative calculations and solver logic or rely on general-purpose libraries that lack the specialized optimizations needed for graphics and vision tasks. This gap makes it difficult for researchers to quickly prototype and deploy efficient solvers for their specific problems.

Methods

Opt tackles this challenge by providing a high-level DSL that abstracts away the complexities of optimization. Key aspects of their approach include:

  • Domain-Specific Language (DSL): Opt allows users to define energy functions using a Lua-embedded language, focusing on the problem's structure (images, meshes, graphs) and local relationships (stencils).
  • Automatic Differentiation: The system employs a hybrid symbolic-automatic differentiation approach to derive necessary gradient and Hessian information without manual intervention.
  • Compiler Optimization: Opt's compiler transforms the high-level energy descriptions into efficient intermediate representations (IR) and then generates highly optimized GPU code for solver routines (e.g., evalJTF, applyJTJ).
  • Generic Solver Framework: The generated routines plug into a flexible framework that supports both Gauss-Newton (GN) and Levenberg-Marquardt (LM) optimization methods.
  • Matrix-Free and Materialized Solvers: Opt can generate solvers that operate "matrix-free" (computing values on-the-fly) or "materialized" (storing matrices), allowing users to choose based on performance trade-offs. This is crucial for GPU efficiency, minimizing memory transfers.
  • Parallel Preconditioned Conjugate Gradient (PCG): The core of the solver uses a parallel PCG implementation tailored for GPUs.

Datasets

The paper does not explicitly mention training datasets. For evaluation, they use a variety of standard graphics and vision problems, including:

  • ARAP Image Warping
  • ARAP Mesh Deformation
  • Shape From Shading
  • Poisson Image Editing
  • 3D LARAP Mesh Deformation
  • Embedded Deformation
  • Cotangent Mesh Smoothing
  • Optical Flow
  • Robust Mesh Deformation
  • Intrinsic Image Decomposition
  • Volumetric Mesh Deformation

Additionally, they evaluate their system's numerical behavior on univariate problems from the NIST non-linear least squares optimization benchmark.

Key Insights and Ideas

  • High-Level Abstraction Pays Off: The ability to express complex optimization problems in a few lines of code, rather than hundreds of lines of hand-tuned GPU kernels, dramatically speeds up development and experimentation.
  • Automatic Generation Outperforms Manual Tuning: Opt's generated solvers not only match but often exceed the performance of state-of-the-art, hand-optimized custom solvers. This suggests that the compiler's systematic optimization strategies can be more effective than manual efforts for certain problem classes.
  • Matrix-Free is Key for GPU Performance: The paper strongly advocates for matrix-free approaches on GPUs, highlighting significant speedups due to reduced memory bandwidth requirements. Opt's ability to seamlessly generate these is a major advantage.
  • Flexibility in Solver Variants: Opt's architecture allows easy exploration of different solver configurations (GN vs. LM, float vs. double precision, matrix-free vs. materialized) without altering the energy function, enabling users to find optimal settings for their specific problems.
  • Implicit Connectivity Advantage: For image-based problems, Opt's use of implicit connectivity (via stencils) offers substantial performance benefits over explicit graph representations, especially as problem size increases.

Key Results

  • Performance Speedups: Opt-generated solvers consistently outperform general-purpose solvers like Ceres by 1-3 orders of magnitude. They also outperform hand-written custom GPU solvers by 10-75% for several benchmark problems.
  • Implementation Effort Reduction: Energy functions in Opt are expressed in tens of lines of code, compared to hundreds or even thousands for custom CUDA implementations.
  • Matrix-Free Efficiency: Matrix-free variants of Opt solvers are 1.16x to 3x faster than materialized versions for most tested problems.
  • Numerical Stability: Opt supports both float and double precision, allowing users to trade speed for stability when needed, as demonstrated on the NIST benchmark.

Limitations and Future Work

  • Stencil Limitations: Currently, Opt's image-based energies are limited to constant-sized neighboring stencils. The authors plan to extend this to support more general neighborhood functions, provided they are invertible.
  • Graph Language Extension: The graph language could be extended to support variable numbers of neighbors for certain energy types.
  • Broader Applicability: While Opt is currently GPU-focused, the authors believe its core principles of symbolic differentiation and optimization are applicable to multi-core CPUs and clusters.
  • Beyond GN/LM: The authors acknowledge that many graphics problems are better solved with other optimization techniques (e.g., interior-point methods, quadratic programming). Future work could extend Opt to support these.

Summary updated

BibTeX
@article{devito2017opt,
  author = {Zachary DeVito and Michael Mara and Michael Zollhöfer and Gilbert Bernstein and Jonathan Ragan-Kelley and Christian Theobalt and Pat Hanrahan and Matthew Fisher and Matthias Nießner},
  title = {{Opt: A Domain Specific Language for Non-Linear Least Squares Optimization in Graphics and Imaging}},
  journal = {ACM Trans. Graphics},
  year = {2017},
  doi = {10.1145/3132188},
}
Figure