172 lines · plain
1// RUN: mlir-opt %s -test-parallel-loop-unrolling='unroll-factors=1,2' -split-input-file | FileCheck %s2// RUN: mlir-opt %s -test-parallel-loop-unrolling='unroll-factors=1,2 loop-depth=1' -split-input-file | FileCheck %s --check-prefix CHECK-UNROLL-INNER3// RUN: mlir-opt %s -test-parallel-loop-unrolling='unroll-factors=3,1' -split-input-file | FileCheck %s --check-prefix CHECK-UNROLL-BY-34 5func.func @unroll_simple_parallel_loop(%src: memref<1x16x12xf32>, %dst: memref<1x16x12xf32>) {6 %c12 = arith.constant 12 : index7 %c16 = arith.constant 16 : index8 %c0 = arith.constant 0 : index9 %c1 = arith.constant 1 : index10 scf.parallel (%arg2, %arg3, %arg4) = (%c0, %c0, %c0) to (%c1, %c16, %c12) step (%c1, %c1, %c1) {11 %read = memref.load %src[%arg2, %arg3, %arg4] : memref<1x16x12xf32>12 memref.store %read, %dst[%arg2, %arg3, %arg4] : memref<1x16x12xf32>13 scf.reduce14 }15 return16}17 18// CHECK-LABEL: func @unroll_simple_parallel_loop19// CHECK-SAME: ([[ARG0:%.*]]: memref<1x16x12xf32>, [[ARG1:%.*]]: memref<1x16x12xf32>)20// CHECK-DAG: [[C0:%.*]] = arith.constant 0 : index21// CHECK-DAG: [[C1:%.*]] = arith.constant 1 : index22// CHECK-DAG: [[C2:%.*]] = arith.constant 2 : index23// CHECK-DAG: [[C12:%.*]] = arith.constant 12 : index24// CHECK-DAG: [[C16:%.*]] = arith.constant 16 : index25// CHECK: scf.parallel ([[IV0:%.*]], [[IV1:%.*]], [[IV2:%.*]]) = ([[C0]], [[C0]], [[C0]]) to ([[C1]], [[C16]], [[C12]]) step ([[C1]], [[C1]], [[C2]])26// CHECK: [[LOADED1:%.*]] = memref.load [[ARG0]][[[IV0]], [[IV1]], [[IV2]]] : memref<1x16x12xf32>27// CHECK: memref.store [[LOADED1]], [[ARG1]][[[IV0]], [[IV1]], [[IV2]]] : memref<1x16x12xf32>28// CHECK: [[UNR_IV2:%.*]] = affine.apply {{.*}}([[IV2]])29// CHECK: [[LOADED2:%.*]] = memref.load [[ARG0]][[[IV0]], [[IV1]], [[UNR_IV2]]] : memref<1x16x12xf32>30// CHECK: memref.store [[LOADED2]], [[ARG1]][[[IV0]], [[IV1]], [[UNR_IV2]]] : memref<1x16x12xf32>31 32// -----33 34func.func @negative_unroll_factors_dont_divide_evenly(%src: memref<1x16x12xf32>, %dst: memref<1x16x12xf32>) {35 %c12 = arith.constant 12 : index36 %c16 = arith.constant 16 : index37 %c0 = arith.constant 0 : index38 %c1 = arith.constant 1 : index39 scf.parallel (%arg2, %arg3, %arg4) = (%c0, %c0, %c0) to (%c1, %c16, %c12) step (%c1, %c1, %c1) {40 %read = memref.load %src[%arg2, %arg3, %arg4] : memref<1x16x12xf32>41 memref.store %read, %dst[%arg2, %arg3, %arg4] : memref<1x16x12xf32>42 scf.reduce43 }44 return45}46 47// CHECK-UNROLL-BY-3-LABEL: func @negative_unroll_factors_dont_divide_evenly48// CHECK-UNROLL-BY-3-SAME: ([[ARG0:%.*]]: memref<1x16x12xf32>, [[ARG1:%.*]]: memref<1x16x12xf32>)49// CHECK-UNROLL-BY-3: [[C1:%.*]] = arith.constant 1 : index50// CHECK-UNROLL-BY-3: scf.parallel ([[IV0:%.*]], [[IV1:%.*]], [[IV2:%.*]]) = {{.*}} step ([[C1]], [[C1]], [[C1]])51// CHECK-UNROLL-BY-3: [[LOADED:%.*]] = memref.load [[ARG0]][[[IV0]], [[IV1]], [[IV2]]] : memref<1x16x12xf32>52// CHECK-UNROLL-BY-3: memref.store [[LOADED]], [[ARG1]][[[IV0]], [[IV1]], [[IV2]]] : memref<1x16x12xf32>53// CHECK-UNROLL-BY-3-NOT: affine.apply54// CHECK-UNROLL-BY-3-NOT: memref.load55// CHECK-UNROLL-BY-3-NOT: memref.store56 57// -----58 59func.func @unroll_outer_nested_parallel_loop(%src: memref<5x16x12x4x4xf32>, %dst: memref<5x16x12x4x4xf32>) {60 %c4 = arith.constant 4 : index61 %c12 = arith.constant 12 : index62 %c16 = arith.constant 16 : index63 %c5 = arith.constant 5 : index64 %c0 = arith.constant 0 : index65 %c1 = arith.constant 1 : index66 scf.parallel (%arg3, %arg4, %arg5) = (%c0, %c0, %c0) to (%c5, %c16, %c12) step (%c1, %c1, %c1) {67 scf.parallel (%arg6, %arg7) = (%c0, %c0) to (%c4, %c4) step (%c1, %c1) {68 %0 = affine.apply affine_map<(d0, d1) -> (d0 + (d1 floordiv 4) * 4)>(%arg4, %arg6)69 %1 = affine.apply affine_map<(d0, d1) -> (d0 + (d1 floordiv 4) * 4)>(%arg5, %arg7)70 %subv_in = memref.subview %src[%arg3, %0, %1, 0, 0] [1, 1, 1, 4, 4] [1, 1, 1, 1, 1] : memref<5x16x12x4x4xf32> to memref<4x4xf32, strided<[4, 1], offset: ?>>71 %subv_out = memref.subview %dst[%arg3, %0, %1, 0, 0] [1, 1, 1, 4, 4] [1, 1, 1, 1, 1] : memref<5x16x12x4x4xf32> to memref<4x4xf32, strided<[4, 1], offset: ?>>72 linalg.erf ins(%subv_in : memref<4x4xf32, strided<[4, 1], offset: ?>>) outs(%subv_out : memref<4x4xf32, strided<[4, 1], offset: ?>>)73 scf.reduce74 }75 scf.reduce76 }77 return78}79 80// CHECK-UNROLL-BY-3-LABEL: func @unroll_outer_nested_parallel_loop81// CHECK-LABEL: func @unroll_outer_nested_parallel_loop82// CHECK-SAME: ([[ARG0:%.*]]: memref<5x16x12x4x4xf32>, [[ARG1:%.*]]: memref<5x16x12x4x4xf32>)83// CHECK-DAG: [[C0:%.*]] = arith.constant 0 : index84// CHECK-DAG: [[C1:%.*]] = arith.constant 1 : index85// CHECK-DAG: [[C2:%.*]] = arith.constant 2 : index86// CHECK-DAG: [[C4:%.*]] = arith.constant 4 : index87// CHECK-DAG: [[C5:%.*]] = arith.constant 5 : index88// CHECK-DAG: [[C12:%.*]] = arith.constant 12 : index89// CHECK-DAG: [[C16:%.*]] = arith.constant 16 : index90// CHECK: scf.parallel ([[OUTV0:%.*]], [[OUTV1:%.*]], [[OUTV2:%.*]]) = ([[C0]], [[C0]], [[C0]]) to ([[C5]], [[C16]], [[C12]]) step ([[C1]], [[C1]], [[C2]])91// CHECK: scf.parallel ([[INV0:%.*]], [[INV1:%.*]]) = ([[C0]], [[C0]]) to ([[C4]], [[C4]]) step ([[C1]], [[C1]])92// CHECK: affine.apply {{.*}}([[OUTV1]], [[INV0]])93// CHECK: affine.apply {{.*}}([[OUTV2]], [[INV1]])94// CHECK: linalg.erf95 96// CHECK: [[UNR_OUTV2:%.*]] = affine.apply {{.*}}([[OUTV2]])97// CHECK: scf.parallel ([[INV0B:%.*]], [[INV1B:%.*]]) = ([[C0]], [[C0]]) to ([[C4]], [[C4]]) step ([[C1]], [[C1]])98// CHECK: affine.apply {{.*}}([[OUTV1]], [[INV0B]])99// CHECK: affine.apply {{.*}}([[UNR_OUTV2]], [[INV1B]])100// CHECK: linalg.erf101 102// -----103 104func.func @negative_unroll_dynamic_parallel_loop(%src: memref<1x16x12xf32>, %dst: memref<1x16x12xf32>, %ub3: index) {105 %c12 = arith.constant 12 : index106 %c16 = arith.constant 16 : index107 %c0 = arith.constant 0 : index108 %c1 = arith.constant 1 : index109 scf.parallel (%arg2, %arg3, %arg4) = (%c0, %c0, %c0) to (%c1, %c16, %ub3) step (%c1, %c1, %c1) {110 %read = memref.load %src[%arg2, %arg3, %arg4] : memref<1x16x12xf32>111 memref.store %read, %dst[%arg2, %arg3, %arg4] : memref<1x16x12xf32>112 scf.reduce113 }114 return115}116 117// CHECK-LABEL: func @negative_unroll_dynamic_parallel_loop118// CHECK-SAME: ([[ARG0:%.*]]: memref<1x16x12xf32>, [[ARG1:%.*]]: memref<1x16x12xf32>, [[UB3:%.*]]: index)119// CHECK-DAG: [[C0:%.*]] = arith.constant 0 : index120// CHECK-DAG: [[C1:%.*]] = arith.constant 1 : index121// CHECK-DAG: [[C16:%.*]] = arith.constant 16 : index122// CHECK: scf.parallel ([[IV0:%.*]], [[IV1:%.*]], [[IV2:%.*]]) = ([[C0]], [[C0]], [[C0]]) to ([[C1]], [[C16]], [[UB3]]) step ([[C1]], [[C1]], [[C1]])123// CHECK: [[LOADED:%.*]] = memref.load [[ARG0]][[[IV0]], [[IV1]], [[IV2]]] : memref<1x16x12xf32>124// CHECK: memref.store [[LOADED]], [[ARG1]][[[IV0]], [[IV1]], [[IV2]]] : memref<1x16x12xf32>125// CHECK-NOT: affine.apply126// CHECK-NOT: memref.load127// CHECK-NOT: memref.store128 129// -----130 131func.func @unroll_inner_nested_parallel_loop(%src: memref<5x16x12x4x4xf32>, %dst: memref<5x16x12x4x4xf32>) {132 %c4 = arith.constant 4 : index133 %c12 = arith.constant 12 : index134 %c16 = arith.constant 16 : index135 %c5 = arith.constant 5 : index136 %c0 = arith.constant 0 : index137 %c1 = arith.constant 1 : index138 scf.parallel (%arg3, %arg4, %arg5) = (%c0, %c0, %c0) to (%c5, %c16, %c12) step (%c1, %c1, %c1) {139 scf.parallel (%arg6, %arg7) = (%c0, %c0) to (%c4, %c4) step (%c1, %c1) {140 %0 = affine.apply affine_map<(d0, d1) -> (d0 + (d1 floordiv 4) * 4)>(%arg4, %arg6)141 %1 = affine.apply affine_map<(d0, d1) -> (d0 + (d1 floordiv 4) * 4)>(%arg5, %arg7)142 %subv_in = memref.subview %src[%arg3, %0, %1, 0, 0] [1, 1, 1, 4, 4] [1, 1, 1, 1, 1] : memref<5x16x12x4x4xf32> to memref<4x4xf32, strided<[4, 1], offset: ?>>143 %subv_out = memref.subview %dst[%arg3, %0, %1, 0, 0] [1, 1, 1, 4, 4] [1, 1, 1, 1, 1] : memref<5x16x12x4x4xf32> to memref<4x4xf32, strided<[4, 1], offset: ?>>144 linalg.erf ins(%subv_in : memref<4x4xf32, strided<[4, 1], offset: ?>>) outs(%subv_out : memref<4x4xf32, strided<[4, 1], offset: ?>>)145 scf.reduce146 }147 scf.reduce148 }149 return150}151 152// CHECK-LABEL: func @unroll_inner_nested_parallel_loop153// CHECK-UNROLL-INNER-LABEL: func @unroll_inner_nested_parallel_loop154// CHECK-UNROLL-INNER-SAME: ([[ARG0:%.*]]: memref<5x16x12x4x4xf32>, [[ARG1:%.*]]: memref<5x16x12x4x4xf32>)155// CHECK-UNROLL-INNER-DAG: [[C0:%.*]] = arith.constant 0 : index156// CHECK-UNROLL-INNER-DAG: [[C1:%.*]] = arith.constant 1 : index157// CHECK-UNROLL-INNER-DAG: [[C4:%.*]] = arith.constant 4 : index158// CHECK-UNROLL-INNER-DAG: [[C5:%.*]] = arith.constant 5 : index159// CHECK-UNROLL-INNER-DAG: [[C12:%.*]] = arith.constant 12 : index160// CHECK-UNROLL-INNER-DAG: [[C16:%.*]] = arith.constant 16 : index161// CHECK-UNROLL-INNER: scf.parallel ([[OUTV0:%.*]], [[OUTV1:%.*]], [[OUTV2:%.*]]) = ([[C0]], [[C0]], [[C0]]) to ([[C5]], [[C16]], [[C12]]) step ([[C1]], [[C1]], [[C1]])162// CHECK-UNROLL-INNER-DAG: [[C2:%.*]] = arith.constant 2 : index163// CHECK-UNROLL-INNER: scf.parallel ([[INV0:%.*]], [[INV1:%.*]]) = ([[C0]], [[C0]]) to ([[C4]], [[C4]]) step ([[C1]], [[C2]])164// CHECK-UNROLL-INNER: affine.apply {{.*}}([[OUTV1]], [[INV0]])165// CHECK-UNROLL-INNER: affine.apply {{.*}}([[OUTV2]], [[INV1]])166// CHECK-UNROLL-INNER: linalg.erf167 168// CHECK-UNROLL-INNER: [[UNR_INV1:%.*]] = affine.apply {{.*}}([[INV1]])169// CHECK-UNROLL-INNER: affine.apply {{.*}}([[OUTV1]], [[INV0]])170// CHECK-UNROLL-INNER: affine.apply {{.*}}([[OUTV2]], [[UNR_INV1]])171// CHECK-UNROLL-INNER: linalg.erf172