This is an archive of the discontinued LLVM Phabricator instance.

[CUDA][HIP] Don't diagnose use for __bf16
AbandonedPublic

Authored by Pierre-vh on Nov 24 2022, 3:55 AM.

Details

Summary

e0fb01e97b6b7d2fe66b17b36eeb98aa78c6e3bb caused issues in some of our HIP projects. Builds were failing because "__bf16" wasn't allowed on the target. This is because in those cases, the main target is AMDGPU (which doesn't have bf16), and the aux target is X86 (which has bf16).

This implements a fix similar to D57369 but for bf16 which prevents Clang from diagnosing uses of bf16 when compiling heterogenous applications.

Diff Detail

Event Timeline

Pierre-vh created this revision.Nov 24 2022, 3:55 AM
Herald added a project: Restricted Project. · View Herald TranscriptNov 24 2022, 3:55 AM
Pierre-vh requested review of this revision.Nov 24 2022, 3:55 AM
Herald added a project: Restricted Project. · View Herald Transcript
Pierre-vh updated this revision to Diff 477734.Nov 24 2022, 3:59 AM

Add newline at end of file

Pierre-vh planned changes to this revision.Nov 24 2022, 5:20 AM

Need to fix a test crash

Pierre-vh updated this revision to Diff 477760.Nov 24 2022, 5:54 AM

Not all targets have bf16 and AuxTarget may not be available all the time so I changed the condition slightly

Fixing condition, adding new test case

tra added a comment.Nov 28 2022, 10:38 AM

Builds were failing because "__bf16" wasn't allowed on the target.

For CUDA/NVPTX we've solved the issue by implementing storage-only support for NVPTX: https://reviews.llvm.org/D136311
It's a bit more work, but I think it would be a better fix long-term for AMDGPU, too.

clang/lib/AST/ASTContext.cpp
2177

Is there a particular reason we're singling out OpenMP here and not HIP/CUDA?

2177

Nit: I'd use if (Target->hasBFloat16Type() && !(getLangOpts().OpenMP && getLangOpts().OpenMPIsDevice))

clang/lib/Sema/SemaType.cpp
1521–1525

CUDA/NVPTX does have __bf16 support since https://reviews.llvm.org/rG0e8a414ab3d330ebb2996ec95d8141618ee0278b

On the other hand, OpenMP is special-cased, but is not mentioned.

clang/test/SemaCUDA/amdgpu-bf16.cu
2

The changes do affect OpenMP, but there are no OpenMP tests. I think we could use some.

tra added a reviewer: yaxunl.Nov 28 2022, 10:39 AM

Builds were failing because "__bf16" wasn't allowed on the target.

For CUDA/NVPTX we've solved the issue by implementing storage-only support for NVPTX: https://reviews.llvm.org/D136311
It's a bit more work, but I think it would be a better fix long-term for AMDGPU, too.

Agree supportting bf16 in backend is a better solution. Limited by resource, overall this patch LGTM.

clang/test/SemaCUDA/amdgpu-bf16.cu
17

missing new line

Pierre-vh marked 5 inline comments as done.
  • Recentering the patch around HIP only.
    • I was using too much from D57369 and was involving OpenMP when there's no reason to. Just checking if HIP is being used should be enough.
tra added inline comments.Nov 30 2022, 9:44 AM
clang/test/SemaCUDA/amdgpu-bf16.cu
9

We should probably also have a case verifying that actual attempt to use __bf16 in device code is still diagnosed.

Pierre-vh marked an inline comment as done.Dec 1 2022, 12:16 AM
Pierre-vh added inline comments.
clang/test/SemaCUDA/amdgpu-bf16.cu
9

Good catch, it's currently no longer diagnosed.
What can I use in ConvertDeclSpecToType to make it diagnose only if the current function is a device function? If I understand correctly, LangOpts are for the whole TU so I can't use that (e.g. CUDAIsDevice), right?

tra added inline comments.Dec 1 2022, 10:39 AM
clang/test/SemaCUDA/amdgpu-bf16.cu
9

I don't have a good answer. That was one of the reasons I ended up implementing __bf16 support in NVPTX. :-)
You may need to use deferred diagnostics, instead of disabling them) and trigger them if we need to codegen anything that uses __bf16.

Pierre-vh planned changes to this revision.Dec 2 2022, 7:51 AM
Pierre-vh marked an inline comment as done.

I'll take a look at handling bf16 storage-only for AMDGPU. Looks like our Backend already handles it and converts it to i16 so maybe it'll be really easy.

Pierre-vh abandoned this revision.Dec 6 2022, 12:25 AM

Added bf16 storage support instead: D139398