Skip to content

Conversation

@anujshuk-amd
Copy link

@anujshuk-amd anujshuk-amd commented Jan 8, 2026

Later will move/remove this
Used by : ROCm/rocm-systems#2542

Motivation

These updates ensure that storage can grow as needed and that concurrent accesses are safely managed.

Technical Details

This pull request refactors the storage management logic in source/timemory/operations/types.hpp to improve thread safety and scalability. The main changes are the switch from a fixed-size array to a dynamically resizing vector for storage, the introduction of atomic and mutex-based synchronization for concurrent access, and the use of a configurable thread limit.

Thread safety and dynamic storage management

  • Changed set_storage from using a fixed-size std::array to a dynamically resizing std::vector, allowing for more flexible and scalable storage of thread-local data. ([source/timemory/operations/types.hppL816-R872](https://github.com/ROCm/timemory/pull/21/files#diff-e60a89742e16350cc3b36bbb562d4c77c8b1b7e34bd8a2011b6f81cf13fb771eL816-R872))
  • Added atomic and mutex-based synchronization (std::atomic, std::mutex) to ensure safe concurrent resizing and access of the storage vector. ([[1]](https://github.com/ROCm/timemory/pull/21/files#diff-e60a89742e16350cc3b36bbb562d4c77c8b1b7e34bd8a2011b6f81cf13fb771eR42-R45), [[2]](https://github.com/ROCm/timemory/pull/21/files#diff-e60a89742e16350cc3b36bbb562d4c77c8b1b7e34bd8a2011b6f81cf13fb771eL816-R872))
  • Implemented an ensure_capacity method in set_storage to grow the storage vector geometrically (doubling size) when a new thread index exceeds current capacity, ensuring efficient scaling and minimizing lock contention. ([source/timemory/operations/types.hppL816-R872](https://github.com/ROCm/timemory/pull/21/files#diff-e60a89742e16350cc3b36bbb562d4c77c8b1b7e34bd8a2011b6f81cf13fb771eL816-R872))
  • Updated thread limit configuration by replacing the hardcoded 4096 with the TIMEMORY_MAX_THREADS macro for greater flexibility. ([source/timemory/operations/types.hppL816-R872](https://github.com/ROCm/timemory/pull/21/files#diff-e60a89742e16350cc3b36bbb562d4c77c8b1b7e34bd8a2011b6f81cf13fb771eL816-R872))

Safe access and read logic

  • Modified get_storage to use atomic capacity checks before accessing the storage vector, returning nullptr for out-of-bounds thread indices to prevent unsafe reads. ([source/timemory/operations/types.hppR905-R907](https://github.com/ROCm/timemory/pull/21/files#diff-e60a89742e16350cc3b36bbb562d4c77c8b1b7e34bd8a2011b6f81cf13fb771eR905-R907))

Test Plan

To be tested in CI/CD or rocm-system

Test Result

TBA

Submission Checklist

ajanicijamd and others added 18 commits January 31, 2025 11:39
Fixed a bug in processing command line parameters
…ction not being called when a default is defined (#3)
Invalid RPATH used for libunwind properties. Failing RPM generations and rpath check on RHEL 10.

---------

Signed-off-by: David Galiffi <[email protected]>
Update submodule to ROCm/GOTCHA@c04cc3f (v1.0.8 +).
Now points to the ROCm fork of GOTCHA
* Exclude perf_event_uncore events from evaluation

* Change1: Optimization and cleaner code fixes
Fallback to use `patchelf`, if `chrpath` is not present.
Change some logging from "WARNING"s to "AUTHOR_WARNING"s.

Signed-off-by: David Galiffi <[email protected]>
…owth

- Replace fixed std::array with std::vector for dynamic thread storage
- Add ensure_capacity() with double-checked locking pattern
- Use std::atomic<size_t> for lock-free capacity reads
- Add bounds checking in get_storage operation
- Implement geometric growth (2x doubling) when capacity exceeded
- Initial capacity set to TIMEMORY_MAX_THREADS, grows as needed
@anujshuk-amd anujshuk-amd force-pushed the users/anujshuk/dynamic-thread-storage_ds branch 2 times, most recently from 8d9b5e6 to 696a160 Compare January 14, 2026 09:16
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.

8 participants