Skip to content

Add reverse mode autodiff to the autodiff performance benchmark - #1670

Open
reach2sayan wants to merge 2 commits into
boostorg:developfrom
reach2sayan:feature/autodiff-reverse-benchmark
Open

reach2sayan wants to merge 2 commits into
boostorg:developfrom
reach2sayan:feature/autodiff-reverse-benchmark

Conversation

@reach2sayan

@reach2sayan reach2sayan commented Nov 22, 2026 •

Copy link
Copy Markdown
Contributor

Adds reverse mode autodiff (rvar) to reporting/performance/autodiff_performance.cpp.

  • TranscendentalReverse, InverseFunctionsReverse, TwoVariablesReverse, ThreeVariablesReverse, BlackScholesFourVariablesReverse: the gradient in every input (rdiff::grad).

  • Benchmarks over a problem size:

    • HornerReverse: over the number of coefficients, 8 to 1024.
    • MseGibbsEnergy<1> / MseGibbsEnergy<2>: the gradient / Hessian (rdiff::hess) in P over the number of species, 4 to 128.
    • RosenbrockReverse<1> / RosenbrockReverse<2>: the extended Rosenbrock function of n variables, 8 to 1024 / 8 to 128. One sweep gives all n partials, so the gradient is O(n); the Hessian sweeps once per variable, so it is O(n²).

@reach2sayan
reach2sayan marked this pull request as draft November 22, 2026 15:55
@reach2sayan

reach2sayan commented Nov 22, 2026 •

Copy link
Copy Markdown
Contributor Author

@NAThompson I was thinking of some speedups in reverse mode as well.

The idea I wanna pitch is to try to
(a) reduce the size of the node, and
(b) get rid of the linear search for the node lookup.

The tape's blocks never move, and memory is freed only on clear(). So pointers into a block stay valid exactly as long as the iterators do. So instead of holding the 3 iterators, each node can just hold 3 plain pointers: to its adjoint, and to the start of its derivatives and arguments.

That means a node's derivatives and arguments must each be one unbroken array, to be indexed through a pointer. A function say emplace_back_contiguous can guarantee that: if a run wouldn't fit in what's left of the current block, it pads to the next block, and it throws if a run is longer than a whole block.

For the lookup, backward() can just find the block that holds the node's address (one check per block, not per node), then walk each block backwards through a plain pointer.

This does put a bound on the node: one expression can have at most BOOST_MATH_BUFFER_SIZE (65536 by default) rvar operands. But I think its big enough. The tape itself stays unbounded.

I could provide an initial implementation.

@reach2sayan
reach2sayan marked this pull request as ready for review November 24, 2026 12:08
…er the degree, MseGibbsEnergy<1>/<2> over the species, and the extended Rosenbrock functionover the number of variables.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant