This is an archive of the discontinued LLVM Phabricator instance.

[StreamExecutor] Add kernel types
ClosedPublic

Authored by jhen on Aug 3 2016, 2:24 PM.

Diff Detail

Repository
rL LLVM

Event Timeline

jhen updated this revision to Diff 66721.Aug 3 2016, 2:24 PM
jhen retitled this revision from to [StreamExecutor] Add kernel types.
jhen updated this object.
jhen added reviewers: jlebar, tra.
jhen added a subscriber: parallel_libs-commits.
jlebar edited edge metadata.Aug 3 2016, 5:33 PM

Looks pretty good to me.

streamexecutor/include/streamexecutor/Kernel.h
11 ↗(On Diff #66721)

If we're being helpful, maybe s/on a device/on a GPU or other accelerator/.

14 ↗(On Diff #66721)

Too many adjectives in a row. "user API's"

15 ↗(On Diff #66721)

s/unsafe/type-unsafe/?

18 ↗(On Diff #66721)

s/methods/functions/?

18 ↗(On Diff #66721)

Uber-nit, but "type-safe"? The latter seems ~5x more common in my searching.

23 ↗(On Diff #66721)

One thing I don't get is, why do we have to implement a Launch function like this at all? Surely a better API would be to do

Kernel.Launch(a1, a2, a3);

?

24 ↗(On Diff #66721)

I'm finding these code blocks pretty hard to read. I'm sure they look great in doxygen, but...even under the highly generous estimate that as many people are going to read this in doxygen as in source, that's still a pretty bad situation.

What if we indented the code two or four spaces?

28 ↗(On Diff #66721)

Maybe s/The problem/A problem/ or something?

97 ↗(On Diff #66721)

In general if you implement a move (copy) constructor, you should implement a move (copy) assignment operator.

http://en.cppreference.com/w/cpp/language/rule_of_three

streamexecutor/lib/unittests/KernelTest.cpp
52 ↗(On Diff #66721)

Not sure about this comment...it will just return null, but not do anything unsafe? But maybe you want to return an error or something the second time? Or assert()?

85 ↗(On Diff #66721)

If I'm honest I have no idea what this is testing.

Maybe it is not in fact currently testing anything? :) If so I would almost prefer you wait to add it until we actually have something to test, so that I can better judge whether it's doing something reasonable. But if there's a reason to do it this way, that's fine too.

jhen updated this revision to Diff 66749.Aug 3 2016, 6:20 PM
jhen marked 10 inline comments as done.
jhen edited edge metadata.
  • Respond to jlebar's comments
jhen added a comment.Aug 3 2016, 6:21 PM

jlebar, thanks for your review on this. I'm sorry this patch has been so hard to read. :) Hopefully it's improved a lot now.

streamexecutor/include/streamexecutor/Kernel.h
23 ↗(On Diff #66721)

It's because the real launch function is used in chaining like this

Stream.Initialize(...).thenMemcpyToDevice(...).thenLaunch(...).thenMemcpyToHost(...).thenBlock(...);
24 ↗(On Diff #66721)

Sorry about that. I tried indenting them four spaces. I think it helps a lot.

streamexecutor/lib/unittests/KernelTest.cpp
52 ↗(On Diff #66721)

I added an assert and changed the comment to warn about the assert.

85 ↗(On Diff #66721)

Sorry for the confusing code. I added a comment to the test to describe what it's doing and I changed the test name to better describe what is going on.

From my point of view, I think that it is really testing something, but I admit that it's testing something very simple. Let me know if you think the functionality it is testing is too simple to need a test.

jhen added a comment.Aug 3 2016, 6:24 PM

Oh, and in response to our offline discussion about gmock. I realized that gmock is not used in LLVM, so I'm not going to use it either. So, I removed the comment that mentioned gmock and I'm now just defining my mock class without mentioning gmock.

jprice added a subscriber: jprice.Aug 4 2016, 5:10 AM
jprice added inline comments.
streamexecutor/lib/Kernel.cpp
42 ↗(On Diff #66749)

This needed a std::move() for me to build with GCC 5 on Ubuntu or Apple Clang on OS X.

jlebar accepted this revision.Aug 4 2016, 9:54 AM
jlebar edited edge metadata.

I'm sorry this patch has been so hard to read. :)

Oh, sorry if I gave you the wrong impression. I do a lot of reviews, and your patches are consistently in the top quintile, both for readability and just in general. This one is no exception!

Thank you for the fixes, this looks good to me (modulo the outstanding std::move issue).

streamexecutor/include/streamexecutor/Kernel.h
24 ↗(On Diff #66749)

Ah, I see. Okay!

streamexecutor/lib/unittests/KernelTest.cpp
86 ↗(On Diff #66749)

Okay, I get it now! Thanks. This is fine. Like you say it's simple, but that's not a problem.

This revision is now accepted and ready to land.Aug 4 2016, 9:54 AM
jhen updated this revision to Diff 66823.Aug 4 2016, 10:07 AM
jhen edited edge metadata.
  • Fix bug found by jprice
streamexecutor/lib/Kernel.cpp
42 ↗(On Diff #66749)

Thanks for spotting this jprice. I can confirm that it fails to build with GCC 4.8 on Ubuntu as well without the std::move(). I have now added the std::move() to prevent this error.

This revision was automatically updated to reflect the committed changes.