This is an archive of the discontinued LLVM Phabricator instance.

[CUDA] Add utility functions for dealing with CUDA versions / architectures.
ClosedPublic

Authored by jlebar on Jun 29 2016, 3:58 PM.

Details

Summary

Currently our handling of CUDA architectures is scattered all around
clang. This patch centralizes it.

A key advantage of this centralization is that you can now write a C++
switch on e.g. CudaArch and get a compile error if you don't handle one
of the enum values.

Diff Detail

Repository
rL LLVM

Event Timeline

jlebar updated this revision to Diff 62299.Jun 29 2016, 3:58 PM
jlebar retitled this revision from to [CUDA] Add utility functions for dealing with CUDA versions / architectures..
jlebar updated this object.
jlebar added a reviewer: tra.
jlebar added a subscriber: cfe-commits.
tra accepted this revision.Jun 30 2016, 9:50 AM
tra edited edge metadata.

LGTM.

lib/Basic/Cuda.cpp
8–19 ↗(On Diff #62299)

We seem to do a lot of enum->string and string->enum mapping in this file.
Is there something comparable to Boost.bimap in standard c++ library or in LLVM?

lib/Driver/Driver.cpp
1026–1028 ↗(On Diff #62299)

I think this could be collapsed to just CudaArchToString(CDA->getGpuArch()).
"(multiple archs)" is as informative as (and indistinguishable from) "unknown" here.

This revision is now accepted and ready to land.Jun 30 2016, 9:50 AM
jlebar marked an inline comment as done.Jun 30 2016, 12:53 PM
jlebar added inline comments.
lib/Basic/Cuda.cpp
8–19 ↗(On Diff #62299)

Not to my knowledge.

lib/Driver/Driver.cpp
1026–1028 ↗(On Diff #62299)

I'm not crazy about "unknown", since it *is* actually known. How about we just not output anything?

tra added inline comments.Jun 30 2016, 1:27 PM
lib/Driver/Driver.cpp
1026–1028 ↗(On Diff #62299)

It's a debugging output so it would be good to accurately reflect our internal state.
In this case if we for some reason end up with CudaArch::UNKNOWN, I'd want to know that.
If we really use UNKNOWN to represent multiple archs, perhaps it needs an enum for multiple-archs.

jlebar marked an inline comment as done.Jun 30 2016, 1:31 PM
jlebar added inline comments.
lib/Driver/Driver.cpp
1026–1028 ↗(On Diff #62299)

We really do use UNKNOWN here to represent multiple architectures. It is used for the architecture of the Action corresponding to the call to fatbin.

I think adding an enum value for multiple-archs is going to be more harmful than useful, because it means that everywhere that we switch() on arch, we're going to have to handle (and assert) MULTIPLE_ARCHs.

tra added inline comments.Jun 30 2016, 1:44 PM
lib/Driver/Driver.cpp
1026–1028 ↗(On Diff #62299)

OK. No output is fine with me.

jlebar updated this revision to Diff 62409.Jun 30 2016, 1:49 PM
jlebar edited edge metadata.

Address Art's review.

jlebar marked 4 inline comments as done.Jun 30 2016, 1:49 PM
This revision was automatically updated to reflect the committed changes.