Skip to content

Commit 802c940

Browse files
committed
add tests
1 parent e8173c7 commit 802c940

File tree

4 files changed

+18
-7
lines changed

4 files changed

+18
-7
lines changed

mlir/include/mlir/Dialect/Bufferization/TransformOps/BufferizationTransformOps.td

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ def OneShotBufferizeOp
8888
DefaultValuedAttr<BoolAttr, "false">:$dump_alias_sets,
8989
DefaultValuedAttr<BoolAttr, "false">:$test_analysis_only,
9090
DefaultValuedAttr<BoolAttr, "false">:$print_conflicts,
91+
DefaultValuedAttr<BoolAttr, "true">:$check_parallel_regions,
9192
DefaultValuedAttr<StrAttr, "\"memref.copy\"">:$memcpy_op);
9293

9394
let results = (outs TransformHandleTypeInterface:$transformed);

mlir/include/mlir/Dialect/Bufferization/Transforms/Passes.td

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -498,6 +498,8 @@ def OneShotBufferize : Pass<"one-shot-bufferize", "ModuleOp"> {
498498
Option<"bufferizeFunctionBoundaries", "bufferize-function-boundaries",
499499
"bool", /*default=*/"0",
500500
"Bufferize function boundaries (experimental).">,
501+
Option<"checkParallelRegions", "check-parallel-regions", "bool",
502+
/*default=*/"true", "Account for parallel regions in RaW analysis.">,
501503
Option<"copyBeforeWrite", "copy-before-write", "bool", /*default=*/"false",
502504
"Skip the analysis. Make a buffer copy on every write.">,
503505
ListOption<"dialectFilter", "dialect-filter", "std::string",

mlir/lib/Dialect/Bufferization/Transforms/Bufferize.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,7 @@ struct OneShotBufferizePass
226226
opt.printConflicts = printConflicts;
227227
opt.testAnalysisOnly = testAnalysisOnly;
228228
opt.bufferizeFunctionBoundaries = bufferizeFunctionBoundaries;
229+
opt.checkParallelRegions = checkParallelRegions;
229230
opt.noAnalysisFuncFilter = noAnalysisFuncFilter;
230231

231232
// Configure type converter.

mlir/test/Dialect/SCF/one-shot-bufferize-analysis.mlir

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
// RUN: mlir-opt %s -one-shot-bufferize="allow-return-allocs-from-loops bufferize-function-boundaries test-analysis-only" -split-input-file | FileCheck %s
1+
// RUN: mlir-opt %s -one-shot-bufferize="allow-return-allocs-from-loops bufferize-function-boundaries test-analysis-only" -split-input-file | FileCheck %s --check-prefixes=CHECK,PARALLEL-CHECK
2+
// RUN: mlir-opt %s -one-shot-bufferize="allow-return-allocs-from-loops bufferize-function-boundaries test-analysis-only check-parallel-regions=false" -split-input-file | FileCheck %s --check-prefixes=CHECK,NO-PARALLEL-CHECK
23

34
// Run fuzzer with different seeds.
45
// RUN: mlir-opt %s -one-shot-bufferize="allow-return-allocs-from-loops bufferize-function-boundaries test-analysis-only analysis-heuristic=fuzzer analysis-fuzzer-seed=23" -split-input-file -o /dev/null
@@ -811,8 +812,10 @@ func.func @parallel_region() -> tensor<320xf32>
811812
%0 = scf.forall (%arg0) in (%c320) shared_outs(%arg1 = %alloc0) -> (tensor<320xf32>) {
812813
%val = "test.foo"() : () -> (f32)
813814
// linalg.fill must bufferize out-of-place because every thread needs a
814-
// private copy of %alloc1.
815-
// CHECK: linalg.fill {__inplace_operands_attr__ = ["none", "false"]}
815+
// private copy of %alloc1. If not accounting for parallel regions, the fill
816+
// can bufferize in place.
817+
// PARALLEL-CHECK: linalg.fill {__inplace_operands_attr__ = ["none", "false"]}
818+
// NO-PARALLEL-CHECK: linalg.fill {__inplace_operands_attr__ = ["none", "true"]}
816819
%fill = linalg.fill ins(%val : f32) outs(%alloc1 : tensor<1xf32>) -> tensor<1xf32>
817820
scf.forall.in_parallel {
818821
// CHECK: tensor.parallel_insert_slice {{.*}} {__inplace_operands_attr__ = ["true", "true", "none"]}
@@ -841,8 +844,10 @@ func.func @parallel_region_mixed_def(%c: i1) -> tensor<320xf32>
841844
}
842845
%val = "test.foo"() : () -> (f32)
843846
// linalg.fill must bufferize out-of-place because every thread needs a
844-
// private copy of %alloc1.
845-
// CHECK: linalg.fill {__inplace_operands_attr__ = ["none", "false"]}
847+
// private copy of %alloc1. If not accounting for parallel regions, the fill
848+
// can bufferize in place.
849+
// PARALLEL-CHECK: linalg.fill {__inplace_operands_attr__ = ["none", "false"]}
850+
// NO-PARALLEL-CHECK: linalg.fill {__inplace_operands_attr__ = ["none", "true"]}
846851
%fill = linalg.fill ins(%val : f32) outs(%selected : tensor<1xf32>) -> tensor<1xf32>
847852
scf.forall.in_parallel {
848853
// CHECK: tensor.parallel_insert_slice {{.*}} {__inplace_operands_attr__ = ["true", "true", "none"]}
@@ -866,8 +871,10 @@ func.func @parallel_region_two_writes(%f: f32) -> tensor<320xf32>
866871
%0 = scf.forall (%arg0) in (%c320) shared_outs(%arg1 = %alloc0) -> (tensor<320xf32>) {
867872
%val = "test.foo"() : () -> (f32)
868873
// linalg.fill must bufferize out-of-place because every thread needs a
869-
// private copy of %alloc1.
870-
// CHECK: linalg.fill {__inplace_operands_attr__ = ["none", "false"]}
874+
// private copy of %alloc1. If not accounting for parallel regions, the fill
875+
// can bufferize in place.
876+
// PARALLEL-CHECK: linalg.fill {__inplace_operands_attr__ = ["none", "false"]}
877+
// NO-PARALLEL-CHECK: linalg.fill {__inplace_operands_attr__ = ["none", "true"]}
871878
%fill = linalg.fill ins(%val : f32) outs(%alloc1 : tensor<1xf32>) -> tensor<1xf32>
872879
// CHECK: tensor.insert
873880
// CHECK-SAME: __inplace_operands_attr__ = ["none", "true", "none"]

0 commit comments

Comments
 (0)