Skip to content

Commit

Permalink
improve error handling with gpu names
Browse files Browse the repository at this point in the history
  • Loading branch information
YellowRoseCx committed Jul 14, 2023
1 parent 860e738 commit f208670
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions koboldcpp.py
Original file line number Diff line number Diff line change
Expand Up @@ -729,14 +729,15 @@ def getfilename(var, text):
button.grid(row=row+1, column=1, stick="nw")
return

from subprocess import run
from subprocess import run, CalledProcessError
def get_device_names():
CUdevices = []
CLdevices = []
try: # Get OpenCL GPU names
output = run(['clinfo'], capture_output=True, text=True, check=True, encoding='utf-8').stdout
CLdevices = [line.split(":", 1)[1].strip() for line in output.splitlines() if line.strip().startswith("Board name:")]
except FileNotFoundError: pass
except Exception as e:
pass
try: # Get AMD ROCm GPU names
output = run(['rocminfo'], capture_output=True, text=True, check=True, encoding='utf-8').stdout
device_name = None
Expand All @@ -745,12 +746,14 @@ def get_device_names():
if line.startswith("Marketing Name:"): device_name = line.split(":", 1)[1].strip()
elif line.startswith("Device Type:") and "GPU" in line and device_name is not None: CUdevices.append(device_name)
elif line.startswith("Device Type:") and "GPU" not in line: device_name = None
except FileNotFoundError: pass
except Exception as e:
pass
# try: # Get NVIDIA GPU names , Couldn't test so probably not working yet.
# output = run(['nvidia-smi', '-L'], capture_output=True, text=True, check=True, encoding='utf-8').stdout
# CUdevices = [line.split(":", 1)[1].strip() for line in output.splitlines() if line.startswith("GPU:")]
# except FileNotFoundError: pass
if CUdevices: CUdevices.append('All')
CUdevices.append('All') if CUdevices else CUdevices.extend(['1', '2', '3', 'All'])
if not CLdevices: CLdevices.extend(['1', '2', '3'])
return CUdevices, CLdevices

# Vars - should be in scope to be used by multiple widgets
Expand Down

0 comments on commit f208670

Please sign in to comment.