TensorPlay
API symbolsset_default_device
Copy
View MarkdownDownload .md

tensorplay.set_default_device

tensorplay.set_default_device(device: Device) None[source]

Sets the default tensorplay.Tensor to be allocated on device. This does not affect factory function calls which are called with an explicit device argument. Factory calls will be performed as if they were passed device as an argument.

To only temporarily change the default device instead of setting it globally, use with tensorplay.device(device): instead.

The default device is initially cpu. If you set the default tensor device to another device (e.g., cuda) without a device index, tensors will be allocated on whatever the current device for the device type, even after tensorplay.cuda.set_device() is called.

Warning

This function imposes a slight performance cost on every Python call to the tensorplay API (not just factory functions).

Note

This doesn’t affect functions that create tensors that share the same memory as the input, like: tensorplay.from_numpy() and tensorplay.frombuffer()

Parameters:

device (tensorplay.device, str, int, or None) – the device to set as default, or None to clear the override. An integer is interpreted as an index for the current accelerator.

Example:

>>> # xdoctest: +SKIP("requires cuda, changes global state")
>>> tensorplay.get_default_device()
device(type='cpu')
>>> tensorplay.set_default_device('cuda')  # current device is 0
>>> tensorplay.get_default_device()
device(type='cuda', index=0)
>>> tensorplay.set_default_device('cuda')
>>> tensorplay.cuda.set_device('cuda:1')  # current device is 1
>>> tensorplay.get_default_device()
device(type='cuda', index=1)
>>> tensorplay.set_default_device('cuda:1')
>>> tensorplay.get_default_device()
device(type='cuda', index=1)
Ask DeepWiki