Skip to content

Conversation

arsenm
Copy link
Contributor

@arsenm arsenm commented Sep 26, 2025

Report __opencl_c_program_scope_global_variables and
__opencl_c_device_enqueue as supported. These 2.0 features are
supported but were missing from the extension map.

__opencl_c_atomic_scope_all_devices should also be reported, but
that seems to not just work by adding it to the map for some
reason.

The existing test for these macros was also broken, since it was
missing CL3.0 run lines, so add those.

Report __opencl_c_program_scope_global_variables and
__opencl_c_device_enqueue as supported. These 2.0 features are
supported but were missing from the extension map.

__opencl_c_atomic_scope_all_devices should also be reported, but
that seems to not just work by adding it to the map for some
reason.

The existing test for these macros was also broken, since it was
missing CL3.0 run lines, so add those.
Copy link
Contributor Author

arsenm commented Sep 26, 2025

This stack of pull requests is managed by Graphite. Learn more about stacking.

@arsenm arsenm marked this pull request as ready for review September 26, 2025 08:14
@llvmbot
Copy link
Member

llvmbot commented Sep 26, 2025

@llvm/pr-subscribers-clang

@llvm/pr-subscribers-backend-amdgpu

Author: Matt Arsenault (arsenm)

Changes

Report __opencl_c_program_scope_global_variables and
__opencl_c_device_enqueue as supported. These 2.0 features are
supported but were missing from the extension map.

__opencl_c_atomic_scope_all_devices should also be reported, but
that seems to not just work by adding it to the map for some
reason.

The existing test for these macros was also broken, since it was
missing CL3.0 run lines, so add those.


Full diff: https://github.com/llvm/llvm-project/pull/160826.diff

2 Files Affected:

  • (modified) clang/lib/Basic/Targets/AMDGPU.h (+5-2)
  • (modified) clang/test/Misc/amdgcn.languageOptsOpenCL.cl (+29-5)
diff --git a/clang/lib/Basic/Targets/AMDGPU.h b/clang/lib/Basic/Targets/AMDGPU.h
index 552698a680d3e..dfcc79402257a 100644
--- a/clang/lib/Basic/Targets/AMDGPU.h
+++ b/clang/lib/Basic/Targets/AMDGPU.h
@@ -319,9 +319,12 @@ class LLVM_LIBRARY_VISIBILITY AMDGPUTargetInfo final : public TargetInfo {
       Opts["__opencl_c_images"] = true;
       Opts["__opencl_c_3d_image_writes"] = true;
       Opts["cl_khr_3d_image_writes"] = true;
+      Opts["__opencl_c_program_scope_global_variables"] = true;
 
-      Opts["__opencl_c_generic_address_space"] =
-          GPUKind >= llvm::AMDGPU::GK_GFX700;
+      if (GPUKind >= llvm::AMDGPU::GK_GFX700) {
+        Opts["__opencl_c_generic_address_space"] = true;
+        Opts["__opencl_c_device_enqueue"] = true;
+      }
     }
   }
 
diff --git a/clang/test/Misc/amdgcn.languageOptsOpenCL.cl b/clang/test/Misc/amdgcn.languageOptsOpenCL.cl
index 50c78d70b83d9..e09cfd08d9f6a 100644
--- a/clang/test/Misc/amdgcn.languageOptsOpenCL.cl
+++ b/clang/test/Misc/amdgcn.languageOptsOpenCL.cl
@@ -8,6 +8,9 @@
 // RUN: %clang_cc1 -x cl -cl-std=CL1.2 %s -verify -triple amdgcn-unknown-unknown -Wpedantic-core-features -DTEST_CORE_FEATURES
 // RUN: %clang_cc1 -x cl -cl-std=CL2.0 %s -verify -triple amdgcn-unknown-unknown -Wpedantic-core-features -DTEST_CORE_FEATURES
 
+// RUN: %clang_cc1 -x cl -cl-std=CL3.0 %s -verify -triple amdgcn-unknown-unknown -Wpedantic-core-features -DTEST_CORE_FEATURES
+// RUN: %clang_cc1 -x cl -cl-std=CL3.0 %s -verify -triple amdgcn-unknown-unknown -target-cpu gfx700 -Wpedantic-core-features -DTEST_CORE_FEATURES -DFLAT_SUPPORT
+
 // Extensions in all versions
 #ifndef cl_clang_storage_class_specifiers
 #error "Missing cl_clang_storage_class_specifiers define"
@@ -156,10 +159,31 @@
 #pragma OPENCL EXTENSION cl_amd_media_ops2: enable
 
 #if (__OPENCL_C_VERSION__ >= 300)
-#ifndef __opencl_c_generic_address_space
-#error "Missing __opencl_c_generic_address_space define"
-#else
-#error "Incorrect __opencl_c_generic_address_space define"
+  #ifndef __opencl_c_program_scope_global_variables
+    #error "Missing __opencl_c_program_scope_global_variables define"
+  #endif
 #endif
-#pragma OPENCL EXTENSION __opencl_c_generic_address_space: enable
+
+#if (__OPENCL_C_VERSION__ >= 300)
+  #ifdef FLAT_SUPPORT
+    #ifndef __opencl_c_generic_address_space
+      #error "Missing __opencl_c_generic_address_space define"
+    #endif
+  #else
+    #ifdef __opencl_c_generic_address_space
+      #error "Incorrect __opencl_c_atomic_scope_all_devices define"
+    #endif
+  #endif
+#endif
+
+#if (__OPENCL_C_VERSION__ >= 300)
+  #ifdef FLAT_SUPPORT
+    #ifndef __opencl_c_device_enqueue
+      #error "Missing __opencl_c_device_enqueue define"
+    #endif
+  #else
+    #ifdef __opencl_c_device_enqueue
+      #error "Incorrect __opencl_c_device_enqueue define"
+    #endif
+  #endif
 #endif

@llvmbot llvmbot added clang Clang issues not falling into any other category clang:frontend Language frontend issues, e.g. anything involving "Sema" labels Sep 26, 2025
@arsenm
Copy link
Contributor Author

arsenm commented Oct 1, 2025

ping

@arsenm
Copy link
Contributor Author

arsenm commented Oct 6, 2025

ping

@arsenm arsenm merged commit 9194703 into main Oct 6, 2025
9 checks passed
@arsenm arsenm deleted the users/arsenm/clang/amdgpu-add-missing-cl-extensions branch October 6, 2025 14:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backend:AMDGPU clang:frontend Language frontend issues, e.g. anything involving "Sema" clang Clang issues not falling into any other category OpenCL
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants