Skip to content

Commit d5803fd

Browse files
add cuda-related docs (#7441)
* add cuda-related docs * fix * add * fix * fix * remove examles * fix format
1 parent 17d69f3 commit d5803fd

File tree

10 files changed

+129
-0
lines changed

10 files changed

+129
-0
lines changed

docs/api/index_cn.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@ API 文档
3434
| paddle.compat | PyTorch 兼容的函数与模块, |
3535
| | 行为与 PyTorch 对应接口一致 |
3636
+--------------------------+------------------------------------------------------------------------------------+
37+
| paddle.cuda | PyTorch 兼容的函数与模块, |
38+
| | 包含与 CUDA 设备相关的函数和模块 |
39+
+--------------------------+------------------------------------------------------------------------------------+
3740
| paddle.device | 设备管理相关 API,包括 set_device、get_device 等。 |
3841
+--------------------------+------------------------------------------------------------------------------------+
3942
| paddle.distributed | 分布式相关基础 API。 |

docs/api/index_en.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@ In this version, PaddlePaddle has made many optimizations to the APIs. You can r
3737
| paddle.compat | PyTorch-compatible APIs, with identical calling methods |
3838
| | and behaviors to their PyTorch counterparts. |
3939
+--------------------------+---------------------------------------------------------------+
40+
| paddle.cuda | PyTorch-compatible APIs, |
41+
| | including CUDA-related utilities |
42+
+--------------------------+---------------------------------------------------------------+
4043
| paddle.device | Device management related APIs, such as set_device, |
4144
| | get_device, etc. |
4245
+--------------------------+---------------------------------------------------------------+

docs/api/paddle/compat/Overview_cn.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ PyTorch 兼容函数
1919
" :ref:`min <cn_api_paddle_compat_min>` ", "包含 `amin`、同时返回 values 及 indices 的轴向最小值、`minimum` 三种功能"
2020
" :ref:`nanmedian <cn_api_paddle_compat_nanmedian>` ", "忽略 NaN 的兼容版中位数,支持 dim/keepdim/out 签名"
2121
" :ref:`pad <cn_api_paddle_compat_pad>` ", "从最后一维度开始进行 padding、padding 正确兼容转换的填充函数"
22+
" :ref:`slogdet <cn_api_paddle_compat_slogdet>` ", "slogdet 函数"
2223
" :ref:`softmax <cn_api_paddle_compat_softmax>` ", "softmax 函数"
2324
" :ref:`sort <cn_api_paddle_compat_sort>` ", "同时返回 values 及 indices 的排序"
2425
" :ref:`split <cn_api_paddle_compat_split>` ", "允许非整除块大小输入的 Tensor 轴向切分"
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
.. _cn_api_paddle_compat_slogdet:
2+
3+
slogdet
4+
-------------------------------
5+
6+
.. py:function:: paddle.compat.slogdet(x, out=None)
7+
8+
PyTorch 兼容的 :ref:`cn_api_paddle_slogdet` 版本,计算方阵或批量方阵行列式的符号与绝对值的自然对数,行列式的值可以通过 ``sign * exp(logabsdet)`` 复原。
9+
10+
使用前请详细参考:`【返回参数类型不一致】torch.slogdet`_ 以确定是否使用此模块。
11+
12+
.. _【返回参数类型不一致】torch.slogdet: https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/guides/model_convert/convert_from_pytorch/api_difference/torch/torch.slogdet.html
13+
14+
15+
参数
16+
::::::::::::
17+
18+
- **x** (Tensor) - 输入的多维 ``Tensor``,支持的数据类型:float32, float64, complex64, complex128。
19+
- **out** (tuple(Tensor, Tensor),可选) - 用于引用式传入输出值。``sign`` 在前,``logabsdet`` 在后。默认值为 None。``out`` 返回方法与静态图联合使用是被禁止的行为,静态图下将报错。
20+
21+
返回
22+
::::::::::::
23+
24+
SlogdetResult(Tensor, Tensor),此处的 ``SlogdetResult`` 是一个具名元组,含有 ``sign`` (在前)和 ``logabsdet`` (在后)两个域,用法与 tuple 一致。
25+
26+
27+
代码示例
28+
::::::::::::
29+
30+
COPY-FROM: paddle.compat.slogdet
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
.. _cn_overview_cuda:
2+
3+
paddle.cuda
4+
---------------------
5+
6+
paddle.cuda 目录下包含飞桨框架支持的 ``torch.cuda`` 兼容函数与模块接口
7+
8+
.. _about_cuda_funcs:
9+
10+
PyTorch 兼容函数
11+
::::::::::::::::::::
12+
13+
.. csv-table::
14+
:header: "API 名称", "API 功能"
15+
:widths: 10, 30
16+
17+
" :ref:`check_error <cn_api_paddle_cuda_check_error>` ", "检测 CUDA 错误码"
18+
" :ref:`cudart <cn_api_paddle_cuda_cudart>` ", "以模块的形式返回 CUDA Runtime 对象"
19+
" :ref:`is_initialized <cn_api_paddle_cuda_is_initialized>` ", "判断 CUDA 是否已经初始化"
20+
" :ref:`mem_get_info <cn_api_paddle_cuda_mem_get_info>` ", "获取指定设备上的全局空闲显存和显存总量"
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
.. _cn_api_paddle_cuda_check_error:
2+
3+
check_error
4+
-----------
5+
6+
.. py:function:: paddle.cuda.check_error(res)
7+
8+
检查给定的 CUDA 运行时返回的状态码,当 ``res`` 是错误码时,抛出对应的 CUDA 错误异常。
9+
10+
参数
11+
::::::::::::
12+
13+
- **res** (int) - CUDA 运行时返回的状态码。
14+
15+
代码示例
16+
::::::::::::
17+
COPY-FROM: paddle.cuda.check_error

docs/api/paddle/cuda/cudart_cn.rst

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
.. _cn_api_paddle_cuda_cudart:
2+
3+
cudart
4+
-----------
5+
6+
.. py:function:: paddle.cuda.cudart()
7+
8+
获取 CUDA 运行时 API 模块(_cudart),CUDA 运行时 API 模块提供对各种 CUDA 运行时函数的访问。
9+
10+
11+
返回
12+
::::::::::::
13+
14+
以 Python 模块形式返回 CUDA 运行时 API 模块(_cudart)。
15+
16+
代码示例
17+
::::::::::::
18+
COPY-FROM: paddle.cuda.cudart
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
.. _cn_api_paddle_cuda_is_initialized:
2+
3+
is_initialized
4+
--------------
5+
6+
.. py:function:: paddle.cuda.is_initialized()
7+
8+
返回 Paddle 的 CUDA 状态是否已初始化。
9+
10+
返回
11+
::::::::::::
12+
13+
bool, CUDA 是否已初始化。
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
.. _cn_api_paddle_cuda_mem_get_info:
2+
3+
mem_get_info
4+
------------
5+
6+
.. py:function:: paddle.cuda.mem_get_info(device=None)
7+
8+
使用 ``cudaMemGetInfo`` 返回指定设备的全局空闲显存和显存总量。
9+
10+
参数
11+
::::::::::::
12+
13+
- **device** (DeviceLike) - 指定要查询的设备,可以是形如 "gpu:0" 之类的设备描述字符串,也可以是 `paddle.CUDAPlace(0)` 之类的设备实例。如果为 None(默认值)或未指定设备索引,则返回由 ``paddle.device.get_device()`` 给出的当前设备的统计信息。
14+
15+
返回
16+
:::::::::
17+
返回指定设备的统计信息。
18+
19+
代码示例
20+
::::::::::::
21+
COPY-FROM: paddle.cuda.mem_get_info

docs/guides/model_convert/convert_from_pytorch/pytorch_api_mapping_cn.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -507,6 +507,9 @@ paddle.nn.Softplus(beta=0.5, threshold=15)
507507
| 459 | torch.Tensor.scatter | paddle.Tensor.scatter | - |
508508
| 460 | torch.Tensor.scatter_ | paddle.Tensor.scatter_ | - |
509509
| 461 | torch.scatter | paddle.scatter | - |
510+
| 445 | [torch.cuda.is_initialized](https://docs.pytorch.org/docs/stable/generated/torch.cuda.is_initialized.html#torch-cuda-is-initialized) | [paddle.cuda.is_initialized](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/cuda/is_initialized.html) | - |
511+
| 446 | [torch.cuda.mem_get_info](https://docs.pytorch.org/docs/stable/generated/torch.cuda.memory.mem_get_info.html#torch.cuda.memory.mem_get_info) | [paddle.cuda.mem_get_info](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/cuda/mem_get_info.html) | - |
512+
| 447 | [torch.cuda.cudart](https://docs.pytorch.org/docs/stable/generated/torch.cuda.is_initialized.html#torch-cuda-is-initialized) | [paddle.cuda.cudart](https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/api/paddle/cuda/cudart.html) | - |
510513

511514
## 2. 仅 API 调用方式不一致
512515
**分类简介**

0 commit comments

Comments
 (0)