This is an archive of the discontinued LLVM Phabricator instance.

[StreamExecutor] Add Stream::blockHostUntilDone
ClosedPublic

Authored by jhen on Aug 30 2016, 4:55 PM.

Details

Summary

Add the type-safe wrapper to the platform-specific implementation.

Diff Detail

Repository
rL LLVM

Event Timeline

jhen updated this revision to Diff 69783.Aug 30 2016, 4:55 PM
jhen retitled this revision from to [StreamExecutor] Add Stream::blockHostUntilDone.
jhen updated this object.
jhen added a reviewer: jlebar.
jhen added subscribers: parallel_libs-commits, jprice.
jlebar accepted this revision.Aug 30 2016, 5:04 PM
jlebar edited edge metadata.

I initially thought this should be "thenable", but there's no reason for that. This is good.

streamexecutor/include/streamexecutor/Stream.h
87 ↗(On Diff #69783)

Would "thenBlockHostUntilDone" be more consistent with the other names? Or are you intentionally being inconsistent to signal that this is a different sort of thing (e.g. it doesn't return a Stream&)?

This revision is now accepted and ready to land.Aug 30 2016, 5:04 PM
jhen added inline comments.Aug 30 2016, 5:16 PM
streamexecutor/include/streamexecutor/Stream.h
87 ↗(On Diff #69783)

Right, I'm being intentionally inconsistent for just the reason you gave.

Side note: things are kind of funny now because there is no Stream::init method. It used to be S->init().thenA().thenB().block(), now it's S->thenA()->thenB().block(). I almost want to change the names so it's S->aThen().bThen().block(), but of course that doesn't read well because the parameter list is after the "then".

This revision was automatically updated to reflect the committed changes.
jlebar added inline comments.Aug 30 2016, 5:36 PM
streamexecutor/include/streamexecutor/Stream.h
87 ↗(On Diff #69783)

I was wondering about that...

Of course even before you could do something like

Stream *s = ...;
s->init()->thenA().thenB().block();
s->thenC().thenD().block();

Right? That is, we only init the stream once. But I guess that's a less-common use-case?

Should we encourage people to treat streams as ephemeral?

Device.getStream()->thenA().thenB().thenC();

That doesn't scan so bad.

While we're thinking about it, it's also weird that you have to switch between . and ->. Although I'm not sure that returning a Stream* would be an improvement. Maybe...

jhen added inline comments.Aug 30 2016, 6:11 PM
streamexecutor/include/streamexecutor/Stream.h
87 ↗(On Diff #69783)

You're right, it was a problem even with the init function because the stream could be reused.

It's probably not right to suggest that Stream references shouldn't be held. The most common case is probably to create one Stream and then use it for everything in your program, and there is also overhead in creating and destroying streams.

We could be silly and make an extra "doer" object that would just be there to make things read like English:

Doer Stream::listenUp();
Doer &Doer::thenA();
Doer &Doer::thenB();
...
Stream *s = ...;
s->listenUp().thenA().thenB();
s->block();

:) We could make all Doer instances ephemeral. I better stop talking about this, I think I'm actually talking myself into this joke suggestion.

I'm also not thrilled with the switch from -> to ., but I think I'd rather live with it than use all ->.