[PATCH] D49022: [Polly-ACC] disallow managed memory code generation for OpenCL

Alain Denzler via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Jul 6 06:57:25 PDT 2018


alaindenzler created this revision.
alaindenzler added reviewers: bollu, grosser, philip.pfaffe.
Herald added subscribers: llvm-commits, kbarton, Anastasia, yaxunl, nemanjai.

This patch disables the ManagedMemoryRewrite pass if we are not generating CUDA code. The pass was enabled by default when generating GPU code, which resulted in a failed compilation when only OpenCL was present. Additionally it attempted to rewrite alloc() and free() calls even when the command line flag was set to false, because the cli option did not guard the pass correctly.

Using this patch, the ManagedMemoryRewrite pass is only enabled if both the command line option is set and we are generating ptx code.


Repository:
  rPLO Polly

https://reviews.llvm.org/D49022

Files:
  lib/CodeGen/PPCGCodeGeneration.cpp
  lib/Support/RegisterPasses.cpp


Index: lib/Support/RegisterPasses.cpp
===================================================================
--- lib/Support/RegisterPasses.cpp
+++ lib/Support/RegisterPasses.cpp
@@ -131,6 +131,15 @@
                                         "target SPIR 64-bit architecture")),
                   cl::init(GPUArch::NVPTX64), cl::ZeroOrMore,
                   cl::cat(PollyCategory));
+
+bool polly::PollyManagedMemory;
+static cl::opt<bool, true>
+    XManagedMemory("polly-acc-codegen-managed-memory",
+                   cl::desc("Generate Host kernel code assuming"
+                            " that all memory has been"
+                            " declared as managed memory"),
+                   cl::location(PollyManagedMemory), cl::Hidden,
+                   cl::init(false), cl::ZeroOrMore, cl::cat(PollyCategory));
 #endif
 
 VectorizerChoice polly::PollyVectorizerChoice;
@@ -353,7 +362,8 @@
   if (Target == TARGET_HYBRID) {
     PM.add(
         polly::createPPCGCodeGenerationPass(GPUArchChoice, GPURuntimeChoice));
-    PM.add(polly::createManagedMemoryRewritePassPass(GPUArchChoice,
+    if (PollyManagedMemory && (GPURuntimeChoice == GPURuntime::CUDA))
+      PM.add(polly::createManagedMemoryRewritePassPass(GPUArchChoice,
                                                      GPURuntimeChoice));
   }
 #endif
@@ -385,7 +395,8 @@
   else {
     PM.add(
         polly::createPPCGCodeGenerationPass(GPUArchChoice, GPURuntimeChoice));
-    PM.add(polly::createManagedMemoryRewritePassPass());
+    if (PollyManagedMemory && (GPURuntimeChoice == GPURuntime::CUDA))
+      PM.add(polly::createManagedMemoryRewritePassPass());
   }
 #endif
 
Index: lib/CodeGen/PPCGCodeGeneration.cpp
===================================================================
--- lib/CodeGen/PPCGCodeGeneration.cpp
+++ lib/CodeGen/PPCGCodeGeneration.cpp
@@ -91,15 +91,6 @@
                                    cl::init(false), cl::ZeroOrMore,
                                    cl::cat(PollyCategory));
 
-bool polly::PollyManagedMemory;
-static cl::opt<bool, true>
-    XManagedMemory("polly-acc-codegen-managed-memory",
-                   cl::desc("Generate Host kernel code assuming"
-                            " that all memory has been"
-                            " declared as managed memory"),
-                   cl::location(PollyManagedMemory), cl::Hidden,
-                   cl::init(false), cl::ZeroOrMore, cl::cat(PollyCategory));
-
 static cl::opt<bool>
     FailOnVerifyModuleFailure("polly-acc-fail-on-verify-module-failure",
                               cl::desc("Fail and generate a backtrace if"
@@ -3240,7 +3231,7 @@
       LLVM_DEBUG(dbgs() << getUniqueScopName(S)
                         << " does not have permutable bands. Bailing out\n";);
     } else {
-      const bool CreateTransferToFromDevice = !PollyManagedMemory;
+      const bool CreateTransferToFromDevice = (!PollyManagedMemory || (Runtime == GPURuntime::OpenCL));
       Schedule = map_to_device(PPCGGen, Schedule, CreateTransferToFromDevice);
       PPCGGen->tree = generate_code(PPCGGen, isl_schedule_copy(Schedule));
     }
@@ -3574,6 +3565,9 @@
       return false;
     }
 
+    // only use managed memory if we generate code for a NVPTX device
+    PollyManagedMemory = (PollyManagedMemory && (Architecture == GPUArch::NVPTX64));
+
     auto PPCGScop = createPPCGScop();
     auto PPCGProg = createPPCGProg(PPCGScop);
     auto PPCGGen = generateGPU(PPCGScop, PPCGProg);


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D49022.154396.patch
Type: text/x-patch
Size: 3467 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180706/10ab1cc5/attachment.bin>


More information about the llvm-commits mailing list