Skip to content

Compile interpolation through the GEM optimisation pipeline - #5381

Merged
pbrubeck merged 1 commit into
mainfrom
pbrubeck/interp-spectral
Aug 26, 2026
Merged

Compile interpolation through the GEM optimisation pipeline#5381
pbrubeck merged 1 commit into
mainfrom
pbrubeck/interp-spectral

Conversation

@pbrubeck

@pbrubeck pbrubeck commented Aug 24, 2026

Copy link
Copy Markdown
Contributor

Description

assemble(interpolate) now contracts over the points with the same GEM optimisations as in assemble(Form).

Depends on firedrakeproject/fiat#288

Benchmark

Interpolation into CG on a 16x16x16 extruded hex mesh, minimum of 15 timed
batches. f scalar, u vector, A tensor, all CG of the given degree.

case flops main flops PR ratio time main time PR ratio
f*f*f -> S (CG1) 96 96 1.00x 0.85 ms 0.85 ms 1.00x
dot(u,u)*u -> V (CG1) 520 304 1.71x 1.49 ms 1.43 ms 1.04x
inner(A,A) -> S (CG1) 792 792 1.00x 1.48 ms 1.52 ms 0.97x
dot(A,A) -> T (CG1) 1728 1080 1.60x 2.18 ms 2.04 ms 1.07x
dot(A,dot(A,u)) -> V (CG1) 1776 1128 1.57x 2.15 ms 2.08 ms 1.03x
dot(A,dot(A,A)) -> T (CG1) 2736 1440 1.90x 2.72 ms 2.47 ms 1.10x
f*f*f -> S (CG2) 486 486 1.00x 1.13 ms 1.16 ms 0.97x
dot(u,u)*u -> V (CG2) 2727 1512 1.80x 2.76 ms 2.43 ms 1.14x
inner(A,A) -> S (CG2) 4131 4131 1.00x 2.94 ms 2.93 ms 1.01x
dot(A,A) -> T (CG2) 8748 5103 1.71x 6.83 ms 6.63 ms 1.03x
dot(A,dot(A,u)) -> V (CG2) 9396 5751 1.63x 6.35 ms 5.61 ms 1.13x
dot(A,dot(A,A)) -> T (CG2) 13608 6318 2.15x 9.42 ms 7.29 ms 1.29x
f*f*f -> S (CG3) 1728 1728 1.00x 2.65 ms 2.80 ms 0.95x
dot(u,u)*u -> V (CG3) 9920 5312 1.87x 11.25 ms 7.55 ms 1.49x
inner(A,A) -> S (CG3) 14976 14976 1.00x 6.45 ms 6.51 ms 0.99x
dot(A,A) -> T (CG3) 31104 17280 1.80x 27.49 ms 15.93 ms 1.73x
dot(A,dot(A,u)) -> V (CG3) 34368 20544 1.67x 23.89 ms 14.43 ms 1.66x
dot(A,dot(A,A)) -> T (CG3) 47808 20160 2.37x 33.72 ms 16.91 ms 1.99x

Speed up comes from Delta cancellation that was missing for tensor-valued expressions.

f*f*f and inner(A,A) have an empty value shape, so this change cannot
affect them: they are the control, and come out at 1.00x flops and
0.95-1.01x time. Every case with a value shape improves.

Temporaries rise in two cases (81 to 120 at CG2 dot(A,A), 44 to 65 at CG1
dot(A,A)), and both are still faster, so the extra register pressure does
not cost anything measurable.

Generated with Claude Code

@pbrubeck
pbrubeck requested a review from connorjward August 24, 2026 14:54

@connorjward connorjward left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How much of this code is the same as in compile_form? Ideally they would be the same code path no?

@pbrubeck

Copy link
Copy Markdown
Contributor Author

How much of this code is the same as in compile_form? Ideally they would be the same code path no?

Ideally we would have a unified assembler that would deal with compositions of same-mesh interpolate and Form.

#5258

I suggest we take this as the first step.

connorjward
connorjward previously approved these changes Aug 24, 2026

@connorjward connorjward left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems fine

@connorjward

Copy link
Copy Markdown
Contributor

How much of this code is the same as in compile_form? Ideally they would be the same code path no?

Ideally we would have a unified assembler that would deal with compositions of same-mesh interpolate and Form.

#5258

I suggest we take this as the first step.

Agreed. Fine to do in pieces.

Dual evaluation now leaves the point indices free, so interpolation can go
through mode.Integrals and mode.flatten with the points as its quadrature
multiindex, exactly as form assembly does. The value shape is summed before
the pipeline: those indices are carried by Deltas, so they want cancellation
rather than sum factorisation.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@pbrubeck
pbrubeck force-pushed the pbrubeck/interp-spectral branch from 4976308 to 37671b8 Compare August 26, 2026 11:26
@pbrubeck
pbrubeck merged commit 22c6bc4 into main Aug 26, 2026
4 of 6 checks passed
@pbrubeck
pbrubeck deleted the pbrubeck/interp-spectral branch August 26, 2026 11:26
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.

2 participants