Skip to content

Decouple CommandEncoder from Device#3316

Merged
zcbenz merged 1 commit intoml-explore:mainfrom
zcbenz:encoder-refactor-3
Mar 31, 2026
Merged

Decouple CommandEncoder from Device#3316
zcbenz merged 1 commit intoml-explore:mainfrom
zcbenz:encoder-refactor-3

Conversation

@zcbenz
Copy link
Copy Markdown
Collaborator

@zcbenz zcbenz commented Mar 25, 2026

Refs #3078, #3216.

Refactor code to use metal::get_command_encoder and CommandEncoder APIs, instead of the Device methods like Device::get_command_encoder/add_temporary that take stream index.

The motivation is that, Device are global objects that shared by all threads, but we do not want to share CommandEncoder between threads, which does not have any performance benefit and brings various race conditions. This refactoring would allow us to store CommandEncoder in thread-local storages and detect thread-safety issues caused by using streams from different threads.

@zcbenz zcbenz force-pushed the encoder-refactor-3 branch from e732b85 to 2daec6c Compare March 25, 2026 09:52
Copy link
Copy Markdown
Member

@angeloskath angeloskath left a comment

Choose a reason for hiding this comment

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

Looks great to me!

@zcbenz zcbenz merged commit 939e425 into ml-explore:main Mar 31, 2026
16 checks passed
@zcbenz zcbenz deleted the encoder-refactor-3 branch March 31, 2026 23: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.

2 participants