Skip to content

Commit 3af7a67

Browse files
add paddle.device.device_guard API (#7361)
1 parent f8aaef1 commit 3af7a67

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

docs/api/paddle/device/Overview_cn.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ Stream 与 Event 相关 API
8585
" :ref:`current_stream <cn_api_paddle_device_current_stream>` ", "通过 device 返回当前的 stream"
8686
" :ref:`set_stream <cn_api_paddle_device_set_stream>` ", "设置当前的 stream"
8787
" :ref:`stream_guard <cn_api_paddle_device_stream_guard>` ", "切换当前的 stream 为输入指定的 stream,该 API 目前仅支持动态图模式"
88+
" :ref:`device_guard <cn_api_paddle_device_device_guard>` ", "切换当前的 device 为输入指定的 device,该 API 目前仅支持动态图模式"
8889
" :ref:`synchronize <cn_api_paddle_device_synchronize>` ", "等待给定的设备上的计算完成"
8990

9091

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
.. _cn_api_paddle_device_device_guard:
2+
3+
device_guard
4+
-------------------------------
5+
6+
.. py:function:: paddle.device.device_guard(device)
7+
8+
可以切换当前的 device 为输入指定的 device。
9+
10+
.. note::
11+
该 API 目前仅支持动态图模式。
12+
13+
参数
14+
::::::::::::
15+
16+
- **device** (PlaceLike) - 指定的 device,可以是形如 "cpu", "gpu:0" 之类的设备描述字符串,也可以是 `paddle.CUDAPlace(0)`, `paddle.CPUPlace()` 之类的设备实例。
17+
18+
代码示例
19+
::::::::::::
20+
COPY-FROM: paddle.device.device_guard

0 commit comments

Comments
 (0)