Skip to content

Commit 25dee65

Browse files
authored
[OpenCL] Disable __opencl_c_ext_fp64_* features if cl_khr_fp64 is not supported (#169252)
Fix kernel build when cl_khr_fp64 is not enabled: opencl-c.h:13785:50: error: unknown type name 'atomic_double' 13785 | double __ovld atomic_fetch_min(volatile __global atomic_double *, double); opencl-c.h:13785:67: error: use of type 'double' requires cl_khr_fp64 and __opencl_c_fp64 support 13785 | double __ovld atomic_fetch_min(volatile __global atomic_double *, double); This is a regression introduced by 423bdb2. Before that commit, __opencl_c_ext_fp64_global_atomic_add was guarded by cl_khr_fp64 in opencl-c-base.h.
1 parent a8a504a commit 25dee65

File tree

4 files changed

+32
-0
lines changed

4 files changed

+32
-0
lines changed

clang/include/clang/Basic/TargetInfo.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1848,6 +1848,9 @@ class TargetInfo : public TransferrableTargetInfo,
18481848
}
18491849
}
18501850

1851+
/// Set features that depend on other features.
1852+
virtual void setDependentOpenCLOpts();
1853+
18511854
/// Get supported OpenCL extensions and optional core features.
18521855
llvm::StringMap<bool> &getSupportedOpenCLOpts() {
18531856
return getTargetOpts().OpenCLFeaturesMap;

clang/lib/Basic/TargetInfo.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -640,6 +640,17 @@ bool TargetInfo::areDefaultedSMFStillPOD(const LangOptions &LangOpts) const {
640640
return LangOpts.getClangABICompat() > LangOptions::ClangABI::Ver15;
641641
}
642642

643+
void TargetInfo::setDependentOpenCLOpts() {
644+
auto &Opts = getSupportedOpenCLOpts();
645+
if (!hasFeatureEnabled(Opts, "cl_khr_fp64") ||
646+
!hasFeatureEnabled(Opts, "__opencl_c_fp64")) {
647+
setFeatureEnabled(Opts, "__opencl_c_ext_fp64_global_atomic_add", false);
648+
setFeatureEnabled(Opts, "__opencl_c_ext_fp64_local_atomic_add", false);
649+
setFeatureEnabled(Opts, "__opencl_c_ext_fp64_global_atomic_min_max", false);
650+
setFeatureEnabled(Opts, "__opencl_c_ext_fp64_local_atomic_min_max", false);
651+
}
652+
}
653+
643654
LangAS TargetInfo::getOpenCLTypeAddrSpace(OpenCLTypeKind TK) const {
644655
switch (TK) {
645656
case OCLTK_Image:

clang/lib/Basic/Targets.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -862,6 +862,7 @@ TargetInfo *TargetInfo::CreateTargetInfo(DiagnosticsEngine &Diags,
862862

863863
Target->setSupportedOpenCLOpts();
864864
Target->setCommandLineOpenCLOpts();
865+
Target->setDependentOpenCLOpts();
865866
Target->setMaxAtomicWidth();
866867

867868
if (!Opts->DarwinTargetVariantTriple.empty())
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// RUN: %clang_cc1 -verify -triple spir-unknown-unknown -cl-std=CL3.0 -cl-ext=-__opencl_c_fp64,-cl_khr_fp64 %s
2+
// RUN: %clang_cc1 -verify -triple spir-unknown-unknown -cl-std=clc++2021 -cl-ext=-__opencl_c_fp64,-cl_khr_fp64 %s
3+
4+
#if __opencl_c_ext_fp64_global_atomic_add != 0
5+
#error "Incorrectly defined __opencl_c_ext_fp64_global_atomic_add"
6+
#endif
7+
#if __opencl_c_ext_fp64_local_atomic_add != 0
8+
#error "Incorrectly defined __opencl_c_ext_fp64_local_atomic_add"
9+
#endif
10+
#if __opencl_c_ext_fp64_global_atomic_min_max != 0
11+
#error "Incorrectly defined __opencl_c_ext_fp64_global_atomic_min_max"
12+
#endif
13+
#if __opencl_c_ext_fp64_local_atomic_min_max != 0
14+
#error "Incorrectly defined __opencl_c_ext_fp64_local_atomic_min_max"
15+
#endif
16+
17+
// expected-no-diagnostics

0 commit comments

Comments
 (0)