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 - 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 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); 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 + 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