Last active
March 29, 2021 12:30
-
-
Save huitseeker/b2c79e5b763d58b06b9985de2b3c0d4d to your computer and use it in GitHub Desktop.
Find a CUDA compute capability from a GPU name programmatically
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
""" | |
Obtain the correspondence of a local GPU name to its cuda compute capability | |
Names match the output of nvidia-smi --query-gpu=gpu_name --format=csv,noheader | |
Usage: | |
---- | |
./get_ccompute.py <GPU_NAME> | |
""" | |
import sys | |
try: | |
from urllib.request import urlopen | |
except ImportError: | |
from urllib2 import urlopen | |
import collections | |
from bs4 import BeautifulSoup | |
def process(url): | |
page = urlopen(url) | |
text = page.read() | |
page.close() | |
soup = BeautifulSoup(text, "lxml") | |
d = collections.defaultdict(str) | |
for table in soup.findAll('table', {'class': 'table table-striped'}): | |
for line in table.findAll('tr'): | |
gpu = line.findNext('td').text.strip() | |
compute = line.findNext('td').findNext('td').text.strip() | |
d[gpu] = compute | |
return d | |
def main(): | |
if len(sys.argv) > 1: | |
gpu = sys.argv[1] | |
if len(sys.argv) == 1: | |
print("Usage: %s <GPU_NAME> ..." % sys.argv[0]) | |
sys.exit(1) | |
# at least one gpu was passed | |
d = process("https://developer.nvidia.com/cuda-gpus") | |
print(d[gpu]) | |
if __name__ == "__main__": | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Tweaked to use python3, and added more useful Usage. Only 2 non-comment lines changed:
#!/usr/bin/env python3
andWould be nice to add URL to this gist in comments at top, too...