Cut the allocations on the calls that go inside a loop - #301
Merged
Merged
Conversation
with_local_array! queried each vector's PetscMemType with a checkout of its own before checking the vectors out for real, memtype_backend dispatched on a Val built from that run-time value, and read/write changed type mid-function. Host memory now answers before the dispatch, the extra query is gone, and a one-vector checkout costs 2 allocations (the unsafe_wrap, the floor) and infers, from 23 and Any. with_field_views! goes 24 to 8, a 3-step SNES solve 210 to 47, and v[i] = a to zero. Devices dispatch as before.
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.
Checking arrays out of a Vec.
with_local_array!cost 23 allocations and inferredAny: it asked each vector for itsPetscMemTypewith a checkout of its own before checking the vectors out for real, andmemtype_backenddispatched on aValbuilt from that run-time value. Host memory now answers before the dispatch and the extra query is gone. Devices dispatch as before, so the CUDA extension is untouched.Out-of-place broadcast.
w = 2 .* xread one entry at a time throughVecGetValues. APetscVecStylestyle putscopyon the same local-array pathcopyto!already took. It still returns aVector; a distributed one now throws anArgumentErrornaming the in-place form, where before it died with a raw PETSc error.with_local_array!, 1 vectorAnywith_field_views!Any2 .* x, 10 000 entriesv[i] = a