Skip to content

[CUDA] Thread safety - #3367

Merged
zcbenz merged 1 commit into
ml-explore:mainfrom
zcbenz:encoder-refactor-5
Apr 8, 2026
Merged

zcbenz merged 1 commit into
ml-explore:mainfrom
zcbenz:encoder-refactor-5

Conversation

@zcbenz

@zcbenz zcbenz commented Apr 4, 2026

Copy link
Copy Markdown
Member

Refs #3078.

These are the thread safety changes for CUDA backend, which basically do the same thing with the Metal backend:

  • Use lock for JIT compilation.
  • Make CommandEncoder thread local.
  • Leak the device-level resources on exit.
  • Move management of cublasLt/cuDNN handles out of cu::Device to avoid using locks for multi-thread environment.

@angeloskath angeloskath left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Shouldn't the cudnn and cublas handles also be thread local? I think the docs say the libraries are only thread safe if each thread has their own handle.

@zcbenz
zcbenz force-pushed the encoder-refactor-5 branch from e00ae11 to 854c025 Compare April 5, 2026 02:08
@zcbenz

zcbenz commented Apr 5, 2026

Copy link
Copy Markdown
Member Author

Yeah you are right, somehow I remembered it the opposite way. The cudnn/cublas handles are now thread local and destroyed on thread teardown.

@angeloskath angeloskath left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

👍

@zcbenz
zcbenz merged commit 4403165 into ml-explore:main Apr 8, 2026
16 checks passed
@zcbenz
zcbenz deleted the encoder-refactor-5 branch April 8, 2026 23:18
@BrewTestBot BrewTestBot mentioned this pull request Apr 22, 2026
1 task done
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.

2 participants