Skip to content
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

Merged
merged 2 commits into from
May 2, 2024

Conversation

zhangchiming
Copy link
Collaborator

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.

Copy link
Collaborator

@stsoe stsoe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor

@@ -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);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
std::lock_guard<std::mutex> lock(m_mutex);
std::lock_guard lock(m_mutex);

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed.

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);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
std::lock_guard<std::mutex> lock(m_mutex);
std::lock_guard lock(m_mutex);

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

@zhangchiming zhangchiming requested a review from stsoe May 1, 2024 16:09
@chvamshi-xilinx chvamshi-xilinx merged commit 2e25aab into Xilinx:master May 2, 2024
17 checks passed
Copy link
Collaborator

@chvamshi-xilinx chvamshi-xilinx left a 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.

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.

3 participants