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

[RTG][Elaboration] Add support for 'scf.if' and 'scf.for' #7986

Open
wants to merge 1 commit into
base: maerhart-rtg-elaboration-indexops
Choose a base branch
from

Conversation

maerhart
Copy link
Member

Did a quick profile of the following input:

func.func @dummy(%arg0: index) -> () {return}

rtg.test @test : !rtg.dict<> {
  %0 = index.constant 0
  %1 = index.constant 1
  %2 = index.constant 10000000
  %3 = index.constant 2
  %4 = scf.for %i = %0 to %2 step %1 iter_args(%a = %0) -> (index) {
    %5 = index.add %a, %3
    scf.yield %5 : index
  }
  func.call @dummy(%4) : (index) -> ()
}

Currently takes ~5.4 sec on my machine, with most of the time spent internalizing the intermediate integers.
Will follow-up with a PR that refactors the ElaboratorValue to only internalize complex values such as sets and bags, but not primitive integers.

Copy link
Contributor

@darthscsi darthscsi left a comment

Choose a reason for hiding this comment

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

LGTM. I think maybe we can be a bit simpler for some of the structure rewriting, but I'm not going to push on that right now.

/// Interprets the IR to perform and lower the represented randomizations.
class Elaborator : public RTGOpVisitor<Elaborator, FailureOr<DeletionKind>> {
class Elaborator
Copy link
Contributor

Choose a reason for hiding this comment

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

A number of passes have assumed that the visitor is cheap to construct and thus embed this kind of state locally and create new visitors as needed. I don't know if this is relevant here.

return DeletionKind::Delete;
}

// First iteration
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm wondering if there is some alternate, forward-rewriting kind of approach:
elab(for (ind = start, end) { block; }) -> elab(let ind = start in block) ; elab(for(ind = start + 1, end) { block }))
let is essentially the clone block with mapping api.

Copy link
Member Author

Choose a reason for hiding this comment

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

You mean actually cloning the MLIR ops? I intentionally tried to write this in a way that does not require any IR cloning/materialization because that's quite expensive. But from a readability perspective that would be better, I agree.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
RTG Involving the `rtg` dialect
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants