torch.xpu.memory_stats
- torch.xpu.memory_stats(device=None)[源代码]
-
为给定设备返回XPU内存分配器的统计信息字典。
此函数的返回值是一个包含统计信息的字典,每项统计信息都为非负整数。
核心统计:
-
"allocated_bytes.{all,large_pool,small_pool}.{current,peak,allocated,freed}"
: 表示已分配的内存数量。 -
"reserved_bytes.{all,large_pool,small_pool}.{current,peak,allocated,freed}"
: 表示已预留内存的数量。 -
"active_bytes.{all,large_pool,small_pool}.{current,peak,allocated,freed}"
: 表示活跃内存的数量。 -
"requested_bytes.{all,large_pool,small_pool}.{current,peak,allocated,freed}"
: 客户端代码请求的内存,通过与allocated_bytes
对比来检查分配过程中是否因舍入导致了过多的开销。
这些核心统计信息的值分解如下。
池类型:
-
all
: 所有内存池的汇总统计信息。 -
large_pool
: 大于或等于 1MB 分配的大分配池的统计信息。 -
small_pool
: 小分配池的统计信息(适用于小于 1MB 的分配)。
度量类型:
-
current
: 当前指标的值。 -
peak
: 指标的最大值。 -
allocated
: 此指标的历史总增量。 -
freed
: 这个指标的历史总减少量。
- 参数
-
device (torch.device 或 int 或 str, 可选) – 选定的设备。如果未指定
device
(默认为None
),则返回当前设备的统计信息,该信息由current_device()
提供。 - 返回类型
-