Skip to content

Sum factorisation on simplices - #5263

Open
pbrubeck wants to merge 13 commits into
pbrubeck/optimise-sum-factorfrom
pbrubeck/simplex-sum-fact
Open

Sum factorisation on simplices#5263
pbrubeck wants to merge 13 commits into
pbrubeck/optimise-sum-factorfrom
pbrubeck/simplex-sum-fact

Conversation

@pbrubeck

@pbrubeck pbrubeck commented Jul 18, 2026

Copy link
Copy Markdown
Contributor

Stack\n\n- Base: #5335\n- Paired FIAT simplex PR: firedrakeproject/fiat#262\n- Paired FIAT generic base: firedrakeproject/fiat#276\n\n## Summary\n\n- exercise simplex and Bernstein sum factorisation through TSFC spectral lowering\n- check compact parameterized loop domains instead of rectangular masked loops\n- benchmark Bernstein Laplacian code generation with copyable Markdown output\n- retain Johnson--Mercier FLOP, temporary, storage, and AST metrics for the generic stack\n\n## Bernstein code-generation snapshot\n\nReproduce with:\n\n python benchmarks/bernstein_laplacian.py --cell tetrahedron --degrees 10\n python benchmarks/bernstein_laplacian.py --cell triangle --degrees 10\n\n| cell | degree | scheme | compile (s) | FLOPs | scalar temps | array temps | stored values | largest | AST lines |\n| :--- | ---: | :--- | ---: | ---: | ---: | ---: | ---: | ---: | ---: |\n| tetrahedron | 10 | collapsed | 0.404 | 585,587,154 | 33 | 27 | 153,524 | 28,600 | 168 |\n| tetrahedron | 10 | canonical | 0.366 | 576,863,054 | 29 | 7 | 859,887 | 286,000 | 106 |\n| triangle | 10 | collapsed | 0.101 | 2,323,413 | 16 | 14 | 4,348 | 1,210 | 91 |\n| triangle | 10 | canonical | 0.102 | 2,217,713 | 14 | 5 | 13,446 | 6,600 | 69 |\n\nThe collapsed kernels materially reduce temporary storage. Their remaining degree-10 FLOP overhead is explicit: about 1.5% in 3D and 4.8% in 2D.\n\n## Johnson--Mercier snapshot\n\n| dim | compile (s) | FLOPs | scalar temps | array temps | stored elements | largest | AST lines |\n| ---: | ---: | ---: | ---: | ---: | ---: | ---: | ---: |\n| 2 | 0.507 | 39,619 | 41 | 29 | 1,509 | 135 | 196 |\n| 3 | 3.216 | 1,016,342 | 130 | 69 | 17,992 | 672 | 530 |\n\nReproduce with benchmarks/johnson_mercier.py --dims 2 3.\n\n## Validation\n\n- make srclint\n- TSFC sum-factorisation and refactorisation tests\n- paired FIAT documentation, source lint, and 68 selected regression tests\n\n## AI assistance\n\nOpenAI Codex was used for implementation, refactoring, testing, benchmarking, and drafting this PR. The human contributor remains responsible for understanding, validating, and maintaining the changes.

Comment thread tsfc/fem.py Outdated
Comment thread tsfc/fem.py Outdated
Comment thread tsfc/fem.py Outdated
Comment thread tsfc/fem.py Outdated
Comment thread tsfc/fem.py Outdated

@pbrubeck pbrubeck left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

TSFC codegen diff should be as tight as possible. Add the new code in a separate finat submodule.

Comment thread tsfc/fem.py Outdated
Comment thread tsfc/fem.py Outdated
Comment thread tests/firedrake/regression/test_quadrature.py Outdated
Comment thread tests/firedrake/regression/test_quadrature.py Outdated
Comment thread tests/firedrake/regression/test_quadrature.py Outdated
Comment thread tests/tsfc/test_codegen.py Outdated

@rckirby rckirby 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 just checks that the code gives a correct answer. Do we have a way of checking whether the algorithm has the right complexity?

@pbrubeck

Copy link
Copy Markdown
Contributor Author

This just checks that the code gives a correct answer. Do we have a way of checking whether the algorithm has the right complexity?

This PR adds both correctness and complexity tests. Complexity in flops is not enough, I also had to enforce tests on temporaries

@rckirby

rckirby commented Jul 23, 2026

Copy link
Copy Markdown
Contributor

This PR adds both correctness and complexity tests. Complexity in flops is not enough, I also had to enforce tests on temporaries

I see those tests, was thinking about FIAT. We should also test out Bernstein in the one-element benchmarks -- it doesn't have the indirection internally that modified C^0 expansions have but can be directly (after Duffy) sum-factored.

@pbrubeck
pbrubeck force-pushed the pbrubeck/simplex-sum-fact branch from 7cfae19 to 6e30e23 Compare July 24, 2026 10:27
Comment thread tests/firedrake/regression/test_helmholtz_bernstein.py Outdated
Comment thread DESIGN.md Outdated
@pbrubeck
pbrubeck force-pushed the pbrubeck/simplex-sum-fact branch from eeb157d to 72c2ee7 Compare August 7, 2026 22:12
@pbrubeck
pbrubeck changed the base branch from main to pbrubeck/optimise-sum-factor August 7, 2026 22:15
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