Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
8 changes: 8 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,16 @@ 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_current_stream_capturing <cn_api_paddle_cuda_is_current_stream_capturing>` ", "检查当前流是否处于捕获状态"
" :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
24 changes: 24 additions & 0 deletions docs/api/paddle/cuda/current_stream_cn.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
.. _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
16 changes: 16 additions & 0 deletions docs/api/paddle/cuda/is_current_stream_capturing_cn.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
.. _cn_api_paddle_cuda_is_current_stream_capturing:

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

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

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

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

代码示例
::::::::::::
COPY-FROM: paddle.cuda.is_current_stream_capturing
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
5 changes: 5 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,10 @@ 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:`manual_seed_all <cn_api_paddle_device_manual_seed_all>` ", "设置全局随机种子"
" :ref:`set_rng_state <cn_api_paddle_device_set_rng_state>` ", "设置随机数生成器状态"

.. _cn_device_compile:

Expand Down Expand Up @@ -97,6 +101,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
20 changes: 20 additions & 0 deletions docs/api/paddle/device/manual_seed_all_cn.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
.. _cn_api_paddle_device_manual_seed_all:

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

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

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

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

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

代码示例
::::::::::::
COPY-FROM: paddle.device.manual_seed_all
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
29 changes: 29 additions & 0 deletions docs/api/paddle/get_default_device_cn.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
.. _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()
Loading