Created
July 18, 2022 15:05
-
-
Save tamara-schmitz/ae36fe840973f33bc3667c69f98a887a to your computer and use it in GitHub Desktop.
supported-gpus.json to pci_ids script
This file contains 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 python3 | |
# Copyright (c) 2022 Tamara Schmitz <tamara.schmitz@suse.com>. | |
# | |
# This program is free software: you can redistribute it and/or modify | |
# it under the terms of the GNU General Public License as published by | |
# the Free Software Foundation, version 3. | |
# | |
# This program is distributed in the hope that it will be useful, but | |
# WITHOUT ANY WARRANTY; without even the implied warranty of | |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
# General Public License for more details. | |
# | |
# You should have received a copy of the GNU General Public License | |
# along with this program. If not, see <http://www.gnu.org/licenses/>. | |
# | |
import argparse | |
import json | |
# arg parsing | |
parser = argparse.ArgumentParser(description="Parse an NVIDIA supported devices\ | |
JSON and convert it to a pci id list.") | |
parser.add_argument("INPUT_JSON", | |
help="The JSON file to be parsed", | |
type=argparse.FileType('r') | |
) | |
parser.add_argument("OUTPUT_PCI_ID_LIST", | |
help="The output file to save to", | |
type=argparse.FileType('w') | |
) | |
parser.add_argument("--skiplegacy", help="Skip GPUs that are in a legacy branch", | |
action="store_true") | |
parser.add_argument("--kernelopen", help="Only select GPUs that are supported by\ | |
the Open GPU kernel modules", | |
action="store_true") | |
args = parser.parse_args() | |
# json parsing | |
json = json.load(args.INPUT_JSON) | |
pci_id_list = {} | |
for chip in json["chips"]: | |
if args.skiplegacy and "legacybranch" in chip: | |
continue | |
if args.kernelopen and \ | |
("features" not in chip or "kernelopen" not in chip["features"]): | |
continue | |
if "devid" in chip and "name" in chip: | |
pci_id_list[chip["devid"]] = chip["name"] | |
# write to file | |
for devid, name in sorted(pci_id_list.items(), key=lambda i: i[0]): | |
# there are no duplicates since a dictionary's key is unique | |
args.OUTPUT_PCI_ID_LIST.write("%s %s\n" % (devid, name)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment