Skip to content

PROJECT: Performance Benchmarks Suite for Numba, Dask, JAX (CPU/GPU) #264

Open

Description

@mmcky

Overview

Build a comprehensive benchmarks suite for computational libraries commonly used in QuantEcon projects to help define optimal workflow and program structure guidelines.

Motivation

Different computational backends (Numba, Dask, JAX CPU, JAX GPU) have different performance characteristics and overheads:

  • JAX GPU has kernel launch overheads, making it only worthwhile for problems above a certain size
  • Numba has JIT compilation overhead on first call
  • Dask has scheduling overhead that may not pay off for small datasets
  • JAX CPU vs GPU crossover points vary by operation type

Currently, guidance on when to use each backend is based on rules of thumb. A systematic benchmarking suite would provide data-driven recommendations.

Proposed Features

1. Benchmark Categories

  • Array operations: matrix multiplication, element-wise ops, reductions
  • Numerical algorithms: linear solvers, optimization, root finding
  • Monte Carlo simulations: varying sample sizes
  • Dynamic programming: value function iteration, policy iteration
  • Common QuantEcon patterns: Markov chains, asset pricing, etc.

2. Problem Size Scaling

For each benchmark, test across problem sizes to identify:

  • Minimum problem size where GPU becomes beneficial
  • Crossover points between backends
  • Memory bandwidth vs compute bound regimes

3. Automated Results Updates

  • CI workflow that runs benchmarks on schedule (weekly/monthly)
  • Triggered on new releases of key libraries (JAX, Numba, etc.)
  • Results published to a dashboard or static site
  • Historical tracking to show performance changes over versions

4. Guidelines Generation

  • Automatically generate recommendations based on benchmark results
  • "Use JAX GPU when matrix size > N" type guidance
  • Integration with lecture documentation

Example Output

Matrix Multiplication Crossover Points (JAX 0.4.x, CUDA 12.x, A100)
-------------------------------------------------------------------
Size < 500x500:     CPU faster (GPU overhead dominates)
Size 500-2000:      Similar performance
Size > 2000x2000:   GPU 10-100x faster

Recommendation: Use JAX GPU for matrices larger than 1000x1000

Technical Approach

  • Use pytest-benchmark or similar for consistent measurement
  • Run on standardized hardware (GitHub Actions runners, cloud GPU instances)
  • Store results in structured format (JSON/Parquet)
  • Generate reports and visualizations automatically

Related

Questions to Explore

  1. What hardware configurations should we benchmark on?
  2. Should this be a standalone repo or part of an existing project?
  3. How to handle GPU availability in CI (cost considerations)?
  4. What's the update frequency that balances freshness vs compute cost?

Activity

  1. mmcky commented on Oct 24, 2026

    @mmcky
    ContributorAuthor

    Workstream A's first experiment is scoped as QuantEcon/benchmarks#1: float64 against float32 on CPU, CUDA and Apple Silicon, split by kernel type (compute-, memory- and launch-bound). Its problem-size sweeps also give this issue's CPU/GPU crossover curves. It extends hardware/benchmark_hardware.py rather than replacing it, and keeps the programme's as-used method: a fresh process per measurement, with compile time counted.

    It runs first on qe-wharton1-gpu, which takes up the hardware offer on #335. Phase 0 needs none of that machine's time: the harness is built and calibrated on Apple Silicon and the RunsOn T4 while the machine is brought back online.

  2. mmcky commented on Nov 3, 2026

    @mmcky
    ContributorAuthor

    Workstream A's first crossovers by problem type (2026-11-03). QuantEcon/benchmarks#5's Phase 1 has run four of its eight problem types. Each is written in NumPy, Numba and JAX and timed as used: a fresh process per cell, compile included, cold and warm times kept apart, and every answer checked against NumPy's. It ran on an Apple M6 (qe-mini1) and on qe-wharton1-gpu's Threadripper 2990WX and TITAN RTX. The tables are in QuantEcon/benchmarks' problems/README.md (QuantEcon/benchmarks#25, QuantEcon/benchmarks#26, QuantEcon/benchmarks#28).

    Where the TITAN RTX overtakes the M6's fastest stack, in float64. "From N" means at N and at every larger size measured.

    Problem type Warm: one process, many solves Cold: a fresh process, one solve
    Value function iteration on a dense grid From a grid of 200 From 1,000
    Endogenous grid method From a grid of 1,000 From 5,000
    Monte Carlo across households From 10,000 households From 10,000,000
    A Kalman filter, batched or with more states Never, up to 10,000 filters or 200 states Never
    • The card's start moves every crossover up. A fresh process on the card takes at least 1.08 s before any work. So for a lecture that solves once, the cold column is the one that applies. Past the crossover, the card is 2.4× to 4.5× ahead at the largest sizes.
    • Latency-bound recursions stay on the CPU. Each Kalman step costs the card about 0.13 ms, against about 1.4 µs for Numba on the M6, as the precision benchmark (Precision and platform: float64 against float32 on CPU, CUDA and Apple Silicon benchmarks#1) found on every GPU it measured. In float32 the card wins the batched filter from 1,000 filters.
    • On a CPU, no one stack is best.
      • On the M6, JAX wins the dense Bellman step. Parallel Numba wins the Monte Carlo, the batched filters and the large EGM grids, and serial Numba a single small filter.
      • In a fresh process, NumPy is fastest in 16 of the 28 cells, because it compiles nothing. Numba's first call takes 0.2 s to 3.2 s.
    • The machine matters as much as the stack. The 12-core M6 beats the 32-core Threadripper on every problem except Monte Carlo from 100,000 households, by up to 21×. The Threadripper's parallel Numba scales on only two of the four.

    How this fits with the earlier results:

    Still to come:

    • Phase 2's problem types: policy iteration, Markov chains, root finding per state and gradient-based estimation;
    • the suite on the M5 Pro and the T4 runner;
    • a view by problem type on the dashboard, which so far shows the precision and lecture results.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions