get_device
- paddle.device. get_device ( input: None = None ) str [source]
- paddle.device. get_device ( input: Tensor ) int
-
This function can get the current global device of the program is running. It’s a string which is like ‘cpu’, ‘gpu:x’, ‘xpu:x’ and ‘npu:x’. if the global device is not set, it will return a string which is ‘gpu:x’ when cuda is available or it will return a string which is ‘cpu’ when cuda is not available.
- Returns
-
if input is Tensor, this function will return the device ID where the given Tensor is located. int:
-1, if the Tensor is on CPU.
The device ID (e.g., 0, 1, …) if the Tensor is on GPU.
if input is not Tensor, this function will return the device name where the program is running. str:
’cpu’: If the program is running on CPU.
’gpu:x’: If the program is running on GPU, where x is the index of the GPU.
’xpu:x’: If the program is running on XPU, where x is the index of the XPU.
’npu:x’: If the program is running on NPU, where x is the index of
Examples
>>> import paddle >>> device = paddle.device.get_device() >>> x_cpu = paddle.to_tensor([1, 2, 3], place=paddle.CPUPlace()) >>> id = paddle.get_device(x_cpu) # -1
