This is an archive of the discontinued LLVM Phabricator instance.

[NVPTX] Add __CUDA_ARCH__ macro to standalone NVPTX compilations
ClosedPublic

Authored by jhuber6 on Mar 27 2023, 8:20 AM.

Details

Summary

We can now target the NVPTX architecture directly via
--target=nvptx64-nvidia-cuda. This currently does not define the
__CUDA_ARCH__ macro with is used to allow code to target different
codes based on support. This patch simply adds this support.

Diff Detail

Event Timeline

jhuber6 created this revision.Mar 27 2023, 8:20 AM
Herald added a project: Restricted Project. · View Herald TranscriptMar 27 2023, 8:20 AM
jhuber6 requested review of this revision.Mar 27 2023, 8:20 AM
This revision is now accepted and ready to land.Mar 27 2023, 10:12 AM
tra accepted this revision.Mar 27 2023, 10:22 AM
tra added inline comments.
clang/lib/Basic/Targets/NVPTX.cpp
171

Wouldn't just if(!HostTarget) be sufficient here?

clang/test/Frontend/nvptx-macros.c
1 ↗(On Diff #508672)

I'd rename the file to make it more obvious that it deals with a standalone compilation.

standalone-nvptx-macros.c ?

jhuber6 marked an inline comment as done.Mar 27 2023, 10:23 AM
jhuber6 added inline comments.
clang/lib/Basic/Targets/NVPTX.cpp
171

HostTarget is the host toolchain, provided via -aux-triple. So it's set for OpenMP and CUDA but not for a standalone.

clang/test/Frontend/nvptx-macros.c
1 ↗(On Diff #508672)

I can do that.

This revision was landed with ongoing or failed builds.Mar 27 2023, 4:08 PM
This revision was automatically updated to reflect the committed changes.
jhuber6 marked an inline comment as done.