Skip to content

P7: where a GPU overtakes a CPU on Kalman filters, by filters and states together #58

Closed

Description

@mmcky

For QuantEcon/project-benchmarks-jax#1, whose tracker lists it as a candidate for #5: where a GPU overtakes a CPU on step-by-step work, as a rule of thumb for a JAX for Economists guide. Drafted 2026-11-10 at Matt's go-ahead. The plan below is agreed (Matt, 2026-11-10), with the changes from review folded in: 300 and 3,000 filters added, serial Numba dropped from 1,000 filters up, and a 1,800 s limit on the new sweeps' cells.

The question

P7's two sweeps are each one line through a plane. batch varies the number of filters at 10 states, and state varies the states for one filter. Neither says how the crossover moves when both grow, which is what a model being estimated does: more states, and a likelihood evaluated at many parameter values at once.

What #26 (b98983c) and #25 (387351b) found on 2026-11-02, warm, each device's fastest stack:

M6 TITAN RTX Who wins
float64, 1,000 filters at 10 states 0.220 s, numba-parallel 0.372 s M6, 1.7×
float64, 10,000 filters at 10 states 2.28 s, numba-parallel 3.15 s M6, 1.4×
float64, one filter at 200 states 0.107 s, numba 0.494 s M6, 4.6×
float32, 100 filters at 10 states 0.0256 s, numba-parallel 0.135 s M6, 5.3×
float32, 1,000 filters at 10 states 0.242 s, numba-parallel 0.135 s TITAN, 1.8×
float32, 10,000 filters at 10 states 2.37 s, numba-parallel 0.518 s TITAN, 4.6×
float32, one filter at 200 states 0.0577 s, numpy 0.115 s M6, 2.0×

So in float64 the card never caught the M6 on either line, and in float32 it did only on the batch line, between 100 and 1,000 filters. The card pays about 0.13 ms a step whatever the size, against about 1.4 µs for one filter on the M6. Cold, its first answer takes at least 1.2 s.

What's expected off the two lines: a step's work grows as filters × states³. Once that work, not the card's fixed cost per step, sets the card's time, the comparison becomes throughput against throughput. In float32 that favours the card, since Turing runs float32 at about 16 TFLOPS. In float64 it may not, since Turing runs float64 at 1/32 of that rate, about 0.5 TFLOPS, which is the range of the M6's CPU. Whether the float64 crossover exists at all on this card is part of the question.

The plan

1. A harness change first, by PR. P7 gains three batch sweeps at more states. Each runs 1, 10, 100, 300, 1,000, 3,000 and 10,000 filters, with --quick at 10. The 300 and 3,000 are there because the float32 crossover at 10 states already falls between 100 and 1,000, and sizes 10× apart leave each crossover a 10× span.

Sweep States Filters
batch (as now) 10 1 to 10,000, by decades
batch20 20 1 to 10,000, with 300 and 3,000
batch50 50 1 to 10,000, with 300 and 3,000
batch100 100 1 to 10,000, with 300 and 3,000
state (as now) 2 to 200 1
  • The new sweeps run only when named in --sweeps, so a default run of the suite stays Phase 1's. summarise.py already handles any sweep name.
  • kalman.py takes the states from the sweep, through spec.KALMAN_BATCH_STATES. The model is otherwise unchanged: A's off-diagonal draws are already scaled by 1/√K, and each filter has its own A, as now.
  • spec.py's memory estimate becomes 20 × filters × states² × the item size. The largest cell, 10,000 filters at 100 states in float64, comes to 14.9 GiB. That's under the 0.8 limit on both the M6 (32 GB) and the TITAN (24 GB), so nothing is skipped for memory.
  • States stop at 100. At 200 states, 10,000 filters would need about 60 GiB by the same estimate, and hours on the CPU.

2. The M6 half, on qe-mini1. Three invocations of problems/run_suite.py, each with --problems kalman --label kalman-grid, from a runs checkout at the harness PR's merge commit:

Part Sweeps Filters Stacks Cell limit
a batch20, batch50, batch100 1 to 300 numpy, numba, numba-parallel, jax-cpu 1,800 s
b batch20, batch50, batch100 1,000 to 10,000 numpy, numba-parallel, jax-cpu 1,800 s
c batch, state their usual sizes all four 900 s, as before
  • Both precisions. The harness's defaults stay otherwise: five warm runs or 60 s.
  • Serial Numba is left out from 1,000 filters. numba-parallel runs the same code faster there, so serial never wins.
  • The 1,800 s limit: by the estimate below, NumPy's and JAX's cells at 10,000 filters and 100 states take about 7 and 17 minutes with their cold run.
  • Part c is a same-day baseline: the last M6 rows are from macOS 27.0.1, and the Mac now runs 27.2.1 (26B131).
  • JAX's float32 stays at XLA's defaults. On the Mac it pays about 1 µs a small float32 product (QuantEcon/project-benchmarks-jax#4), but it was the M6's fastest P7 stack in only 3 of the 24 cells on 2026-11-02. The finding will note it.
  • Window: a quiet window agreed with the sessions on qe-mini1, which stay running, with the console logged in. --quick first, as a check.
  • Expected time, an estimate: about 2 hours.
    • The test run: the harness PR's --quick run, at 10 filters, cost these per filter and step at 100 states in float64: numpy 21 µs, numba 26 µs, jax-cpu 51 µs, and numba-parallel 9.8 µs with 10 filters on 12 cores.
    • Scaled to 10,000 filters: taken linearly, jax-cpu would take about 8.5 minutes a run and numpy about 3.5. Parallel batching may do better than linear.
    • The rest: most of the remaining time is the 3,000-filter cells and the 60 s floor on every cell from 300 filters up.

3. The TITAN half, on qe-wharton1-gpu.

  • What runs: jax-gpu only, on the card at 0b:00.0, both precisions, the same five sweeps, under econ-on-ai-hardware's lock.
  • Environment: the runs checkout's own venv, as on 2026-11-02.
  • Why jax-gpu only: the Threadripper's fastest CPU stack is 4 to 21 times slower than the M6's on P7, so it doesn't bear on the crossover.
  • Expected time: about 15 minutes. The card's driver is now 595.99.02, newer than on 2026-11-02, so batch and state run again here too.

4. Not now: the M5 Pro, which ran P7's batch of 10,000 filters 1.45× as fast as the M6, and would move the crossover up. Rented cards too, through run_by_hand.sh --sweeps. The RTX PRO 6000 and the H100 pay about 0.07 ms to 0.11 ms a step, and run float64 far faster than Turing.

What comes out

  • For each precision, a map of who wins at each pair of filters and states, warm and cold, with the margin.
  • A rule of thumb, if one fits: the card wins once filters × states³ passes some figure, in float32. In float64, either the same with a larger figure, or "not on a Turing card".
  • The time a step costs on each device and stack, as filters × states³ grows, to show where each device's fixed cost per step gives way to its throughput.

Done when

Activity

  1. mmcky commented on Nov 11, 2026

    @mmcky
    ContributorAuthor

    Done: the map and a rule of thumb. The finding is in QuantEcon/project-benchmarks-jax (findings/2026-11-10-kalman-filters-cpu-against-a-gpu.md, merged as 24b5555). Beyond the plan, at Matt's request, the M5 Pro and two rented cards ran too. The rows are #61's (4bf6f72: the M6, the M5 Pro and the TITAN RTX) and #63's (18199ee: an H100 and an RTX PRO 6000), run with #60's sweeps (0222630) and, on the rented cards, #62's variables (314b061). Every cell ran (246 on each Mac, 66 on each card), and every answer agreed with NumPy's in float64.

    The plan asked for The answer
    Whether the float64 crossover exists on the TITAN No. Warm, the TITAN never beat either Mac in float64, at any size. At 10,000 filters it's 0.53× to 0.74× the M6's speed. Its float64 rate sets its time almost from the start: one filter of 100 states already takes it 0.33 ms a step, against a fixed cost of 0.13 ms
    A rule of thumb Not filters × states³, but the CPU's step against the card's fixed cost. Warm, a card wins where one step of the whole batch takes the CPU longer than the card's fixed cost per step, if the card has the throughput for the precision. That cost is about 0.13 ms on the TITAN, 0.08 ms on the H100 and 0.07 ms on the RTX PRO 6000
    How well the rule calls it 32 or 33 of the 33 pairs of filters and states for every card and Mac in float32, and for the H100 in float64. Where a card lacks float64 throughput it fails: the TITAN at 17 of 33, and at the edge the RTX PRO 6000 at 30 and 31. Each count moves by one pair at most across each card's range of fixed costs
    The map, warm and cold Below, as the first number of filters from which the card wins at every larger size

    Warm, against the M6 / the M5 Pro, at 10, 20, 50 and 100 states (a dash: never):

    Card, precision 10 20 50 100
    TITAN, float32 1,000 / 1,000 1,000 / 1,000 100 / 300 100 / 10
    TITAN, float64 – / – – / – – / – – / –
    H100, float32 1,000 / 1,000 300 / 300 100 / 300 10 / 10
    H100, float64 1,000 / 1,000 300 / 300 100 / 100 10 / 10
    RTX PRO 6000, float32 1,000 / 1,000 300 / 300 100 / 100 10 / 10
    RTX PRO 6000, float64 1,000 / 1,000 300 / 300 100 / 300 100 / 100

    Cold, from a fresh process to the first answer, the crossovers move 3× to 10× higher: 10,000, 3,000, 1,000 and 300 filters on the TITAN in float32 and the H100 in both precisions. The RTX PRO 6000's compiles, up to 17 s a fresh process, push its float64 crossovers to 3,000 or 10,000 filters, or past the sizes measured.

    The margin at 10,000 filters (the M6's time over the card's, at 10 to 100 states):

    • float32: the TITAN 3.0× to 6.8×, the H100 17× to 44×, the RTX PRO 6000 13× to 30×.
    • float64: the H100 12× to 20×, the RTX PRO 6000 2.1× to 4.0×.

    One filter stays on the CPU, from 2 to 200 states, except at 200 states, where the H100 is 1.27× the M6 in float64 and the RTX PRO 6000 is level with the Macs in both precisions (0.93× to 1.09×).

    The Done-when:

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