MCPcopy Index your code
hub / github.com/EverMind-AI/MSA / monitor_gpu_memory_example

Function monitor_gpu_memory_example

src/utils/gpu_monitor.py:218–247  ·  view source on GitHub ↗

使用示例

()

Source from the content-addressed store, hash-verified

216
217# 使用示例函数
218def monitor_gpu_memory_example():
219 """使用示例"""
220 print("GPU显存监控示例")
221 print("=" * 50)
222
223 try:
224 # 创建监控器
225 monitor = GPUMemoryMonitor(
226 gpu_index=0, # 监控第一个GPU
227 interval=0.5, # 每0.5秒检查一次
228 unit='GB' # 使用GB作为单位
229 )
230
231 # 启动监控
232 if monitor.start():
233 # 这里可以运行你的GPU任务
234 print("\n现在开始运行你的GPU任务...")
235 print("监控正在后台进行")
236
237 # 模拟一些工作(在实际使用中,这里应该是你的GPU任务)
238 print("按回车键停止监控并获取峰值显存用量...")
239 input() # 等待用户按回车
240
241 # 停止监控并获取结果
242 peak_memory_gb = monitor.stop()
243
244 print(f"\n监控完成!峰值显存用量: {peak_memory_gb:.3f} GB")
245
246 except Exception as e:
247 print(f"错误: {e}")
248
249
250# 多GPU监控示例

Callers

nothing calls this directly

Calls 3

startMethod · 0.95
stopMethod · 0.95
GPUMemoryMonitorClass · 0.85

Tested by

no test coverage detected