-
Notifications
You must be signed in to change notification settings - Fork 13.6k
[mlir][ArmSME] Add support for lowering masked tile_store ops #71180
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
c-rhodes
merged 2 commits into
llvm:main
from
c-rhodes:mlir-arm-sme-masked-tile-store-lowering
Nov 6, 2023
Merged
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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
121 changes: 121 additions & 0 deletions
121
mlir/test/Integration/Dialect/Vector/CPU/ArmSME/test-transfer-write-2d.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 |
---|---|---|
@@ -0,0 +1,121 @@ | ||
// DEFINE: %{entry_point} = entry | ||
// DEFINE: %{compile} = mlir-opt %s \ | ||
// DEFINE: -enable-arm-streaming="mode=locally enable-za" \ | ||
// DEFINE: -convert-vector-to-arm-sme -convert-arm-sme-to-scf \ | ||
// DEFINE: -convert-vector-to-llvm="enable-arm-sme" -cse -canonicalize \ | ||
// DEFINE: -allocate-arm-sme-tiles -test-lower-to-llvm | ||
// DEFINE: %{run} = %mcr_aarch64_cmd \ | ||
// DEFINE: -march=aarch64 -mattr=+sve,+sme \ | ||
// DEFINE: -e %{entry_point} -entry-point-result=void \ | ||
// DEFINE: -shared-libs=%mlir_runner_utils,%mlir_c_runner_utils | ||
|
||
// RUN: %{compile} | %{run} | FileCheck %s | ||
|
||
// Vector store. | ||
func.func @transfer_write_2d(%A : memref<?x?xf32>, %base1: index, %base2: index) { | ||
%c0 = arith.constant 0.0 : f32 | ||
%zero = vector.splat %c0 : vector<[4]x[4]xf32> | ||
vector.transfer_write %zero, %A[%base1, %base2] {in_bounds=[true, true]} : | ||
vector<[4]x[4]xf32>, memref<?x?xf32> | ||
return | ||
} | ||
|
||
// Masked vector store. | ||
func.func @transfer_write_2d_mask(%A : memref<?x?xf32>, %base1: index, %base2: index) { | ||
%c0 = arith.constant 0.0 : f32 | ||
%c2 = arith.constant 2 : index | ||
%c3 = arith.constant 3 : index | ||
%mask = vector.create_mask %c2, %c3 : vector<[4]x[4]xi1> | ||
%zero = vector.splat %c0 : vector<[4]x[4]xf32> | ||
vector.transfer_write %zero, %A[%base1, %base2], %mask {in_bounds=[true, true]} : | ||
vector<[4]x[4]xf32>, memref<?x?xf32> | ||
return | ||
} | ||
|
||
// Vector load + print. | ||
func.func @load_and_print(%A : memref<?x?xf32>, %base1: index, %base2: index) { | ||
%0 = vector.load %A[%base1, %base2] : memref<?x?xf32>, vector<[4]x[4]xf32> | ||
|
||
vector.print str "TILE BEGIN:" | ||
vector.print %0: vector<[4]x[4]xf32> | ||
|
||
return | ||
} | ||
|
||
// Allocate heap memory of size 'd0' x 'd1' and initialize. | ||
// | ||
// Example: | ||
// | ||
// initialize_memory(%c4, %c5) | ||
// | ||
// 0, 1, 2, 3, 4 | ||
// 10, 11, 12, 13, 14 | ||
// 20, 21, 22, 23, 24 | ||
// 30, 31, 32, 33, 34 | ||
// | ||
// Returns dynamic memref. It's the callers responsiblity to free the returned | ||
// memref. | ||
func.func @initialize_memory(%d0 : index, %d1 : index) -> memref<?x?xf32> { | ||
%c0 = arith.constant 0 : index | ||
%c1 = arith.constant 1 : index | ||
%c1_f32 = arith.constant 1.0 : f32 | ||
%c10_f32 = arith.constant 10.0 : f32 | ||
|
||
%A = memref.alloc(%d0, %d1) : memref<?x?xf32> | ||
|
||
%init = arith.constant 0.0 : f32 | ||
scf.for %i = %c0 to %d0 step %c1 iter_args(%val = %init) -> f32 { | ||
scf.for %j = %c0 to %d1 step %c1 iter_args(%inner_val = %val) -> f32 { | ||
memref.store %inner_val, %A[%i, %j] : memref<?x?xf32> | ||
%inner_val_next = arith.addf %inner_val, %c1_f32 : f32 | ||
scf.yield %inner_val_next : f32 | ||
} | ||
%val_next = arith.addf %val, %c10_f32 : f32 | ||
scf.yield %val_next : f32 | ||
} | ||
|
||
return %A : memref<?x?xf32> | ||
} | ||
|
||
func.func @entry() { | ||
%c0 = arith.constant 0 : index | ||
%c2 = arith.constant 2 : index | ||
%c4 = arith.constant 4 : index | ||
|
||
// Allocate enough memory to load a 32-bit tile plus a tiny bit more to test | ||
// non-zero offsets while remaining inbounds. | ||
%vscale = vector.vscale | ||
%svl_s = arith.muli %c4, %vscale : index | ||
%svl_s_plus_two = arith.addi %svl_s, %c2 : index | ||
|
||
// 1. Initialize memory | ||
// CHECK-LABEL: TILE BEGIN: | ||
// CHECK-NEXT: ( 0, 1, 2, 3 | ||
// CHECK-NEXT: ( 10, 11, 12, 13 | ||
// CHECK-NEXT: ( 20, 21, 22, 23 | ||
// CHECK-NEXT: ( 30, 31, 32, 33 | ||
%A = call @initialize_memory(%svl_s_plus_two, %svl_s_plus_two) : (index, index) -> memref<?x?xf32> | ||
call @load_and_print(%A, %c0, %c0) : (memref<?x?xf32>, index, index) -> () | ||
|
||
// 2. Write 2-D vector of zeroes to 1. at offset [2, 2]. | ||
// CHECK-LABEL: TILE BEGIN: | ||
// CHECK-NEXT: ( 0, 1, 2, 3 | ||
// CHECK-NEXT: ( 10, 11, 12, 13 | ||
// CHECK-NEXT: ( 20, 21, 0, 0 | ||
// CHECK-NEXT: ( 30, 31, 0, 0 | ||
call @transfer_write_2d(%A, %c2, %c2) : (memref<?x?xf32>, index, index) -> () | ||
call @load_and_print(%A, %c0, %c0) : (memref<?x?xf32>, index, index) -> () | ||
|
||
// 3. Write 2-D vector of zeroes to 2. but with mask (nrows=2, ncols=3). | ||
// CHECK-LABEL: TILE BEGIN: | ||
// CHECK-NEXT: ( 0, 0, 0, 3 | ||
// CHECK-NEXT: ( 0, 0, 0, 13 | ||
// CHECK-NEXT: ( 20, 21, 0, 0 | ||
// CHECK-NEXT: ( 30, 31, 0, 0 | ||
call @transfer_write_2d_mask(%A, %c0, %c0) : (memref<?x?xf32>, index, index) -> () | ||
call @load_and_print(%A, %c0, %c0) : (memref<?x?xf32>, index, index) -> () | ||
|
||
memref.dealloc %A : memref<?x?xf32> | ||
|
||
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.