-
Notifications
You must be signed in to change notification settings - Fork 17
[Transform] Only use gc runtime allocator for stack-like alloca ops #287
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
71e675b
fallback memref transformation when alloc / dealloc not in FILO fashion
bd4d269
add test case
2329aff
Merge remote-tracking branch 'origin/main' into zhangyan/enhance_allo…
8a7f5c4
remove alias
dda790d
align gc bufferization pipeline
zhczhong cf4ad61
stash
d2ed37f
Merge remote-tracking branch 'origin/zhicong/align_bufferization_pipe…
2cf5dcf
fix comment
d987fa2
add test case
6ff8ef8
Merge remote-tracking branch 'origin/main' into zhangyan/enhance_allo…
87a51b1
only convert stack-style alloca to cgc runtime allocator, with deallo…
3fdce87
update
9494fdc
update
6668da9
Merge remote-tracking branch 'origin/main' into zhangyan/enhance_allo…
280ca6c
Merge remote-tracking branch 'origin/main' into zhangyan/enhance_allo…
06a580e
fix comment
5ba2a01
add test
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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
113 changes: 67 additions & 46 deletions
113
test/mlir/test/gc/Dialect/CPURuntime/memref-to-cpuruntime.mlir
This file contains hidden or 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 |
---|---|---|
@@ -1,68 +1,89 @@ | ||
// RUN: gc-opt --split-input-file --convert-memref-to-cpuruntime %s -verify-diagnostics | FileCheck %s | ||
func.func @alloc() { | ||
// CHECK-LABEL: func @alloc() | ||
|
||
func.func @alloca() { | ||
// CHECK-LABEL: func @alloca() | ||
// CHECK: %[[m0:.*]] = cpuruntime.alloc() : memref<1024xf32> | ||
%m0 = memref.alloc() : memref<1024xf32> | ||
%m0 = memref.alloca() : memref<1024xf32> | ||
scf.forall (%i) in (32) { | ||
} | ||
// CHECK: cpuruntime.dealloc %[[m0]] : memref<1024xf32> | ||
cpuruntime.dealloc %m0 : memref<1024xf32> | ||
return | ||
} | ||
|
||
func.func @thread_alloc() { | ||
// CHECK-LABEL: func.func @thread_alloc() | ||
// CHECK: %[[m0:.*]] = cpuruntime.alloc thread_local() : memref<1024xf32> | ||
func.func @thread_alloca() { | ||
// CHECK-LABEL: func.func @thread_alloca() | ||
// CHECK-NEXT: scf.forall {{.*}} { | ||
// CHECK-NEXT: %[[m0:.*]] = cpuruntime.alloc thread_local() : memref<1024xf32> | ||
// CHECK-NEXT: cpuruntime.dealloc thread_local %[[m0]] : memref<1024xf32> | ||
// CHECK-NEXT: } | ||
scf.forall (%i) in (32) { | ||
%0 = memref.alloc() : memref<1024xf32> | ||
// CHECK: cpuruntime.dealloc thread_local %[[m0]] : memref<1024xf32> | ||
memref.dealloc %0 : memref<1024xf32> | ||
%0 = memref.alloca() : memref<1024xf32> | ||
} | ||
return | ||
} | ||
|
||
func.func @return_alloc() -> memref<32x18xf32> { | ||
// CHECK-LABEL: func @return_alloc() -> memref<32x18xf32> | ||
// CHECK: %[[m0:.*]] = memref.alloc() : memref<32x18xf32> | ||
%0 = memref.alloc() : memref<32x18xf32> | ||
return %0 : memref<32x18xf32> | ||
func.func @dynamic_ranked_alloca(%arg0: memref<*xf32>) { | ||
// CHECK-LABEL: func @dynamic_ranked_alloca(%arg0: memref<*xf32>) | ||
// CHECK: %[[RANK:.*]] = memref.rank %{{.*}} : memref<*xf32> | ||
// CHECK: %[[m0:.*]] = cpuruntime.alloc(%[[RANK]]) : memref<?xindex> | ||
// CHECK: cpuruntime.dealloc %[[m0]] : memref<?xindex> | ||
%0 = memref.rank %arg0 : memref<*xf32> | ||
%alloca = memref.alloca(%0) : memref<?xindex> | ||
return | ||
} | ||
|
||
func.func @yield_alloc() -> memref<32x18xf32> { | ||
// CHECK-LABEL: func @yield_alloc() -> memref<32x18xf32> | ||
// CHECK: %[[m0:.*]] = memref.alloc() : memref<32x18xf32> | ||
%c32 = arith.constant 32 : index | ||
%c1 = arith.constant 1 : index | ||
%c0 = arith.constant 0 : index | ||
%lastBuffer = memref.alloc() : memref<32x18xf32> | ||
scf.for %arg3 = %c0 to %c32 step %c1 iter_args(%arg1 = %lastBuffer) -> (memref<32x18xf32>) { | ||
%newBuffer = memref.alloc() : memref<32x18xf32> | ||
memref.dealloc %arg1 : memref<32x18xf32> | ||
scf.yield %newBuffer : memref<32x18xf32> | ||
func.func @loop_nested_if_alloca(%arg0: index, %arg1: index, %arg2: index, %arg3: memref<64xf32>) { | ||
// CHECK-LABEL: func @loop_nested_if_alloca(%arg0: index, %arg1: index, %arg2: index, %arg3: memref<64xf32>) | ||
// CHECK: %[[m0:.*]] = cpuruntime.alloc() : memref<64xf32> | ||
%alloca = memref.alloca() : memref<64xf32> | ||
%0 = scf.for %arg5 = %arg0 to %arg1 step %arg2 iter_args(%arg6 = %arg3) -> (memref<64xf32>) { | ||
%1 = arith.cmpi eq, %arg5, %arg1 : index | ||
%2 = scf.if %1 -> (memref<64xf32>) { | ||
// CHECK: yield %[[m0]] : memref<64xf32> | ||
scf.yield %alloca : memref<64xf32> | ||
} else { | ||
// CHECK: %[[m1:.*]] = memref.alloca() : memref<2xf32> | ||
%alloca_0 = memref.alloca() : memref<2xf32> | ||
scf.yield %arg6 : memref<64xf32> | ||
} | ||
scf.yield %2 : memref<64xf32> | ||
} | ||
return %lastBuffer : memref<32x18xf32> | ||
// CHECK: cpuruntime.dealloc %[[m0]] : memref<64xf32> | ||
return | ||
} | ||
|
||
func.func @return_view_alloc() -> memref<16xf32> { | ||
// CHECK-LABEL: func @return_view_alloc() -> memref<16xf32> | ||
// CHECK: %[[m0:.*]] = memref.alloc() : memref<128xi8> | ||
%c0 = arith.constant 0: index | ||
%f0 = arith.constant 0.0: f32 | ||
%alloc = memref.alloc() : memref<128xi8> | ||
%view = memref.view %alloc[%c0][] : memref<128xi8> to memref<32xf32> | ||
%subview = memref.subview %view[0][16][1] : memref<32xf32> to memref<16xf32> | ||
return %subview : memref<16xf32> | ||
func.func @alloca_sequence() { | ||
// CHECK-LABEL: func @alloca_sequence() | ||
// CHECK: %[[m0:.*]] = cpuruntime.alloc() : memref<128xf32> | ||
// CHECK: %[[m1:.*]] = cpuruntime.alloc() : memref<128xf32> | ||
// CHECK: %[[m2:.*]] = cpuruntime.alloc() : memref<128xf32> | ||
%alloc = memref.alloca() : memref<128xf32> | ||
%alloc_0 = memref.alloca() : memref<128xf32> | ||
%alloc_1 = memref.alloca() : memref<128xf32> | ||
// CHECK: cpuruntime.dealloc %[[m2]] : memref<128xf32> | ||
// CHECK: cpuruntime.dealloc %[[m1]] : memref<128xf32> | ||
// CHECK: cpuruntime.dealloc %[[m0]] : memref<128xf32> | ||
return | ||
} | ||
|
||
func.func @alloc_dealloc_view() { | ||
// CHECK-LABEL: func @alloc_dealloc_view() | ||
// CHECK: %[[m0:.*]] = cpuruntime.alloc() : memref<128xi8> | ||
%c0 = arith.constant 0: index | ||
%f0 = arith.constant 0.0: f32 | ||
%alloc = memref.alloc() : memref<128xi8> | ||
%view = memref.view %alloc[%c0][] : memref<128xi8> to memref<32xf32> | ||
%subview = memref.subview %view[0][16][1] : memref<32xf32> to memref<16xf32> | ||
// CHECK: cpuruntime.dealloc | ||
memref.dealloc %subview : memref<16xf32> | ||
func.func @nested_alloca() { | ||
// CHECK-LABEL: func @nested_alloca() | ||
// CHECK: %[[m0:.*]] = cpuruntime.alloc() : memref<512xf32> | ||
// CHECK-NEXT: scf.forall {{.*}} { | ||
// CHECK-NEXT: %[[m1:.*]] = cpuruntime.alloc thread_local() : memref<32xf32> | ||
// CHECK-NEXT: cpuruntime.dealloc thread_local %[[m1]] : memref<32xf32> | ||
// CHECK-NEXT: } | ||
// CHECK-NEXT: scf.forall {{.*}} { | ||
// CHECK-NEXT: %[[m2:.*]] = cpuruntime.alloc thread_local() : memref<64xf32> | ||
// CHECK-NEXT: cpuruntime.dealloc thread_local %[[m2]] : memref<64xf32> | ||
// CHECK-NEXT: } | ||
// CHECK: cpuruntime.dealloc %[[m0]] : memref<512xf32> | ||
%0 = memref.alloca() : memref<512xf32> | ||
scf.forall (%i) in (32) { | ||
%1 = memref.alloca() : memref<32xf32> | ||
} | ||
scf.forall (%i) in (32) { | ||
%1 = memref.alloca() : memref<64xf32> | ||
} | ||
return | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.