diff options
author | Alex Voicu <alexandru.voicu@amd.com> | 2023-10-03 13:29:12 +0100 |
---|---|---|
committer | Alex Voicu <alexandru.voicu@amd.com> | 2023-10-03 13:29:12 +0100 |
commit | 4d680f56475ce17d8fb793655eb3d77ac8aee1b9 (patch) | |
tree | 438f7843ab5a37e2d7805eb8b14c3e46df5710e7 /clang/lib/Sema/SemaCUDA.cpp | |
parent | 5ec9faf007cc2589682cd28a10aa5a351f6aebda (diff) | |
download | llvm-4d680f56475ce17d8fb793655eb3d77ac8aee1b9.zip llvm-4d680f56475ce17d8fb793655eb3d77ac8aee1b9.tar.gz llvm-4d680f56475ce17d8fb793655eb3d77ac8aee1b9.tar.bz2 |
[HIP][Clang][Sema] Add Sema support for `hipstdpar`
This patch adds the Sema changes needed for enabling HIP parallel algorithm offload on AMDGPU targets. This change impacts the CUDA / HIP language specific checks, and only manifests if compiling in `hipstdpar` mode. In this case, we essentially do three things:
1. Allow device side callers to call host side callees - since the user visible HLL would be standard C++, with no annotations / restriction mechanisms, we cannot unambiguously establish that such a call is an error, so we conservatively allow all such calls, deferring actual cleanup to a subsequent pass over IR;
2. Allow host formed lambdas to capture by reference;
3. Allow device functions to use host global variables.
Reviewed by: yaxunl
Differential Revision: https://reviews.llvm.org/D155833
Diffstat (limited to 'clang/lib/Sema/SemaCUDA.cpp')
-rw-r--r-- | clang/lib/Sema/SemaCUDA.cpp | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/clang/lib/Sema/SemaCUDA.cpp b/clang/lib/Sema/SemaCUDA.cpp index 88f5484..3336dbf 100644 --- a/clang/lib/Sema/SemaCUDA.cpp +++ b/clang/lib/Sema/SemaCUDA.cpp @@ -249,6 +249,15 @@ Sema::IdentifyCUDAPreference(const FunctionDecl *Caller, (CallerTarget == CFT_Global && CalleeTarget == CFT_Device)) return CFP_Native; + // HipStdPar mode is special, in that assessing whether a device side call to + // a host target is deferred to a subsequent pass, and cannot unambiguously be + // adjudicated in the AST, hence we optimistically allow them to pass here. + if (getLangOpts().HIPStdPar && + (CallerTarget == CFT_Global || CallerTarget == CFT_Device || + CallerTarget == CFT_HostDevice) && + CalleeTarget == CFT_Host) + return CFP_HostDevice; + // (d) HostDevice behavior depends on compilation mode. if (CallerTarget == CFT_HostDevice) { // It's OK to call a compilation-mode matching function from an HD one. @@ -895,7 +904,7 @@ void Sema::CUDACheckLambdaCapture(CXXMethodDecl *Callee, if (!ShouldCheck || !Capture.isReferenceCapture()) return; auto DiagKind = SemaDiagnosticBuilder::K_Deferred; - if (Capture.isVariableCapture()) { + if (Capture.isVariableCapture() && !getLangOpts().HIPStdPar) { SemaDiagnosticBuilder(DiagKind, Capture.getLocation(), diag::err_capture_bad_target, Callee, *this) << Capture.getVariable(); |