[PATCH] D73685: Fix conversion of loops to GPU with no block/thread dimensions.
Stephan Herhut via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Fri Jan 31 02:16:30 PST 2020
This revision was automatically updated to reflect the committed changes.
Closed by commit rG84695dd4d788: Fix conversion of loops to GPU with no block/thread dimensions. (authored by herhut).
Herald added a subscriber: Joonsoo.
Changed prior to commit:
https://reviews.llvm.org/D73685?vs=241381&id=241661#toc
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D73685/new/
https://reviews.llvm.org/D73685
Files:
mlir/lib/Conversion/LoopsToGPU/LoopsToGPU.cpp
mlir/test/Conversion/LoopsToGPU/no_blocks_no_threads.mlir
Index: mlir/test/Conversion/LoopsToGPU/no_blocks_no_threads.mlir
===================================================================
--- /dev/null
+++ mlir/test/Conversion/LoopsToGPU/no_blocks_no_threads.mlir
@@ -0,0 +1,34 @@
+// RUN: mlir-opt -convert-loops-to-gpu -gpu-block-dims=0 -gpu-thread-dims=1 %s | FileCheck --check-prefix=CHECK-THREADS %s --dump-input-on-failure
+// RUN: mlir-opt -convert-loops-to-gpu -gpu-block-dims=1 -gpu-thread-dims=0 %s | FileCheck --check-prefix=CHECK-BLOCKS %s --dump-input-on-failure
+
+// CHECK-THREADS-LABEL: @one_d_loop
+// CHECK-BLOCKS-LABEL: @one_d_loop
+func @one_d_loop(%A : memref<?xf32>, %B : memref<?xf32>) {
+ // Bounds of the loop, its range and step.
+ // CHECK-THREADS-NEXT: %{{.*}} = constant 0 : index
+ // CHECK-THREADS-NEXT: %{{.*}} = constant 42 : index
+ // CHECK-THREADS-NEXT: %[[BOUND:.*]] = subi %{{.*}}, %{{.*}} : index
+ // CHECK-THREADS-NEXT: %{{.*}} = constant 1 : index
+ // CHECK-THREADS-NEXT: %[[ONE:.*]] = constant 1 : index
+ //
+ // CHECK-BLOCKS-NEXT: %{{.*}} = constant 0 : index
+ // CHECK-BLOCKS-NEXT: %{{.*}} = constant 42 : index
+ // CHECK-BLOCKS-NEXT: %[[BOUND:.*]] = subi %{{.*}}, %{{.*}} : index
+ // CHECK-BLOCKS-NEXT: %{{.*}} = constant 1 : index
+ // CHECK-BLOCKS-NEXT: %[[ONE:.*]] = constant 1 : index
+
+ // CHECK-THREADS-NEXT: gpu.launch blocks(%[[B0:.*]], %[[B1:.*]], %[[B2:.*]]) in (%{{.*}} = %[[ONE]], %{{.*}} = %[[ONE]], %{{.*}}0 = %[[ONE]]) threads(%[[T0:.*]], %[[T1:.*]], %[[T2:.*]]) in (%{{.*}} = %[[BOUND]], %{{.*}} = %[[ONE]], %{{.*}} = %[[ONE]])
+ // CHECK-BLOCKS-NEXT: gpu.launch blocks(%[[B0:.*]], %[[B1:.*]], %[[B2:.*]]) in (%{{.*}} = %[[BOUND]], %{{.*}} = %[[ONE]], %{{.*}}0 = %[[ONE]]) threads(%[[T0:.*]], %[[T1:.*]], %[[T2:.*]]) in (%{{.*}} = %[[ONE]], %{{.*}} = %[[ONE]], %{{.*}} = %[[ONE]])
+ affine.for %i = 0 to 42 {
+ // CHECK-THREADS-NEXT: %[[INDEX:.*]] = addi %{{.*}}, %[[T0]]
+ // CHECK-THREADS-NEXT: load %{{.*}}[%[[INDEX]]]
+ // CHECK-BLOCKS-NEXT: %[[INDEX:.*]] = addi %{{.*}}, %[[B0]]
+ // CHECK-BLOCKS-NEXT: load %{{.*}}[%[[INDEX]]]
+ %0 = load %A[%i] : memref<?xf32>
+ store %0, %B[%i] : memref<?xf32>
+ // CHECK-THREADS: gpu.terminator
+ // CHECK-BLOCKS: gpu.terminator
+ }
+ return
+}
+
Index: mlir/lib/Conversion/LoopsToGPU/LoopsToGPU.cpp
===================================================================
--- mlir/lib/Conversion/LoopsToGPU/LoopsToGPU.cpp
+++ mlir/lib/Conversion/LoopsToGPU/LoopsToGPU.cpp
@@ -403,10 +403,10 @@
Value constOne = (numBlockDims < 3 || numThreadDims < 3)
? builder.create<ConstantIndexOp>(rootForOp.getLoc(), 1)
: nullptr;
- Value gridSizeX = dims[0];
+ Value gridSizeX = numBlockDims > 0 ? dims[0] : constOne;
Value gridSizeY = numBlockDims > 1 ? dims[1] : constOne;
Value gridSizeZ = numBlockDims > 2 ? dims[2] : constOne;
- Value blockSizeX = dims[numBlockDims];
+ Value blockSizeX = numThreadDims > 0 ? dims[numBlockDims] : constOne;
Value blockSizeY = numThreadDims > 1 ? dims[numBlockDims + 1] : constOne;
Value blockSizeZ = numThreadDims > 2 ? dims[numBlockDims + 2] : constOne;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D73685.241661.patch
Type: text/x-patch
Size: 3136 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200131/c80b6501/attachment.bin>
More information about the llvm-commits
mailing list