as_native_dev#

ivy.as_native_dev(device, /)[source]#

Convert device string representation to native device type.

Parameters:

device (Union[Device, NativeDevice]) – The device string to convert to native device handle. A native device handle can be passed in instead - in this case the unmodified parameter is returned.

Return type:

NativeDevice

Returns:

ret – Native device handle.

Examples

With ivy.Device input:

>>> ivy.set_backend("numpy")
>>> ivy.as_native_dev("cpu")
'cpu'
>>> ivy.set_backend("tensorflow")
>>> ivy.as_native_dev("tpu:3")
'/TPU:3'

With ivy.NativeDevice input:

>>> import torch
>>> device = torch.device("cuda")
>>> device
device(type='cuda')
>>> ivy.as_native_dev(device)
device(type='cuda')