Skip to content

Commit

Permalink
Show GPU names in GUI, Only show GPUs that exist
Browse files Browse the repository at this point in the history
changed the pre-set 1,2,3 and 1,2,3,all settings that the GPU selector had and replaced them with a function that grabs the GPU names and sets the names as the values for the selector boxes.
  • Loading branch information
YellowRoseCx committed Jul 14, 2023
1 parent ac7ebc3 commit 860e738
Showing 1 changed file with 39 additions and 10 deletions.
49 changes: 39 additions & 10 deletions koboldcpp.py
Original file line number Diff line number Diff line change
Expand Up @@ -728,12 +728,37 @@ def getfilename(var, text):
button = ctk.CTkButton(parent, 50, text="Browse", command= lambda a=var,b=searchtext:getfilename(a,b))
button.grid(row=row+1, column=1, stick="nw")
return

from subprocess import run
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
try: # Get AMD ROCm GPU names
output = run(['rocminfo'], capture_output=True, text=True, check=True, encoding='utf-8').stdout
device_name = None
for line in output.splitlines():
line = line.strip()
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
# 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')
return CUdevices, CLdevices

# Vars - should be in scope to be used by multiple widgets
CUdevices, CLdevices = get_device_names()
gpulayers_var = ctk.StringVar(value="0")
threads_var = ctk.StringVar(value=str(default_threads))
runopts_var = ctk.StringVar()
gpu_choice_var = ctk.StringVar(value="1")
gpu_choice_var = ctk.StringVar(value=CLdevices[0] if not None else CUdevices[0] if not None else "1")

launchbrowser = ctk.IntVar(value=1)
highpriority = ctk.IntVar()
Expand Down Expand Up @@ -773,11 +798,12 @@ def getfilename(var, text):
quick_tab = tabcontent["Quick Launch"]

# gpu options
quick_gpu_layers_entry,quick_gpu_layers_label = makelabelentry(quick_tab,"GPU Layers:", gpulayers_var, 4, 50)

quick_gpu_layers_entry, quick_gpu_layers_label = makelabelentry(quick_tab, "GPU Layers:", gpulayers_var, 4, 50)
quick_gpu_selector_label = makelabel(quick_tab, "GPU ID:", 3)
quick_gpu_selector_box = ctk.CTkComboBox(quick_tab, values=["1","2","3"], width=60, variable=gpu_choice_var, state="readonly")
CUDA_quick_gpu_selector_box = ctk.CTkComboBox(quick_tab, values=["1","2","3","All"], width=60, variable=gpu_choice_var, state="readonly")
quick_lowvram_box = makecheckbox(quick_tab, "Low VRAM", lowvram_var, 5)
quick_gpu_selector_box = ctk.CTkComboBox(quick_tab, values=CLdevices, width=180, variable=gpu_choice_var, state="readonly")
CUDA_quick_gpu_selector_box = ctk.CTkComboBox(quick_tab, values=CUdevices, width=180, variable=gpu_choice_var, state="readonly")
quick_lowvram_box = makecheckbox(quick_tab, "Low VRAM", lowvram_var, 5)

def changerunmode(a,b,c):
index = runopts_var.get()
Expand Down Expand Up @@ -846,8 +872,8 @@ def changerunmode(a,b,c):
# gpu options
gpu_layers_entry,gpu_layers_label = makelabelentry(hardware_tab,"GPU Layers:", gpulayers_var, 4, 50)
gpu_selector_label = makelabel(hardware_tab, "GPU ID:", 3)
gpu_selector_box = ctk.CTkComboBox(hardware_tab, values=["1","2","3"], width=60, variable=gpu_choice_var, state="readonly")
CUDA_gpu_selector_box = ctk.CTkComboBox(hardware_tab, values=["1","2","3", "All"], width=60, variable=gpu_choice_var, state="readonly")
gpu_selector_box = ctk.CTkComboBox(hardware_tab, values=CLdevices, width=180, variable=gpu_choice_var, state="readonly")
CUDA_gpu_selector_box = ctk.CTkComboBox(hardware_tab, values=CUdevices, width=180, variable=gpu_choice_var, state="readonly")
lowvram_box = makecheckbox(hardware_tab, "Low VRAM", lowvram_var, 5)

# presets selector
Expand Down Expand Up @@ -960,11 +986,14 @@ def export_vars():
args.stream = stream.get()==1
args.smartcontext = smartcontext.get()==1
args.unbantokens = unbantokens.get()==1
gpu_choice_str = gpu_choice_var.get()
gpuchoiceidx = 0

if gpu_choice_var.get()!="All":
gpuchoiceidx = int(gpu_choice_var.get())-1
if runopts_var.get() == runopts[1]: #if CLBlast selected
if (gpu_choice_var.get()) in CLdevices:
gpuchoiceidx = CLdevices.index((gpu_choice_var.get()))
elif runopts_var.get() == runopts[2]:
if (gpu_choice_var.get()) in CUdevices:
gpuchoiceidx = CUdevices.index((gpu_choice_var.get()))
if runopts_var.get() == runopts[1]:
args.useclblast = [[0,0], [1,0], [0,1]][gpuchoiceidx]
if runopts_var.get() == runopts[2]:
Expand Down

0 comments on commit 860e738

Please sign in to comment.