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

Implementation of irregular flattening #1740

Draft
wants to merge 108 commits into
base: master
Choose a base branch
from
Draft

Implementation of irregular flattening #1740

wants to merge 108 commits into from

Conversation

athas
Copy link
Member

@athas athas commented Oct 16, 2022

This highly WIP PR contains an implementation of full flattening as a transformation that goes from the SOACS representation to GPU. It is the result of a few hours of hacking and can handle the following program:

def main = map (\n -> #[unsafe] i64.sum (iota n))

Flattened versions of all core Futhark constructs must be defined, and so far I have only done Iota and Reduce. The main design challenge was the representation of irregular arrays in the compiler, as well as the overall structure of the algorithm. It is currently based on (irregular) distribution, much like the moderate flattening algorithm. I think that is the best way to do it.

The ultimate goals are:

  1. Replace the current implementation of flattening with one that is more principled (the old one is really dirty in places because I had no idea what I was doing).
  2. Maintain incremental flattening, just in a more principled framework. The "fully flattened" code version will only be used as a last resort.
  3. Experiment with whether (possibly virtualised) full flattening may perhaps have acceptable performance in the intra-group case.
  4. Support compiling any Futhark program to GPU code; not just the subset that uses only regular nested parallelism.
  5. Bring back recursive functions.

An explicit non-goal is adding support for irregular arrays in the source language.

@athas athas marked this pull request as draft October 16, 2022 20:02
@Munksgaard
Copy link
Collaborator

Wow, this is exciting stuff! What are the prospects for success?

@athas
Copy link
Member Author

athas commented Oct 17, 2022

There is no real risk of this not succeeding. Flattening a first-order monomorphic language is not particularly difficult, although implementing all the cases will be tedious. The main challenge is writing the code in a clean and maintainable way. Time is the main constraint.

That's only for naive flattening, though, which is notoriously inefficient in practice. It's a more open question how efficient we can make it subsequently. I'm fairly confident we can do a good job, though.

The only somewhat bothersome wrinkle is that we allow arbitrary (potentially irregular) parallelism in reduce/scan/histogram operators. Flattening doesn't have a solution for that. However, nontrivial parallelism in those operators is exceedingly rare, and in all cases these constructs can be turned into maps without any asymptotic overhead, so we can always do that for the really nasty cases. (Although so can the original programmer who writes the source code.)

@melsman
Copy link
Contributor

melsman commented Oct 17, 2022 via email

@FluxusMagna
Copy link

FluxusMagna commented Oct 28, 2022

What does the type of a irregular nested array look like? [n][?]a or similar? I guess existentials come in handy here somehow?

Will there be any limitations on recursion? For example, I'd assume we still wouldn't have recursive data types.

@athas
Copy link
Member Author

athas commented Oct 28, 2022

This is not a source language extension, so there will be no (source) irregular arrays. in the core language, they are represented as flag arrays with flag vectors.

There will be no restrictions on recursive functions, but still no recursive data types (these would require a more substantial change to the internal value representation).

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.

7 participants