Zero-allocation tangent for ViscousPolyconvex - #231
Open
miguelmaso wants to merge 1 commit into
Open
miguelmaso wants to merge 1 commit into
miguelmaso wants to merge 1 commit into
Conversation
Add generated implementations of `-` (binary and unary) for `TensorValue`,
mirroring the existing `+`. Without them, subtraction of fourth-order tensors
fell back to the generic Gridap implementation, which exceeds Julia's inlining
threshold for `TensorValue{9,9}` and heap-allocates the result.
Those subtractions appear in `∂Sv∂C_Cᵥfix` and `∂Cv⁻¹∂C`, i.e. exactly on the
path of the viscoelastic tangent operator, which is why only `∂∂Ψ∂FF` allocated
while `Ψ` and `∂Ψ∂F` did not.
`+` is also generalized from `TensorValue{D,D}` to `TensorValue{D1,D2}` so that
non-square tensors are covered as well. No change in the mathematics.
Visco-polyconvex ∂∂Ψ∂FF: 187 allocs / 15552 B / 5367 ns -> 0 allocs / 0 B / 599 ns.
Visco-elastic ∂∂Ψ∂FF: 1021 allocs / 49600 ns -> 501 allocs / 34200 ns.
Also interpolate the arguments of the tensor algebra benchmarks. Without `$`,
the benchmarked expressions read non-const globals, so the call is dynamically
dispatched and the result is boxed: this is the source of the spurious "1 alloc
of 0.656 kB" reported for `IIsym`, `push_forward_C_to_F` and `×ᵢ⁴`, which are
already allocation-free.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Benchmark Results (Julia v1)Time benchmarks
Memory benchmarks
|
Collaborator
Author
|
The Speed-up with respect to
|
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.
Add generated implementations of
-(binary and unary) forTensorValue, mirroring the existing+. Without them, subtraction of fourth-order tensors fell back to the generic Gridap implementation, which exceeds Julia's inlining threshold forTensorValue{9,9}and heap-allocates the result.Those subtractions appear in
∂Sv∂C_Cᵥfixand∂Cv⁻¹∂C, i.e. exactly on the path of the viscoelastic tangent operator, which is why only∂∂Ψ∂FFallocated whileΨand∂Ψ∂Fdid not.+is also generalized fromTensorValue{D,D}toTensorValue{D1,D2}so that non-square tensors are covered as well. No change in the mathematics.Visco-polyconvex ∂∂Ψ∂FF: 187 allocs / 15552 B / 5367 ns -> 0 allocs / 0 B / 599 ns.
Visco-elastic ∂∂Ψ∂FF: 1021 allocs / 49600 ns -> 501 allocs / 34200 ns.
Also interpolate the arguments of the tensor algebra benchmarks. Without
$, the benchmarked expressions read non-const globals, so the call is dynamically dispatched and the result is boxed: this is the source of the spurious "1 alloc of 0.656 kB" reported forIIsym,push_forward_C_to_Fand×ᵢ⁴, which are already allocation-free.