Skip to content

Conversation

@suo
Copy link
Member

@suo suo commented Jul 9, 2019

Stack from ghstack:

We need re-run the marking pass over loop sub-blocks until they converge
to a fixed point. Thanks to @Chillee for catching this bug!

Differential Revision: D16184469

We need re-run the marking pass over loop sub-blocks until they converge
to a fixed point. Thanks to @Chillee for catching this bug!
@pytorchbot pytorchbot added oncall: jit Add this issue/PR to JIT oncall triage queue module: cpp Related to C++ API labels Jul 9, 2019
@suo suo requested review from Krovatkin, ZolotukhinM and zdevito July 9, 2019 18:25
Copy link
Collaborator

@Chillee Chillee left a comment

Choose a reason for hiding this comment

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

Otherwise looks pretty straightforward and correct to me.

auto node = *it;
for (auto subBlock : node->blocks()) {
mark(subBlock);
if (node->kind() == prim::Loop) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Do we need to check for c10::onnx::loop here like we do in the other place?

Copy link
Member Author

Choose a reason for hiding this comment

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

onnx is purely functional and has no aliasing, so we wouldn't need the special behavior

Copy link
Contributor

@Krovatkin Krovatkin left a comment

Choose a reason for hiding this comment

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

:shipit:

// `b` are dead, even though `b[0] += 1` mutates a live memory location (since
// `b[0]` is an alias of `a`).
//
// We need to mark the loop again with the information that `a` is live, and
Copy link
Contributor

@Krovatkin Krovatkin Jul 9, 2019

Choose a reason for hiding this comment

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

// We need to mark the loop again with the information that a is live, and

we could also add

i.e. `a` is used to compute `tot` in the next iteration

bool marked = mark(node->blocks().at(0));
innerMarked = marked;
anyMarked |= marked;
} while (innerMarked);
Copy link
Contributor

Choose a reason for hiding this comment

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

    bool marked = false;
    // Did we ever mark anything new?
    bool anyMarked = false;
    do {
      marked = mark(node->blocks().at(0));
      anyMarked |= marked;
    } while (marked);

// return block. We consider all graph outputs to be "used", so just mark
// this node normally.
return mark(node);
mark(node);
Copy link
Contributor

@Krovatkin Krovatkin Jul 9, 2019

Choose a reason for hiding this comment

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

I don't quite like the fact that markReturnNode isn't changed to bool. I get that we only call mark for the top-level (function return) and in this case we aren't in a loop, so it doesn't matter, and if we are in a loop we make live only body outputs. When we'll get early returns we might want to consider revisiting this and make markReturnNode to actually return a bool

Copy link
Contributor

@zdevito zdevito left a comment

Choose a reason for hiding this comment

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

Seems fine.

[jit] fix dce over loops

We need re-run the marking pass over loop sub-blocks until they converge
to a fixed point. Thanks to @Chillee for catching this bug!

gh-metadata: pytorch pytorch 22632 gh/suo/79/head
@zou3519 zou3519 deleted the gh/suo/79/head branch July 10, 2019 19:06
@facebook-github-bot
Copy link
Contributor

@suo merged this pull request in ec1b669.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Merged module: cpp Related to C++ API oncall: jit Add this issue/PR to JIT oncall triage queue

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants