set_device

paddle.cuda. set_device ( device ) [源代码]

设置当前设备。

参数

  • device (DeviceLike) - 要设置的设备,可以是 "int" 用来表示设备 id,可以是形如 "gpu:0" 之类的设备描述字符串,也可以是 paddle.CUDAPlace(0) 之类的设备实例。

代码示例

>>> import paddle
>>> # Set current device to GPU:0
>>> paddle.cuda.set_device(0)
>>> # Set current device to GPU:0
>>> paddle.cuda.set_device('gpu:0')
>>> # Set current device to a specific CUDAPlace
>>> place = paddle.CUDAPlace(0)
>>> paddle.cuda.set_device(place)