-
Notifications
You must be signed in to change notification settings - Fork 877
[API Compatibility] Add some device related API #7467
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 16 commits
2566bee
dbff885
00e0d26
6d624de
a24df74
b5be53c
d8aef5b
38c3769
8686cee
f85aaed
3ee3341
055fe3f
25bdb30
6eb767c
cda9ced
0c94078
da8483e
5e5eca8
c81cdfd
7bdb45c
8f02a8b
080c9e6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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 | ||
| 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 |
| 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 |
| 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 |
| 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 |
| 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()``获取 | ||||||
|
||||||
| - **new_state** (core.GeneratorState) - 要设置的 RNG 状态对象,通常从``get_rng_state()``获取 | |
| - **new_state** (core.GeneratorState) - 要设置的 RNG 状态对象,通常从 ``get_rng_state()`` 获取 |
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| - 如果不指定,则使用当前默认设备(由``paddle.framework._current_expected_place_()``返回) | |
| - 如果不指定,则使用当前默认设备(由 ``paddle.framework._current_expected_place_()`` 返回) |
| 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 | ||
| 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 |
| 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 |
| 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 |
| 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()``获取 | ||||||
|
||||||
| - **new_state** (core.GeneratorState) - 要设置的 RNG 状态对象,通常从``get_rng_state()``获取 | |
| - **new_state** (core.GeneratorState) - 要设置的 RNG 状态对象,通常从 ``get_rng_state()`` 获取 |
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| - 如果不指定,则使用当前默认设备(由``paddle.framework._current_expected_place_()``返回) | |
| - 如果不指定,则使用当前默认设备(由 ``paddle.framework._current_expected_place_()`` 返回) |
| 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 设备) | ||
fxyfxy777 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| 如果全局设备未明确设置,将根据以下规则返回: | ||
| - 当 CUDA 可用时返回'gpu:x' | ||
| - 当 CUDA 不可用时返回'cpu' | ||
fxyfxy777 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| 返回 | ||
| ::::::::: | ||
| str: 表示当前设备的字符串 | ||
|
|
||
| 代码示例 | ||
| ::::::::: | ||
| .. code-block:: python | ||
|
|
||
| >>> import paddle | ||
| >>> device = paddle.get_default_device() | ||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,33 @@ | ||||||
| .. _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) | ||||||
|
|
||||||
| 异常 | ||||||
| ::::::::: | ||||||
| - RuntimeError: 如果设备类型是 CPU(Paddle 不暴露`paddle.cpu`模块)或找不到匹配的设备模块 | ||||||
|
||||||
| - RuntimeError: 如果设备类型是 CPU(Paddle 不暴露`paddle.cpu`模块)或找不到匹配的设备模块 | |
| - RuntimeError: 如果设备类型是 CPU(Paddle 不暴露 ``paddle.cpu`` 模块)或找不到匹配的设备模块 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.