Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

core: (affine) Add functions dealing with dimensions to AffineMap and AffineExpr #4007

Merged

Conversation

watermelonwolverine
Copy link
Contributor

Add a couple of utility functions to AffineMap and AffineExpr that deal with dimensions.
Cherry picked from #3650, prerequisite for implementing vector.transfer_read and vector.transfer_write ops

Copy link

codecov bot commented Mar 3, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 90.19%. Comparing base (a9ee7c9) to head (bf55c00).
Report is 2 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #4007   +/-   ##
=======================================
  Coverage   90.19%   90.19%           
=======================================
  Files         458      458           
  Lines       58319    58341   +22     
  Branches     5688     5692    +4     
=======================================
+ Hits        52598    52619   +21     
  Misses       4331     4331           
- Partials     1390     1391    +1     

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

@superlopuh
Copy link
Member

Do you know what MLIR does here? We should probably mimic their beaviour.

@watermelonwolverine
Copy link
Contributor Author

watermelonwolverine commented Mar 4, 2025

is_function_of_dim is basically bool isFunctionOfDim(unsigned position)
ununsed_dims_bit_vector is basically llvm::SmallBitVector getUnusedDimsBitVector(ArrayRef<AffineMap> maps); (or at least a precursor to it)
Both are in mlir/include/mlir/IR/AffineMap.h

Both used_dims and unused_dims are just utiltity functions I added to make the implementation a bit more pythonic

@watermelonwolverine watermelonwolverine changed the title Add functions dealing with dimensions to AffineMap and AffineExpr core: Add functions dealing with dimensions to AffineMap and AffineExpr Mar 4, 2025

return result

def unused_dims(self) -> set[int]:
Copy link
Member

Choose a reason for hiding this comment

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

Am I right in understanding that neither unused_dims nor the bit vector version are used in your other PR? Are we sure we need these helpers?

Copy link
Member

Choose a reason for hiding this comment

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

Actually it seems like none of these helpers are used?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I just updated that PR, have a look now. I removed some verification that wasn't ready yet because of the changes that needed to be done to the VectorType

@compor compor changed the title core: Add functions dealing with dimensions to AffineMap and AffineExpr core: (affine) Add functions dealing with dimensions to AffineMap and AffineExpr Mar 5, 2025
@compor compor added the core xDSL core (ir, textual format, ...) label Mar 5, 2025
@compor compor self-requested a review March 5, 2025 10:23
Comment on lines 264 to 269
result: set[int] = set()

for expr in self.results:
result = result.union(expr.used_dims())

return result
Copy link
Member

Choose a reason for hiding this comment

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

Set construction feels expensive enough to me to only want to do it once:

Suggested change
result: set[int] = set()
for expr in self.results:
result = result.union(expr.used_dims())
return result
return {expr.position for res_expr in self.results for expr in res_expr.dfs() if isinstance(expr, AffineDimExpr)}

Comment on lines 282 to 286
used_dims = self.used_dims()
return tuple(
True if position in used_dims else False
for position in range(self.num_dims)
)
Copy link
Member

Choose a reason for hiding this comment

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

Same here, let's avoid the set construction

Suggested change
used_dims = self.used_dims()
return tuple(
True if position in used_dims else False
for position in range(self.num_dims)
)
used_dims = [False] * self.num_dims
for res_expr in self.results:
for expr in res_expr.dfs():
if isinstance(expr, AffineDimExpr):
used_dims[expr.position] = True
return tuple(used_dims)

@superlopuh
Copy link
Member

Thank you!

@superlopuh superlopuh merged commit 7cac2bf into xdslproject:main Mar 5, 2025
17 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
core xDSL core (ir, textual format, ...)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants