Skip to content

[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
intel:syclfrom
zjin-lcf:amd-matrix-loadpath-fixes
Open

[SYCL][HIP] Fix AMD joint_matrix use::a row-major load and multi-sub-group lane indexing#22681
zjin-lcf wants to merge 1 commit into
intel:syclfrom
zjin-lcf:amd-matrix-loadpath-fixes

Conversation

@zjin-lcf

Copy link
Copy Markdown
Contributor

Summary

Two independent correctness fixes in the AMD (HIP) joint_matrix backend (matrix-hip.hpp), affecting existing gfx90a support:

  1. use::a row-major load was transposed. The per-lane access pattern was selected from the layout enum 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. The double and non-double paths are unified (Size == 1 reduces to the former double special case), which also fixes use::b col-major for double. Fixes the natural row-major GEMM formulation reported in joint_matrix performance issues and wrong results for AMD MI210 #17265.

  2. 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 + lane instead of sg.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 declared use::a as col_major while storing A row-major (relying on the old buggy behavior); they now use row_major.

Changes

  • sycl/include/.../matrix/matrix-hip.hpp — the two fixes above.
  • sycl/test-e2e/Matrix/Inputs/joint_matrix_hip_{apply,copy,fill,mfma}.hppuse::a -> row_major.
  • New regression e2e tests (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

  • Both new e2e tests pass on MI300A (gfx942).
  • Existing joint_matrix_hip_gfx90a e2e + hip codegen tests still pass.
  • CI on gfx90a hardware.

…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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant