Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[mlir][bufferize] Infer memory space in all bufferization patterns
This change updates all remaining bufferization patterns (except for scf.while) and the remaining bufferization infrastructure to infer the memory space whenever possible instead of falling back to "0". (If a default memory space is set in the bufferization options, we still fall back to that value if the memory space could not be inferred.) Differential Revision: https://reviews.llvm.org/D128423
- Loading branch information
1 parent
13fb97d
commit c0b0b6a
Showing
16 changed files
with
273 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
mlir/test/Dialect/Arithmetic/one-shot-bufferize-memory-space-invalid.mlir
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
// RUN: mlir-opt %s -one-shot-bufferize="must-infer-memory-space" -split-input-file -verify-diagnostics | ||
|
||
func.func @inconsistent_memory_space_arith_select(%c: i1) -> tensor<10xf32> { | ||
// Selecting tensors with different memory spaces. Such IR cannot be | ||
// bufferized. | ||
%0 = bufferization.alloc_tensor() {memory_space = 0 : ui64} : tensor<10xf32> | ||
%1 = bufferization.alloc_tensor() {memory_space = 1 : ui64} : tensor<10xf32> | ||
// expected-error @+2 {{inconsistent memory space on true/false operands}} | ||
// expected-error @+1 {{failed to bufferize op}} | ||
%r = arith.select %c, %0, %1 : tensor<10xf32> | ||
func.return %r : tensor<10xf32> | ||
} | ||
|
||
// ----- | ||
|
||
func.func @constant_memory_space(%idx: index, %v: i32) -> tensor<3xi32> { | ||
// expected-error @+2 {{memory space not implemented yet}} | ||
// expected-error @+1 {{failed to bufferize op}} | ||
%cst = arith.constant dense<[5, 1000, 20]> : tensor<3xi32> | ||
%0 = tensor.insert %v into %cst[%idx] : tensor<3xi32> | ||
return %0 : tensor<3xi32> | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletions
12
mlir/test/Dialect/Bufferization/Transforms/tensor-copy-insertion-memory-space-invalid.mlir
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
// RUN: mlir-opt %s -tensor-copy-insertion="must-infer-memory-space" -split-input-file -verify-diagnostics | ||
|
||
// An alloc is inserted but the copy is emitted. Therefore, the memory space | ||
// should be specified on the alloc_tensor op. | ||
func.func @memory_space_of_unknown_op() -> (tensor<10xf32>, tensor<10xf32>) { | ||
%c0 = arith.constant 0 : index | ||
%cst = arith.constant 0.0 : f32 | ||
// expected-error @+1 {{could not infer memory space}} | ||
%t = bufferization.alloc_tensor() : tensor<10xf32> | ||
%s = tensor.insert %cst into %t[%c0] : tensor<10xf32> | ||
return %s, %t : tensor<10xf32>, tensor<10xf32> | ||
} |
25 changes: 25 additions & 0 deletions
25
mlir/test/Dialect/Bufferization/Transforms/tensor-copy-insertion-memory-space.mlir
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
// RUN: mlir-opt %s -tensor-copy-insertion="must-infer-memory-space" -split-input-file | FileCheck %s | ||
|
||
// CHECK-LABEL: func @unknown_op_copy | ||
func.func @unknown_op_copy() -> (tensor<10xf32>, tensor<10xf32>) { | ||
%c0 = arith.constant 0 : index | ||
%cst = arith.constant 0.0 : f32 | ||
// CHECK: %[[dummy:.*]] = "test.dummy_op"() : () -> tensor<10xf32> | ||
%t = "test.dummy_op"() : () -> tensor<10xf32> | ||
// CHECK: %[[copy:.*]] = bufferization.alloc_tensor() copy(%[[dummy]]) {bufferization.escape = [false]} : tensor<10xf32> | ||
%s = tensor.insert %cst into %t[%c0] : tensor<10xf32> | ||
return %s, %t : tensor<10xf32>, tensor<10xf32> | ||
} | ||
|
||
// ----- | ||
|
||
// CHECK-LABEL: func @alloc_tensor_copy | ||
func.func @alloc_tensor_copy() -> (tensor<10xf32>, tensor<10xf32>) { | ||
%c0 = arith.constant 0 : index | ||
%cst = arith.constant 0.0 : f32 | ||
// CHECK: bufferization.alloc_tensor() {bufferization.escape = [false], memory_space = 1 : ui64} : tensor<10xf32> | ||
%t = bufferization.alloc_tensor() {memory_space = 1 : ui64} : tensor<10xf32> | ||
// CHECK: bufferization.alloc_tensor() {bufferization.escape = [false], memory_space = 1 : ui64} : tensor<10xf32> | ||
%s = tensor.insert %cst into %t[%c0] : tensor<10xf32> | ||
return %s, %t : tensor<10xf32>, tensor<10xf32> | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
// RUN: mlir-opt %s -one-shot-bufferize -split-input-file -verify-diagnostics | ||
|
||
func.func @inconsistent_memory_space_scf_if(%c: i1) -> tensor<10xf32> { | ||
// Yielding tensors with different memory spaces. Such IR cannot be | ||
// bufferized. | ||
%0 = bufferization.alloc_tensor() {memory_space = 0 : ui64} : tensor<10xf32> | ||
%1 = bufferization.alloc_tensor() {memory_space = 1 : ui64} : tensor<10xf32> | ||
// expected-error @+2 {{inconsistent memory space on then/else branches}} | ||
// expected-error @+1 {{failed to bufferize op}} | ||
%r = scf.if %c -> tensor<10xf32> { | ||
scf.yield %0 : tensor<10xf32> | ||
} else { | ||
scf.yield %1 : tensor<10xf32> | ||
} | ||
func.return %r : tensor<10xf32> | ||
} |
Oops, something went wrong.