set_device

paddle.set_device ( device ) [源代码]

Paddle支持包括CPU和GPU在内的多种设备运行,设备可以通过字符串标识符表示,此功能可以指定OP运行的全局设备。

参数:

  • device (str)- 此参数确定特定的运行设备,它可以是 cpugpu:x 或者是 xpu:x 。其中, x 是GPU 或者是 XPU 的编号。当 devicecpu 的时候, 程序在CPU上运行, 当device是 gpu:x 的时候,程序在GPU上运行。

返回:Place, 设置的Place。

代码示例

  1. import paddle
  2. paddle.set_device("cpu")
  3. x1 = paddle.ones(name='x1', shape=[1, 2], dtype='int32')
  4. x2 = paddle.zeros(name='x2', shape=[1, 2], dtype='int32')
  5. data = paddle.stack([x1,x2], axis=1)