Skip to content

Add scratch memory input to nonaffine pull back#4126

Open
jorgensd wants to merge 6 commits intomainfrom
dokken/pull_back_scratch_memory
Open

Add scratch memory input to nonaffine pull back#4126
jorgensd wants to merge 6 commits intomainfrom
dokken/pull_back_scratch_memory

Conversation

@jorgensd
Copy link
Copy Markdown
Member

Currently pull back nonaffine allocate a whole lot of arrays, making it incredibly slow for repeated computation.
This PR makes the scratch memory a mandatory input argument.

@jorgensd jorgensd changed the title Add pull back scratch memory Add scratch memory input to nonaffine pull back Mar 16, 2026

std::vector<T> Xk_b(tdim);
mdspan2_t<T> Xk(Xk_b.data(), 1, tdim);
mdspan2_t<T> dphi(working_array.data(), tdim, num_xnodes);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

You could put all of these into a struct PullBackNonAffineScratch with a constructor taking the needed integer sizes, which then does the dynamic memory allocation with multiple std::vectors + holds the std::spans and mdspan2_t for use inside the routine.

Then the struct would handle the (in my view, a bit messy and error-prone) offsetting automatically.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Unless there is some genuine performance benefit from the current approach with just a single span as input - but on my reading, there probably isn't.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I vibed this out at jhale/pull_back_scratch_memory, if you like it feel free to merge here and tidy it up/fix up.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants