Skip to content

Decouple CommandEncoder from Device - #3316

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

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

Conversation

@zcbenz

@zcbenz zcbenz commented Mar 25, 2026 •

Copy link
Copy Markdown
Member

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

@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.

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
@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