Skip to content

Commit 5ae6446

Browse files
committed
[mlir][affine] Skip point-wise copy for scalar memref
Point wise copy does not consider scalar typed memref and it does not generate any affine.for on top. It causes segmentation fault. We can skip the point-wise copy in case of scalar memref. Fixes #61167
1 parent 55f2547 commit 5ae6446

File tree

2 files changed

+52
-0
lines changed

2 files changed

+52
-0
lines changed

mlir/lib/Dialect/Affine/Utils/LoopUtils.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2131,6 +2131,9 @@ static LogicalResult generateCopy(
21312131

21322132
if (!copyOptions.generateDma) {
21332133
// Point-wise copy generation.
2134+
// Unable to copy generation for scala memref due to lack of access point.
2135+
if (rank == 0)
2136+
return failure();
21342137
auto copyNest =
21352138
generatePointWiseCopy(loc, memref, fastMemRef, lbMaps,
21362139
/*lbOperands=*/regionSymbols, ubMaps,

mlir/test/Dialect/Affine/affine-data-copy.mlir

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -354,3 +354,52 @@ func.func @arbitrary_memory_space() {
354354
}
355355
return
356356
}
357+
358+
359+
// CHECK-LABEL: func @scalar_memref_copy_without_dma
360+
func.func @scalar_memref_copy_without_dma() {
361+
%false = arith.constant false
362+
%4 = memref.alloc() {alignment = 128 : i64} : memref<i1>
363+
affine.store %false, %4[] : memref<i1>
364+
365+
// CHECK: %[[FALSE:.*]] = arith.constant false
366+
// CHECK: %[[MEMREF:.*]] = memref.alloc() {alignment = 128 : i64} : memref<i1>
367+
// CHECK: affine.store %[[FALSE]], %[[MEMREF]][] : memref<i1>
368+
return
369+
}
370+
371+
// CHECK-LABEL: func @scalar_memref_copy_in_loop
372+
func.func @scalar_memref_copy_in_loop(%3:memref<480xi1>) {
373+
%false = arith.constant false
374+
%4 = memref.alloc() {alignment = 128 : i64} : memref<i1>
375+
affine.store %false, %4[] : memref<i1>
376+
%5 = memref.alloc() {alignment = 128 : i64} : memref<i1>
377+
memref.copy %4, %5 : memref<i1> to memref<i1>
378+
affine.for %arg0 = 0 to 480 {
379+
%11 = affine.load %3[%arg0] : memref<480xi1>
380+
%12 = affine.load %5[] : memref<i1>
381+
%13 = arith.cmpi slt, %11, %12 : i1
382+
%14 = arith.select %13, %11, %12 : i1
383+
affine.store %14, %5[] : memref<i1>
384+
}
385+
386+
// CHECK: %[[FALSE:.*]] = arith.constant false
387+
// CHECK: %[[MEMREF:.*]] = memref.alloc() {alignment = 128 : i64} : memref<i1>
388+
// CHECK: affine.store %[[FALSE]], %[[MEMREF]][] : memref<i1>
389+
// CHECK: %[[TARGET:.*]] = memref.alloc() {alignment = 128 : i64} : memref<i1>
390+
// CHECK: memref.copy %alloc, %[[TARGET]] : memref<i1> to memref<i1>
391+
// CHECK: %[[FAST_MEMREF:.*]] = memref.alloc() : memref<480xi1>
392+
// CHECK: affine.for %{{.*}} = 0 to 480 {
393+
// CHECK: %{{.*}} = affine.load %arg0[%{{.*}}] : memref<480xi1>
394+
// CHECK: affine.store %{{.*}}, %[[FAST_MEMREF]][%{{.*}}] : memref<480xi1>
395+
// CHECK: }
396+
// CHECK: affine.for %arg1 = 0 to 480 {
397+
// CHECK: %[[L0:.*]] = affine.load %[[FAST_MEMREF]][%arg1] : memref<480xi1>
398+
// CHECK: %[[L1:.*]] = affine.load %[[TARGET]][] : memref<i1>
399+
// CHECK: %[[CMPI:.*]] = arith.cmpi slt, %[[L0]], %[[L1]] : i1
400+
// CHECK: %[[SELECT:.*]] = arith.select %[[CMPI]], %[[L0]], %[[L1]] : i1
401+
// CHECK: affine.store %[[SELECT]], %[[TARGET]][] : memref<i1>
402+
// CHECK: }
403+
// CHECK: memref.dealloc %[[FAST_MEMREF]] : memref<480xi1>
404+
return
405+
}

0 commit comments

Comments
 (0)