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

[Blog] Polyhedral Compilation #433

Merged
merged 2 commits into from
Dec 23, 2023
Merged

[Blog] Polyhedral Compilation #433

merged 2 commits into from
Dec 23, 2023

Conversation

bcarlet
Copy link
Contributor

@bcarlet bcarlet commented Dec 12, 2023

Closes #405.

@bcarlet
Copy link
Contributor Author

bcarlet commented Dec 12, 2023

Repository.

Copy link
Owner

@sampsyo sampsyo left a comment

Choose a reason for hiding this comment

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

Thanks for the detailed writeup! This was definitely a hard thing to do, but you made a good case for why you wanted to start from scf/memref and not affine. I think it's pretty cool that you were able to get the domains constructed using isl at all. It of course would have been better to get real code emitted and executing so you can check correctness, but this was a good start.

I just have a few high-level comments on the text.


Having identified regions with polyhedral domain, the next step is to construct those domains explicitly in a format that can be manipulated by integer programming tools. We use [isl](https://libisl.sourceforge.io/) to build sets from affine constraints and discharge queries such as emptiness checking.

For a given operation, we begin by determining the space in which its iteration domain should be constructed. This determination depends on the SCoP in which the operation resides: loop induction variables within the SCoP correspond to dimensions of the space, while other variables correspond to parameters.
Copy link
Owner

Choose a reason for hiding this comment

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

I think this is just my ignorance about the polyhedral model showing, but I don't quite grok what "space" and "dimensions" mean concretely here. Maybe it would be helpful to add a little context-setting above about what isl defines a "domain" to be? What are all the ingredients required to create an iteration domain?


To construct the iteration domain, we traverse the loop nest moving outwards from the operation, accumulating constraints imposed by loop bounds and `if` conditions, until we reach the root of the SCoP. Each constraint we encounter introduces an inequality between affine expressions. We convert these expressions from MLIR `Value`s into isl's internal representation of affine functions, construct integer sets corresponding to the inequalities, and finally compute the intersection across all constraints.

In the implementation, this analysis is wrapped up in an MLIR pass that annotates each operation in the IR with an attribute encoding the operation's iteration domain. The figure from the introduction was generated from the pass' output.
Copy link
Owner

Choose a reason for hiding this comment

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

Do you think you could include one or two examples of what that annotation looks like, in MLIR syntax? I know it will be messy, but I think it would be helpful to get a concrete picture of what the domain consists of, in a way that is separate from the internal isl data structures.


Testing the legality of transformations in the polyhedral model requires encoding dependence relations between statement executions. Dependences arise from accesses to a common memory location, where one access is a store. There are many techniques for identifying such dependences; following Bastoul, we take the approach of dependence polyhedra.

A dependence polyhedron, for a given pair of statements, encodes dependences between executions of the respective statements as integer points. The question of whether the statements are free of dependences then amounts to an emptiness check on the polyhedron.
Copy link
Owner

Choose a reason for hiding this comment

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

FWIW, it took me a couple tries to understand this paragraph: namely, each dependence is one point, so the set of all dependencies is a polyhedron (a set of points).


## Evaluation

Unfortunately, the project has not reached a point where it is practical to perform a systematic evaluation across a wide range of benchmarks. To check correctness, I have thus far relied on manual inspection of the internal data structures. I've tested with a modest set of examples from the literature, with mostly encouraging results.
Copy link
Owner

Choose a reason for hiding this comment

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

That's OK! Can you say a bit more about what that modest set of examples consists of?


With respect to the implementation itself, construction of the dependence polyhedra was certainly the trickiest part, and is also the part of the implementation in whose correctness I'm least confident. And as I mentioned above, testing is currently limited to manual inspection of internal data structures (though I did write utilities to visualize those structures where appropriate).

## References
Copy link
Owner

Choose a reason for hiding this comment

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

I don't think you need this section heading; the footnote will be rendered in a way that makes it clear it's not part of the body text. 😃

Copy link
Owner

@sampsyo sampsyo left a comment

Choose a reason for hiding this comment

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

Excellent! Nice work on this!!

@sampsyo sampsyo merged commit b77a752 into sampsyo:2023fa Dec 23, 2023
2 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.

Project Proposal: Polyhedral Compilation
2 participants