Skip to content

Preserve current device across runtime operations #3

Description

@voltjia

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions