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 paddle.devices.cuda docs (PaddlePaddle#3656)
* add current_stream doc * add synchronize docs * modify current_stream doc * add event and stream docs * add sample codes * modify devices to device * move cuda api into devcie direction
- Loading branch information
1 parent
0e6e6db
commit 0747dd4
Showing
4 changed files
with
214 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,69 @@ | ||
.. _cn_api_device_cuda_Event: | ||
|
||
Event | ||
------------------------------- | ||
|
||
.. py:class:: paddle.device.cuda.Event(enable_timing=False, blocking=False, interprocess=False) | ||
CUDA event的句柄。 | ||
|
||
参数: | ||
- **enable_timing** (bool, 可选) - Event 是否需要统计时间。默认值为False。 | ||
- **blocking** (bool, 可选) - wait()函数是否被阻塞。默认值为False。 | ||
- **interprocess** (bool, 可选) - Event是否能在进程间共享。默认值为False。 | ||
|
||
返回:None | ||
|
||
**代码示例**: | ||
|
||
.. code-block:: python | ||
# required: gpu | ||
import paddle | ||
event = paddle.device.cuda.Event() | ||
.. py:method:: record(CUDAStream=None) | ||
记录event 到给定的stream。 | ||
|
||
参数: | ||
- **stream** (CUDAStream, 可选) - CUDA stream的句柄。如果为None,stream为当前的stream。默认值为False。 | ||
|
||
**代码示例**: | ||
|
||
.. code-block:: python | ||
# required: gpu | ||
import paddle | ||
event = paddle.device.cuda.Event() | ||
event.record() | ||
.. py:method:: query() | ||
查询event的状态。 | ||
|
||
返回: 一个boolean 变量,用于标识当前event 获取的所有任务是否被完成。 | ||
|
||
**代码示例**: | ||
|
||
.. code-block:: python | ||
# required: gpu | ||
import paddle | ||
event = paddle.device.cuda.Event() | ||
is_done = event.query() | ||
.. py:method:: synchronize() | ||
等待当前event 完成。 | ||
|
||
**代码示例**: | ||
|
||
.. code-block:: python | ||
# required: gpu | ||
import paddle | ||
event = paddle.device.cuda.Event() | ||
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,109 @@ | ||
.. _cn_api_device_cuda_Stream: | ||
|
||
Stream | ||
------------------------------- | ||
|
||
.. py:class:: paddle.device.cuda.Stream(device=None, priority=None) | ||
CUDA stream的句柄。 | ||
|
||
参数: | ||
- **device** (paddle.CUDAPlace()|int|None, 可选) - 希望分配stream的设备。如果是None或者负数,则设备为当前的设备。如果是正数,则必须小于设备的个数。默认值为None。 | ||
- **priority** (int|None, 可选) - stream的优先级。优先级可以为1(高优先级)或者2(正常优先级)。如果优先级为None,优先级为2(正常优先级)。默认值为None。 | ||
|
||
|
||
**代码示例**: | ||
|
||
.. code-block:: python | ||
# required: gpu | ||
import paddle | ||
s1 = paddle.device.cuda.Stream(paddle.CUDAPlace(0), 1) | ||
s2 = paddle.device.cuda.Stream(0, 1) | ||
s3 = paddle.device.cuda.Stream() | ||
.. py:method:: wait_event(event) | ||
使所有将来提交到stream的任务等待event中已获取的任务。 | ||
|
||
参数: | ||
- **event** (CUDAEvent) - 要等待的event。 | ||
|
||
**代码示例**: | ||
|
||
.. code-block:: python | ||
# required: gpu | ||
import paddle | ||
s = paddle.device.cuda.Stream(paddle.CUDAPlace(0), 1) | ||
event = paddle.device.cuda.Event() | ||
s.wait_event(event) | ||
.. py:method:: wait_stream(stream) | ||
和给定的stream 保持同步。 | ||
|
||
参数: | ||
- **stream** (CUDAStream) - 要同步的stream。 | ||
|
||
|
||
**代码示例**: | ||
|
||
.. code-block:: python | ||
# required: gpu | ||
import paddle | ||
s1 = paddle.device.cuda.Stream(paddle.CUDAPlace(0), 1) | ||
s2 = paddle.device.cuda.Stream(0, 1) | ||
s1.wait_stream(s2) | ||
.. py:method:: query() | ||
返回stream 中所有的操作是否完成的状态。 | ||
|
||
返回: 一个boolean 值。 | ||
|
||
**代码示例**: | ||
|
||
.. code-block:: python | ||
# required: gpu | ||
import paddle | ||
s = paddle.device.cuda.Stream(paddle.CUDAPlace(0), 1) | ||
is_done = s.query() | ||
.. py:method:: synchronize() | ||
等待所有的stream的任务完成。 | ||
|
||
**代码示例**: | ||
|
||
.. code-block:: python | ||
# required: gpu | ||
import paddle | ||
s = paddle.device.cuda.Stream(paddle.CUDAPlace(0), 1) | ||
s.synchronize() | ||
.. py:method:: record_event(event=None) | ||
标记一个CUDA event 到当前stream中。 | ||
|
||
参数: | ||
- **event** (CUDAEvent,可选) - 要标记的event。如果event 为None,新建一个event。默认值为None。 | ||
|
||
返回: 被标记的event。 | ||
|
||
**代码示例**: | ||
|
||
.. code-block:: python | ||
# required: gpu | ||
import paddle | ||
s = paddle.device.cuda.Stream(paddle.CUDAPlace(0), 1) | ||
event = s.record_event() | ||
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_cuda_current_stream: | ||
|
||
current_stream | ||
------------------------------- | ||
|
||
.. py:function:: paddle.device.cuda.current_stream(device=None) | ||
通过device 返回当前的CUDA stream。 | ||
|
||
|
||
参数: | ||
- **device** (paddle.CUDAPlace()|int, 可选) - 希望获取stream的设备或者设备ID。如果为None,则为当前的设备。默认值为None。 | ||
|
||
返回: CUDAStream, 设备的stream | ||
|
||
**代码示例**: | ||
COPY-FROM: paddle.device.cuda.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,18 @@ | ||
.. _cn_api_device_cuda_synchronize: | ||
|
||
synchronize | ||
------------------------------- | ||
|
||
.. py:function:: paddle.device.cuda.synchronize(device=None) | ||
等待给定的CUDA 设备上的计算完成。 | ||
|
||
|
||
参数: | ||
- **device** (paddle.CUDAPlace()|int, 可选) - 设备或者设备ID。如果为None,则为当前的设备。默认值为None。 | ||
|
||
返回:None | ||
|
||
**代码示例**: | ||
COPY-FROM: paddle.device.cuda.synchronize | ||
|