Skip to content

Commit 2474897

Browse files
committed
add apis
1 parent d5803fd commit 2474897

File tree

7 files changed

+113
-0
lines changed

7 files changed

+113
-0
lines changed

docs/api/paddle/cuda/Overview_cn.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,9 @@ PyTorch 兼容函数
1818
" :ref:`cudart <cn_api_paddle_cuda_cudart>` ", "以模块的形式返回 CUDA Runtime 对象"
1919
" :ref:`is_initialized <cn_api_paddle_cuda_is_initialized>` ", "判断 CUDA 是否已经初始化"
2020
" :ref:`mem_get_info <cn_api_paddle_cuda_mem_get_info>` ", "获取指定设备上的全局空闲显存和显存总量"
21+
" :ref:`current_device <cn_api_paddle_cuda_current_device>` ", "返回当前设备的索引"
22+
" :ref:`device_count <cn_api_paddle_cuda_device_count>` ", "返回可用的 CUDA 设备数量"
23+
" :ref:`empty_cache <cn_api_paddle_cuda_empty_cache>` ", "释放当前设备上所有未占用的缓存内存"
24+
" :ref:`memory_allocated <cn_api_paddle_cuda_memory_allocated>` ", "返回当前设备上分配的内存总量"
25+
" :ref:`memory_reserved <cn_api_paddle_cuda_memory_reserved>` ", "返回当前设备上由缓存分配器管理的内存总量"
26+
" :ref:`set_device <cn_api_paddle_cuda_set_device>` ", "设置当前设备"
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
.. _cn_api_paddle_cuda_current_device:
2+
3+
current_device
4+
--------------
5+
6+
.. py:function:: paddle.cuda.current_device()
7+
8+
返回当前设备的索引。
9+
10+
返回
11+
::::::::::::
12+
13+
int, 当前设备的索引。
14+
15+
代码示例
16+
::::::::::::
17+
COPY-FROM: paddle.cuda.current_device
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
.. _cn_api_paddle_cuda_device_count:
2+
3+
device_count
4+
------------
5+
6+
:: paddle.cuda.device_count()
7+
8+
返回可用的计算卡设备数量。
9+
10+
返回
11+
::::::::::::
12+
13+
int, 可用的计算卡设备数量。
14+
15+
代码示例
16+
::::::::::::
17+
COPY-FROM: paddle.cuda.device_count
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
.. _cn_api_paddle_cuda_empty_cache:
2+
3+
empty_cache
4+
-----------
5+
6+
:: paddle.cuda.empty_cache()
7+
8+
该函数用于释放显存分配器中空闲的显存,这样其他的 GPU 应用程序就可以使用释放出来的显存,并在 nvidia-smi 中可见。大多数情况下您不需要使用该函数,当您删除 GPU 上的 Tensor 时,Paddle 框架并不会将显存释放,而是将显存保留起来,以便在下一次申明显存时可以更快的完成分配。
9+
10+
代码示例
11+
::::::::::::
12+
COPY-FROM: paddle.cuda.empty_cache
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
.. _cn_api_paddle_cuda_memory_allocated:
2+
3+
memory_allocated
4+
---------------
5+
6+
:: paddle.cuda.memory_allocated(device=None)
7+
8+
返回给定设备上当前分配给 Tensor 的显存大小。
9+
10+
参数
11+
::::::::::::
12+
13+
- **device** (DeviceLike) - 指定要查询的设备,可以是 "int" 用来表示设备id,可以是形如 "gpu:0" 之类的设备描述字符串,也可以是 `paddle.CUDAPlace(0)` 之类的设备实例。如果为 None(默认值)或未指定设备索引,则返回由 ``paddle.device.get_device()`` 给出的当前设备的统计信息。
14+
15+
返回
16+
::::::::::::
17+
18+
int, 当前设备上分配的内存总量(字节)。
19+
20+
代码示例
21+
::::::::::::
22+
COPY-FROM: paddle.cuda.memory_allocated
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
.. _cn_api_paddle_cuda_memory_reserved:
2+
3+
memory_reserved
4+
---------------
5+
6+
:: paddle.cuda.memory_reserved(device=None)
7+
8+
返回当前设备上由缓存分配器管理的内存总量。
9+
10+
参数
11+
::::::::::::
12+
13+
- **device** (DeviceLike) - 指定要查询的设备,可以是 "int" 用来表示设备id,可以是形如 "gpu:0" 之类的设备描述字符串,也可以是 `paddle.CUDAPlace(0)` 之类的设备实例。如果为 None(默认值)或未指定设备索引,则返回由 ``paddle.device.get_device()`` 给出的当前设备的统计信息。
14+
15+
返回
16+
::::::::::::
17+
18+
int, 当前设备上由缓存分配器管理的内存总量(字节)。
19+
20+
代码示例
21+
::::::::::::
22+
COPY-FROM: paddle.cuda.memory_reserved
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
.. _cn_api_paddle_cuda_set_device:
2+
3+
set_device
4+
----------
5+
6+
:: paddle.cuda.set_device(device)
7+
8+
设置当前设备。
9+
10+
参数
11+
::::::::::::
12+
13+
- **device** (DeviceLike) - 要设置的设备,可以是 "int" 用来表示设备id,可以是形如 "gpu:0" 之类的设备描述字符串,也可以是 `paddle.CUDAPlace(0)` 之类的设备实例。
14+
15+
代码示例
16+
::::::::::::
17+
COPY-FROM: paddle.cuda.set_device

0 commit comments

Comments
 (0)