UI-side changes for selecting multiple GPUs, and keeping the Use CPU option synchronized with the backend. This change isn't ready to be shipped, it still needs python-side changes to support the req.render_device config

This commit is contained in:
cmdr2
2022-11-09 19:17:44 +05:30
parent 087c10d52d
commit 058ce6fe82
6 changed files with 109 additions and 15 deletions

View File

@ -336,6 +336,8 @@ def render(req : task_manager.ImageRequest):
print('WARNING Replace {use_cpu: true} by {render_device: "cpu"}')
req.render_device = 'cpu'
del req.use_cpu
if req.render_device != 'cpu':
req.render_device = int(req.render_device)
if req.render_device and task_manager.is_alive(req.render_device) <= 0: raise HTTPException(status_code=403, detail=f'{req.render_device} rendering is not enabled in config.json or the thread has died...') # HTTP403 Forbidden
if req.use_face_correction and task_manager.is_alive(0) <= 0: #TODO Remove when GFPGANer is fixed upstream.
raise HTTPException(status_code=412, detail=f'GFPGANer only works GPU:0, use CUDA_VISIBLE_DEVICES if GFPGANer is needed on a specific GPU.') # HTTP412 Precondition Failed
@ -437,7 +439,7 @@ if 'render_devices' in config: # Start a new thread for each device.
print('WARNING: No active render devices after loading config. Validate "render_devices" in config.json')
print('Loading default render devices to replace invalid render_devices field from config', config['render_devices'])
if task_manager.is_alive() <= 0: # Either no defauls or no devices after loading config.
if task_manager.is_alive() <= 0: # Either no defaults or no devices after loading config.
# Select best GPU device using free memory, if more than one device.
if task_manager.start_render_thread('auto'): # Detect best device for renders
# if cuda:0 is missing, another cuda device is better. try to start it...
@ -455,7 +457,7 @@ if is_using_a_gpu and task_manager.is_alive(0) <= 0:
print('Add the line "@set CUDA_VISIBLE_DEVICES=N" where N is the GPUs to use to config.bat')
print('Add the line "CUDA_VISIBLE_DEVICES=N" where N is the GPUs to use to config.sh')
print('active devices', task_manager.get_devices())
# print('active devices', task_manager.get_devices())
# start the browser ui
import webbrowser; webbrowser.open('http://localhost:9000')