Skip to content

fix(rocBLAS): repair d_vector guard logic and HMM accounting - #11398

Open
bobbyphilip-amd wants to merge 5 commits into
developfrom
fix/dvector-guard-and-hmm-accounting
Open

bobbyphilip-amd wants to merge 5 commits into
developfrom
fix/dvector-guard-and-hmm-accounting

Conversation

@bobbyphilip-amd

@bobbyphilip-amd bobbyphilip-amd commented Aug 28, 2026

Copy link
Copy Markdown
Contributor

JIRA ID: AIROCBLAS-1381

AIROCBLAS-1381

Summary

Core bug fixes (d_vector.hpp)

  • device_vector_teardown released the HMM memory count keyed on the base allocation pointer instead of the offset (post-guard) pointer that alloc_ptr_use registered; the map miss was silent so the ceiling rose permanently for the life of the process — fixed by calling free_ptr_use before d -= m_pad
  • device_vector_check read both guard regions into a single shared buffer; a failed hipMemcpy left stale bytes from the previous guard that caused a missed or false corruption report — each guard now reads into its own stack buffer
  • A failed guard write in device_vector_setup now zeros m_guard_len so device_vector_check does not compare uninitialized device memory against the guard pattern; the pointer still advances by m_pad so teardown arithmetic stays consistent; device_vector_check gates on m_guard_len > 0
  • Guard copies keep hipMemcpyDefault (preferred for HMM / managed memory; explicit HostToDevice/DeviceToHost was tried and reverted)
  • m_guard initialized via std::call_once + std::once_flag replacing a racy static bool pattern
  • Stack arrays in device_vector_check instead of heap-allocating containers (safe to use from a destructor; std::vector construction can throw std::bad_alloc → std::terminate)
  • #include <mutex> and m_init_flag declaration and out-of-line definition wrapped in #ifdef GOOGLE_TEST (only used in test builds)

Pre-existing bug fixes

  • d_vector.hpp: #if __GLIBC__ < 3 && __GLIBC_MINOR__ < 39 → #if defined(__GLIBC__) && __GLIBC__ < 3 && __GLIBC_MINOR__ < 39 — on non-glibc platforms __GLIBC__ is undefined and evaluated as 0, silently suppressing _GLIBCXX_USE_C99_INTTYPES_TR1 on every non-glibc build
  • host_alloc.cpp (host_malloc): racy static auto once = false / once = true pattern replaced with std::call_once + std::once_flag; unnecessary [&] capture removed (static locals are accessible without capture)
  • host_alloc.cpp (host_bytes_available): mem_token selection and strlen collapsed into two statics resolved once at first call — removes per-call strlen and the mutable-static-pointer pattern
  • host_alloc.cpp: comment // B to GB corrected to // GB to B

Test plan

  • guard_detects_post_overwrite — deliberately writes zeros into the post-guard; asserts device_vector_check fires with "post-guard" via EXPECT_NONFATAL_FAILURE; uses ASSERT (not EXPECT) on hipMemset so a memset failure produces kFatalFailure rather than a nonfatal failure that would satisfy SingleFailureChecker and mask the real problem
  • guard_detects_pre_overwrite — mirror of above for the pre-guard region
  • guard_no_false_positive_on_clean_alloc — allocates and destroys a device_vector without touching the guards; uses ScopedFakeTestPartResultReporter to assert zero nonfatal failures are emitted
  • hmm_count_returns_to_its_baseline — verifies the HMM accounting count returns to its pre-allocation baseline after a full managed device_vector lifecycle with a nonzero guard pad

@therock-pr-bot

therock-pr-bot Bot commented Aug 28, 2026

Copy link
Copy Markdown

✅ All Checks Passed — Ready for Review

Check Status Details
📝 PR Description ✅ Pass
Forbidden Files ✅ Pass
🧪 Unit Test ✅ Pass
🔎 pre-commit ✅ Pass
🚫 Draft PR 🔜 To Be Enabled
🚩 Feature Flag 🔜 To Be Enabled
📊 Code Coverage 🔜 To Be Enabled
🤖 therock-pr-bot ✅ Pass

🎉 All checks passed! This PR is ready for review.

📖 Need help? See the Policy FAQ for details on every check and how to fix failures.

🙋 Wish to Override Policy?

@therock-pr-bot

therock-pr-bot Bot commented Aug 28, 2026

Copy link
Copy Markdown

🎉 All checks passed! This PR is ready for review.

@bobbyphilip-amd

bobbyphilip-amd commented Aug 28, 2026

Copy link
Copy Markdown
Contributor Author

@TorreZuk, take a look at this. If it makes sense I'll change from draft PR status. It's overly verbose at this point, but I can fix that later. Note there's a follow on that addresses a comment you made on the syrk PR

@bobbyphilip-amd
bobbyphilip-amd force-pushed the fix/dvector-guard-and-hmm-accounting branch from 857d4a1 to b1d004f Compare August 28, 2026 05:45
@codecov

codecov Bot commented Aug 28, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

❌ Your project check has failed because the head coverage (48.25%) 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   #11398      +/-   ##
===========================================
- Coverage    70.71%   70.70%   -0.01%     
===========================================
  Files         2847     2847              
  Lines       466776   466775       -1     
  Branches     68835    68835              
===========================================
- Hits        330060   330026      -34     
- Misses      112771   112812      +41     
+ Partials     23945    23937       -8     
Flag Coverage Δ *Carryforward flag
TensileLite-CPP 48.80% <ø> (ø) Carriedforward from 7a1cd6d
TensileLite-Unit 76.47% <ø> (ø) Carriedforward from 7a1cd6d
hipBLAS 90.62% <ø> (ø) Carriedforward from 7a1cd6d
hipBLASLt 35.28% <ø> (ø) Carriedforward from 7a1cd6d
hipCUB 82.68% <ø> (ø) Carriedforward from 7a1cd6d
hipDNN 86.98% <ø> (ø) Carriedforward from 7a1cd6d
hipFFT 54.81% <ø> (ø) Carriedforward from 7a1cd6d
hipRAND 76.12% <ø> (ø) Carriedforward from 7a1cd6d
hipSOLVER 68.96% <ø> (ø) Carriedforward from 7a1cd6d
hipSPARSE 86.99% <ø> (ø) Carriedforward from 7a1cd6d
rocBLAS 48.25% <ø> (-0.06%) ⬇️
rocFFT 46.27% <ø> (ø) Carriedforward from 7a1cd6d
rocRAND 57.42% <ø> (ø) Carriedforward from 7a1cd6d
rocSOLVER 76.83% <ø> (ø) Carriedforward from 7a1cd6d
rocSPARSE 74.61% <ø> (-<0.01%) ⬇️ Carriedforward from 7a1cd6d
rocThrust 93.15% <ø> (ø) Carriedforward from 7a1cd6d

*This pull request uses carry forward flags. Click here to find out more.
see 6 files 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.

Comment thread projects/rocblas/clients/include/d_vector.hpp Outdated
Comment thread projects/rocblas/clients/gtest/host_alloc_gtest.cpp

@TorreZuk TorreZuk 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.

If all tests pass LGTM

@TorreZuk

Copy link
Copy Markdown
Contributor

@bobbyphilip-amd can you get this one moving again or need help?

Comment thread projects/rocblas/clients/include/d_vector.hpp
@bobbyphilip-amd
bobbyphilip-amd force-pushed the fix/dvector-guard-and-hmm-accounting branch 2 times, most recently from 8816664 to 151ee89 Compare September 16, 2026 21:44
@bobbyphilip-amd
bobbyphilip-amd force-pushed the fix/dvector-guard-and-hmm-accounting branch from 151ee89 to 8eeb747 Compare September 18, 2026 18:13
@bobbyphilip-amd
bobbyphilip-amd marked this pull request as ready for review September 18, 2026 18:30
Copilot AI lite review requested due to automatic review settings September 18, 2026 18:30
@bobbyphilip-amd
bobbyphilip-amd requested review from a team as code owners September 18, 2026 18:30
@bobbyphilip-amd
bobbyphilip-amd force-pushed the fix/dvector-guard-and-hmm-accounting branch from 4e4d546 to 423c9ff Compare September 18, 2026 18:31
@bobbyphilip-amd bobbyphilip-amd self-assigned this Sep 18, 2026

Copilot AI 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.

🟡 Changes recommended

One or more issues must be addressed before approval.

Get a fresh assessment by requesting another Copilot review.

Pull request overview

Repairs rocBLAS client device-guard handling and HMM memory accounting, while adding regression tests and making host allocation initialization thread-safe.

Changes:

  • Fixes guard setup/check/teardown behavior and pointer accounting.
  • Adds guard-corruption and HMM lifecycle tests.
  • Simplifies host-memory environment parsing and initialization.
File summaries
File Description
projects/rocblas/clients/include/d_vector.hpp Updated as part of this pull request.
projects/rocblas/clients/gtest/host_alloc_gtest.cpp Updated as part of this pull request.
projects/rocblas/clients/gtest/CMakeLists.txt Updated as part of this pull request.
projects/rocblas/clients/common/host_alloc.cpp Updated as part of this pull request.
Review details

Suppressed comments (1)

projects/rocblas/clients/common/host_alloc.cpp:198

  • The rocBLAS contribution guide explicitly prefers function-local static initialization over std::call_once for one-time setup (projects/rocblas/.github/CONTRIBUTING.rst:375-392). Since this value is immutable after reading the environment, a static const int value = [] { ... }(); is thread-safe, removes the extra flag, and matches the repository's documented pattern.
        static std::once_flag once_flag;
        std::call_once(once_flag, [] {
  • Files reviewed: 4/4 changed files
  • Comments generated: 3
  • Review effort level: Lite

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread projects/rocblas/clients/gtest/CMakeLists.txt
Comment thread projects/rocblas/clients/gtest/host_alloc_gtest.cpp
Comment thread projects/rocblas/clients/include/d_vector.hpp
@bobbyphilip-amd
bobbyphilip-amd force-pushed the fix/dvector-guard-and-hmm-accounting branch 3 times, most recently from f12440f to 373280f Compare September 18, 2026 22:17
@bobbyphilip-amd

Copy link
Copy Markdown
Contributor Author

@TorreZuk, FYI, this should have passed but of course I got a GPU hang. Rerunning.

@TorreZuk

Copy link
Copy Markdown
Contributor

I don't want to push you too hard, but as you are changing HMM next time you would want to add the ci:extended label as those are the ones that run additional HMM test with HSA_XNACK=1. It is also too late on Friday for me to push a new instruction file that hopefully will suggest this to you when getting co-pilot reviews. If you didn't have a stack I would say you could set auto-merge if you are happy with it. Have a good weekend!

bobbyphilip-amd and others added 5 commits September 18, 2026 21:42
- device_vector_teardown released managed memory count keyed on the
  offset (post-guard) pointer rather than the base allocation pointer,
  leaving the RAM ceiling inflated for the process lifetime; fixed by
  releasing before the pointer advances

- device_vector_check read both guard regions into one buffer; a failed
  hipMemcpy left stale bytes that caused a missed corruption or a false
  one; each guard now reads into its own buffer, conditioned on its copy

- a failed guard write in device_vector_setup now zeros m_guard_len so
  device_vector_check does not compare uninitialized device memory
  against the guard pattern and report corruption that never happened;
  applies to both the pre- and post-guard write; the pointer still
  advances by m_pad so teardown arithmetic stays consistent;
  device_vector_check now gates on m_guard_len > 0

- m_guard_len(0 * sizeof(T)) in the non-test constructor simplified to
  m_guard_len(0); stale m_pad(0) comment removed

Adds three tests: guard_detects_post_overwrite and
guard_detects_pre_overwrite verify that device_vector_check fires when
either guard region is overwritten; hmm_count_returns_to_its_baseline
verifies that the HMM accounting count returns to its baseline after a
managed device_vector lifecycle with a nonzero guard pad.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-authored-by: bobbyphilip-amd <267730874+bobbyphilip-amd@users.noreply.github.com>
Record dv.memcheck() under the fake reporter so a failed 1024-element
allocation cannot greenwash an empty failure list.
@bobbyphilip-amd
bobbyphilip-amd force-pushed the fix/dvector-guard-and-hmm-accounting branch from 373280f to db41589 Compare September 19, 2026 03:43
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.

4 participants