-
Notifications
You must be signed in to change notification settings - Fork 482
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
fix hipMalloc() issue when running in multithreads. #8127
Conversation
Signed-off-by: Chiming Zhang <[email protected]>
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.
Minor
src/runtime_src/hip/core/memory.cpp
Outdated
@@ -171,12 +171,14 @@ namespace xrt::core::hip | |||
void | |||
memory_database::insert(uint64_t addr, size_t size, std::shared_ptr<xrt::core::hip::memory> hip_mem) | |||
{ | |||
std::lock_guard<std::mutex> lock(m_mutex); |
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.
std::lock_guard<std::mutex> lock(m_mutex); | |
std::lock_guard lock(m_mutex); |
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.
fixed.
src/runtime_src/hip/core/memory.cpp
Outdated
m_addr_map.insert({address_range_key(addr, size), hip_mem}); | ||
} | ||
|
||
void | ||
memory_database::remove(uint64_t addr) | ||
{ | ||
std::lock_guard<std::mutex> lock(m_mutex); |
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.
std::lock_guard<std::mutex> lock(m_mutex); | |
std::lock_guard lock(m_mutex); |
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.
fixed
Signed-off-by: Chiming Zhang <[email protected]>
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.
@zhangchiming , You need acquire lock in get_hip_mem_from_addr function also.
Please send a PR for that.
fix hipMalloc() issue when running in multithreads.
Problem solved by the commit
crash on calling hipMalloc() from multiple threads.
Bug / issue (if any) fixed, which PR introduced the bug, how it was discovered
Issue was found during developing unit testing case.
How problem was solved, alternative solutions (if any) and why they were rejected
Add lock for memory_database::remove() and memory_database::insert(). Allow device_init() be called once per thread.
Risks (if any) associated the changes in the commit
None. Code will only be built with switch "-hip".
What has been tested and how, request additional testing if necessary
Compiled and tested on Ubuntu 22.04 running on Ryzen 7840.
Documentation impact (if any)
None.