Problem
Operations that target an explicit device currently call SetDevice and leave
that device current after returning. In particular, synchronize(device) and
tensor copies can unexpectedly mutate caller-visible device state.
Scope
- Preserve and restore the current device around explicit-device runtime calls.
- Cover success and error paths with an exception-safe guard.
- Apply the same rule to allocation, copy, and synchronization entry points.
- Do not add stream support or new operators in this change.
Acceptance criteria
- On a multi-device backend, explicit operations on device 1 leave the original
current device unchanged.
- Same-device and cross-thread behavior remains correct.
- CPU and NVIDIA smoke tests pass.
Depends on #2.
Problem
Operations that target an explicit device currently call
SetDeviceand leavethat device current after returning. In particular,
synchronize(device)andtensor copies can unexpectedly mutate caller-visible device state.
Scope
Acceptance criteria
current device unchanged.
Depends on #2.