get_xp_devices¶
- get_xp_devices(xp: ModuleType) list[str] | list[None][source][source]¶
Returns a list of available devices for the given namespace.
- Parameters:
xp (
module) – The array API namespace to check for available devices.- Returns:
A list of available device strings for the given namespace. For PyTorch, this might include ‘cpu’, ‘cuda:0’, etc. For CuPy, this might include ‘cuda:0’, etc. For JAX, this might include ‘cpu:0’, ‘gpu:0’, ‘tpu:0’, etc. For other namespaces, returns [None].
- Return type:
Examples
>>> import numpy as np >>> get_xp_devices(np) [None]
If PyTorch is available >>> import torch # doctest: +SKIP >>> get_xp_devices(torch) # doctest: +SKIP [‘cpu’, ‘cuda:0’]