Skip to content

Bufferalignment#611

Merged
bknueven merged 12 commits intoPyomo:mainfrom
DLWoodruff:bufferalignment
Mar 3, 2026
Merged

Bufferalignment#611
bknueven merged 12 commits intoPyomo:mainfrom
DLWoodruff:bufferalignment

Conversation

@DLWoodruff
Copy link
Copy Markdown
Collaborator

@DLWoodruff DLWoodruff commented Feb 4, 2026

It seems that Send/Receive buffers (windows) need to align on 512 bit boundaries because solvers use special packages that do that and someone might clobber someone else if we don't all line up.

@DLWoodruff DLWoodruff marked this pull request as draft February 4, 2026 18:50
@DLWoodruff DLWoodruff marked this pull request as ready for review February 4, 2026 19:43
@DLWoodruff DLWoodruff requested a review from bknueven February 10, 2026 21:54
change a comment to be more clear
put back some of the original comments concerning FieldArray
fix minor grammar error in comment
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR adds 64-byte (512-bit) buffer alignment to MPI send/receive staging buffers in the mpisppy cylinder communication framework. The motivation is that some solvers (e.g., those using AVX-512 SIMD) internally align memory to 512-bit boundaries, which could cause memory collisions if the mpisppy communication buffers are not similarly aligned.

Changes:

  • spwindow.py: The SPWindow layout tuple is extended from (offset, length) to (offset, logical_len, padded_len), where padded_len rounds up logical_len to the next multiple of 8 doubles (64 bytes). A _padded_len_8doubles helper is added.
  • spcommunicator.py: communicator_array now allocates MPI-aligned memory via MPI.Alloc_mem with a padded length, and FieldArray exposes both a padded "window view" (window_array()) and a logical view (array()). Validation functions are updated to check both logical and padded lengths.
  • reduced_costs_spoke.py: Minor comment and a (tautological) assertion added.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 6 comments.

File Description
mpisppy/cylinders/spwindow.py Extended layout tuple to 3-element (offset, logical_len, padded_len); added _padded_len_8doubles helper; updated get/put to transfer padded_len doubles; updated WHOLE field construction
mpisppy/cylinders/spcommunicator.py communicator_array now uses MPI.Alloc_mem for alignment; FieldArray gains dual-view (window_array / array); validation in _validate_recv_field and register_recv_field updated for new tuple layout
mpisppy/cylinders/reduced_costs_spoke.py Added a comment about using logical_len and a tautological assert

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread mpisppy/cylinders/spcommunicator.py
Comment thread mpisppy/cylinders/spcommunicator.py
Comment thread mpisppy/cylinders/reduced_costs_spoke.py Outdated
Comment thread mpisppy/cylinders/spcommunicator.py
Comment thread mpisppy/cylinders/spwindow.py Outdated
Comment thread mpisppy/cylinders/spcommunicator.py
Comment on lines +96 to +99
def _padded_len_8doubles(logical_len: int) -> int:
"""Round up length (in doubles) to a multiple of 8 doubles (64 bytes)."""
return ((logical_len + 7) // 8) * 8

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

We hand-calculate this in a bunch of places -- ideally this function would be the singular source of truth on computing the pad.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

And ideally, we'd rename it to something a bit more generic so we can just change the padding here, if needed in the future. (Drop the 8.)

Comment thread mpisppy/cylinders/spwindow.py Outdated
Comment on lines +130 to +133
# Fallback: caller provided padded only (not recommended)
padded_len = int(entry)
logical_len = padded_len

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Is this really needed? If not, let's get rid of it.

Comment thread mpisppy/cylinders/spwindow.py Outdated
bknueven and others added 3 commits March 3, 2026 09:26
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@bknueven bknueven enabled auto-merge March 3, 2026 16:44
@bknueven bknueven merged commit 201b663 into Pyomo:main Mar 3, 2026
19 checks passed
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