-
Notifications
You must be signed in to change notification settings - Fork 24
[water] Add MemoryAccessPatternAttr #490
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
Open
tyb0807
wants to merge
2
commits into
iree-org:main
Choose a base branch
from
tyb0807:mem_acc_attr
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
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
84 changes: 84 additions & 0 deletions
84
water/test/Dialect/Wave/attr-memory-access-pattern-invalid.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,84 @@ | ||
| // RUN: water-opt %s -split-input-file -verify-diagnostics | ||
|
|
||
| // Test: empty group_id should fail | ||
| func.func @memory_access_pattern_empty_group_id(%value: !wave.tensor<any of f32, <register>>, %mem: !wave.tensor<[@M] of f32, <global>>) { | ||
| wave.write %value, %mem { | ||
| // expected-error @+1 {{group_id cannot be empty}} | ||
| memory_access_pattern = #wave.memory_access_pattern< | ||
| use_lds_promotion = false, | ||
| group_id = "" | ||
| > | ||
| } : !wave.tensor<any of f32, <register>>, !wave.tensor<[@M] of f32, <global>> | ||
| return | ||
| } | ||
|
|
||
| // ----- | ||
|
|
||
| // Test: LDS parameters specified when use_lds_promotion=false should fail | ||
| func.func @memory_access_pattern_lds_params_when_disabled(%value: !wave.tensor<any of f32, <register>>, %mem: !wave.tensor<[@M] of f32, <global>>) { | ||
| wave.write %value, %mem { | ||
| // expected-error @+1 {{LDS promotion parameters should not be specified when use_lds_promotion=false}} | ||
| memory_access_pattern = #wave.memory_access_pattern< | ||
| use_lds_promotion = false, | ||
| group_id = "test", | ||
| lds_block_global_base = #wave.expr_list<[#wave.index_symbol<WG0>] -> (WG0)> | ||
| > | ||
| } : !wave.tensor<any of f32, <register>>, !wave.tensor<[@M] of f32, <global>> | ||
| return | ||
| } | ||
|
|
||
| // ----- | ||
|
|
||
| // Test: Partial LDS specification when use_lds_promotion=true should fail | ||
| func.func @memory_access_pattern_partial_lds_specification(%value: !wave.tensor<any of f32, <register>>, %mem: !wave.tensor<[@M] of f32, <global>>) { | ||
| wave.write %value, %mem { | ||
| // expected-error @+1 {{when LDS promotion is enabled, all LDS parameters must be specified: lds_block_global_base, lds_block_shape, lds_load_indices, lds_load_vector_sizes, global_store_indices}} | ||
| memory_access_pattern = #wave.memory_access_pattern< | ||
| use_lds_promotion = true, | ||
| group_id = "test", | ||
| lds_block_global_base = #wave.expr_list<[#wave.index_symbol<WG0>] -> (WG0)> | ||
| > | ||
| } : !wave.tensor<any of f32, <register>>, !wave.tensor<[@M] of f32, <global>> | ||
| return | ||
| } | ||
|
|
||
| // ----- | ||
|
|
||
| // Test: Mismatched ranks between lds_block_global_base and lds_block_shape should fail | ||
| func.func @memory_access_pattern_mismatched_base_shape_ranks(%value: !wave.tensor<any of f32, <register>>, %mem: !wave.tensor<[@M, @N] of f32, <global>>) { | ||
| wave.write %value, %mem { | ||
| // expected-error @+1 {{lds_block_global_base rank (1) must match lds_block_shape rank (2)}} | ||
| memory_access_pattern = #wave.memory_access_pattern< | ||
| use_lds_promotion = true, | ||
| group_id = "test", | ||
| lds_block_global_base = #wave.expr_list<[#wave.index_symbol<WG0>] -> (WG0)>, | ||
| lds_block_shape = #wave.expr_list<[#wave.symbol<"BLOCK_M">, #wave.symbol<"BLOCK_N">] -> (BLOCK_M, BLOCK_N)>, | ||
| lds_load_indices = #wave.expr_list<[#wave.index_symbol<T0>] -> (T0)>, | ||
| lds_load_vector_sizes = #wave.expr_list<[] -> (64)>, | ||
| global_store_indices = #wave.expr_list<[#wave.index_symbol<T0>] -> (T0)> | ||
| > | ||
| } : !wave.tensor<any of f32, <register>>, !wave.tensor<[@M, @N] of f32, <global>> | ||
| return | ||
| } | ||
|
|
||
| // ----- | ||
|
|
||
| // Test: Mismatched ranks between lds_load_indices and lds_load_vector_sizes should fail | ||
| func.func @memory_access_pattern_mismatched_lds_load_ranks(%value: !wave.tensor<any of f32, <register>>, %mem: !wave.tensor<[@M] of f32, <global>>) { | ||
| wave.write %value, %mem { | ||
| // expected-error @+1 {{lds_load_indices rank (1) must match lds_load_vector_sizes rank (2)}} | ||
| memory_access_pattern = #wave.memory_access_pattern< | ||
| use_lds_promotion = true, | ||
| group_id = "test", | ||
| lds_block_global_base = #wave.expr_list<[#wave.index_symbol<WG0>] -> (WG0)>, | ||
| lds_block_shape = #wave.expr_list<[#wave.symbol<"BLOCK_M">] -> (BLOCK_M)>, | ||
| lds_load_indices = #wave.expr_list<[#wave.index_symbol<T0>] -> (T0)>, | ||
| lds_load_vector_sizes = #wave.expr_list<[#wave.symbol<"VEC_M">, #wave.symbol<"VEC_N">] -> (VEC_M, VEC_N)>, | ||
| global_store_indices = #wave.expr_list<[#wave.index_symbol<T0>] -> (T0)> | ||
| > | ||
| } : !wave.tensor<any of f32, <register>>, !wave.tensor<[@M] of f32, <global>> | ||
| return | ||
| } | ||
|
|
||
|
|
||
|
|
Oops, something went wrong.
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is redundant. We can have the verifier that check whether all optional patterns are added or none, and error out when only a subset is set. Having all set then means
truefor this value and havingnonemeans false.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, even that may itself be redundant. This attribute is optional on
writeOpAFAIU, so its mere presence indicates the intention to use the LDS schema. So its parameters can be made mandatory.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well yes. The reason for this is I plan on supporting different other memory access patterns too (that's also why the attribute is named
MemoryAccessPatternand not simplyLDSPromotionor something). For instance, I think using fat raw buffer to load/store directly to global mem is yet another "access pattern" that requires a different lowering path. I'm fine with starting simple with very specific use case then generalize later too, you call it.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can have different attributes for different memory access patterns if we want, so yeah maybe we should start simple and specific.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, premature overgeneralization is a common problem in MLIR-based projects, let's not fall victim to that