Skip to content

tests: Add fix and test for regression with compiler-generated buffers - #3108

Merged
mloubout merged 5 commits into
mainfrom
hotfix-buffering-override
Nov 20, 2026
Merged

mloubout merged 5 commits into
mainfrom
hotfix-buffering-override

Conversation

@EdCaunt

@EdCaunt EdCaunt commented Nov 9, 2026 •

Copy link
Copy Markdown
Contributor

Previous merge broke some decoupler tests in PRO due to compiler-generated arrays taking their neighbouring ranks from the Grid with which they were built rather than the one supplied at apply time. This specifically appeared in diag2/overlap2/full mode.

@codecov

codecov Bot commented Nov 9, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 21.21212% with 52 lines in your changes missing coverage. Please review.
✅ Project coverage is 84.20%. Comparing base (8370ce8) to head (5d1dcff).

Files with missing lines Patch % Lines
tests/test_subdomains.py 17.39% 19 Missing ⚠️
tests/test_mpi.py 10.52% 17 Missing ⚠️
devito/mpi/routines.py 23.80% 16 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3108      +/-   ##
==========================================
- Coverage   84.24%   84.20%   -0.05%     
==========================================
  Files         260      260              
  Lines       59431    59481      +50     
  Branches     5019     5023       +4     
==========================================
+ Hits        50068    50085      +17     
- Misses       8524     8561      +37     
+ Partials      839      835       -4     
Flag Coverage Δ
pytest-gpu-aomp-amdgpuX 68.32% <33.33%> (-0.01%) ⬇️
pytest-gpu-gcc- 78.95% <21.21%> (-0.06%) ⬇️
pytest-gpu-icx- 78.88% <21.21%> (-0.05%) ⬇️
pytest-gpu-nvc-nvidiaX 69.15% <33.33%> (-0.01%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Comment thread devito/mpi/routines.py Outdated
f = alias or self.target.c0
neighborhood = f.grid.distributor.neighborhood

# The ranks are taken from the `nb` provided at runtime by the (possibly

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.

are u sure that the proper fix ain't in _arg_values? _arg_values is where u should pull the override

see for example MPIMsg._arg_values

Comment thread devito/mpi/routines.py Outdated
# The ranks are taken from the `nb` provided at runtime by the (possibly
# overriding) Grid or SubDomain, as `f` may be a compiler-generated Array
# still attached to the Grid the Operator was built with
nb = f.grid.distributor._obj_neighborhood

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.

I still don't get why not args.grid, the grid is supposed to be unique to the operator.

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.

seconded

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Because f.grid may be a subdomain with it's own distributor and _obj_neighborhood which differs from the base grid.

Comment thread devito/mpi/routines.py Outdated
# The ranks are taken from the `nb` provided at runtime by the (possibly
# overriding) Grid or SubDomain, as `f` may be a compiler-generated Array
# still attached to the Grid the Operator was built with
nb = f.grid.distributor._obj_neighborhood

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.

this whole thing looks like it's doing what nb._arg_defaults should be doing by hand

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.

seconded (related to what I wrote above)

Comment thread devito/mpi/routines.py Outdated
# `alias` may be a compiler-generated Array with no override
name = alias.grid.distributor._obj_neighborhood.name
neighborhood = None
for i in getattr(args, 'discretizations', ()):

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.

why do u need getattr?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Good spot, it doesn't need it

@FabioLuporini FabioLuporini 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 sane

Comment thread devito/mpi/routines.py Outdated
return alias

def _arg_values(self, args=None, **kwargs):
return self._arg_defaults(alias=self._arg_alias(**kwargs), args=args)

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.

That's the oposite of the alias logic. alias is the object used to build the operator it should be new._arg_defaults(alias=self, ..

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Good catch

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Wait, but that's not how it's used here in current main. We have alias = kwargs[f.name] above, so alias here is coming from the runtime value, not the build time value. This is essentially just refactoring of what was already here to avoid duplication in MPIMsgEnriched

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.

Then it's incorrect in main too

Comment thread devito/mpi/routines.py Outdated
neighborhood = i.distributor.neighborhood
break

return self._arg_defaults(alias=alias, args=args, neighborhood=neighborhood)

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.

same should new._arg_defaults(alias=self probably should rename the new _arg_alias as _arg_new or something

@EdCaunt
EdCaunt requested a review from mloubout November 11, 2026 15:45
@mloubout mloubout added the MPI mpi-related label Nov 12, 2026
@EdCaunt
EdCaunt force-pushed the hotfix-buffering-override branch from 3b60c57 to 45ea066 Compare November 13, 2026 10:41
Comment thread devito/mpi/routines.py Outdated
entry = self.value[i]
f = self.target.c0
for i, halo in enumerate(alias.halos):
entry = alias.value[i]

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.

that still should be self.value, this process the rutime values for self given alias's name

Comment thread devito/mpi/routines.py Outdated
# Allocate the send/recv buffers
ctype, datasize = infer_datasize(f.dtype, shape)
size = datasize * dtype_len(self.target.dtype)
size = datasize * dtype_len(alias.target.dtype)

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.

same should be self

Comment thread devito/mpi/routines.py Outdated
# The `memfree_args` will be used to deallocate the buffer upon
# returning from C-land
self._memfree_args.extend([bufg_memfree_args, bufs_memfree_args])
alias._memfree_args.extend([bufg_memfree_args, bufs_memfree_args])

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.

self

Comment thread devito/mpi/routines.py Outdated
alias._memfree_args.extend([bufg_memfree_args, bufs_memfree_args])

return {self.name: self.value}
return {alias.name: alias.value}

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.

alias.name: self.value

Comment thread devito/mpi/routines.py Outdated
return self

return self._arg_defaults(alias=alias, args=args)
return self._rebuild(target=new)

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.

why do you need a rbeuil at runtime?

@EdCaunt EdCaunt Nov 18, 2026 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

In current main, alias isn't an MPIMsg, it's the payload of the message (or a component thereof), and so _arg_defaults acts on self and simply sets the buffers to the correct size accordingly (i.e. to match alias if it exists) as far as I can tell. The _rebuild here is a product of making _arg_values get the runtime object and then call runtime_obj._arg_defaults(alias=compiletime_obj). All it is doing is making a duplicate MPIMsg which points at the correct target to make this approach work.

Iirc, there are rebuilds at runtime for other MPI-related objects in the codebase already

@EdCaunt EdCaunt Nov 18, 2026 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

That being said, I do think that current main is actually the correct approach, although alias should probably be given a new name like payload

Comment thread devito/mpi/routines.py Outdated
for i, halo in enumerate(self.halos):
entry = self.value[i]
for i, halo in enumerate(alias.halos):
entry = alias.value[i]

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.

self

Comment thread devito/mpi/routines.py Outdated
ncomp = self.target.ncomp
component_indices = self.target.component_indices
if isinstance(alias.target, BundleView):
ncomp = alias.target.ncomp

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.

self.

Comment thread devito/mpi/routines.py Outdated
entry.components = (c_int*ncomp)(*range(ncomp))

return {self.name: self.value}
return {alias.name: alias.value}

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.

alias.name: self.value

Comment thread devito/mpi/routines.py Outdated
alias = f
return self

if not getattr(new, 'is_AbstractFunction', False):

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.

try-except

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Going to push back on this - whilst we try to avoid getattr, in this case, it simplifies the code and makes it much easier to read

@EdCaunt
EdCaunt force-pushed the hotfix-buffering-override branch from ea4f3f1 to 5d1dcff Compare November 19, 2026 13:22

@FabioLuporini FabioLuporini 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.

LGTM

@mloubout
mloubout merged commit 1eb54aa into main Nov 20, 2026
46 of 47 checks passed
@mloubout
mloubout deleted the hotfix-buffering-override branch November 20, 2026 14:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

MPI mpi-related

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants