Skip to content

[hipblaslt] Fix hipblaslt-test abort issue on Windows - #6121

Merged
chuckwu20000 merged 2 commits into
ROCm:developfrom
chuckwu20000:users/shewu/fix_host_memory_OOM_on_Navi4_windows
Apr 6, 2026
Merged

chuckwu20000 merged 2 commits into
ROCm:developfrom
chuckwu20000:users/shewu/fix_host_memory_OOM_on_Navi4_windows

Conversation

@chuckwu20000

Copy link
Copy Markdown
Contributor

Motivation

According to SWDEV-574584, the gtest aborts on the Windows environment with a gfx1201 arch GPU when running a series of large problem sizes.

The root cause is that the memory pool manager relies on the return error code of hipHostMalloc to determine whether it should perform pool cleanup and reallocation. However, hipHostMalloc does not guarantee that it will return an error code—for example, when encountering an OOM condition, the process may be killed directly.

Technical Details

This commit only affects hipblaslt-test on Windows. It reverts most of the changes introduced in PR1 & PR2.

The reason is that, in the Windows environment, the logic inside get_available_host_memory() cannot reliably determine when to clear the memory pool in order to release space for the next host memory allocation.

Although previous PRs attempted to accumulate host memory usage via h_memory, this approach cannot reflect the actual shared memory usage due to unpredictable host memory behavior. This was observed by running a sequence of small problems, where a large amount of host memory was consumed without any new allocations being recorded.
Additionally, the Windows environment does not provide an API to query available shared host memory.

For the above reasons, hipblaslt-test is not suitable for retaining old allocations under tight shared-memory conditions on Windows.
Therefore, this commit cleans the memory pool whenever a new allocation is required, in order to prevent the process from being killed by an OOM condition.

Test Plan

Test Result

Submission Checklist

@chuckwu20000
chuckwu20000 marked this pull request as ready for review April 2, 2026 08:20
@chuckwu20000
chuckwu20000 requested a review from a team as a code owner April 2, 2026 08:20
@codecov-commenter

codecov-commenter commented Apr 2, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

❌ Your project status has failed because the head coverage (77.72%) is below the target coverage (80.00%). You can increase the head coverage or adjust the target coverage.

Additional details and impacted files
@@           Coverage Diff            @@
##           develop    #6121   +/-   ##
========================================
  Coverage    68.20%   68.20%           
========================================
  Files         1865     1865           
  Lines       288816   288816           
  Branches     40718    40718           
========================================
  Hits        196975   196975           
  Misses       75132    75132           
  Partials     16709    16709           
Flag Coverage Δ *Carryforward flag
hipBLAS 90.67% <ø> (ø) Carriedforward from 06fc0ba
hipBLASLt 43.47% <ø> (ø)
hipCUB 82.21% <ø> (ø) Carriedforward from 06fc0ba
hipDNN 86.32% <ø> (ø) Carriedforward from 06fc0ba
hipFFT 56.31% <ø> (ø) Carriedforward from 06fc0ba
hipRAND 76.12% <ø> (ø) Carriedforward from 06fc0ba
hipSOLVER 68.73% <ø> (ø) Carriedforward from 06fc0ba
hipSPARSE 84.70% <ø> (ø) Carriedforward from 06fc0ba
rocBLAS 47.97% <ø> (ø) Carriedforward from 06fc0ba
rocFFT 57.61% <ø> (ø) Carriedforward from 06fc0ba
rocRAND 57.07% <ø> (ø) Carriedforward from 06fc0ba
rocSOLVER 77.72% <ø> (ø) Carriedforward from 06fc0ba
rocSPARSE 71.48% <ø> (ø) Carriedforward from 06fc0ba

*This pull request uses carry forward flags. Click here to find out more.
see 1 file with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@chuckwu20000
chuckwu20000 merged commit a9ff799 into ROCm:develop Apr 6, 2026
35 checks passed
assistant-librarian Bot pushed a commit to ROCm/hipBLASLt that referenced this pull request Apr 6, 2026
[hipblaslt] Fix hipblaslt-test abort issue on Windows
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

## Motivation

<!-- Explain the purpose of this PR and the goals it aims to achieve.
-->
According to
[SWDEV-574584](https://ontrack-internal.amd.com/browse/SWDEV-574584),
the gtest aborts on the Windows environment with a gfx1201 arch GPU when
running a series of large problem sizes.

The root cause is that the memory pool manager relies on the return
error code of hipHostMalloc to determine whether it should perform pool
cleanup and reallocation. However, hipHostMalloc does not guarantee that
it will return an error code—for example, when encountering an OOM
condition, the process may be killed directly.

## Technical Details

<!-- Explain the changes along with any relevant GitHub links. -->
This commit only affects hipblaslt-test on Windows. It reverts most of
the changes introduced in
[PR1](ROCm/rocm-libraries#4793) &
[PR2](ROCm/rocm-libraries#5270).

The reason is that, in the Windows environment, the logic inside
get_available_host_memory() cannot reliably determine when to clear the
memory pool in order to release space for the next host memory
allocation.

Although previous PRs attempted to accumulate host memory usage via
h_memory, this approach cannot reflect the actual shared memory usage
due to unpredictable host memory behavior. This was observed by running
a sequence of small problems, where a large amount of host memory was
consumed without any new allocations being recorded.
Additionally, the Windows environment does not provide an API to query
available shared host memory.

For the above reasons, hipblaslt-test is not suitable for retaining old
allocations under tight shared-memory conditions on Windows.
Therefore, this commit cleans the memory pool whenever a new allocation
is required, in order to prevent the process from being killed by an OOM
condition.

## Test Plan

<!-- Explain any relevant testing done to verify this PR. -->

## Test Result

<!-- Briefly summarize test outcomes. -->

## Submission Checklist

- [X] Look over the contributing guidelines at
https://github.com/ROCm/ROCm/blob/develop/CONTRIBUTING.md#pull-requests.
vidyasagar-amd pushed a commit that referenced this pull request Apr 9, 2026
## Motivation

<!-- Explain the purpose of this PR and the goals it aims to achieve.
-->
According to
[SWDEV-574584](https://ontrack-internal.amd.com/browse/SWDEV-574584),
the gtest aborts on the Windows environment with a gfx1201 arch GPU when
running a series of large problem sizes.

The root cause is that the memory pool manager relies on the return
error code of hipHostMalloc to determine whether it should perform pool
cleanup and reallocation. However, hipHostMalloc does not guarantee that
it will return an error code—for example, when encountering an OOM
condition, the process may be killed directly.

## Technical Details

<!-- Explain the changes along with any relevant GitHub links. -->
This commit only affects hipblaslt-test on Windows. It reverts most of
the changes introduced in
[PR1](#4793) &
[PR2](#5270).

The reason is that, in the Windows environment, the logic inside
get_available_host_memory() cannot reliably determine when to clear the
memory pool in order to release space for the next host memory
allocation.

Although previous PRs attempted to accumulate host memory usage via
h_memory, this approach cannot reflect the actual shared memory usage
due to unpredictable host memory behavior. This was observed by running
a sequence of small problems, where a large amount of host memory was
consumed without any new allocations being recorded.
Additionally, the Windows environment does not provide an API to query
available shared host memory.

For the above reasons, hipblaslt-test is not suitable for retaining old
allocations under tight shared-memory conditions on Windows.
Therefore, this commit cleans the memory pool whenever a new allocation
is required, in order to prevent the process from being killed by an OOM
condition.

## Test Plan

<!-- Explain any relevant testing done to verify this PR. -->

## Test Result

<!-- Briefly summarize test outcomes. -->

## Submission Checklist

- [X] Look over the contributing guidelines at
https://github.com/ROCm/ROCm/blob/develop/CONTRIBUTING.md#pull-requests.
COrruDXC pushed a commit to COrruDXC/rocm-libraries that referenced this pull request Jun 4, 2026
## Motivation

<!-- Explain the purpose of this PR and the goals it aims to achieve.
-->
According to
[SWDEV-574584](https://ontrack-internal.amd.com/browse/SWDEV-574584),
the gtest aborts on the Windows environment with a gfx1201 arch GPU when
running a series of large problem sizes.

The root cause is that the memory pool manager relies on the return
error code of hipHostMalloc to determine whether it should perform pool
cleanup and reallocation. However, hipHostMalloc does not guarantee that
it will return an error code—for example, when encountering an OOM
condition, the process may be killed directly.

## Technical Details

<!-- Explain the changes along with any relevant GitHub links. -->
This commit only affects hipblaslt-test on Windows. It reverts most of
the changes introduced in
[PR1](ROCm#4793) &
[PR2](ROCm#5270).

The reason is that, in the Windows environment, the logic inside
get_available_host_memory() cannot reliably determine when to clear the
memory pool in order to release space for the next host memory
allocation.

Although previous PRs attempted to accumulate host memory usage via
h_memory, this approach cannot reflect the actual shared memory usage
due to unpredictable host memory behavior. This was observed by running
a sequence of small problems, where a large amount of host memory was
consumed without any new allocations being recorded.
Additionally, the Windows environment does not provide an API to query
available shared host memory.

For the above reasons, hipblaslt-test is not suitable for retaining old
allocations under tight shared-memory conditions on Windows.
Therefore, this commit cleans the memory pool whenever a new allocation
is required, in order to prevent the process from being killed by an OOM
condition.

## Test Plan

<!-- Explain any relevant testing done to verify this PR. -->

## Test Result

<!-- Briefly summarize test outcomes. -->

## Submission Checklist

- [X] Look over the contributing guidelines at
https://github.com/ROCm/ROCm/blob/develop/CONTRIBUTING.md#pull-requests.
tony-davis added a commit that referenced this pull request Nov 6, 2026
… them (#14608)

JIRA ID : AIHPBLAS-5352

## Motivation

`hipblaslt-test`, the hipBLASLt test client, keeps the host buffers that
each test frees in a pool, so the next test can reuse them instead of
allocating again. These buffers are pinned (allocated with
`hipHostMalloc`, so the operating system can neither page them out nor
reclaim them), and the pool kept every one until the process exited. On
the gfx1250 hardware test host, which has about 499 GiB of memory, the
93 cases with 2^31- and 2^32-element sizes enabled in #13504 left about
123 GiB pinned in one process. With 4 CI runners each splitting the
suite into 4 parallel test processes, the out-of-memory killer took the
runners down on 10-23 and 10-27. Separately, a failed host allocation
returns a null buffer, and the test then writes through it.

I don't think this stack guarantees the gfx1250 host never runs short.
What it does is make the client hold much less pinned memory, give it
back sooner, and skip a case with the amounts instead of getting killed,
which is the part of the problem the client can fix. If pressure comes
back, the 110 GiB container caps from #14569 keep a kill inside one job,
and putting the lock back (#14982 removes it) is a one-file revert. So
I'm not planning a long soak test before merging.

The pool comes from ROCm/hipBLASLt#1202, which reused allocations to
speed up `hipblaslt-bench` across about 500,000 small matmuls. Reuse
still matters for large buffers: on the test host below, `hipHostMalloc`
takes about 0.18 s per GiB and `hipHostFree` about 0.06 s per GiB.

## Technical Details

- A pooled host buffer of 1 GiB or more (`kHostPoolRetainLimit` in
`d_vector.hpp`) now stays cached only while consecutive tests reuse it.
The pool records the test count when a buffer comes back, and
`HostPoolReleaseListener`, a new hook that Google Test calls after every
test, frees the large buffers that the test just ended did not use. A
run of same-shape cases, such as the four transpose combinations (NN,
NT, TN, TT) of one size, still shares one allocation.
- When a test asks for a large buffer that no cached buffer fits, the
pool first frees the large buffers that earlier tests left, then pins
new memory. This keeps the peak near one test's footprint when the shape
changes.
- A host buffer no longer gets the pool's 20% extra capacity when the
extra would take it to 1 GiB or more (`host_pool_capacity()`), so a
buffer under the limit stays under it. The existing cutoff for skipping
the extra is a quarter of device memory, so on gfx1250 nearly every host
buffer got it.
- `HipHostBuffer::memcheck()` reports a failed pinned allocation, and
`testing_matmul` checks every host buffer after allocating, including
the four temporary buffers a swizzled A or B is built in. A failure now
skips the test with the requested size ("could not allocate N GiB of
pinned host memory").
- A pooled host buffer under 1 GiB is released once 100 consecutive
tests have not reused it (`kHostPoolSmallIdleTests`). The pool reuses a
buffer only for requests between half its size and its size, so without
this a run of shrinking requests kept every earlier buffer pinned.
- In `hipblaslt-bench`, a failed host allocation now exits with a
failure, as a failed device allocation already did, instead of reporting
success.
- Device memory behaves as before. `hipblaslt-bench` does not install
the listener, so it never frees large buffers early; it does see the 20%
change for host buffers of 1 GiB or more. The hipBLASLt library itself
is unchanged.

This is the first of four stacked PRs for AIHPBLAS-5352. #14609 makes
the client's host-memory query respect container memory limits, #14610
runs the memory preflight for every matmul case, and #14982 drops the
host-wide lock in the gfx1250 workflow.

## Test Plan

- `HostMemory_pre_checkin` (new,
`clients/tests/src/host_memory_gtest.cpp`, 6 tests; the `_pre_checkin`
suffix puts it in the standard tier the PR checks run). The tests check
that a large buffer survives one test boundary and is freed after the
next, that a same-shape test reuses it (what the first test wrote is
still there), that a large miss frees two buffers earlier tests left,
that a 1 GiB request gets exactly 1 GiB, that a small buffer is released
after 100 tests that do not reuse it (and kept when one does), and that
a failed allocation leaves a null buffer whose size is reported. A 0.9
GiB request gets exactly 0.9 GiB (the old rule gave it 1.08 GiB, over
the limit). The tests skip, naming the buffer, on a host that cannot pin
that much, and the reuse test skips on a Windows host where the pool
frees its idle buffers before every request. A temporary variant without
the small-buffer aging failed the new test.
- To confirm the tests can fail, I built two temporary variants of the
pool. One undid four behaviors at once (no release at the end of a test,
no release on a miss, the 20% extra restored, `memcheck()` always
succeeding), and it failed 4 of the 5 tests. The other freed large
buffers whether or not a test used them, and it failed 3. Every test
failed under at least one variant.
- The 82 large-memory cases that apply to gfx90a (the five name patterns
from #14545), and the `smoke` and `quick` tiers, on develop and on this
branch, for wall time and peak resident memory.
- Handle leaks: #14714 and #14700 on develop give the matrix layouts,
matmul descriptors and HIP events owners, so an early return no longer
leaks them. To check that with this stack's new early returns, a
preloaded library counted creates and destroys of all three, on the full
stack, over 1,892 matmul cases, once normally and once under a 1 MiB
host limit so that most cases skip at the preflight.
- Adjacent: the `FastCheck_pre_checkin` and
`FastCheckDevice_pre_checkin` suites, including
`memory_shortfall_reclaims_idle_buffers`, which uses the pool's existing
`ReleaseCached()`. `hipblaslt-bench` was built, because it compiles the
non-gtest form of the new check, but not run.

## Test Result

One MI210 (gfx90a) on a shared host with 2.2 TB of memory. This branch's
clients were built against the 10-25 TheRock nightly hipBLASLt gfx90a
device library. Each pair of runs went back to back, but the host was
busy (load average near 300), so the times carry some noise.

| Measurement | develop | this PR |
| --- | --- | --- |
| 82 large-memory cases, wall time | 316.9 s | 313.8 s |
| 82 large-memory cases, peak resident memory | 81.9 GiB | 49.2 GiB |
| 82 large-memory cases, mean resident memory | 66.9 GiB | 16.6 GiB |
| Resident memory after the last large case | 74 GiB | 2 GiB |
| `smoke` + `quick` (9,171 tests), two runs | 66.6 s, 62.0 s | 63.6 s,
64.1 s |

- Large-memory cases: 82 of 82 passed on both. `smoke` + `quick`: 9,169
passed and 2 skipped (`GroupedMatmul.smoke_Fp16NN` and `smoke_Bf16NN`,
which skip on this GPU) on both.
- `HostMemory_pre_checkin`, `FastCheck_pre_checkin` and
`FastCheckDevice_pre_checkin`: 64 of 64 passed.
- A first version that freed every large buffer at the end of each test
took 449.6 s for the large cases against 318.2 s on develop, which is
why the pool keeps a buffer while the next test reuses it.
- Handle leaks: 0 layouts, descriptors or events left, both normally
(13,580 created) and with 409 cases skipped at the preflight (11,235
created).
- With the small-buffer aging, `smoke` + `quick` passed 9,225 tests in
59.3 s with peak resident memory 2.18 GiB.
- gfx1250: this PR alone passed the hardware workflow's hipBLASLt tests
in
[40934683157](https://github.com/ROCm/rocm-libraries/actions/runs/40934683157),
and Archana dispatched the full stack in
[41582794047](https://github.com/ROCm/rocm-libraries/actions/runs/41582794047),
which passed hipBLASLt twice with no kills and no memory skips. Her run
on the rebased stack,
[41717825380](https://github.com/ROCm/rocm-libraries/actions/runs/41717825380),
was clean too. All three kept the host-wide lock; #14982 covers the run
without it.
- Automated GitHub checks are pending.

## Submission Checklist

- [x] Look over the contributing guidelines at
https://github.com/ROCm/TheRock/blob/main/GOVERNANCE.md#pull-requests.

## Risk level

Medium (3/5). Every `hipblaslt-test` case passes through the new
listener and the host pool, so a mistake here would affect the whole
suite. The hipBLASLt library and device behavior are unchanged; only the
test and bench clients change. The bench sees the 20% change near 1 GiB,
and now exits with a failure when a host allocation fails.

## Related

- Work tracking:
[AIHPBLAS-5352](https://amd-hub.atlassian.net/browse/AIHPBLAS-5352),
fixes 1 (pool retention) and 4 (null host buffer) of its list.
- Cause: #13504. CI workaround this work is meant to replace: #14545,
merged on 10-28.
- Where the pool came from: ROCm/hipBLASLt#1202. Windows already clears
the pool on smaller-memory hosts for the same reason: #4793, #6121.

## Device / Architecture Coverage

Host-side test-client code only, with no kernel, library or
kernel-selection change, so it does not depend on the GPU architecture
and the standard PR checks are enough. Measured on gfx90a.

## Flags / Guardrails

None. The 1 GiB threshold is the constant `kHostPoolRetainLimit`.


[AIHPBLAS-5352]:
https://amd-hub.atlassian.net/browse/AIHPBLAS-5352?atlOrigin=eyJpIjoiNWRkNTljNzYxNjVmNDY3MDlhMDU5Y2ZhYzA5YTRkZjUiLCJwIjoiZ2l0aHViLWNvbS1KU1cifQ

---------

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants