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.
Noneon either side matches any device.- Parameters:
left (torch.device | None) – One device, or
Nonefor no constraint.right (torch.device | None) – The other device, or
Nonefor no constraint.
- Returns:
Truewhen 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