Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
2566bee
add is_available ...
fxyfxy777 Sep 24, 2025
dbff885
Add device related API
fxyfxy777 Sep 24, 2025
00e0d26
Remove unexpected indentation
fxyfxy777 Sep 24, 2025
6d624de
Merge branch 'develop' of github.com:PaddlePaddle/docs into cuda_apis
fxyfxy777 Oct 28, 2025
a24df74
Merge branch 'develop' of github.com:PaddlePaddle/docs into cuda_apis
fxyfxy777 Nov 3, 2025
b5be53c
pre-commit
fxyfxy777 Nov 3, 2025
d8aef5b
Merge branch 'develop' into cuda_apis
fxyfxy777 Nov 3, 2025
38c3769
fix error docs/api/paddle/device/Overview_cn.rst
fxyfxy777 Nov 4, 2025
8686cee
Merge branch 'cuda_apis' of github.com:fxyfxy777/docs into cuda_apis
fxyfxy777 Nov 4, 2025
f85aaed
Merge branch 'develop' into cuda_apis
fxyfxy777 Nov 4, 2025
3ee3341
Merge branch 'develop' into cuda_apis
fxyfxy777 Nov 4, 2025
055fe3f
fix overvirw error
fxyfxy777 Nov 4, 2025
25bdb30
Merge branch 'develop' of github.com:PaddlePaddle/docs into cuda_apis
fxyfxy777 Nov 4, 2025
6eb767c
Merge branch 'cuda_apis' of github.com:fxyfxy777/docs into cuda_apis
fxyfxy777 Nov 4, 2025
cda9ced
fix error
fxyfxy777 Nov 4, 2025
0c94078
Merge branch 'develop' into cuda_apis
fxyfxy777 Nov 4, 2025
da8483e
fix pr error
fxyfxy777 Nov 10, 2025
5e5eca8
Merge branch 'cuda_apis' of github.com:fxyfxy777/docs into cuda_apis
fxyfxy777 Nov 10, 2025
c81cdfd
Merge branch 'develop' into cuda_apis
fxyfxy777 Nov 10, 2025
7bdb45c
Apply suggestion from @sunzhongkai588
fxyfxy777 Nov 10, 2025
8f02a8b
Apply suggestion from @sunzhongkai588
fxyfxy777 Nov 10, 2025
080c9e6
fix reset_peak_memory_stats
fxyfxy777 Nov 10, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions docs/api/paddle/Overview_cn.rst
Original file line number Diff line number Diff line change
Expand Up @@ -636,6 +636,8 @@ device 相关

" :ref:`paddle.get_cuda_rng_state <cn_api_paddle_get_cuda_rng_state>` ", "获取 cuda 随机数生成器的状态信息"
" :ref:`paddle.set_cuda_rng_state <cn_api_paddle_set_cuda_rng_state>` ", "设置 cuda 随机数生成器的状态信息"
" :ref:`paddle.get_default_device <cn_api_paddle_get_default_device>` ", "获取当前默认设备信息"
" :ref:`paddle.get_device_module <cn_api_paddle_get_device_module>` ", "获取指定设备对应的模块"

.. _about_hapi:

Expand Down
7 changes: 7 additions & 0 deletions docs/api/paddle/cuda/Overview_cn.rst
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,15 @@ PyTorch 兼容函数

" :ref:`check_error <cn_api_paddle_cuda_check_error>` ", "检测 CUDA 错误码"
" :ref:`cudart <cn_api_paddle_cuda_cudart>` ", "以模块的形式返回 CUDA Runtime 对象"
" :ref:`current_stream <cn_api_paddle_cuda_current_stream>` ", "获取当前 CUDA 流"
" :ref:`get_device_properties <cn_api_paddle_cuda_get_device_properties>` ", "获取 CUDA 设备属性"
" :ref:`get_rng_state <cn_api_paddle_cuda_get_rng_state>` ", "获取随机数生成器状态"
" :ref:`is_available <cn_api_paddle_cuda_is_available>` ", "检查 CUDA 是否可用"
" :ref:`is_initialized <cn_api_paddle_cuda_is_initialized>` ", "判断 CUDA 是否已经初始化"
" :ref:`manual_seed_all <cn_api_paddle_cuda_manual_seed_all>` ", "设置全局随机种子"
" :ref:`mem_get_info <cn_api_paddle_cuda_mem_get_info>` ", "获取指定设备上的全局空闲显存和显存总量"
" :ref:`set_rng_state <cn_api_paddle_cuda_set_rng_state>` ", "设置随机数生成器状态"
" :ref:`synchronize <cn_api_paddle_cuda_synchronize>` ", "同步 CUDA 设备"
" :ref:`current_device <cn_api_paddle_cuda_current_device>` ", "返回当前设备的索引"
" :ref:`device_count <cn_api_paddle_cuda_device_count>` ", "返回可用的 CUDA 设备数量"
" :ref:`empty_cache <cn_api_paddle_cuda_empty_cache>` ", "释放当前设备上所有未占用的缓存内存"
Expand Down
25 changes: 25 additions & 0 deletions docs/api/paddle/cuda/current_stream_cn.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
.. _cn_api_paddle_cuda_current_stream:

current_stream
-------------------------------

.. py:function:: paddle.cuda.current_stream(device=None)

该功能用于获取指定 CUDA 设备上当前正在使用的计算流(Stream)。

参数
:::::::::
- **device** (int | str | CUDAPlace | CustomPlace | None,可选) – 指定需要查询的设备。
- None:获取当前设备上的默认计算流。
- int:设备索引,例如 0 表示 cuda:0。
- str:设备字符串,例如 'cuda:0' 或 'gpu:1'。
- CUDAPlace:Paddle 的 CUDAPlace 对象。
- CustomPlace:Paddle 的自定义设备 Place 对象。

返回
:::::::::
core.CUDAStream,当前设备对应的 CUDA 计算流对象。

代码示例
:::::::::
COPY-FROM: paddle.cuda.current_stream
25 changes: 25 additions & 0 deletions docs/api/paddle/cuda/get_device_properties_cn.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
.. _cn_api_paddle_cuda_get_device_properties:

get_device_properties
-------------------------------

.. py:function:: paddle.cuda.get_device_properties(device=None)

获取 CUDA 设备的属性信息。

参数
:::::::::
- **device** (int | str | paddle.CUDAPlace | paddle.CustomPlace | None, 可选) - 要查询的目标设备:

- None: 使用当前设备
- int: 设备索引 (例如: 0 -> 'gpu:0')
- str: 设备字符串 (例如: "cuda:0", "gpu:1")
- CUDAPlace 或 CustomPlace: Paddle 设备对象

返回
:::::::::
DeviceProperties: 包含设备属性的对象,如名称、总内存、计算能力和多处理器数量等。

代码示例
::::::::::::
COPY-FROM: paddle.cuda.get_device_properties
23 changes: 23 additions & 0 deletions docs/api/paddle/cuda/get_rng_state_cn.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
.. _cn_api_paddle_cuda_get_rng_state:

get_rng_state
-------------------------------

.. py:function:: paddle.cuda.get_rng_state(device=None)

返回指定设备的随机数生成器状态,以 GeneratorState 形式表示。

参数
:::::::::
- **device** (DeviceLike, 可选) - 要获取 RNG 状态的设备:

- 如果不指定,则使用当前默认设备(由 paddle.framework._current_expected_place_()返回)
- 可以是设备对象、整数设备 ID 或设备字符串

返回
:::::::::
core.GeneratorState: 指定设备的当前 RNG 状态,以 GeneratorState 形式表示。

代码示例
::::::::::::
COPY-FROM: paddle.cuda.get_rng_state
22 changes: 22 additions & 0 deletions docs/api/paddle/cuda/is_available_cn.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
.. _cn_api_paddle_cuda_is_available:

is_available
-------------------------------

.. py:function:: paddle.cuda.is_available()

检查当前环境中是否有任何支持的设备可用。

该函数检查 Paddle 是否编译了至少一种加速器支持(如 CUDA、XPU、CustomDevice 等),
以及当前系统是否有至少一个该类型的设备可用。

如果有任何支持的设备可用,则返回 True,否则返回 False。

返回
:::::::::
bool: 如果有至少一个可用设备(GPU/XPU/CustomDevice)则返回 True,否则返回 False。


代码示例
::::::::::::
COPY-FROM: paddle.cuda.is_available
20 changes: 20 additions & 0 deletions docs/api/paddle/cuda/manual_seed_all_cn.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
.. _cn_api_paddle_cuda_manual_seed_all:

manual_seed_all
-------------------------------

.. py:function:: paddle.cuda.manual_seed_all(seed)

设置全局默认随机数生成器的种子值,用于管理随机数生成。

参数
:::::::::
- **seed** (int) - 要设置的随机种子值

返回
:::::::::
None

代码示例
::::::::::::
COPY-FROM: paddle.cuda.manual_seed_all
24 changes: 24 additions & 0 deletions docs/api/paddle/cuda/set_rng_state_cn.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
.. _cn_api_paddle_cuda_set_rng_state:

set_rng_state
-------------------------------

.. py:function:: paddle.cuda.set_rng_state(new_state, device=None)

设置指定设备的随机数生成器状态。

参数
:::::::::
- **new_state** (core.GeneratorState) - 要设置的 RNG 状态对象,通常从 ``get_rng_state()`` 获取
- **device** (DeviceLike, 可选) - 要设置 RNG 状态的设备:

- 如果不指定,则使用当前默认设备(由 ``paddle.framework._current_expected_place_()`` 返回)
- 可以是设备对象、整数设备 ID 或设备字符串

返回
:::::::::
None

代码示例
:::::::::
COPY-FROM: paddle.cuda.set_rng_state
24 changes: 24 additions & 0 deletions docs/api/paddle/cuda/synchronize_cn.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
.. _cn_api_paddle_cuda_synchronize:

synchronize

.. py:function:: paddle.cuda.synchronize(device=None)

该功能用于同步指定 CUDA 设备上的计算流,确保所有在该设备上提交的计算任务执行完成。

参数
:::::::::
- **device** (int | str | CUDAPlace | CustomPlace | None, optional) – 指定需要同步的设备。
- None:同步当前设备上的计算流。
- int:设备索引,例如 0 表示 cuda:0。
- str:设备字符串,例如 'cuda:0' 或 'gpu:0'。
- CUDAPlace:Paddle 的 CUDAPlace 对象。
- CustomPlace:Paddle 的自定义设备 Place 对象。

返回
:::::::::
无。

代码示例
:::::::::
COPY-FROM: paddle.cuda.synchronize
4 changes: 4 additions & 0 deletions docs/api/paddle/device/Overview_cn.rst
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ paddle.device 目录下包含 cuda 目录和 xpu 目录, cuda 目录中存放
" :ref:`reset_max_memory_reserved <cn_api_paddle_device_reset_max_memory_reserved>` ", "重置给定设备上由内存分配器管理的内存峰值统计"
" :ref:`set_device <cn_api_paddle_device_set_device>` ", "指定 OP 运行的全局设备"
" :ref:`get_device <cn_api_paddle_device_get_device>` ", "获得 OP 运行的全局设备"
" :ref:`is_available <cn_api_paddle_device_is_available>` ", "检查设备是否可用"
" :ref:`get_rng_state <cn_api_paddle_device_get_rng_state>` ", "获取随机数生成器状态"
" :ref:`set_rng_state <cn_api_paddle_device_set_rng_state>` ", "设置随机数生成器状态"

.. _cn_device_compile:

Expand Down Expand Up @@ -97,6 +100,7 @@ Stream 与 Event 相关 API
" :ref:`stream_guard <cn_api_paddle_device_stream_guard>` ", "切换当前的 stream 为输入指定的 stream,该 API 目前仅支持动态图模式"
" :ref:`device_guard <cn_api_paddle_device_device_guard>` ", "切换当前的 device 为输入指定的 device,该 API 目前仅支持动态图模式"
" :ref:`synchronize <cn_api_paddle_device_synchronize>` ", "等待给定的设备上的计算完成"
" :ref:`is_current_stream_capturing <cn_api_paddle_device_is_current_stream_capturing>` ", "检查当前流是否处于捕获状态"

.. _cn_device_cuda:

Expand Down
1 change: 0 additions & 1 deletion docs/api/paddle/device/get_device_properties_cn.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ get_device_properties
---------------------

.. py:function:: paddle.device.get_device_properties(device=None)

返回指定设备的属性。

参数
Expand Down
23 changes: 23 additions & 0 deletions docs/api/paddle/device/get_rng_state_cn.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
.. _cn_api_paddle_device_get_rng_state:

get_rng_state
-------------------------------

.. py:function:: paddle.device.get_rng_state(device=None)

返回指定设备的随机数生成器状态,以 GeneratorState 形式表示。

参数
:::::::::
- **device** (DeviceLike, 可选) - 要获取 RNG 状态的设备:

- 如果不指定,则使用当前默认设备(由 paddle.framework._current_expected_place_()返回)
- 可以是设备对象、整数设备 ID 或设备字符串

返回
:::::::::
core.GeneratorState: 指定设备的当前 RNG 状态,以 GeneratorState 形式表示。

代码示例
::::::::::::
COPY-FROM: paddle.device.get_rng_state
21 changes: 21 additions & 0 deletions docs/api/paddle/device/is_available_cn.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
.. _cn_api_paddle_device_is_available:

is_available
-------------------------------

.. py:function:: paddle.device.is_available()

检查当前环境中是否有任何支持的设备可用。

该函数检查 Paddle 是否编译了至少一种加速器支持(如 CUDA、XPU、CustomDevice 等),
以及当前系统是否有至少一个该类型的设备可用。

如果有任何支持的设备可用,则返回 True,否则返回 False。

返回
:::::::::
bool: 如果有至少一个可用设备(GPU/XPU/CustomDevice)则返回 True,否则返回 False。

代码示例
::::::::::::
COPY-FROM: paddle.device.is_available
16 changes: 16 additions & 0 deletions docs/api/paddle/device/is_current_stream_capturing_cn.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
.. _cn_api_paddle_device_is_current_stream_capturing:

is_current_stream_capturing
-------------------------------

.. py:function:: paddle.device.is_current_stream_capturing()

检查当前设备流是否处于图形捕获状态。

返回
:::::::::
bool: 如果当前流正在捕获则返回 True,否则返回 False。

代码示例
::::::::::::
COPY-FROM: paddle.device.is_current_stream_capturing
18 changes: 18 additions & 0 deletions docs/api/paddle/device/reset_peak_memory_stats_cn.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
.. _cn_api_paddle_device_reset_peak_memory_stats:

reset_peak_memory_stats
-----------------------

.. py:function:: paddle.device.reset_peak_memory_stats(device=None)

重置设备的峰值内存统计信息。

参数
::::::::::::
- **device** (int|paddle.CUDAPlace|None) - 设备、设备的 id 或设备的字符串名称,如 npu:x',从中获取设备的属性。 如果设备为 None,则该设备为当前设备,默认值:None。

代码示例
::::::::::::
.. code-block:: python
>>> import paddle
>>> paddle.device.reset_max_memory_allocated(0)
24 changes: 24 additions & 0 deletions docs/api/paddle/device/set_rng_state_cn.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
.. _cn_api_paddle_device_set_rng_state:

set_rng_state
-------------------------------

.. py:function:: paddle.device.set_rng_state(new_state, device=None)

设置指定设备的随机数生成器状态。

参数
:::::::::
- **new_state** (core.GeneratorState) - 要设置的 RNG 状态对象,通常从 ``get_rng_state()`` 获取
- **device** (DeviceLike, 可选) - 要设置 RNG 状态的设备:

- 如果不指定,则使用当前默认设备(由 ``paddle.framework._current_expected_place_()`` 返回)
- 可以是设备对象、整数设备 ID 或设备字符串

返回
:::::::::
None

代码示例
:::::::::
COPY-FROM: paddle.device.set_rng_state
33 changes: 33 additions & 0 deletions docs/api/paddle/get_default_device_cn.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
.. _cn_api_paddle_get_default_device:

get_default_device
-------------------------------

.. py:function:: paddle.get_default_device()

获取程序当前运行的全局设备信息。

返回一个表示当前设备的字符串,格式可能是:
返回一个表示当前设备的字符串,格式可能是:

- 'cpu'
- 'gpu:x' (CUDA 设备)
- 'xpu:x' (XPU 设备)
- 'npu:x' (NPU 设备)

如果全局设备未明确设置,将根据以下规则返回:
如果全局设备未明确设置,将根据以下规则返回:

- 当 CUDA 可用时返回 'gpu:x'
- 当 CUDA 不可用时返回 'cpu'

返回
:::::::::
str: 表示当前设备的字符串

代码示例
:::::::::
.. code-block:: python

>>> import paddle
>>> device = paddle.get_default_device()
30 changes: 30 additions & 0 deletions docs/api/paddle/get_device_module_cn.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
.. _cn_api_paddle_get_device_module:

get_device_module
-------------------------------

.. py:function:: paddle.get_device_module(device=None)

获取指定设备对应的 Paddle 模块。

参数
:::::::::
- **device** (_CustomPlaceLike, 可选) - 要查询的设备,可以是以下类型之一:

- paddle.Place 对象 (例如 paddle.CUDAPlace(0))
- 字符串 (例如 "gpu:0", "xpu", "npu")
- 整数 (设备索引,例如 0 -> "gpu:0")
- None (使用当前预期设备)

返回
:::::::::
module: 对应的 Paddle 设备模块 (例如 paddle.cuda, paddle.device.xpu)


代码示例
:::::::::
.. code-block:: python

>>> import paddle
>>> paddle.get_device_module("gpu:0")
<module 'paddle.cuda' ...>