[PATCH] D143849: [Clang][OpenCL] Allow pointers in structs as kernel arguments from 2.0

Ayal Zaks via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Sun Feb 12 09:40:50 PST 2023


Ayal created this revision.
Ayal added reviewers: asavonic, Anastasia, yaxunl.
Herald added subscribers: Naghasan, ldrumm.
Herald added a project: All.
Ayal requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Structs that contain global or local pointers can be passed as kernel
arguments starting OpenCL v2.0 which introduces shared virtual memory.

Trying to revive a patch considered in D49723 <https://reviews.llvm.org/D49723>


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D143849

Files:
  clang/lib/Sema/SemaDecl.cpp
  clang/test/SemaOpenCL/invalid-kernel-parameters.cl


Index: clang/test/SemaOpenCL/invalid-kernel-parameters.cl
===================================================================
--- clang/test/SemaOpenCL/invalid-kernel-parameters.cl
+++ clang/test/SemaOpenCL/invalid-kernel-parameters.cl
@@ -87,6 +87,7 @@
 
 
 
+#if __OPENCL_C_VERSION__ <= CL_VERSION_1_2
 typedef struct FooImage2D // expected-note{{within field of type 'FooImage2D' declared here}}
 {
   // TODO: Clean up needed - we don't really need to check for image, event, etc
@@ -96,6 +97,7 @@
 } FooImage2D;
 
 kernel void image_in_struct_arg(FooImage2D arg) { } // expected-error{{struct kernel parameters may not contain pointers}}
+#endif
 
 typedef struct Foo // expected-note{{within field of type 'Foo' declared here}}
 {
@@ -104,6 +106,15 @@
 
 kernel void pointer_in_struct_arg(Foo arg) { } // expected-error{{struct kernel parameters may not contain pointers}}
 
+#if __OPENCL_C_VERSION__ <= CL_VERSION_1_2
+typedef struct FooGlobal // expected-note{{within field of type 'FooGlobal' declared here}}
+{
+  global int* ptrField; // expected-note{{field of illegal pointer type '__global int *' declared here}}
+} FooGlobal;
+
+kernel void global_pointer_in_struct_arg(FooGlobal arg) { } // expected-error{{struct kernel parameters may not contain pointers}}
+#endif
+
 typedef union FooUnion // expected-note{{within field of type 'FooUnion' declared here}}
 {
   int* ptrField; // expected-note-re{{field of illegal pointer type '__{{private|generic}} int *' declared here}}
Index: clang/lib/Sema/SemaDecl.cpp
===================================================================
--- clang/lib/Sema/SemaDecl.cpp
+++ clang/lib/Sema/SemaDecl.cpp
@@ -9489,7 +9489,12 @@
       // OpenCL v1.2 s6.9.p:
       // Arguments to kernel functions that are declared to be a struct or union
       // do not allow OpenCL objects to be passed as elements of the struct or
-      // union.
+      // union. This restriction was lifted in OpenCL v2.0 with the introduction
+      // of SVM.
+      if (S.getLangOpts().getOpenCLCompatibleVersion() > 120 &&
+          (ParamType == PtrKernelParam || ParamType == PtrPtrKernelParam))
+        continue;
+
       if (ParamType == PtrKernelParam || ParamType == PtrPtrKernelParam ||
           ParamType == InvalidAddrSpacePtrKernelParam) {
         S.Diag(Param->getLocation(),


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D143849.496769.patch
Type: text/x-patch
Size: 2326 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20230212/e496596e/attachment.bin>


More information about the cfe-commits mailing list