PaScaL_TDMA  v2.0
Documentation
Loading...
Searching...
No Matches
gpu_power_monitor.py
Go to the documentation of this file.
1"""
2================================================================================
3@file: gpu_power_monitor.py
4@brief: Monitors and prints real-time GPU power usage with timestamps.
5@author: Mingyu Yang (yang926@yonsei.ac.kr), School of Mathematics and Computing (Computational Science and Engineering), Yonsei University
6 Oh-Kyoung Kwon (okkwon@kisti.re.kr), Korea Institute of Science and Technology Information
7 Jung-Il Choi (jic@yonsei.ac.kr), School of Mathematics and Computing (Computational Science and Engineering), Yonsei University
8@date: May 2023
9@version: 2.0
10@copyright: Copyright (c) 2023 Mingyu Yang, Oh-Kyoung Kwon, Jung-Il Choi. All rights reserved.
11@license: This project is released under the terms of the MIT License (see LICENSE file).
12================================================================================
13"""
14
15import pynvml
16import matplotlib.pyplot as plt
17import time
18import numpy as np
19import asyncio
20from datetime import datetime, timedelta
21
22# Initialize NVIDIA Management Library (NVML)
23pynvml.nvmlInit()
24
25# Get handle for the first available GPU
26handle = pynvml.nvmlDeviceGetHandleByIndex(0)
27
28# Set measurement interval (in seconds)
29measurement_interval = 0.01
30mW_to_W = 1e3 # Conversion factor for milliwatts to watts
31
32# Continuously monitor and print GPU power usage
33while True:
34 now = datetime.now()
35 current_datetime = now.strftime("%Y%m%d %H:%M:%S.%f")
36 sec = 0.01
37 measure = pynvml.nvmlDeviceGetPowerUsage(handle) / mW_to_W # Get power usage and convert to watts
38 time.sleep(sec)
39 print("time : ", current_datetime, measure) # Print timestamp and power usage