Skip to content

[ROCM-26590] Fix legacy-CK buffer resource descriptor for gfx1250 - #8758

Merged
adickin-amd merged 5 commits into
developfrom
users/SreecharanGundaboluAMD/bugfix_rocm_26590
Jun 24, 2026
Merged

adickin-amd merged 5 commits into
developfrom
users/SreecharanGundaboluAMD/bugfix_rocm_26590

Conversation

@SreecharanGundaboluAMD

Copy link
Copy Markdown
Contributor

Motivation

LSTM backward weights produced wrong bias gradients (~30% too small) on gfx1250 (mi450/RDNA4), causing test_variable_sequence_cuda_float32 to fail in PyTorch. The bug only manifested with variable-length (packed) sequences and was gfx1250-specific — gfx942 (MI300X) with identical inputs passed.

Root cause: the legacy ComposableKernel code vendored inside MIOpen (src/legacy_composable_kernel/) constructs AMD buffer resource descriptors using two fields that changed format on gfx1250:

  1. CK_BUFFER_RESOURCE_3RD_DWORD (config.hpp): gfx1250 was grouped with gfx10/11 and assigned 0x31014000. gfx1250 (RDNA4/gfx12) requires 0 — confirmed against CK's implementation (composablekernel/include/ck/ck.hpp). With the wrong word-3, buffer_load treats in-range elements as out-of-bounds and returns 0, silently dropping reduction terms.

  2. make_wave_buffer_resource (amd_buffer_addressing.hpp): gfx1250 changed the buffer resource descriptor layout — num_records became a 45-bit field split across dword1[31:25] and dword2[31:0], instead of fitting in dword2 alone. The old single-dword write puts bounds in the wrong bit positions, causing the hardware to see a garbage range and silently return 0 for out-of-bounds elements. Also confirmed by CK's implementation.

Technical Details

Two files changed, both in src/legacy_composable_kernel/composable_kernel/include/utility/:

config.hpp — split gfx1250 out of the gfx10/11 group and assign the correct word-3:

// Before: gfx1250 grouped with gfx10/11, gets 0x31014000 (wrong)
#elif defined(...GFX1201) || defined(CK_AMD_GPU_GFX1250)
#define CK_BUFFER_RESOURCE_3RD_DWORD 0x31014000

// After:
#elif defined(...GFX1201)
#define CK_BUFFER_RESOURCE_3RD_DWORD 0x31014000
#elif defined(CK_AMD_GPU_GFX1250)
#define CK_BUFFER_RESOURCE_3RD_DWORD 0          // matches ck.hpp for __gfx125__

amd_buffer_addressing.hpp — add gfx1250 branch in make_wave_buffer_resource with the correct 45-bit split num_records encoding, matching what modern CK's amd_buffer_addressing_builtins.hpp does for __gfx125__:

#if defined(CK_AMD_GPU_GFX1250)
    wave_buffer_resource.address(Number<0>{}) = const_cast<remove_cv_t<T>*>(p_wave);
    uint64_t num_records = static_cast<uint64_t>(element_space_size) * sizeof(T);
    wave_buffer_resource.range(Number<1>{}) |= static_cast<int32_t>((num_records & 0x7f) << 25);
    wave_buffer_resource.range(Number<2>{}) = static_cast<int32_t>(num_records >> 7);
    wave_buffer_resource.config(Number<3>{}) = CK_BUFFER_RESOURCE_3RD_DWORD;
#else
    // existing pre-gfx12 path unchanged

Why both changes are needed: word-3 controls the descriptor format/control bits; num_records controls the buffer bounds. A descriptor with correct word-3 but wrong range encoding still causes the hardware to misinterpret bounds. Both fields must be correct.

Why the legacy file needs the fix independently: Modern CK routes gfx1250 buffer loads through amd_buffer_addressing_builtins.hpp when __clang_major__ >= 20 (build environment uses clang 23). The legacy path in MIOpen has no such gate — it always uses amd_buffer_addressing.hpp — so the fix must live there directly.

Known follow-up (TODO in config.hpp): gfx11 (1100–1153) and gfx120 (1200/1201) are also assigned 0x31014000 in legacy config.hpp, but modern CK uses 0x31004000 for them (word-3 format changed RDNA2→RDNA3). Only gfx1250 has been verified here; the gfx11/gfx120 discrepancy is tracked in the TODO comment.

Risk Assessment

Risk Level: 🟢 Low

Impacted Components

  • src/legacy_composable_kernel/composable_kernel/include/utility/config.hpp — buffer resource descriptor word-3 definition; affects all legacy-CK kernels compiled for gfx1250.
  • src/legacy_composable_kernel/composable_kernel/include/utility/amd_buffer_addressing.hpp — make_wave_buffer_resource; affects all code using legacy-CK buffer loads on gfx1250.
  • On all other architectures: no change — both fixes are behind #if defined(CK_AMD_GPU_GFX1250).

Potential Side Effects

  • On gfx1250: all legacy-CK buffer load/store operations now use a correctly formed descriptor. This can only improve correctness — wrong descriptors cause silent data corruption or zeros, never correct results, so there is no risk of behavioral regression on gfx1250.
  • On all other arches: changes are completely isolated by the preprocessor guard.

Mitigation Steps

  • Both fixes are strictly additive for gfx1250 and leave all other arches unchanged.
  • Verified with MIOPEN_RNNWRW_REDUCTION=0 and =2 as cross-checks (both use non-buffer-load reduction paths and pass, confirming the RNN logic itself is correct).
  • Verified gfx942 is unaffected.

Test Plan

  1. PyTorch end-to-end on gfx1250 where original failure was observed:
    python test/test_nn.py TestNNDeviceTypeCUDA.test_variable_sequence_cuda_float32
    

Test Result

  • PyTorch test_variable_sequence_cuda_float32 on gfx1250: passes (was: AssertionError: 16/16 elements mismatched, max abs diff 0.988).
  • gfx942 (MI300X): unaffected, continues to pass with default reduction algo (MIOPEN_RNNWRW_REDUCTION=1).

Submission Checklist

SreecharanGundaboluAMD and others added 4 commits June 23, 2026 20:30
In RNNBackwardDataPackedTensors, the activ_cell_offset passed to
LSTMBackwardHiddenStateUpdate used cur_batch (= baccbi) for the
reverse direction (ri==1). However baccbi is incremented at the end
of each time-step iteration, so at the point of the call it holds
the pre-increment value (0 at ti=seqLen-1, growing each step).

The forward pass (RNNForwardTraining) decrements baccbi at the start
of each iteration, so the value it used to write tanh(Ct) into
reserveSpace is baccbi + in_n[seqLen-1-ti] relative to the backward's
baccbi. Reading with the wrong offset causes the backward kernel to
load tanh(Ct) from the wrong location, corrupting all four gate
gradients and producing large errors in the backward data output.

Fix: for ri==1 use baccbi + in_n.at(seqLen-1-ti) as the batch index
in the activ_cell_offset computation, matching the forward write site.

Co-Authored-By: Claude Sonnet 4 <noreply@anthropic.com>

@JonathanLichtnerAMD JonathanLichtnerAMD left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, but could we add a test that reproduces this issue? (We could do that as a follow-on change since we don't want to delay this fix.)

@SreecharanGundaboluAMD

Copy link
Copy Markdown
Contributor Author

LGTM, but could we add a test that reproduces this issue? (We could do that as a follow-on change since we don't want to delay this fix.)

Good point. We should run gtests on gfx1250 first, as this may already be covered by an existing test. We have not really run gtests on gfx1250 before due to limited hardware availability. We should also create a ticket to track this.

@adickin-amd

Copy link
Copy Markdown
Contributor

Merging as change does not affect gfx1151 and windows.

@adickin-amd
adickin-amd merged commit 1dee011 into develop Jun 24, 2026
57 of 61 checks passed
@adickin-amd
adickin-amd deleted the users/SreecharanGundaboluAMD/bugfix_rocm_26590 branch June 24, 2026 17:40
BradPepersAMD pushed a commit that referenced this pull request Jul 2, 2026
…list (#8875)

JIRA ID : ROCM-27193

## Motivation

gfx1250 is a new AMD GPU architecture that was missing from MIOpen's
Composable Kernel (CK) supported architecture list and from the
known-architecture enumeration used in handle unit tests. Without this
entry, any MIOpen build targeting gfx1250 silently skips all CK
grouped-conv solvers, and the `handle_test` suite would fail or produce
a false negative on gfx1250 hardware.

## Technical Details

Two additive, one-line changes following the same pattern used for prior
gfx generations:

1. **`projects/miopen/src/ck_impl/CMakeLists.txt`** — Added `gfx1250` to
`_CK_SUPPORTED_ARCHS`. This list gates which GPU targets receive CK
grouped-conv kernel compilation within MIOpen's CMake build. Missing
entries cause the target to be silently filtered out of the grouped-conv
solver set.

2. **`projects/miopen/test/gtest/handle_test.cpp`** — Added `"gfx1250"`
to the static expected-architecture array in `test_arch_name()`. This
test validates that `MIOpen::Handle::GetDeviceName()` returns a string
from the known-good set; omitting gfx1250 would cause a test failure on
gfx1250 hardware.

No logic changes, no API surface modifications, and no existing
architectures are affected.

## Risk Assessment

**Risk Level: 🟢 Low**

| Level | Indicators |
|-------|-----------|
| 🟢 Low | Purely additive: one new entry in a CMake arch list, one new
string in a gtest array. No logic changes, no existing architecture
affected, trivially revertable. |

### Impacted Components

- `projects/miopen/src/ck_impl/CMakeLists.txt` — CK grouped-conv solver
build configuration
- `projects/miopen/test/gtest/handle_test.cpp` — Handle/arch-name unit
test

### Potential Side Effects

- Builds targeting gfx1250 will now attempt to compile CK grouped-conv
kernels. If CK itself does not yet fully support gfx1250, those builds
may surface new compilation errors — this is the expected discovery
mechanism and not a regression for any existing target.
- No side effects on any other GPU architecture.

### Mitigation Steps

- The change is purely additive and trivially revertable with a
single-line removal in each file.
- CI will exercise the updated `handle_test` and any gfx1250-targeted
build jobs, catching regressions immediately.

## Test Plan

- Run the failing smoke tests and confirm that they are not failing with
the following errors anymore:

- Missing arch in gtest
```
Value of: std::any_of(known_arch.begin(), known_arch.end(),
           [&](std::string arch) { return arch == this_arch; })
  Actual: false
  Expected: true
```
- Add CK to gfx1250 whitelist
```
MIOpen(HIP): Warning [OpenRuntimeLibraryForDevice] CK grouped conv library not found for device gfx1250: libMIOpenCKGroupedConv_gfx1250.so: cannot open shared object file: No such file or directory
```

## Test Result

- [x] `unknown_gpu` exception
```
CPU_Handle_NONE
GPU_MIOpenDriverGemmTest_FP16 
GPU_UnitTestConvSolverFFTFwd_FP32 / FFTBwd_FP32 
GPU_UnitTestActivationDescriptor_FP32 / FP16 
GPU_UnitTestConvSolverWinoRage2x3{Fwd,Bwd,Wrw}_FP16
GPU_UnitTestConvSolverWinoFury2x3{Fwd,Bwd,Wrw}_FP16 
GPU_UnitTestConvSolverTransposedBinWinograd*
GPU_UnitTestConvSolverImplicitGemmGroup{Fwd,Wrw}Xdlops_{FP16,BFP16,FP32,TF32} 
GPU_UnitTestConvSolverGemmFwd* / GemmWrw* 
GPU_CBAFind2FusionWorkspace_FP32 (2 tests — also shows "Gpu data is all zeros")
GPU_GemmFwdRest_LargeMemory_{FP32,FP16}, GPU_GemmBwdRest_LargeMemory_{FP32,FP16}, GPU_GemmWrwUniversal_LargeMemory_{FP32,FP16} 
```
- [x] Reduce accuracy mismatch - Fixed with
#8758
`GPU_Reduce_FP32 (432 tests) and GPU_Reduce_FP16`

- [x] RNN Vanilla backward weights failure - Fixed with
#8758
`GPU_RNNVanilla_FP32 and GPU_RNNVanillaDropout_FP32`


## Submission Checklist

- [ ] Look over the contributing guidelines at
https://github.com/ROCm/ROCm/blob/develop/CONTRIBUTING.md#pull-requests.

---------

Co-authored-by: JonathanLichtnerAMD <195780826+JonathanLichtnerAMD@users.noreply.github.com>
JonathanLichtnerAMD added a commit that referenced this pull request Jul 15, 2026
JIRA ID: ALMIOPEN-2312

## Motivation

`projects/miopen/CHANGELOG.md`'s "MIOpen 3.5.2 for ROCm 7.14.0" section
only had 4 entries, but 68 commits touched `projects/miopen` between the
`therock-7.13` tag and `release/therock-7.14`. Auditing that commit
range (via `git log --oneline
therock-7.13..remotes/origin/release/therock-7.14 -- projects/miopen`)
found 18 additional user-facing changes — new gfx950/gfx1250
architecture support, SystemDB refreshes, AI-heuristic improvements,
several correctness/crash bug fixes, and OpenCL solver removals — that
were never documented. This PR backfills those entries so the 7.14.0
changelog accurately reflects what shipped.

## Technical Details

Added 24 lines to the existing "MIOpen 3.5.2 for ROCm 7.14.0" section of
`projects/miopen/CHANGELOG.md`, merging new bullets into the existing
`Added`/`Changed`/`Resolved Issues` sub-sections (no new entries were
duplicated or reworded) and adding a new `Removed` sub-section for
solver removals. No existing content was altered.

Each new bullet was traced to a specific commit + PR:

| Entry | Commit | PR |
|---|---|---|
| Added gfx950 (MI350X/MI355X) SystemDB | `60d8e1e5175` | #8081 |
| Added initial gfx1250 architecture support | `d3f057b2f22` | #7587 |
| Added JSON-formatted performance logs (`MIOPEN_PERFORMANCE_LOGS`) |
`ffbde871260` | #5736 |
| Refreshed gfx942 SystemDB | `faf754a9ef6` | #8174 |
| Refined 2D AI heuristics (Tunanet/KTN) for gfx942 & gfx950 |
`c24ad415884` | #7109 |
| Fixed thread-safety issue in AI-heuristic model caches | `cd957402309`
| #9149 (cherry-pick of #9131) |
| Fixed CK grouped-conv solvers not always registered in host |
`c971d54d7ae` | #9105 |
| Fixed legacy CK buffer resource descriptor (gfx1250) | `1dee011b8b0` |
#8758 |
| Removed stale gfx942 SystemDB naive-solver entries | `f42668f6316` |
#7028 |
| Fixed softmax NaN when `beta=0` | `fb8157c8512` | #8426 |
| Fixed BN backward spatial variant 1 vectorized memory access bug |
`1351a7e8b10` | #6765 |
| Fixed use-after-free of `kernel_id` in `InitInvokerFactoryNCHW` |
`394ebffb50d` | #7922 |
| Fixed SoftMarginLoss forward reduce-kernel kernarg corruption |
`1e65a31570f` | #8065, #8135 |
| Fixed build with `MIOPEN_ENABLE_AI_KERNEL_TUNING=OFF` | `e6288c3ca61`
| #6800 |
| Fixed install RPATH for MIOpenDriver / CK backend libs | `ef8a4cf2f93`
| #7485 |
| Fixed dangling lambda causing log-level 6 segfault | `190f9791737` |
#6953 |
| Enabled Windows long-path support for `addkernels` | `1f9d69724cf` |
#7387 |
| Removed OCL solver `ConvOclDirectFwd1x1` | `126c720cadd` | #6491 |
| Removed OCL solver `conv_ocl_dir2Dfwdgen` | `2d499ddf709` | #6633 |
| Removed OCL solvers `ConvOclBwdWrW1x1`, `ConvOclBwdWrW2` |
`b5d43a33dc6` | #6859 |
| Removed OCL solvers `OpTensorLeadingOnes`, `Op5dTensorGeneric` |
`8642c83b7de` | #7347 |

The remaining ~40 commits in the 68-commit range were deliberately
excluded (tests/CI/build/docs/internal refactors/1:1 OCL→HIP swaps with
no behavior change, per each commit's own stated scope) and are not
represented here.

## Risk Assessment

**Risk Level: 🟢 Low**

This is a documentation-only change to a single Markdown file. No code,
build configuration, tests, or public API surface is touched.

### Impacted Components

- `projects/miopen/CHANGELOG.md` only.

### Potential Side Effects

None expected. This does not change any runtime behavior; it only
documents changes that already shipped on `release/therock-7.14`.

### Mitigation Steps

None required beyond normal review — a reviewer familiar with the 7.14
release can spot-check a few entries against the linked commit hashes/PR
numbers for accuracy.

## Test Plan

Not applicable (no code changes). Verification was done by
cross-referencing every added bullet against a specific commit hash and
PR number pulled from `git log`, and by diffing the edited section
against `git show
remotes/origin/release/therock-7.14:projects/miopen/CHANGELOG.md` to
confirm no existing entry was duplicated or altered.

## Test Result

All 21 new bullets map 1:1 to a real commit/PR in the
`therock-7.13..release/therock-7.14` range for `projects/miopen`. No
pre-existing changelog text was modified — `git diff` shows a pure
addition (24 insertions, 0 deletions). Two borderline commits
(`a67834413e8` "Standalone build", `7c7cd5774a9` "enable warnings about
deprecated API/features") were deliberately left out pending author
judgment on whether they warrant an entry.
pschang-phy pushed a commit that referenced this pull request Jul 17, 2026
JIRA ID: ALMIOPEN-2312

## Motivation

`projects/miopen/CHANGELOG.md`'s "MIOpen 3.5.2 for ROCm 7.14.0" section
only had 4 entries, but 68 commits touched `projects/miopen` between the
`therock-7.13` tag and `release/therock-7.14`. Auditing that commit
range (via `git log --oneline
therock-7.13..remotes/origin/release/therock-7.14 -- projects/miopen`)
found 18 additional user-facing changes — new gfx950/gfx1250
architecture support, SystemDB refreshes, AI-heuristic improvements,
several correctness/crash bug fixes, and OpenCL solver removals — that
were never documented. This PR backfills those entries so the 7.14.0
changelog accurately reflects what shipped.

## Technical Details

Added 24 lines to the existing "MIOpen 3.5.2 for ROCm 7.14.0" section of
`projects/miopen/CHANGELOG.md`, merging new bullets into the existing
`Added`/`Changed`/`Resolved Issues` sub-sections (no new entries were
duplicated or reworded) and adding a new `Removed` sub-section for
solver removals. No existing content was altered.

Each new bullet was traced to a specific commit + PR:

| Entry | Commit | PR |
|---|---|---|
| Added gfx950 (MI350X/MI355X) SystemDB | `60d8e1e5175` | #8081 |
| Added initial gfx1250 architecture support | `d3f057b2f22` | #7587 |
| Added JSON-formatted performance logs (`MIOPEN_PERFORMANCE_LOGS`) |
`ffbde871260` | #5736 |
| Refreshed gfx942 SystemDB | `faf754a9ef6` | #8174 |
| Refined 2D AI heuristics (Tunanet/KTN) for gfx942 & gfx950 |
`c24ad415884` | #7109 |
| Fixed thread-safety issue in AI-heuristic model caches | `cd957402309`
| #9149 (cherry-pick of #9131) |
| Fixed CK grouped-conv solvers not always registered in host |
`c971d54d7ae` | #9105 |
| Fixed legacy CK buffer resource descriptor (gfx1250) | `1dee011b8b0` |
#8758 |
| Removed stale gfx942 SystemDB naive-solver entries | `f42668f6316` |
#7028 |
| Fixed softmax NaN when `beta=0` | `fb8157c8512` | #8426 |
| Fixed BN backward spatial variant 1 vectorized memory access bug |
`1351a7e8b10` | #6765 |
| Fixed use-after-free of `kernel_id` in `InitInvokerFactoryNCHW` |
`394ebffb50d` | #7922 |
| Fixed SoftMarginLoss forward reduce-kernel kernarg corruption |
`1e65a31570f` | #8065, #8135 |
| Fixed build with `MIOPEN_ENABLE_AI_KERNEL_TUNING=OFF` | `e6288c3ca61`
| #6800 |
| Fixed install RPATH for MIOpenDriver / CK backend libs | `ef8a4cf2f93`
| #7485 |
| Fixed dangling lambda causing log-level 6 segfault | `190f9791737` |
#6953 |
| Enabled Windows long-path support for `addkernels` | `1f9d69724cf` |
#7387 |
| Removed OCL solver `ConvOclDirectFwd1x1` | `126c720cadd` | #6491 |
| Removed OCL solver `conv_ocl_dir2Dfwdgen` | `2d499ddf709` | #6633 |
| Removed OCL solvers `ConvOclBwdWrW1x1`, `ConvOclBwdWrW2` |
`b5d43a33dc6` | #6859 |
| Removed OCL solvers `OpTensorLeadingOnes`, `Op5dTensorGeneric` |
`8642c83b7de` | #7347 |

The remaining ~40 commits in the 68-commit range were deliberately
excluded (tests/CI/build/docs/internal refactors/1:1 OCL→HIP swaps with
no behavior change, per each commit's own stated scope) and are not
represented here.

## Risk Assessment

**Risk Level: 🟢 Low**

This is a documentation-only change to a single Markdown file. No code,
build configuration, tests, or public API surface is touched.

### Impacted Components

- `projects/miopen/CHANGELOG.md` only.

### Potential Side Effects

None expected. This does not change any runtime behavior; it only
documents changes that already shipped on `release/therock-7.14`.

### Mitigation Steps

None required beyond normal review — a reviewer familiar with the 7.14
release can spot-check a few entries against the linked commit hashes/PR
numbers for accuracy.

## Test Plan

Not applicable (no code changes). Verification was done by
cross-referencing every added bullet against a specific commit hash and
PR number pulled from `git log`, and by diffing the edited section
against `git show
remotes/origin/release/therock-7.14:projects/miopen/CHANGELOG.md` to
confirm no existing entry was duplicated or altered.

## Test Result

All 21 new bullets map 1:1 to a real commit/PR in the
`therock-7.13..release/therock-7.14` range for `projects/miopen`. No
pre-existing changelog text was modified — `git diff` shows a pure
addition (24 insertions, 0 deletions). Two borderline commits
(`a67834413e8` "Standalone build", `7c7cd5774a9` "enable warnings about
deprecated API/features") were deliberately left out pending author
judgment on whether they warrant an entry.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants