[SYCL][HIP] Fix AMD joint_matrix use::a row-major load and multi-sub-group lane indexing#22681
Open
zjin-lcf wants to merge 1 commit into
Open
[SYCL][HIP] Fix AMD joint_matrix use::a row-major load and multi-sub-group lane indexing#22681zjin-lcf wants to merge 1 commit into
zjin-lcf wants to merge 1 commit into
Conversation
…group lane indexing Two correctness fixes in the AMD (HIP) joint_matrix backend load path: 1. The use::a row-major load loaded the A multiplicand transposed. The access pattern was chosen from the layout enum alone, but "row-major" implies opposite in-memory stride patterns for A and B (the free dimension is strided for A, contiguous for B). Select the pattern from the combined (use, layout) condition so both layouts are correct for A. The double and non-double paths are unified (Size == 1 reduces to the former double case), which also fixes use::b col-major for double. 2. The per-lane fragment index was computed from the work-group linear id (get_group_linear_id() * sub_group_size + lane) instead of the sub-group local id. With a single sub-group per work-group this is accidentally correct, but kernels launching multiple sub-groups per work-group computed out-of-range element offsets, giving wrong results or memory faults. The hip Inputs helpers previously declared use::a as col_major while storing A row-major, relying on the old (buggy) behavior; they now use row_major. Adds two regression e2e tests: all four A/B layout combinations, and a tiled GEMM with multiple sub-groups per work-group. Co-authored-by: Cursor <cursoragent@cursor.com>
4 tasks
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
Two independent correctness fixes in the AMD (HIP)
joint_matrixbackend (matrix-hip.hpp), affecting existing gfx90a support:use::arow-major load was transposed. The per-lane access pattern was selected from thelayoutenum alone, but a "row-major" layout implies opposite in-memory stride patterns for the A and B multiplicands (the free dimension is strided for A, contiguous for B). The pattern is now selected from the combined(use, layout)condition, so both layouts are correct for A. Thedoubleand non-doublepaths are unified (Size == 1reduces to the formerdoublespecial case), which also fixesuse::bcol-major fordouble. Fixes the natural row-major GEMM formulation reported in joint_matrix performance issues and wrong results for AMD MI210 #17265.Fragment lane index used the work-group linear id. The per-lane element offset was computed as
sg.get_group_linear_id() * sub_group_size + laneinstead ofsg.get_local_linear_id(). With a single sub-group per work-group this is accidentally correct, but any kernel launching multiple sub-groups per work-group computed out-of-range offsets, producing wrong results or faults.The shared hip
Inputs/helpers previously declareduse::aascol_majorwhile storing A row-major (relying on the old buggy behavior); they now userow_major.Changes
sycl/include/.../matrix/matrix-hip.hpp— the two fixes above.sycl/test-e2e/Matrix/Inputs/joint_matrix_hip_{apply,copy,fill,mfma}.hpp—use::a->row_major.REQUIRES: target-amd, arch-neutral):joint_matrix_hip_all_layouts.cpp— all four A/B layout combinations.joint_matrix_hip_multi_subgroup.cpp— tiled GEMM with multiple sub-groups per work-group.Test plan
joint_matrix_hip_gfx90ae2e + hip codegen tests still pass.