nvalchemi.data.datapipes.same_device#

nvalchemi.data.datapipes.same_device(left, right)[source]#

Return whether tensors on two devices collate without a cross-device copy.

An index-less device matches any device of the same type. Two indexed devices must name the same device. None on either side matches any device.

Parameters:
  • left (torch.device | None) – One device, or None for no constraint.

  • right (torch.device | None) – The other device, or None for no constraint.

Returns:

True when the two devices are compatible.

Return type:

bool

Examples

>>> import torch
>>> from nvalchemi.data.datapipes import same_device
>>> same_device(torch.device("cuda"), torch.device("cuda:1"))
True
>>> same_device(torch.device("cuda:0"), torch.device("cuda:1"))
False