-
Notifications
You must be signed in to change notification settings - Fork 13.9k
[mlir][vector] Restrict narrow-type-emulation patterns #115612
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
banach-space
merged 2 commits into
llvm:main
from
banach-space:andrzej/emulate_narrow_type_update_2
Nov 12, 2024
Merged
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
111 changes: 111 additions & 0 deletions
111
mlir/test/Dialect/Vector/emulate-narrow-type-unsupported.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,111 @@ | ||
// RUN: mlir-opt --test-emulate-narrow-int="arith-compute-bitwidth=1 memref-load-bitwidth=32 skip-memref-type-conversion" --split-input-file %s | FileCheck %s | ||
|
||
// These tests mimic tests from vector-narrow-type.mlir, but load/store 2-D | ||
// insted of 1-D vectors. That's currently not supported. | ||
|
||
///---------------------------------------------------------------------------------------- | ||
/// vector.load | ||
///---------------------------------------------------------------------------------------- | ||
|
||
func.func @vector_load_2d_i8_negative(%arg1: index, %arg2: index) -> vector<2x4xi8> { | ||
%0 = memref.alloc() : memref<3x4xi8> | ||
%1 = vector.load %0[%arg1, %arg2] : memref<3x4xi8>, vector<2x4xi8> | ||
return %1 : vector<2x4xi8> | ||
} | ||
|
||
// No support for loading 2D vectors - expect no conversions | ||
// CHECK-LABEL: func @vector_load_2d_i8_negative | ||
// CHECK: memref.alloc() : memref<3x4xi8> | ||
// CHECK-NOT: i32 | ||
|
||
// ----- | ||
|
||
///---------------------------------------------------------------------------------------- | ||
/// vector.transfer_read | ||
///---------------------------------------------------------------------------------------- | ||
|
||
func.func @vector_transfer_read_2d_i4_negative(%arg1: index, %arg2: index) -> vector<2x8xi4> { | ||
%c0 = arith.constant 0 : i4 | ||
%0 = memref.alloc() : memref<3x8xi4> | ||
%1 = vector.transfer_read %0[%arg1, %arg2], %c0 {in_bounds = [true, true]} : | ||
memref<3x8xi4>, vector<2x8xi4> | ||
return %1 : vector<2x8xi4> | ||
} | ||
// CHECK-LABEL: func @vector_transfer_read_2d_i4_negative | ||
// CHECK: memref.alloc() : memref<3x8xi4> | ||
// CHECK-NOT: i32 | ||
|
||
// ----- | ||
|
||
///---------------------------------------------------------------------------------------- | ||
/// vector.maskedload | ||
///---------------------------------------------------------------------------------------- | ||
|
||
func.func @vector_maskedload_2d_i8_negative(%arg1: index, %arg2: index, %arg3: index, %passthru: vector<2x4xi8>) -> vector<2x4xi8> { | ||
%0 = memref.alloc() : memref<3x4xi8> | ||
%mask = vector.create_mask %arg3, %arg3 : vector<2x4xi1> | ||
%1 = vector.maskedload %0[%arg1, %arg2], %mask, %passthru : | ||
memref<3x4xi8>, vector<2x4xi1>, vector<2x4xi8> into vector<2x4xi8> | ||
return %1 : vector<2x4xi8> | ||
} | ||
|
||
// CHECK-LABEL: func @vector_maskedload_2d_i8_negative | ||
// CHECK: memref.alloc() : memref<3x4xi8> | ||
// CHECK-NOT: i32 | ||
|
||
// ----- | ||
|
||
///---------------------------------------------------------------------------------------- | ||
/// vector.extract -> vector.masked_load | ||
///---------------------------------------------------------------------------------------- | ||
|
||
func.func @vector_extract_maskedload_2d_i4_negative(%arg1: index) -> vector<8x8x16xi4> { | ||
%0 = memref.alloc() : memref<8x8x16xi4> | ||
%c0 = arith.constant 0 : index | ||
%c16 = arith.constant 16 : index | ||
%c8 = arith.constant 8 : index | ||
%cst_1 = arith.constant dense<0> : vector<8x8x16xi4> | ||
%cst_2 = arith.constant dense<0> : vector<8x16xi4> | ||
%27 = vector.create_mask %c8, %arg1, %c16 : vector<8x8x16xi1> | ||
%48 = vector.extract %27[0] : vector<8x16xi1> from vector<8x8x16xi1> | ||
%50 = vector.maskedload %0[%c0, %c0, %c0], %48, %cst_2 : memref<8x8x16xi4>, vector<8x16xi1>, vector<8x16xi4> into vector<8x16xi4> | ||
%63 = vector.insert %50, %cst_1 [0] : vector<8x16xi4> into vector<8x8x16xi4> | ||
return %63 : vector<8x8x16xi4> | ||
} | ||
|
||
// CHECK-LABEL: func @vector_extract_maskedload_2d_i4_negative | ||
// CHECK: memref.alloc() : memref<8x8x16xi4> | ||
// CHECK-NOT: i32 | ||
|
||
// ----- | ||
|
||
///---------------------------------------------------------------------------------------- | ||
/// vector.store | ||
///---------------------------------------------------------------------------------------- | ||
|
||
func.func @vector_store_2d_i8_negative(%arg0: vector<2x8xi8>, %arg1: index, %arg2: index) { | ||
%0 = memref.alloc() : memref<4x8xi8> | ||
vector.store %arg0, %0[%arg1, %arg2] :memref<4x8xi8>, vector<2x8xi8> | ||
return | ||
} | ||
|
||
// CHECK-LABEL: func @vector_store_2d_i8_negative | ||
// CHECK: memref.alloc() : memref<4x8xi8> | ||
// CHECK-NOT: i32 | ||
|
||
// ----- | ||
|
||
///---------------------------------------------------------------------------------------- | ||
/// vector.maskedstore | ||
///---------------------------------------------------------------------------------------- | ||
|
||
func.func @vector_maskedstore_2d_i8_negative(%arg0: index, %arg1: index, %arg2: index, %value: vector<2x8xi8>) { | ||
%0 = memref.alloc() : memref<3x8xi8> | ||
%mask = vector.create_mask %arg2, %arg2 : vector<2x8xi1> | ||
vector.maskedstore %0[%arg0, %arg1], %mask, %value : memref<3x8xi8>, vector<2x8xi1>, vector<2x8xi8> | ||
return | ||
} | ||
|
||
// CHECK-LABEL: func @vector_maskedstore_2d_i8_negative | ||
// CHECK: memref.alloc() : memref<3x8xi8> | ||
// CHECK-NOT: i32 |
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
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 might be a bug. Multi-dimensional vector.store should be supported, but there might be a bug...
See comment below. It is explicitly written for multi-dimensional loads. The only general way to emulate sub-byte loads is to linearize the memrefs and do a linear store. So during the emulation the destination memref and the source vector get converted to 1D before the store.
I am not opposed to having this, but seems too big a hammer. There is a bug here for multi-dimensional stores
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 a bug :) In fact, one of many. Please see the summary ;-)
My PR is effectively a bug report. In fact, I should've started with a bug report. This is now reported here:
populateVectorNarrowTypeEmulationPatterns
(1D vs 2D) #115653Yes, two things need to happen: linearization + bitcasting. The former (linearization) seems to work fine only for source/destination
memref
(s). For vectors, it appears to be broken. For reference, see the reproduces that I added as tests.IIUC, we agree that there are multiple bugs here? This should be fixed, but in the meantime, lets document these "discoveries" through:
populateVectorNarrowTypeEmulationPatterns
(1D vs 2D) #115653,How does it sound?
As a side note ...
From what I can tell, dealing with n-D vectors is going to be tricky and might take some time (especially when masking is involved). I'd start by making sure 3 basic cases are covered:
memref
+ 1-Dvector
,memref
+ 1-Dvector
,memref
+ 2-Dvector
.Top 2 seem to be already supported. The bottom one is not. I haven't thought of n-D cases yet (n > 2), but perhaps that's trivial once 2-D is fully supported.
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.
Your taxonomy is right. I think supporting multi dim vectors is much more involved. So with that context looking back at your change, this makes total sense!