-
Notifications
You must be signed in to change notification settings - Fork 76
[LoadStoreOpToLLVM] Transpose 2d load. #4870
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -120,8 +120,9 @@ def warps_per_cta(layout): | |
| @pytest.mark.parametrize("layout", layouts) | ||
| @pytest.mark.parametrize("load_block_ptr, store_block_ptr", [(True, True), (False, False), (True, False), | ||
| (False, True)]) | ||
| @pytest.mark.parametrize("transpose", [True, False]) | ||
| @pytest.mark.skipif(not is_xpu(), reason="Block store tests are specific to the XPU backend") | ||
| def test_block_io(M, N, dtype_str, layout, load_block_ptr, store_block_ptr, device, tmp_path: pathlib.Path): | ||
| def test_block_io(M, N, dtype_str, layout, load_block_ptr, store_block_ptr, transpose, device, tmp_path: pathlib.Path): | ||
|
|
||
| warps = warps_per_cta(layout) | ||
| num_warps = int(np.prod(warps)) | ||
|
|
@@ -132,16 +133,20 @@ def test_block_io(M, N, dtype_str, layout, load_block_ptr, store_block_ptr, devi | |
|
|
||
| support_block_io = torch.xpu.get_device_capability()['has_subgroup_2d_block_io'] | ||
|
|
||
| block_io = "\"column_major\"" if transpose else "\"row_major\"" | ||
|
|
||
| strides = "[%c1_i64, %M_i64]" if transpose else "[%N_i64, %c1_i64]" | ||
|
|
||
| if load_block_ptr: | ||
| load_ops = f""" | ||
| %src_ptr = tt.make_tensor_ptr %src, [%M_i64, %N_i64], [%N_i64, %c1_i64], [%c0_i32, %c0_i32] {{order = array<i32: 1, 0>}} : <tensor<{M}x{N}x{ty}, #layout>> | ||
| %store_val = tt.load %src_ptr {{ttig.block_io = "row_major", boundaryCheck = array<i32: 0, 1>, padding = 1 : i32}} : !tt.ptr<tensor<{M}x{N}x{ty}, #layout>> | ||
| %src_ptr = tt.make_tensor_ptr %src, [%M_i64, %N_i64], {strides}, [%c0_i32, %c0_i32] {{order = array<i32: 1, 0>}} : <tensor<{M}x{N}x{ty}, #layout>> | ||
| %store_val = tt.load %src_ptr {{ttig.block_io = {block_io}, boundaryCheck = array<i32: 0, 1>, padding = 1 : i32}} : !tt.ptr<tensor<{M}x{N}x{ty}, #layout>> | ||
| """ | ||
| else: | ||
| load_ops = f""" | ||
| %src_base = tt.splat %src : !tt.ptr<{ty}> -> tensor<{M}x{N}x!tt.ptr<{ty}>, #layout> | ||
| %src_ptr = tt.addptr %src_base, %row_major_off : tensor<{M}x{N}x!tt.ptr<{ty}>, #layout>, tensor<{M}x{N}xi32, #layout> | ||
| %store_val = tt.load %src_ptr {{ttig.block_io = "row_major"}} : tensor<{M}x{N}x!tt.ptr<{ty}>, #layout> | ||
| %src_ptr = tt.addptr %src_base, {"%col_major_off" if transpose else "%row_major_off" } : tensor<{M}x{N}x!tt.ptr<{ty}>, #layout>, tensor<{M}x{N}xi32, #layout> | ||
| %store_val = tt.load %src_ptr {{ttig.block_io = {block_io}}} : tensor<{M}x{N}x!tt.ptr<{ty}>, #layout> | ||
| """ | ||
| if store_block_ptr: | ||
| store_ops = f""" | ||
|
|
@@ -175,6 +180,12 @@ def test_block_io(M, N, dtype_str, layout, load_block_ptr, store_block_ptr, devi | |
| %7 = tt.broadcast %5 : tensor<1x{N}xi32, #layout> -> tensor<{M}x{N}xi32, #layout> | ||
| %row_major_off = arith.addi %6, %7 : tensor<{M}x{N}xi32, #layout> | ||
|
|
||
| %stride_M = arith.constant dense<{M}> : tensor<1x{N}xi32, #layout> | ||
| %col_stride = arith.muli %5, %stride_M : tensor<1x{N}xi32, #layout> | ||
| %8 = tt.broadcast %2 : tensor<{M}x1xi32, #layout> -> tensor<{M}x{N}xi32, #layout> | ||
| %9 = tt.broadcast %col_stride : tensor<1x{N}xi32, #layout> -> tensor<{M}x{N}xi32, #layout> | ||
| %col_major_off = arith.addi %8, %9 : tensor<{M}x{N}xi32, #layout> | ||
|
|
||
| {load_ops} | ||
| {store_ops} | ||
|
|
||
|
|
@@ -195,10 +206,14 @@ def test_block_io(M, N, dtype_str, layout, load_block_ptr, store_block_ptr, devi | |
| temp_file.write_text(ir) | ||
| kernel = triton.compile(str(temp_file)) | ||
|
|
||
| a = a.permute(1, 0).contiguous().permute(1, 0) if transpose else a | ||
|
|
||
| kernel[(1, 1, 1)](a, x) | ||
| assert torch.equal(a, x) | ||
|
|
||
| if support_block_io: | ||
| if not load_block_ptr: | ||
| assert 'spirv_Subgroup2DBlockLoad' in kernel.asm['llir'] or 'GenISA.LSC2DBlockRead' in kernel.asm['llir'] | ||
| if not ((transpose and type(layout) in [SliceLayout]) or | ||
| (transpose and dtype_str in ["float16", "int8"])): # TODO: add support for these cases | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @chengjunlu I do not understand the reason int8 does not work given that the feature objective is to add support for fp8 and the width of i8 and fp8 is the same.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. fp8 is not tested. |
||
| assert 'spirv_Subgroup2DBlockLoad' in kernel.asm['llir'] or 'GenISA.LSC2DBlockRead' in kernel.asm['llir'] | ||
| assert 'spirv_Subgroup2DBlockStoreINTEL' in kernel.asm['llir'] or 'GenISA.LSC2DBlockWrite' in kernel.asm['llir'] | ||
Uh oh!
There was an error while loading. Please reload this page.