warp.ScopedDevice#

class warp.ScopedDevice(device)[source]#

A context manager to temporarily change the current default device.

For CUDA devices, this context manager makes the device’s CUDA context current and restores the previous CUDA context on exit. This is handy when running Warp scripts as part of a bigger pipeline because it avoids any side effects of changing the CUDA context in the enclosed code.

Parameters:

device (DeviceLike)

device#

The device that will temporarily become the default device within the context.

Type:

Device

saved_device#

The previous default device. This is restored as the default device on exiting the context.

Type:

Device

__init__(device)[source]#

Initializes the context manager with a device.

Parameters:

device (Device | str | None) – The device that will temporarily become the default device within the context.

Methods

__init__(device)

Initializes the context manager with a device.