Skip to content

api: fix handling of multiple conditions for buffering#2850

Open
mloubout wants to merge 6 commits into
mainfrom
multi-cond-again
Open

api: fix handling of multiple conditions for buffering#2850
mloubout wants to merge 6 commits into
mainfrom
multi-cond-again

Conversation

@mloubout
Copy link
Copy Markdown
Contributor

No description provided.

@mloubout mloubout added the API api (symbolics, types, ...) label Feb 16, 2026
@codecov
Copy link
Copy Markdown

codecov Bot commented Feb 16, 2026

Codecov Report

❌ Patch coverage is 85.61873% with 43 lines in your changes missing coverage. Please review.
✅ Project coverage is 83.49%. Comparing base (cf29367) to head (5ac1c04).
⚠️ Report is 4 commits behind head on main.

Files with missing lines Patch % Lines
devito/passes/clusters/buffering.py 75.00% 20 Missing and 11 partials ⚠️
devito/ir/support/guards.py 85.29% 4 Missing and 1 partial ⚠️
devito/passes/clusters/asynchrony.py 86.11% 3 Missing and 2 partials ⚠️
devito/ir/clusters/algorithms.py 77.77% 1 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2850      +/-   ##
==========================================
+ Coverage   83.45%   83.49%   +0.03%     
==========================================
  Files         249      249              
  Lines       52219    52446     +227     
  Branches     4500     4543      +43     
==========================================
+ Hits        43580    43790     +210     
- Misses       7880     7891      +11     
- Partials      759      765       +6     
Flag Coverage Δ
pytest-gpu-aomp-amdgpuX 68.61% <73.51%> (+<0.01%) ⬆️
pytest-gpu-gcc- 78.19% <75.58%> (-0.01%) ⬇️
pytest-gpu-icx- 78.15% <75.58%> (+0.05%) ⬆️
pytest-gpu-nvc-nvidiaX 69.13% <73.51%> (-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/symbolics/extended_sympy.py Outdated
return CondNe(*self.args, evaluate=False)

@property
def _as_min(self):
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 would drop this and rather have a singledispatch handler for CondEq where necessary


def relational_shift(expr, s):
"""
Infer shift incurred by the expression. Generally only
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 could use an example here to quickly visualise what's it trying to do

expr = uxreplace(expr, {d: IntDiv(index, d.symbolic_factor)})

# Merge conditionals when possible. E.g if we have an implicit_dim
# and there is a dimension with the same parent, we ca merged
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.

Dimension

"ca merged"

"their conditions"

you could also make the example a bit more practical

for d in input_expr.implicit_dims:
if d not in conditionals:
continue
for cd in dict(conditionals):
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.

list(...) is fine

# Replace the ConditionalDimensions in `expr`
for d, cond in conditionals.items():
# Replace dimension with index
index = d.index
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.

you can spare this line

ispace = IterationSpace(intervals, iterators)

# Construct the conditionals and replace the ConditionalDimensions in `expr`
# Construct the conditionals
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 think we should place this whole block of code, which constructs/lowers the conditionals, into its own separate functions, and a docstring with some examples

@mloubout mloubout force-pushed the multi-cond-again branch 4 times, most recently from ef708e5 to b997156 Compare May 22, 2026 15:13
@mloubout mloubout force-pushed the multi-cond-again branch 5 times, most recently from 7a1a6aa to c7786ea Compare May 28, 2026 17:17
@review-notebook-app
Copy link
Copy Markdown

Check out this pull request on  ReviewNB

See visual diffs & provide feedback on Jupyter Notebooks.


Powered by ReviewNB

@mloubout mloubout force-pushed the multi-cond-again branch 11 times, most recently from f904760 to 0500469 Compare May 29, 2026 16:45
shift = relational_shift(cond, d.parent)
expr = uxreplace(expr, {d: IntDiv(index, d.symbolic_factor) + shift})

# Merge conditionals when possible. E.g if we have an implicit_dim
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.

btw this block imho deserves its own function

Comment thread devito/passes/clusters/asynchrony.py Outdated
if d is not dim:
continue

if d in c0.guards and not c0.guards[d].has(Mod):
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.

searching for Mod is a bit meh, I'd rather add a special guard to ir/support/guards.py and look for that instead (there's quite a few already in there!)

Comment thread devito/passes/clusters/asynchrony.py Outdated
_actions_from_update_memcpy(c, d, clusters, actions, sregistry)
elif d.is_Custom and is_integer(c.ispace[d].size):
_actions_from_init(c, d, actions)
_actions_from_init(c, d, clusters, actions)
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.

leftover, I guess

Comment thread devito/passes/clusters/asynchrony.py Outdated


def _actions_from_init(c, d, actions):
def _actions_from_init(c, d, clusters, actions):
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.

leftover, I guess

"\n",
" * ``And`` (default): all conditions must hold (mutually exclusive merging).\n",
" * ``Or``: any one condition is enough for the if-branch to fire.\n",
" * ``'strict'``: this condition takes precedence over every other condition\n",
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.

how about an int, representing priority, instead of strict? it would also make it more natural to generalise it

@mloubout mloubout force-pushed the multi-cond-again branch from 0500469 to 30790f0 Compare May 30, 2026 14:35
@mloubout mloubout force-pushed the multi-cond-again branch 15 times, most recently from 550e222 to e315b38 Compare June 4, 2026 13:39
@mloubout mloubout force-pushed the multi-cond-again branch 4 times, most recently from 797592b to ab5242a Compare June 5, 2026 15:45
@mloubout mloubout force-pushed the multi-cond-again branch from ab5242a to 5ac1c04 Compare June 5, 2026 17:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

API api (symbolics, types, ...)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants