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: Correct mutex scope in execute_engine() #3310

Merged
merged 2 commits into from
Dec 16, 2024

Conversation

keehyuna
Copy link
Collaborator

@keehyuna keehyuna commented Dec 4, 2024

Description

//tests/cpp:test_runtime_thread_safety test fails inconsistently.
Currently mutex protects only enqueueV3(), it should protect setTensorAddress as they are part of the same operation.

Below logging confirms race condition.
execute_engine() {
compiled_engine->exec_ctx->setTensorAddress()
+std::cout << gettid() << " setTensorAddress " << outputs[pyt_idx].data_ptr() << std::endl;
std::unique_lockstd::mutex lock()
compiled_engine->exec_ctx->enqueueV3()
+std::cout << "enqueueV3" << std::endl;

759630 setTensorAddress 0xaeeffaa00
759626 setTensorAddress 0xaeeffba00
759624 setTensorAddress 0xaeeffca00
759631 setTensorAddress 0xaeeffda00
759629 setTensorAddress 0xaeeffea00
759627 setTensorAddress 0xaef5f5a00
759633 setTensorAddress 0xaef5f6a00
759628 setTensorAddress 0xaef5f7a00
759632 setTensorAddress 0xaef5f8a00
759625 setTensorAddress 0xaef5f9a00
759630 enqueueV3 //expects 0xaeeffaa00, but 759625 thread interrupted and set wrong output tensor
759626 enqueueV3
759624 enqueueV3
759631 enqueueV3
759629 enqueueV3
759627 enqueueV3
759633 enqueueV3
759628 enqueueV3
759632 enqueueV3
759625 enqueueV3

Fixes # (issue)

Type of change

Please delete options that are not relevant and/or add your own.

  • Bug fix (non-breaking change which fixes an issue)

Checklist:

  • My code follows the style guidelines of this project (You can use the linters)
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas and hacks
  • I have made corresponding changes to the documentation
  • I have added tests to verify my fix or my feature
  • New and existing unit tests pass locally with my changes
  • I have added the relevant labels to my PR in so that relevant reviewers are notified

@github-actions github-actions bot added component: core Issues re: The core compiler component: runtime labels Dec 4, 2024
@github-actions github-actions bot requested a review from narendasan December 4, 2024 12:49
@keehyuna keehyuna requested a review from peri044 December 4, 2024 12:55
@keehyuna keehyuna self-assigned this Dec 4, 2024
Copy link
Collaborator

@narendasan narendasan left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Collaborator

@peri044 peri044 left a comment

Choose a reason for hiding this comment

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

LGTM

@narendasan
Copy link
Collaborator

@keehyuna rebase once @zewenli98 has the CI fixes merged

@peri044 peri044 merged commit bed5d37 into pytorch:main Dec 16, 2024
62 of 68 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants