Repository navigation
Conversation
With sum factorisation, the full table of a tensor product element on a tensor product rule is only used for its shape and type: kernels read the 1D tensor factors. Tabulating it costs O(Q^d N^2d) time and O(Q^d N^d) memory, which dominated code generation at high degree (33 s and a 353 MB table per argument at P=80 on a quadrilateral). For cell integrals without permutations or averages, derive the table type from the 1D factors and store a zero-memory placeholder of the right shape instead. Generated code is unchanged. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
- The placeholder of a table that isn't formed was an all-zero array, which any code reading its values would have used silently. It now has a shape but raises if its values are read, and tables that reach code generation are checked to be formed. - Full tables are clamped before their type is analysed, but tensor factors weren't. Clamp them the same way, and find a zero table when every product of the factors clamps to zero, as the full table would. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Conflicts in ffcx/ir/elementtables.py and test/test_tensor_product.py. This branch moves the permutation block of `build_optimized_tables` after the sum factorisation block and wraps it in a branch, so the full table can be skipped when an element has tensor factors. Meanwhile main edited that block in place: #900 added a 'peak' entity branch and #902 gave the tensor factor tables a per-quadrature-rule name. Kept the restructure and moved main's 'peak' branch into it; the table rename and main's expression codimension check merged cleanly. Both branches appended tests to test/test_tensor_product.py. Kept both. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Member
|
LGTM. |
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
With
sum_factorization=True, FFCx tabulates each tensor product element both as 1D factors and as a full table on the whole tensor product rule. Kernels only read the 1D factors; the full table is used only for its shape and its type (zeros, ones, piecewise, ...). Tabulating it costs O(Q^d N^2d) time and O(Q^d N^d) memory, which dominates code generation at high degree.For a P=80 mass matrix on a quadrilateral, the full table is 6724 points × 6561 dofs = 353 MB, and Basix takes 13.6 s to build it, once for the trial and once for the test function. Code generation took 33 s, almost all of it in this tabulation and in scanning the table. With this change it takes 0.7 s, with a peak of 2 MB.
Changes
build_optimized_tablesno longer forms the full table:analyse_tensor_product_table_typederives its type from the 1D factors.TensorProductTablePlaceholder, which has the table's shape but raises if its values are read. Tables that reach code generation are asserted to be formed.get_component_element.clamp_table_small_numbers). A table is "zeros" when every product of its factors clamps to zero, as the clamped full table would be.Generated code
Kernels without sum factorisation are unchanged. Of the 66 sum-factorised kernels I compared (11 forms, quadrilateral and hexahedron, P = 1–3), 8 differ, only where clamping the factors now writes round-off such as
-5.55e-17as0.0.Tests
test_tensor_product_table_type: the type derived from the factors matchesanalyse_table_typeon the full table, for quadrilaterals and hexahedra, P = 1–3, several 1D rules including collocated GLL points (quadrature tables), and derivatives up to second order, including vanishing ones.test_tensor_product_table_type_clamped_to_zero: factors whose products all clamp to zero give a zero table, as the full table does.test_tensor_product_table_placeholder: reading the placeholder's values raises.🤖 Generated with Claude Code
I have reviewed the contribution and stand by the implementation