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

make CollectTrace for profiling by iteration async #966

Closed
wants to merge 12 commits into from

Conversation

staugust
Copy link
Contributor

This fix issue #953. Makes libkineto::api().client()->stop() and stopTraceInternal run in profilerThread_ so that, the training process will not be blocked.

libkineto/src/CuptiActivityProfiler.h Outdated Show resolved Hide resolved
libkineto/src/CuptiActivityProfiler.cpp Outdated Show resolved Hide resolved
libkineto/src/CuptiActivityProfiler.cpp Outdated Show resolved Hide resolved
libkineto/src/CuptiActivityProfiler.cpp Outdated Show resolved Hide resolved
if (!stopByIterThread) {
std::lock_guard<std::mutex> guard(mutex_);
if (!stopByIterThread) {
stopByIterThread = new std::thread([collection_done, this, now](){
Copy link
Contributor

Choose a reason for hiding this comment

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

std_make_unique

libkineto/src/CuptiActivityProfiler.cpp Outdated Show resolved Hide resolved
std::lock_guard<std::mutex> guard(mutex_);
if (stopByIterThread) {
stopByIterThread->join();
delete stopByIterThread;
Copy link
Contributor

Choose a reason for hiding this comment

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

with unique ptr this woudl be stopByIterThread.reset()

libkineto/src/CuptiActivityProfiler.cpp Outdated Show resolved Hide resolved
@staugust
Copy link
Contributor Author

staugust commented Aug 2, 2024

Thank you for those helpful tips, I'll improve this pr as comments advised.

@staugust
Copy link
Contributor Author

@briancoutinho It seems this pr is ignored after last commit. I've rebased master branch, please take some time to re-review this pr, thank you.

@briancoutinho
Copy link
Contributor

briancoutinho commented Aug 31, 2024 via email

@staugust
Copy link
Contributor Author

staugust commented Sep 2, 2024

@briancoutinho it's ok. @sraikund16 would you like to review this pr?

@staugust
Copy link
Contributor Author

@briancoutinho @sraikund16 Is there any update?

@sraikund16
Copy link
Contributor

@staugust sorry I didn't notice this. Let me take a look later today. Thanks for your patience!

@facebook-github-bot
Copy link
Contributor

@sraikund16 has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator.

@facebook-github-bot
Copy link
Contributor

@staugust has updated the pull request. You must reimport the pull request before landing.

#if defined(HAS_CUPTI) || defined(HAS_ROCTRACER)
if (cupti_.stopCollection) {
ecs_.cupti_stopped_early = cupti_.stopCollection;
LOG(ERROR)
Copy link
Contributor

Choose a reason for hiding this comment

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

Any reason why we removed this LOG? Doesn't appear in the new function

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Those lines are added to the main branch after this pr. I'd rebase from master branch, and update this pr.
image

Copy link
Contributor

Choose a reason for hiding this comment

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

Oh interesting, that diff was supposed to be only formatting hmm. I'll add it myself, thanks!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

main...staugust:kineto:main2_new , I have reorganized the code on a new branch based on Kineto's main branch, hoping this will help.

@facebook-github-bot
Copy link
Contributor

@sraikund16 has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator.

@facebook-github-bot
Copy link
Contributor

@staugust has updated the pull request. You must reimport the pull request before landing.

@facebook-github-bot
Copy link
Contributor

@staugust has updated the pull request. You must reimport the pull request before landing.

@facebook-github-bot
Copy link
Contributor

@sraikund16 has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator.

@facebook-github-bot
Copy link
Contributor

@staugust has updated the pull request. You must reimport the pull request before landing.

@facebook-github-bot
Copy link
Contributor

@staugust has updated the pull request. You must reimport the pull request before landing.

@facebook-github-bot
Copy link
Contributor

@sraikund16 has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator.

@facebook-github-bot
Copy link
Contributor

@staugust has updated the pull request. You must reimport the pull request before landing.

@facebook-github-bot
Copy link
Contributor

@sraikund16 has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator.

// currentIter > 0 means this is an iteration-based collection,
// triggered by pytorch main thread, it should be executed in another
// thread in case pytorch main thread is blocked
if (currentIter > 0) {
Copy link
Member

Choose a reason for hiding this comment

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

I think iteration based is >= 0

Copy link
Contributor

Choose a reason for hiding this comment

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

Good catch! I think this didn't get caught because all it would do is make a single step trace still synchronous but we should make it async for all traces. Thanks!

Copy link
Member

@aaronenyeshi aaronenyeshi left a comment

Choose a reason for hiding this comment

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

Looks good, should we add any new test cases?

@sraikund16
Copy link
Contributor

Looks good, should we add any new test cases?

I don't see any functional tests with on-demand so its hard to test it any other way than the unit tests that I changed in this PR

@facebook-github-bot
Copy link
Contributor

@staugust has updated the pull request. You must reimport the pull request before landing.

@facebook-github-bot
Copy link
Contributor

@sraikund16 has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator.

@facebook-github-bot
Copy link
Contributor

@sraikund16 merged this pull request in 7a2a167.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants