Skip to content

Instantly share code, notes, and snippets.

@userbox020
Last active February 17, 2024 02:45
Show Gist options
  • Save userbox020/284588c776e107e320b6abd5ce1f57ee to your computer and use it in GitHub Desktop.
Save userbox020/284588c776e107e320b6abd5ce1f57ee to your computer and use it in GitHub Desktop.
Check nvidia gpu pcie lines, seep and memory
#Works for Windows and Linux
import re
import subprocess
def get_gpu_details():
try:
# Execute the nvidia-smi command to get detailed GPU information
result = subprocess.run(['nvidia-smi', '-q'], stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True)
if result.stderr:
print("Error executing nvidia-smi:", result.stderr)
return
# Extract the section for each GPU
gpu_sections = result.stdout.split('GPU 00000000')[1:] # Skip the first part, split for each GPU info
for index, section in enumerate(gpu_sections, start=1):
print(f"\nGPU {index} Details:")
# Extract and print Product Name
product_name = re.search(r"Product Name\s*:\s*(.+)", section)
if product_name:
print(f" Product Name: {product_name.group(1)}")
# Extract and print FB Memory Usage Total
fb_memory_total = re.search(r"FB Memory Usage\s*\n.*Total\s*:\s*(\d+\s*MiB)", section)
if fb_memory_total:
print(f" FB Memory Usage - Total: {fb_memory_total.group(1)}")
# Extract and print PCIe Generation Max and Current
pcie_gen = re.search(r"PCIe Generation\s*\n.*Max\s*:\s*(\d+)\s*\n.*Current\s*:\s*(\d+)", section)
if pcie_gen:
print(f" PCIe Generation - Max: {pcie_gen.group(1)}, Current: {pcie_gen.group(2)}")
# Extract and print Link Width Max and Current
link_width = re.search(r"Link Width\s*\n.*Max\s*:\s*(\d+x)\s*\n.*Current\s*:\s*(\d+x)", section)
if link_width:
print(f" Link Width - Max: {link_width.group(1)}, Current: {link_width.group(2)}")
print("-" * 40)
except Exception as e:
print(f"An error occurred: {e}")
if __name__ == "__main__":
get_gpu_details()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment