Skip to content

Optimise the computation of axes layouts - #5749

Open
achanbour wants to merge 15 commits into
mainfrom
achanbour/optimise-compute-layouts
Open

achanbour wants to merge 15 commits into
mainfrom
achanbour/optimise-compute-layouts

Conversation

@achanbour

Copy link
Copy Markdown
Contributor

Profiling my particle scripts revealed that compute_layouts is an expensive operation, which we frequently hit when mutating VoMs and subsequently refreshing their FunctionSpaces. This is an attempt at optimising this function, leveraging the fact that VoM axes have SF with empty leaves (see #5748 or #5747).

Investigating compute_layouts in detail revealed that one of the most costly operations there is walking the AxisTree and particularly building the offset tables. My first attempt at reducing the cost of this function is to prevent the computation of offset tables when all axis components are trivial i.e, their SFs have no leaves and their only regions are owned/ghost group splits.

@achanbour

Copy link
Copy Markdown
Contributor Author

Even after this fix, it appears that prepare_layouts can still be optimised... can we reuse layouts instead of recomputing them after every rebuild, thus avoiding even more of the processing done in prepare_layouts?

@connorjward connorjward left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The idea as a whole is good I think, but the current implementation isn't there yet. I think you want to visit things like component.has_nontrivial_regions etc and handle things there.

Comment thread pyop3/axis_tree/visitors/layout.py Resolved
Comment thread pyop3/axis_tree/visitors/layout.py Resolved
Comment thread pyop3/axis_tree/visitors/layout.py Resolved
Comment thread pyop3/axis_tree/visitors/layout.py Resolved
Comment thread pyop3/axis_tree/visitors/layout.py Resolved
@achanbour
achanbour requested a review from connorjward December 2, 2026 11:52
@achanbour

Copy link
Copy Markdown
Contributor Author

@connorjward I have rewritten my former attempt at optimising the tabulation of layouts: now inside compute_layouts, I localise the axis tree (merge the regions/ strip the SF) and call compute layouts of the new axis tree. This seems to be much less invasive than trying to remove the split at the level of the AxisComponent definition (which is what I first did) which required me to change the code in various places.

@connorjward connorjward left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Looks great. Very happy with how little code is needed.

Comment thread firedrake/functionspaceimpl.py Resolved
@achanbour
achanbour force-pushed the achanbour/optimise-compute-layouts branch from ef8ae20 to 319e82f Compare December 4, 2026 14:34
@achanbour
achanbour requested a review from connorjward December 4, 2026 14:38
connorjward
connorjward previously approved these changes Dec 4, 2026
@achanbour

Copy link
Copy Markdown
Contributor Author

@connorjward this PR is basically done at this point. There are probably other things that could be optimised in this function (particularly in prepare_layouts). But I decided to defer digging into this until later, once I am done optimising the other more predominant operations.

@connorjward

Copy link
Copy Markdown
Contributor

This is failing firedrake-check

@achanbour

Copy link
Copy Markdown
Contributor Author

@connorjward I now fixed this. There was a bug in AxisComponent.localize which meant that compute_layouts was still tabulating offsets for components which didn't have regions.

This branch has not been deployed

No deployments
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.

2 participants