-
Notifications
You must be signed in to change notification settings - Fork 15.2k
[MLIR][XeGPU] Allow create mem desc from 2d memref #167767
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
Jianhui-Li
merged 7 commits into
main
from
users/Jianhui-Li/XeGPU/create-mem-desc-from-2d-memref
Nov 19, 2025
+97
−67
Merged
Changes from 3 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
d9a5376
inital implementation
Jianhui-Li 18f8cb9
adding tests
Jianhui-Li c0ba80e
fixing documentation
Jianhui-Li 158edd6
Merge branch 'main' into create-mem-desc-from-2d-memref
Jianhui-Li 281393e
address feedback
Jianhui-Li 8138f3a
change documentation
Jianhui-Li 164c72f
using implict type converter for memref input
Jianhui-Li 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
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 |
|---|---|---|
|
|
@@ -4,8 +4,8 @@ gpu.module @test_kernel [#xevm.target<chip = "pvc">] { | |
|
|
||
| // e.g. for mem_desc<32x32xf16, @strides=[1, 16]> | ||
| // its memory layout tuple is (blocked shape = [1,1,32,32],strides=[1024,1024,32,1]) | ||
| //CHECK-LABEL: load_store_matrix_1 | ||
| gpu.func @load_store_matrix_1(%arg0: memref<4096xi8, 3>) -> f32 { | ||
| //CHECK-LABEL: load_store_matrix_plain | ||
| gpu.func @load_store_matrix_plain(%arg0: memref<4096xi8, 3>) -> f32 { | ||
| %0 = xegpu.create_mem_desc %arg0 : memref<4096xi8, 3> -> !xegpu.mem_desc<32x32xf32> | ||
|
|
||
| //CHECK: %[[TID:.*]] = gpu.thread_id x | ||
|
|
@@ -26,20 +26,48 @@ gpu.module @test_kernel [#xevm.target<chip = "pvc">] { | |
| gpu.return %1: f32 | ||
| } | ||
|
|
||
| //CHECK-LABEL: load_store_matrix_plain_2d_input | ||
| gpu.func @load_store_matrix_plain_2d_input(%arg0: memref<8192xi8, 3>) -> f32 { | ||
| %c0 = arith.constant 0 : index | ||
| %view = memref.view %arg0[%c0][]: memref<8192xi8, 3> to memref<64x32xf32, 3> | ||
|
|
||
| %subview = memref.subview %view[32, 0] [32, 32] [1, 1] : memref<64x32xf32, 3> to memref<32x32xf32, strided<[32, 1], offset: 1024>, 3> | ||
|
|
||
| %0 = xegpu.create_mem_desc %subview : memref<32x32xf32, strided<[32, 1], offset: 1024>, 3> -> !xegpu.mem_desc<32x32xf32> | ||
|
|
||
| //CHECK: %[[TID:.*]] = gpu.thread_id x | ||
| //CHECK: %[[C1:.*]] = arith.constant 1 : index | ||
| //CHECK: %[[MUL1:.*]] = arith.muli %[[TID]], %[[C1]] : index | ||
| //CHECK: %[[C4:.*]] = arith.constant 4 : i32 | ||
| //CHECK: %[[MUL2:.*]] = arith.muli {{.*}}, %[[C4]] : i32 | ||
| //CHECK: llvm.load {{.*}} : !llvm.ptr<3> -> f32 | ||
|
|
||
| %tid_x = gpu.thread_id x | ||
|
|
||
| %1 = xegpu.load_matrix %0[%c0, %tid_x]: !xegpu.mem_desc<32x32xf32>, index, index -> f32 | ||
|
|
||
| //CHECK: llvm.store {{.*}}, {{.*}} : f32, !llvm.ptr<3> | ||
|
|
||
| xegpu.store_matrix %1, %0[%c0, %tid_x]: f32, !xegpu.mem_desc<32x32xf32>, index, index | ||
|
|
||
| gpu.return %1: f32 | ||
| } | ||
|
|
||
|
|
||
| // e.g. for mem_desc<32x64xf16, @block=[16, 16], @strides=[1, 32]> | ||
| // its memory layout tuple is ([2,4,16,16],[256,512,1,16]) | ||
| //CHECK-LABEL: load_store_matrix_2 | ||
| gpu.func @load_store_matrix_2(%arg0: memref<4096xi8, 3>) -> f16 { | ||
| //CHECK-LABEL: load_store_matrix_blocked_strided | ||
| gpu.func @load_store_matrix_blocked_strided(%arg0: memref<4096xi8, 3>) -> f16 { | ||
| %0 = xegpu.create_mem_desc %arg0 : memref<4096xi8, 3> -> !xegpu.mem_desc<32x64xf16, #xegpu.mem_layout<stride = [1, 32], block = [16, 16]>> | ||
| //CHECK: %[[c0:.*]] = arith.constant 0 : index | ||
|
|
||
| //CHECK: %[[tid_x:.*]] = gpu.thread_id x | ||
| //CHECK: %[[c13:.*]] = arith.constant 13 : index | ||
| //CHECK: %[[c16:.*]] = arith.constant 16 : index | ||
| //CHECK: %[[offsetx_0:.*]] = arith.divsi %[[c13]], %[[c16]] : index | ||
| //CHECK: %[[offsetx_1:.*]] = arith.remsi %[[c13]], %[[c16]] : index | ||
| //CHECK: %[[offsety_0:.*]] = arith.divsi %[[tid_x]], %[[c16]] : index | ||
| //CHECK: %[[offsety_1:.*]] = arith.remsi %[[tid_x]], %[[c16]] : index | ||
|
|
||
| //CHECK: %[[c0:.*]] = arith.constant 0 : index | ||
| //CHECK: %[[c256:.*]] = arith.constant 256 : index | ||
| //CHECK: %[[mul0:.*]] = arith.muli %[[offsetx_0]], %[[c256]] : index | ||
| //CHECK: %[[add0:.*]] = arith.addi %[[mul0]], %[[c0]] : index | ||
|
|
@@ -68,24 +96,24 @@ gpu.module @test_kernel [#xevm.target<chip = "pvc">] { | |
|
|
||
| // e.g. for mem_desc<32x64xf16, @block=[16, 16]> | ||
| // its memory layout tuple is ([2,4,16,16],[1024,256,16,1]) | ||
| //CHECK-LABEL: load_store_matrix_3 | ||
| gpu.func @load_store_matrix_3(%arg0: memref<4096xi8, 3>) -> f16 { | ||
| //CHECK: %[[c0:.*]] = arith.constant 0 : index | ||
| //CHECK: %[[view:.*]] = memref.view %arg0[%[[c0]]][] : memref<4096xi8, 3> to memref<2048xf16, 3> | ||
| //CHECK-LABEL: load_store_matrix_blocked_nostride | ||
| gpu.func @load_store_matrix_blocked_nostride(%arg0: memref<4096xi8, 3>) -> f16 { | ||
|
|
||
| //CHECK: %[[intptr:.*]] = memref.extract_aligned_pointer_as_index %arg0 : memref<4096xi8, 3> -> index | ||
| //CHECK: %[[basePtrI64:.*]] = arith.index_castui %[[intptr]] : index to i32 | ||
| %0 = xegpu.create_mem_desc %arg0 : memref<4096xi8, 3> -> !xegpu.mem_desc<32x64xf16, #xegpu.mem_layout<block = [16, 16]>> | ||
|
|
||
| //CHECK: %[[tid_x:.*]] = gpu.thread_id x | ||
| //CHECK: %[[c19:.*]] = arith.constant 19 : index | ||
| %tid_x = gpu.thread_id x | ||
| %c19 = arith.constant 19: index | ||
|
|
||
| //CHECK: %[[intptr:.*]] = memref.extract_aligned_pointer_as_index %[[view]] : memref<2048xf16, 3> -> index | ||
| //CHECK: %[[basePtrI64:.*]] = arith.index_castui %[[intptr]] : index to i32 | ||
| //CHECK: %[[c16:.*]] = arith.constant 16 : index | ||
| //CHECK: %[[offsetx_0:.*]] = arith.divsi %[[c19]], %[[c16]] : index | ||
| //CHECK: %[[offsetx_1:.*]] = arith.remsi %[[c19]], %[[c16]] : index | ||
| //CHECK: %[[offsety_0:.*]] = arith.divsi %[[tid_x]], %[[c16]] : index | ||
| //CHECK: %[[offsety_1:.*]] = arith.remsi %[[tid_x]], %[[c16]] : index | ||
| //CHECK: %[[c0:.*]] = arith.constant 0 : index | ||
| //CHECK: %[[c1024:.*]] = arith.constant 1024 : index | ||
| //CHECK: %[[mul0:.*]] = arith.muli %[[offsetx_0]], %[[c1024]] : index | ||
| //CHECK: %[[add0:.*]] = arith.addi %[[mul0]], %[[c0]] : index | ||
|
|
@@ -97,7 +125,6 @@ gpu.module @test_kernel [#xevm.target<chip = "pvc">] { | |
| //CHECK: %[[c1:.*]] = arith.constant 1 : index | ||
| //CHECK: %[[mul3:.*]] = arith.muli %[[offsety_1]], %[[c1]] : index | ||
| //CHECK: %[[add3:.*]] = arith.addi %[[mul3]], %[[add2]] : index | ||
|
|
||
| //CHECK: %[[loaded:.*]] = llvm.load {{.*}} : !llvm.ptr<3> -> f16 | ||
| %1 = xegpu.load_matrix %0[%c19, %tid_x]: !xegpu.mem_desc<32x64xf16, #xegpu.mem_layout<block = [16, 16]>>, index, index -> f16 | ||
|
|
||
|
|
@@ -110,19 +137,17 @@ gpu.module @test_kernel [#xevm.target<chip = "pvc">] { | |
|
|
||
| // e.g. for mem_desc<32x64xf16, @block=[16, 16], @strides=[1, 16]> | ||
| // its memory layout tuple is ([2,4,16,16],[256,512,1,16]) | ||
| //CHECK-LABEL: load_store_matrix_4 | ||
| gpu.func @load_store_matrix_4(%arg0: memref<4096xi8, 3>) -> vector<8xf16> { | ||
| //CHECK-LABEL: load_store_matrix_blocked_strided_return_vector | ||
| gpu.func @load_store_matrix_blocked_strided_return_vector(%arg0: memref<4096xi8, 3>) -> vector<8xf16> { | ||
| %0 = xegpu.create_mem_desc %arg0 : memref<4096xi8, 3> -> !xegpu.mem_desc<32x64xf16, #xegpu.mem_layout<stride = [1, 32], block = [16, 16]>> | ||
|
|
||
| //CHECK: %[[c0:.*]] = arith.constant 0 : index | ||
| //CHECK: %[[tid_x:.*]] = gpu.thread_id x | ||
|
|
||
| //CHECK: %[[c16:.*]] = arith.constant 16 : index | ||
| //CHECK: %[[offsetx_0:.*]] = arith.divsi %[[c16]], %[[c16]] : index | ||
| //CHECK: %[[offsetx_1:.*]] = arith.remsi %[[c16]], %[[c16]] : index | ||
| //CHECK: %[[offsety_0:.*]] = arith.divsi %[[tid_x]], %[[c16]] : index | ||
| //CHECK: %[[offsety_1:.*]] = arith.remsi %[[tid_x]], %[[c16]] : index | ||
|
|
||
| //CHECK: %[[c0:.*]] = arith.constant 0 : index | ||
| //CHECK: %[[c256:.*]] = arith.constant 256 : index | ||
| //CHECK: %[[mul0:.*]] = arith.muli %[[offsetx_0]], %[[c256]] : index | ||
| //CHECK: %[[add0:.*]] = arith.addi %[[mul0]], %[[c0]] : index | ||
|
|
@@ -150,25 +175,24 @@ gpu.module @test_kernel [#xevm.target<chip = "pvc">] { | |
|
|
||
| // e.g. for mem_desc<32x64xf16, @block=[16, 16]> | ||
| // its memory layout tuple is ([2,4,16,16],[1024,256,16,1]) | ||
| //CHECK-LABEL: load_store_matrix_5 | ||
| gpu.func @load_store_matrix_5(%arg0: memref<4096xi8, 3>) -> vector<8xf16> { | ||
| //CHECK: %[[c0:.*]] = arith.constant 0 : index | ||
| //CHECK: %[[view:.*]] = memref.view %arg0[%[[c0]]][] : memref<4096xi8, 3> to memref<2048xf16, 3> | ||
|
|
||
| %0 = xegpu.create_mem_desc %arg0 : memref<4096xi8, 3> -> !xegpu.mem_desc<32x64xf16, #xegpu.mem_layout<block = [16, 16]>> | ||
|
|
||
| //CHECK-LABEL: load_store_matrix_blocked_subgroupblockio | ||
| gpu.func @load_store_matrix_blocked_subgroupblockio(%arg0: memref<4096xi8, 3>) -> vector<8xf16> { | ||
|
|
||
| //CHECK: %[[intptr:.*]] = memref.extract_aligned_pointer_as_index %arg0 : memref<4096xi8, 3> -> index | ||
| //CHECK: %[[basePtrI64:.*]] = arith.index_castui %[[intptr]] : index to i32 | ||
|
||
| %0 = xegpu.create_mem_desc %arg0 : memref<4096xi8, 3> -> !xegpu.mem_desc<32x64xf16, #xegpu.mem_layout<block = [16, 16]>> | ||
|
|
||
|
|
||
| //CHECK: %[[c16:.*]] = arith.constant 16 : index | ||
| //CHECK: %[[c48:.*]] = arith.constant 48 : index | ||
|
|
||
| %c16 = arith.constant 16 : index | ||
| %c48 = arith.constant 48 : index | ||
|
|
||
| //CHECK: %[[intptr:.*]] = memref.extract_aligned_pointer_as_index %[[view]] : memref<2048xf16, 3> -> index | ||
| //CHECK: %[[basePtrI64:.*]] = arith.index_castui %[[intptr]] : index to i32 | ||
| //CHECK: %[[offset0:.*]] = arith.divsi %[[c16]], %[[c16]] : index | ||
| //CHECK: %[[offset1:.*]] = arith.remsi %[[c16]], %[[c16]] : index | ||
| //CHECK: %[[offset2:.*]] = arith.divsi %[[c48]], %[[c16]] : index | ||
| //CHECK: %[[offset3:.*]] = arith.remsi %[[c48]], %[[c16]] : index | ||
| //CHECK: %[[c0:.*]] = arith.constant 0 : index | ||
| //CHECK: %[[c1024:.*]] = arith.constant 1024 : index | ||
| //CHECK: %[[mul0:.*]] = arith.muli %[[offset0]], %[[c1024]] : index | ||
| //CHECK: %[[add0:.*]] = arith.addi %[[mul0]], %[[c0]] : index | ||
|
|
||
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.
Uh oh!
There was an error while loading. Please reload this page.