diff options
| author | Tobias Grosser <tobias@grosser.es> | 2016-07-28 06:47:59 +0000 |
|---|---|---|
| committer | Tobias Grosser <tobias@grosser.es> | 2016-07-28 06:47:59 +0000 |
| commit | d8b94bcac1e43a3ccd9a3d94199026e7bfb921eb (patch) | |
| tree | 24b64d65ac948d7d5ff5187ee3aeba9456be2864 | |
| parent | a490147c908272a85285a658850ca47949773b9d (diff) | |
| download | bcm5719-llvm-d8b94bcac1e43a3ccd9a3d94199026e7bfb921eb.tar.gz bcm5719-llvm-d8b94bcac1e43a3ccd9a3d94199026e7bfb921eb.zip | |
GPGPU: Pass context parameters to GPU kernel
llvm-svn: 276963
| -rw-r--r-- | polly/lib/CodeGen/PPCGCodeGeneration.cpp | 18 | ||||
| -rw-r--r-- | polly/test/GPGPU/parametric-loop-bound.ll | 60 |
2 files changed, 78 insertions, 0 deletions
diff --git a/polly/lib/CodeGen/PPCGCodeGeneration.cpp b/polly/lib/CodeGen/PPCGCodeGeneration.cpp index f8cf3b78515..955aaac08b4 100644 --- a/polly/lib/CodeGen/PPCGCodeGeneration.cpp +++ b/polly/lib/CodeGen/PPCGCodeGeneration.cpp @@ -929,6 +929,24 @@ Value *GPUNodeBuilder::createLaunchParameters(ppcg_kernel *Kernel, Index++; } + int NumVars = isl_space_dim(Kernel->space, isl_dim_param); + + for (long i = 0; i < NumVars; i++) { + isl_id *Id = isl_space_get_dim_id(Kernel->space, isl_dim_param, i); + Value *Val = IDToValue[Id]; + isl_id_free(Id); + Instruction *Param = new AllocaInst( + Val->getType(), Launch + "_param_" + std::to_string(Index), + EntryBlock->getTerminator()); + Builder.CreateStore(Val, Param); + Value *Slot = Builder.CreateGEP( + Parameters, {Builder.getInt64(0), Builder.getInt64(Index)}); + Value *ParamTyped = + Builder.CreatePointerCast(Param, Builder.getInt8PtrTy()); + Builder.CreateStore(ParamTyped, Slot); + Index++; + } + auto Location = EntryBlock->getTerminator(); return new BitCastInst(Parameters, Builder.getInt8PtrTy(), Launch + "_params_i8ptr", Location); diff --git a/polly/test/GPGPU/parametric-loop-bound.ll b/polly/test/GPGPU/parametric-loop-bound.ll new file mode 100644 index 00000000000..6ea4951f9b5 --- /dev/null +++ b/polly/test/GPGPU/parametric-loop-bound.ll @@ -0,0 +1,60 @@ +; RUN: opt %loadPolly -polly-codegen-ppcg -polly-acc-dump-code \ +; RUN: -disable-output < %s | \ +; RUN: FileCheck -check-prefix=CODE %s + +; RUN: opt %loadPolly -polly-codegen-ppcg \ +; RUN: -S < %s | \ +; RUN: FileCheck -check-prefix=IR %s +; +; void foo(long A[], long n) { +; for (long i = 0; i < n; i++) +; A[i] += 100; +; } + +; CODE: if (n >= 1) { +; CODE-NEXT: cudaCheckReturn(cudaMemcpy(dev_MemRef_A, MemRef_A, (n) * sizeof(i64), cudaMemcpyHostToDevice)); +; CODE-NEXT: { +; CODE-NEXT: dim3 k0_dimBlock(32); +; CODE-NEXT: dim3 k0_dimGrid(n >= 1048546 ? 32768 : floord(n + 31, 32)); +; CODE-NEXT: kernel0 <<<k0_dimGrid, k0_dimBlock>>> (dev_MemRef_A, n); +; CODE-NEXT: cudaCheckKernel(); +; CODE-NEXT: } + +; CODE: cudaCheckReturn(cudaMemcpy(MemRef_A, dev_MemRef_A, (n) * sizeof(i64), cudaMemcpyDeviceToHost)); +; CODE-NEXT: } + +; CODE: # kernel0 +; CODE-NEXT: for (int c0 = 0; c0 <= (n - 32 * b0 - 1) / 1048576; c0 += 1) +; CODE-NEXT: if (n >= 32 * b0 + t0 + 1048576 * c0 + 1) +; CODE-NEXT: Stmt_bb2(32 * b0 + t0 + 1048576 * c0); + +; IR: store i64 %n, i64* %polly_launch_0_param_1 +; IR-NEXT: %8 = getelementptr [2 x i8*], [2 x i8*]* %polly_launch_0_params, i64 0, i64 1 +; IR-NEXT: %9 = bitcast i64* %polly_launch_0_param_1 to i8* +; IR-NEXT: store i8* %9, i8** %8 + +target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128" + +define void @foo(i64* %A, i64 %n) { +bb: + br label %bb1 + +bb1: ; preds = %bb6, %bb + %i.0 = phi i64 [ 0, %bb ], [ %tmp7, %bb6 ] + %tmp = icmp slt i64 %i.0, %n + br i1 %tmp, label %bb2, label %bb8 + +bb2: ; preds = %bb1 + %tmp3 = getelementptr inbounds i64, i64* %A, i64 %i.0 + %tmp4 = load i64, i64* %tmp3, align 8 + %tmp5 = add nsw i64 %tmp4, 100 + store i64 %tmp5, i64* %tmp3, align 8 + br label %bb6 + +bb6: ; preds = %bb2 + %tmp7 = add nuw nsw i64 %i.0, 1 + br label %bb1 + +bb8: ; preds = %bb1 + ret void +} |

