pytorch3d.common

pytorch3d.common.get_device(x, device: Union[str, torch.device, None] = None) → torch.device[source]

Gets the device of the specified variable x if it is a tensor, or falls back to a default CPU device otherwise. Allows overriding by providing an explicit device.

Parameters:
  • x – a torch.Tensor to get the device from or another type
  • device – Device (as str or torch.device) to fall back to
Returns:

A matching torch.device object

pytorch3d.common.make_device(device: Union[str, torch.device]) → torch.device[source]

Makes an actual torch.device object from the device specified as either a string or torch.device object. If the device is cuda without a specific index, the index of the current device is assigned.

Parameters:device – Device (as str or torch.device)
Returns:A matching torch.device object