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

[Hexagon] Add HexagonThreadManager #11653

Merged
merged 46 commits into from
Jun 13, 2022
Merged

Conversation

adstraw
Copy link
Contributor

@adstraw adstraw commented Jun 9, 2022

This PR was made in collaboration with @JosephTheOctonaut.

Add HexagonThreadManager class and unit testing. HexagonThreadManager can be used to spawn a given number of QURT threads on which the user can Dispatch work including basic Signal and Wait functionality to create synchronization points between threads. This PR adds the low-level HexagonThreadManager class only. Related Hexagon Device API support and codegen to come in future PRs.

This PR is dependent on #11635 to pass CI.

cc @mehrdadh

JosephTheOctonaut and others added 30 commits June 9, 2022 10:28
- Updated HexagonThreadManager interface to use TVMStreams
- Added second `Dispatch` interfce in thread manager to use PackedFuncs
- Updated thread manager to use vector for dynamic semaphore allocation
- Added "#if defined(__hexagon__)" in several places to prevent compilation errors
 - Fixed GetStreams not returning the streams properly
 - Added missing semaphore cleanup to prevent qurt kernel resource leakage
 - new interface functions:
   - Start() : now all worker threads are blocked on initialization until ThreadManager->Start() is called
   - WaitOnThreads() : blocking call which waits until all worker thread queues are empty
 - added extra debug logging
 - Two new basic thread tests working
… capacity adjustment invaliding in-use addresses).
Copy link
Contributor

@kparzysz-quic kparzysz-quic left a comment

Choose a reason for hiding this comment

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

Could you move the buffer manager changes to a separate PR? They seem independent from the thread manager.

src/runtime/hexagon/hexagon_buffer_manager.h Outdated Show resolved Hide resolved
src/runtime/hexagon/hexagon_buffer_manager.h Outdated Show resolved Hide resolved
src/runtime/hexagon/hexagon_device_api.cc Outdated Show resolved Hide resolved
@kparzysz-quic
Copy link
Contributor

On another note---all the thread manager files spell "threadmanager" without the underscore, while "buffer manager" has one. Could you add the underscore for consistency?

@github-actions github-actions bot requested a review from mehrdadh June 9, 2022 23:38
@adstraw adstraw requested a review from kparzysz-quic June 9, 2022 23:39
@adstraw
Copy link
Contributor Author

adstraw commented Jun 9, 2022

Could you move the buffer manager changes to a separate PR? They seem independent from the thread manager.

I am basically moving this functionality from within the Hexagon Device API where it lived previously to a separate header file. Both the Hexagon Device API and the Hexagon Thread Manager need a Hexagon Buffer Manager. The alternative would be two duplicate code in two places.

Copy link
Contributor

@kparzysz-quic kparzysz-quic left a comment

Choose a reason for hiding this comment

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

My general feedback would be mostly about coding style. This patch doesn't conform to the style used in TVM (for example, private class member names should end with _, etc.). Besides that:

  • Almost any pointer can be implicitly converted to void*, so most (if not all) of the reinterpret_cast<void*>(...) are unnecessary.
  • Please use nullptr instead of reinterpret_cast<...>(0).
  • Please avoid C-style casts, i.e. (type)value. In particular, please replace (TVMStreamHandle)i with static_cast<TVMStreamHandle>(i).
  • In several cases, there is code that constructs a message for DBG/DLOG that will execute unconditionally, even if DLOG is disabled. Even though the constructed string is not used, the code creating it will most likely not be removed (because it can contain library calls, etc).

src/runtime/hexagon/hexagon_thread_manager.h Outdated Show resolved Hide resolved
src/runtime/hexagon/hexagon_thread_manager.h Outdated Show resolved Hide resolved
@adstraw adstraw requested a review from kparzysz-quic June 10, 2022 20:30
Copy link
Contributor

@kparzysz-quic kparzysz-quic left a comment

Choose a reason for hiding this comment

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

The (TVMStreamHandle)i is still there. It's not that much of a big deal, but it would be nice to replace it with static_cast eventually.

@kparzysz-quic
Copy link
Contributor

Thanks Adam!

@adstraw
Copy link
Contributor Author

adstraw commented Jun 10, 2022

The (TVMStreamHandle)i is still there. It's not that much of a big deal, but it would be nice to replace it with static_cast eventually.

Missed this. Will fix. [Edit] We need reinterpret_cast to cast between unsigned and pointer type.
[Edit] Also missed the comment about member_variables_. Will fix that too.

@adstraw
Copy link
Contributor Author

adstraw commented Jun 10, 2022

Just realized that I named my commit static cast for TVMStreamHandle before I realized that reinterpret_cast was required. I can rename that commit or ...

Just thinking out loud here ... the other thing we can do RE TVMStreamHandle is just remove it from this PR. It's there because we are looking ahead to working with actual stream handles at the Device API level. But, what we really need is just an unsigned thread ID. What's there is a bit of a misuse of a pointer type to stash an integer and probably over-engineered at least for the time being.

@kparzysz-quic
Copy link
Contributor

I wouldn't worry about renaming a commit in the PR. The code looks fine. For some reason I thought that the stream handle was actually an integer...
When the CI passes, I can change the entry in the commit message to read "reinterpret" instead of "static" right before committing.

@adstraw
Copy link
Contributor Author

adstraw commented Jun 10, 2022

Just a reminder that CI is failing because it requires this PR #11635

@kparzysz-quic kparzysz-quic merged commit 76b9ce9 into apache:main Jun 13, 2022
@adstraw adstraw deleted the hex-thread-mgr branch June 13, 2022 17:51
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