This is an archive of the discontinued LLVM Phabricator instance.

[CUDA] Add appropriate host/device attribute to target-specific builtins.
ClosedPublic

Authored by tra on Aug 18 2015, 3:36 PM.

Diff Detail

Repository
rL LLVM

Event Timeline

tra updated this revision to Diff 32463.Aug 18 2015, 3:36 PM
tra retitled this revision from to [CUDA] Add appropriate host/device attribute to target-specific builtins..
tra updated this object.
tra added reviewers: eliben, echristo.
tra added a subscriber: cfe-commits.
eliben added inline comments.Aug 18 2015, 4:05 PM
include/clang/Basic/Builtins.h
85 ↗(On Diff #32463)

You can also use it in SemaChecking now

lib/Sema/SemaDecl.cpp
11166 ↗(On Diff #32463)

It is not immediately clear why you would mark target-specific builtins as host in host compilation mode. So for example __builtin_ptx_read_tid_x would be callable from a host function when compiling in host mode? Can you clarify this with a comment here, and also add a relevant test?

tra updated this revision to Diff 32478.Aug 18 2015, 4:50 PM
tra marked an inline comment as done.

used isTSBuiltin in SemaChecking.cpp

tra updated this revision to Diff 32481.Aug 18 2015, 4:57 PM

Added a comment explaining reasoning behind attribute choice for target-specific builtins.

tra marked an inline comment as done.Aug 18 2015, 5:04 PM
tra added inline comments.
lib/Sema/SemaDecl.cpp
11166 ↗(On Diff #32463)

Target triple used for particular compilation pass is assumed to be valid for this particular compilation mode. Builtins provided by the target are therefore assumed to be intended to be used in that compilation mode. builtins.cu already includes test cases for using target-specific builtins from different targets and and non-target-specific builtins in host and device functions in host and device compilation.

Your example scenario (builtin_ptx_read_tid_x getting host attribute) is possible only if you compile in host mode *and* use --triple nvptx-unknown-cuda. IMO, host__ would be an appropriate attribute to assign to builtins in this scenario, even though I don't think we can currently do anything useful with NVPTX as the host at the moment. If you attempt to use __builtin_ptx_read_tid_x() during host compilation using non-NVPTX target (which is a typical scenario), then compilation will fail because that particular builtin would not be available at all.

That said, another corner case would be compiling CUDA for device with the same architecture as host. Again, it's not a practical scenario at the moment. If/when we get to the point when we may want to do that, it should be easy to check for it and treat builtins as host device which would reflect their intended use domain.

eliben accepted this revision.Aug 19 2015, 8:09 AM
eliben edited edge metadata.

lgtm

This revision is now accepted and ready to land.Aug 19 2015, 8:09 AM
This revision was automatically updated to reflect the committed changes.
tra added a comment.Aug 20 2015, 5:03 PM

Reverted in r245592 due to breaking internal tests.