forked from PaddlePaddle/docs
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add unified device management api (PaddlePaddle#5481)
* add custom device api * update * update * update
- Loading branch information
Showing
6 changed files
with
249 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
.. _cn_api_device_Event: | ||
|
||
Event | ||
------------------------------- | ||
|
||
.. py:class:: paddle.device.Event(device=None, enable_timing=False, blocking=False, interprocess=False) | ||
event 的句柄。 | ||
|
||
参数 | ||
:::::::::::: | ||
|
||
- **device** (paddle.CUDAPlace|paddle.CustomPlace|str) - 希望分配 event 的设备或设备类型。如果为 None,则为当前期望的 place。默认值为 None。 | ||
- **enable_timing** (bool,可选) - event 是否需要统计时间。默认值为 False。 | ||
- **blocking** (bool,可选) - wait()函数是否被阻塞。默认值为 False。 | ||
- **interprocess** (bool,可选) - event 是否能在进程间共享。默认值为 False。 | ||
|
||
返回 | ||
:::::::::::: | ||
None | ||
|
||
代码示例 | ||
:::::::::::: | ||
|
||
COPY-FROM: paddle.device.Event | ||
|
||
|
||
方法 | ||
:::::::::::: | ||
record(stream=None) | ||
''''''''' | ||
|
||
记录 event 到给定的 stream。 | ||
|
||
**参数** | ||
|
||
- **stream** (paddle.device.Stream,可选) - stream 的句柄。如果为 None,stream 为当前的 stream。默认值为 None。 | ||
|
||
**代码示例** | ||
|
||
COPY-FROM: paddle.device.Event.record | ||
|
||
query() | ||
''''''''' | ||
|
||
查询 event 的状态。 | ||
|
||
**返回** | ||
|
||
一个 boolean 变量,用于标识当前 event 获取的所有任务是否被完成。 | ||
|
||
**代码示例** | ||
|
||
COPY-FROM: paddle.device.Event.query | ||
|
||
|
||
synchronize() | ||
''''''''' | ||
|
||
等待当前 event 完成。 | ||
|
||
**代码示例** | ||
|
||
COPY-FROM: paddle.device.Event.synchronize |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
.. _cn_api_device_Stream: | ||
|
||
Stream | ||
------------------------------- | ||
|
||
.. py:class:: paddle.device.Stream(device=None, priority=None, blocking=False) | ||
custom device stream 的句柄。 | ||
|
||
参数 | ||
:::::::::::: | ||
|
||
- **device** (paddle.CUDAPlace|paddle.CustomPlace|str) - 希望分配 stream 的设备或设备类型。如果为 None,则为当前期望的 place。默认值为 None。 | ||
- **priority** (int|None,可选) - stream 的优先级。优先级可以为 1(高优先级)或者 2(正常优先级)。如果优先级为 None,优先级为 2(正常优先级)。默认值为 None。 | ||
- **blocking** (bool|None,可选) - stream 是否同步执行。默认值为 False。 | ||
|
||
|
||
代码示例 | ||
:::::::::::: | ||
|
||
COPY-FROM: paddle.device.Stream | ||
|
||
方法 | ||
:::::::::::: | ||
|
||
record_event(event=None) | ||
''''''''' | ||
|
||
标记一个 event 到当前 stream 中。 | ||
|
||
**参数** | ||
|
||
- **event** (paddle.device.Event) - 要标记的 event。如果 event 为 None,新建一个 event。默认值为 None。 | ||
|
||
**返回** | ||
被标记的 event。 | ||
|
||
**代码示例** | ||
|
||
COPY-FROM: paddle.device.Stream.record_event | ||
|
||
wait_event(event) | ||
''''''''' | ||
|
||
使所有将来提交到 stream 的任务等待 event 中已获取的任务。 | ||
|
||
**参数** | ||
|
||
- **event** (paddle.device.Event) - 要等待的 event。 | ||
|
||
**代码示例** | ||
|
||
COPY-FROM: paddle.device.Stream.wait_event | ||
|
||
|
||
wait_stream(stream) | ||
''''''''' | ||
|
||
和给定的 stream 保持同步。 | ||
|
||
**参数** | ||
|
||
- **stream** (paddle.device.Stream) - 要同步的 stream。 | ||
|
||
|
||
**代码示例** | ||
|
||
COPY-FROM: paddle.device.Stream.wait_stream | ||
|
||
record_event(event=None) | ||
''''''''' | ||
|
||
记录给定的 event。 | ||
|
||
**参数** | ||
|
||
- **event** (paddle.device.Event) - 要记录的 event,如果为 None,则新建一个 event。 | ||
|
||
|
||
**代码示例** | ||
|
||
COPY-FROM: paddle.device.Stream.record_event | ||
|
||
query() | ||
''''''''' | ||
|
||
返回 stream 中所有的操作是否完成的状态。 | ||
|
||
**返回** | ||
一个 boolean 值。 | ||
|
||
**代码示例** | ||
|
||
COPY-FROM: paddle.device.Stream.query | ||
|
||
synchronize() | ||
''''''''' | ||
|
||
等待所有的 stream 的任务完成。 | ||
|
||
**代码示例** | ||
|
||
COPY-FROM: paddle.device.Stream.synchronize |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
.. _cn_api_device_current_stream: | ||
|
||
current_stream | ||
------------------------------- | ||
|
||
.. py:function:: paddle.device.current_stream(device=None) | ||
通过 device 返回当前的 stream。 | ||
|
||
|
||
参数 | ||
:::::::::::: | ||
|
||
- **device** (paddle.CUDAPlace|paddle.CustomPlace|str) - 希望获取 stream 的设备或者设备类型。如果为 None,则为当前期望的 place。默认值为 None。 | ||
|
||
返回 | ||
:::::::::::: | ||
paddle.device.Stream,设备的 stream。 | ||
|
||
代码示例 | ||
:::::::::::: | ||
COPY-FROM: paddle.device.current_stream |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
.. _cn_api_device_set_stream: | ||
|
||
set_stream | ||
------------------------------- | ||
|
||
.. py:function:: paddle.device.set_stream(stream=None) | ||
设置当前的 stream。 | ||
|
||
|
||
参数 | ||
:::::::::::: | ||
|
||
- **stream** (paddle.device.Stream) - 希望设置的 stream。 | ||
|
||
返回 | ||
:::::::::::: | ||
paddle.device.Stream,设备之前的 stream。 | ||
|
||
代码示例 | ||
:::::::::::: | ||
COPY-FROM: paddle.device.set_stream |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
.. _cp_api_device_stream_guard: | ||
|
||
stream_guard | ||
------------------------------- | ||
|
||
.. py:function:: paddle.device.stream_guard(stream) | ||
可以切换当前的 stream 为输入指定的 stream。 | ||
|
||
.. note:: | ||
该 API 目前仅支持动态图模式。 | ||
|
||
参数 | ||
:::::::::::: | ||
|
||
- **stream** (paddle.device.Stream) - 指定的 stream。如果为 None,则不进行 stream 切换。 | ||
|
||
代码示例 | ||
:::::::::::: | ||
COPY-FROM: paddle.device.stream_guard |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
.. _cn_api_device_synchronize: | ||
|
||
synchronize | ||
------------------------------- | ||
|
||
.. py:function:: paddle.device.synchronize(device=None) | ||
等待给定的设备上的计算完成。 | ||
|
||
|
||
参数 | ||
:::::::::::: | ||
|
||
- **device** (paddle.CUDAPlace|paddle.CustomPlace|str) - 希望等待的设备或者设备类型。如果为 None,则为当前期望的 place。默认值为 None。 | ||
|
||
代码示例 | ||
:::::::::::: | ||
COPY-FROM: paddle.device.synchronize |