set_device¶
Paddle支持包括CPU和GPU在内的多种设备运行,设备可以通过字符串标识符表示,此功能可以指定OP运行的全局设备。
- 参数:
-
device (str)- 此参数确定特定的运行设备,它可以是
cpu、gpu、xpu、npu、gpu:x、xpu:x或者是npu:x。其中,x是GPU、 XPU 或者是 NPU 的编号。当device是cpu的时候, 程序在CPU上运行, 当device是gpu:x的时候,程序在GPU上运行, 当device是npu:x的时候,程序在NPU上运行。
返回:Place, 设置的Place。
代码示例
import paddle
paddle.device.set_device("cpu")
x1 = paddle.ones(name='x1', shape=[1, 2], dtype='int32')
x2 = paddle.zeros(name='x2', shape=[1, 2], dtype='int32')
data = paddle.stack([x1,x2], axis=1)