Skip to content

[NOT READY] Add a fused multiply add for AD tensors - #73

Draft
GiudGiud wants to merge 92 commits into
libMesh:masterfrom
GiudGiud:PR_fma
Draft

GiudGiud wants to merge 92 commits into
libMesh:masterfrom
GiudGiud:PR_fma

Conversation

@GiudGiud

Copy link
Copy Markdown

written by Claude.
I ll report on the timings and find out if it compiles soon

roystgnr and others added 30 commits November 23, 2021 10:27
m4 doesn't use subshells to keep local variables local, and I think we
were getting false positives from one macro's commonly-named "local"
variable infecting another.
Even with the prefix we're not really safe unless we make sure to ignore
any pre-existing variable settings.
This was useful for debugging
I don't want to rewrite 1.3.2 history since it was *almost* working,
everything save for libMesh distcheck.

Since we haven't actually changed any APIs we don't bother updating
libtool version info this time.
This prepares all the build system changes from the new FE exceptions
code and configuration.
@GiudGiud GiudGiud changed the title [NOT READY] Add a fused multiply add [NOT READY] Add a fused multiply add for AD tensors Jun 23, 2026
@GiudGiud
GiudGiud changed the base branch from bootstrapped to master September 13, 2026 23:01
GiudGiud and others added 5 commits September 17, 2026 09:47
When a tensor of AD Reals has every component sharing one derivative sparsity
pattern (the usual case: all components depend on the same element DOFs), the
sparsity union is identical for every component. Compute it once for the whole
tensor instead of once per component, eliminating the per-component union scans
and temporaries. Works for DynamicSparseNumberArray and SemiDynamicSparseNumberArray
(MOOSE's ADReal derivative type) derivatives.

- NumberArray/NumberVector::operator*= now route through a component_multiply_assign
  customization point (default: the per-component loop). shared_sparsity_tensor_multiply.h
  adds specializations for DualNumber over DynamicSparseNumberArray and
  SemiDynamicSparseNumberArray that use the batched one-union path, with a safe
  per-component fallback when the patterns are not shared.
- shared_sparsity_tensor_contract.h provides fused_shared_sparsity_contract<DIM> for
  the matrix product C = A*B (e.g. a RankTwoTensor exposing operator()(i,j)): one union
  for the whole contraction, no temporaries, with a plain_tensor_contract fallback.
- dualdynamicsparsenumberarray.h includes the multiply header last, so the component-wise
  fused path is active by default for AD sparse tensors. Per-thread reusable scratch
  keeps the batched paths allocation-free in steady state.

Co-Authored-By: Claude <noreply@anthropic.com>
…ty AD tensors

Lets a generic tensor operator (e.g. libMesh TypeTensor::operator*) use the shared-sparsity
fast path: fused_shared_sparsity_contract and fused_shared_sparsity_rotate are safe to call
for any entry type. A has_sparse_derivatives trait dispatches to the fused one-union path for
AD entries backed by a dynamic sparse derivative array and to the plain implementation
otherwise, with a run-time fallback to plain when component patterns are not shared.

- New sparse_pattern_compare.h holds same_index_pattern so consumers can use these routines
  without pulling in the DualNumber/container headers.
- shared_sparsity_tensor_contract.h: trait + tag-dispatched plain/fused contract (plain
  accumulates in the output/supertype so mixed-type products are correct) and
  fused_shared_sparsity_rotate for A = R*A*R^T, one union over P_R u P_A.

Co-Authored-By: Claude <noreply@anthropic.com>
…rank4)

fused_shared_sparsity_rank4_times_rank2 (C_ij = A_ijkl b_kl) and
fused_shared_sparsity_rank4_times_rank4 (C_ijkl = A_ijpq B_pqkl) contract over the flat
N^2 storage and, when every entry of each operand shares one derivative sparsity pattern,
compute the union once per product instead of once per scalar multiply. Same trait-based
dispatch as the rank-2 routines: fused for sparse-AD entries, plain otherwise, with a
run-time fallback when patterns are not shared.

Co-Authored-By: Claude <noreply@anthropic.com>
@lindsayad

Copy link
Copy Markdown
Member

Isn't that what draft is for? 😄

@GiudGiud
GiudGiud marked this pull request as draft September 18, 2026 20:50
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.

3 participants