-
Notifications
You must be signed in to change notification settings - Fork 186
[rocBLAS] Refactor memory management in host_alloc.cpp #3672
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
Conversation
Updated the memory deallocation logic in free_ptr_use to use an iterator for accessing allocated memory. This change improves code clarity and efficiency by directly checking the existence of the pointer in the mem_allocated map and adjusting the memory usage accordingly.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR refactors the memory deallocation logic in free_ptr_use() to use iterator-based map access, improving both efficiency and correctness. The change eliminates redundant map lookups and prevents unintended insertions that could occur with operator[].
Key Changes:
- Replaced three sequential map lookups with a single
find()call using an iterator - Used the cached iterator for subsequent operations (accessing size and erasing entry)
- Eliminated risk of unintended map insertions when checking for pointer existence
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## develop #3672 +/- ##
===========================================
- Coverage 49.69% 46.04% -3.65%
===========================================
Files 134 365 +231
Lines 33491 51594 +18103
Branches 4399 5964 +1565
===========================================
+ Hits 16641 23752 +7111
- Misses 15607 24359 +8752
- Partials 1243 3483 +2240
Flags with carried forward coverage won't be shown. Click here to find out more. 🚀 New features to boost your workflow:
|
TorreZuk
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I approve but my suggestions I usually want considered to be made before merge :-)
My style is I only don't approve if I think the merge would cause trouble as is.
… users/todavis/host_alloc_fix
…reeing untracked pointers.
… users/todavis/host_alloc_fix
|
Looks like you have to run clang format again, otherwise only baseline fails. |
Summary
Improved memory management in
host_alloc.cppby refactoring the deallocation logic for better efficiency and adding diagnostic warnings for untracked pointer frees.Changes
free_ptr_use()to use iterator-based access (reduces redundant map lookups)Motivation
The current implementation of
free_ptr_use()inhost_alloc.cpphad two issues:operator[]on a map can unintentionally insert entries for non-existent keysThis PR addresses all three issues by refactoring the lookup logic and adding diagnostic warnings.
Technical Details
File:
projects/rocblas/clients/common/host_alloc.cppChange 1: Iterator-based memory deallocation
Before:
After:
Benefits:
operator[]Change 2: Diagnostic warning for untracked pointers
Added:
Benefits:
Test Plan
Test Result
Submission Checklist