@@ -728,12 +728,37 @@ def getfilename(var, text):
728728 button = ctk .CTkButton (parent , 50 , text = "Browse" , command = lambda a = var ,b = searchtext :getfilename (a ,b ))
729729 button .grid (row = row + 1 , column = 1 , stick = "nw" )
730730 return
731+
732+ from subprocess import run
733+ def get_device_names ():
734+ CUdevices = []
735+ CLdevices = []
736+ try : # Get OpenCL GPU names
737+ output = run (['clinfo' ], capture_output = True , text = True , check = True , encoding = 'utf-8' ).stdout
738+ CLdevices = [line .split (":" , 1 )[1 ].strip () for line in output .splitlines () if line .strip ().startswith ("Board name:" )]
739+ except FileNotFoundError : pass
740+ try : # Get AMD ROCm GPU names
741+ output = run (['rocminfo' ], capture_output = True , text = True , check = True , encoding = 'utf-8' ).stdout
742+ device_name = None
743+ for line in output .splitlines ():
744+ line = line .strip ()
745+ if line .startswith ("Marketing Name:" ): device_name = line .split (":" , 1 )[1 ].strip ()
746+ elif line .startswith ("Device Type:" ) and "GPU" in line and device_name is not None : CUdevices .append (device_name )
747+ elif line .startswith ("Device Type:" ) and "GPU" not in line : device_name = None
748+ except FileNotFoundError : pass
749+ # try: # Get NVIDIA GPU names , Couldn't test so probably not working yet.
750+ # output = run(['nvidia-smi', '-L'], capture_output=True, text=True, check=True, encoding='utf-8').stdout
751+ # CUdevices = [line.split(":", 1)[1].strip() for line in output.splitlines() if line.startswith("GPU:")]
752+ # except FileNotFoundError: pass
753+ if CUdevices : CUdevices .append ('All' )
754+ return CUdevices , CLdevices
731755
732756 # Vars - should be in scope to be used by multiple widgets
757+ CUdevices , CLdevices = get_device_names ()
733758 gpulayers_var = ctk .StringVar (value = "0" )
734759 threads_var = ctk .StringVar (value = str (default_threads ))
735760 runopts_var = ctk .StringVar ()
736- gpu_choice_var = ctk .StringVar (value = "1" )
761+ gpu_choice_var = ctk .StringVar (value = CLdevices [ 0 ] if not None else CUdevices [ 0 ] if not None else "1" )
737762
738763 launchbrowser = ctk .IntVar (value = 1 )
739764 highpriority = ctk .IntVar ()
@@ -773,11 +798,12 @@ def getfilename(var, text):
773798 quick_tab = tabcontent ["Quick Launch" ]
774799
775800 # gpu options
776- quick_gpu_layers_entry ,quick_gpu_layers_label = makelabelentry (quick_tab ,"GPU Layers:" , gpulayers_var , 4 , 50 )
801+
802+ quick_gpu_layers_entry , quick_gpu_layers_label = makelabelentry (quick_tab , "GPU Layers:" , gpulayers_var , 4 , 50 )
777803 quick_gpu_selector_label = makelabel (quick_tab , "GPU ID:" , 3 )
778- quick_gpu_selector_box = ctk .CTkComboBox (quick_tab , values = [ "1" , "2" , "3" ], width = 60 , variable = gpu_choice_var , state = "readonly" )
779- CUDA_quick_gpu_selector_box = ctk .CTkComboBox (quick_tab , values = [ "1" , "2" , "3" , "All" ], width = 60 , variable = gpu_choice_var , state = "readonly" )
780- quick_lowvram_box = makecheckbox (quick_tab , "Low VRAM" , lowvram_var , 5 )
804+ quick_gpu_selector_box = ctk .CTkComboBox (quick_tab , values = CLdevices , width = 180 , variable = gpu_choice_var , state = "readonly" )
805+ CUDA_quick_gpu_selector_box = ctk .CTkComboBox (quick_tab , values = CUdevices , width = 180 , variable = gpu_choice_var , state = "readonly" )
806+ quick_lowvram_box = makecheckbox (quick_tab , "Low VRAM" , lowvram_var , 5 )
781807
782808 def changerunmode (a ,b ,c ):
783809 index = runopts_var .get ()
@@ -846,8 +872,8 @@ def changerunmode(a,b,c):
846872 # gpu options
847873 gpu_layers_entry ,gpu_layers_label = makelabelentry (hardware_tab ,"GPU Layers:" , gpulayers_var , 4 , 50 )
848874 gpu_selector_label = makelabel (hardware_tab , "GPU ID:" , 3 )
849- gpu_selector_box = ctk .CTkComboBox (hardware_tab , values = [ "1" , "2" , "3" ], width = 60 , variable = gpu_choice_var , state = "readonly" )
850- CUDA_gpu_selector_box = ctk .CTkComboBox (hardware_tab , values = [ "1" , "2" , "3" , "All" ], width = 60 , variable = gpu_choice_var , state = "readonly" )
875+ gpu_selector_box = ctk .CTkComboBox (hardware_tab , values = CLdevices , width = 180 , variable = gpu_choice_var , state = "readonly" )
876+ CUDA_gpu_selector_box = ctk .CTkComboBox (hardware_tab , values = CUdevices , width = 180 , variable = gpu_choice_var , state = "readonly" )
851877 lowvram_box = makecheckbox (hardware_tab , "Low VRAM" , lowvram_var , 5 )
852878
853879 # presets selector
@@ -960,11 +986,14 @@ def export_vars():
960986 args .stream = stream .get ()== 1
961987 args .smartcontext = smartcontext .get ()== 1
962988 args .unbantokens = unbantokens .get ()== 1
963- gpu_choice_str = gpu_choice_var .get ()
964989 gpuchoiceidx = 0
965-
966990 if gpu_choice_var .get ()!= "All" :
967- gpuchoiceidx = int (gpu_choice_var .get ())- 1
991+ if runopts_var .get () == runopts [1 ]: #if CLBlast selected
992+ if (gpu_choice_var .get ()) in CLdevices :
993+ gpuchoiceidx = CLdevices .index ((gpu_choice_var .get ()))
994+ elif runopts_var .get () == runopts [2 ]:
995+ if (gpu_choice_var .get ()) in CUdevices :
996+ gpuchoiceidx = CUdevices .index ((gpu_choice_var .get ()))
968997 if runopts_var .get () == runopts [1 ]:
969998 args .useclblast = [[0 ,0 ], [1 ,0 ], [0 ,1 ]][gpuchoiceidx ]
970999 if runopts_var .get () == runopts [2 ]:
0 commit comments