Repository navigation
feat: init stream guard - #247
Open
Chamberlain0w0 wants to merge 2 commits into
Open
Chamberlain0w0 wants to merge 2 commits into
Chamberlain0w0 wants to merge 2 commits into
Conversation
chen2021673
reviewed
Oct 13, 2026
… from multiple streams
chen2021673
approved these changes
Oct 14, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
概述
由于 CP 实现涉及切换计算流操作,所以新增公共运行时组件
StreamGuard,支持在作用域内切换 device 和 stream,并在退出时自动恢复,供多流计算等场景复用。主要修改
DeviceGuardImpl::ExchangeStream:切换指定设备在线程内的当前 stream,返回原 stream,不切换当前设备、不执行同步。stream_guard.h/.cc:进入作用域时保存并切换 device 和 stream;退出时先恢复目标设备的原 stream,再恢复原 device。禁止拷贝和移动。StreamGuard 不持有 stream 所有权,也不执行同步;调用方负责 stream 的设备归属、生命周期和跨 stream 依赖。