[PATCH] D107718: [cuda] Mark builtin texture/surface reference variable as 'externally_initialized'.

Michael Liao via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Sun Aug 8 10:14:34 PDT 2021


hliao created this revision.
hliao added reviewers: tra, yaxunl.
Herald added a reviewer: a.sidorin.
hliao requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

- They need to be preserved even if there's no reference within the device code as the host code may need to initialize them based on the application logic.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D107718

Files:
  clang/lib/CodeGen/CodeGenModule.cpp
  clang/test/CodeGenCUDA/surface.cu
  clang/test/CodeGenCUDA/texture.cu


Index: clang/test/CodeGenCUDA/texture.cu
===================================================================
--- clang/test/CodeGenCUDA/texture.cu
+++ clang/test/CodeGenCUDA/texture.cu
@@ -19,8 +19,8 @@
 };
 
 // On the device side, texture references are represented as `i64` handles.
-// DEVICE: @tex ={{.*}} addrspace(1) global i64 undef, align 4
-// DEVICE: @norm ={{.*}} addrspace(1) global i64 undef, align 4
+// DEVICE: @tex ={{.*}} addrspace(1) externally_initialized global i64 undef, align 4
+// DEVICE: @norm ={{.*}} addrspace(1) externally_initialized global i64 undef, align 4
 // On the host side, they remain in the original type.
 // HOST: @tex = internal global %struct.texture
 // HOST: @norm = internal global %struct.texture
Index: clang/test/CodeGenCUDA/surface.cu
===================================================================
--- clang/test/CodeGenCUDA/surface.cu
+++ clang/test/CodeGenCUDA/surface.cu
@@ -19,7 +19,7 @@
 };
 
 // On the device side, surface references are represented as `i64` handles.
-// DEVICE: @surf ={{.*}} addrspace(1) global i64 undef, align 4
+// DEVICE: @surf ={{.*}} addrspace(1) externally_initialized global i64 undef, align 4
 // On the host side, they remain in the original type.
 // HOST: @surf = internal global %struct.surface
 // HOST: @0 = private unnamed_addr constant [5 x i8] c"surf\00"
Index: clang/lib/CodeGen/CodeGenModule.cpp
===================================================================
--- clang/lib/CodeGen/CodeGenModule.cpp
+++ clang/lib/CodeGen/CodeGenModule.cpp
@@ -4438,7 +4438,9 @@
   if (GV && LangOpts.CUDA) {
     if (LangOpts.CUDAIsDevice) {
       if (Linkage != llvm::GlobalValue::InternalLinkage &&
-          (D->hasAttr<CUDADeviceAttr>() || D->hasAttr<CUDAConstantAttr>()))
+          (D->hasAttr<CUDADeviceAttr>() || D->hasAttr<CUDAConstantAttr>() ||
+           D->getType()->isCUDADeviceBuiltinSurfaceType() ||
+           D->getType()->isCUDADeviceBuiltinTextureType()))
         GV->setExternallyInitialized(true);
     } else {
       getCUDARuntime().internalizeDeviceSideVar(D, Linkage);


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D107718.365034.patch
Type: text/x-patch
Size: 2091 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20210808/31cec09c/attachment.bin>


More information about the cfe-commits mailing list