From cfd395abe700469624a1801635fc603bb8210374 Mon Sep 17 00:00:00 2001 From: kushalkolar Date: Fri, 18 Oct 2024 02:02:04 -0400 Subject: [PATCH 1/2] display adapters in HTML table upon import in notebooks --- fastplotlib/utils/gui.py | 57 +++++++++++++++++++++++++++++----------- 1 file changed, 42 insertions(+), 15 deletions(-) diff --git a/fastplotlib/utils/gui.py b/fastplotlib/utils/gui.py index 1f13c1406..5591d10f8 100644 --- a/fastplotlib/utils/gui.py +++ b/fastplotlib/utils/gui.py @@ -45,7 +45,7 @@ def _notebook_print_banner(): from ipywidgets import Image - from IPython.display import display + from IPython.display import display, HTML logo_path = Path(__file__).parent.parent.joinpath( "assets", "fastplotlib_face_logo.png" @@ -54,40 +54,67 @@ def _notebook_print_banner(): with open(logo_path, "rb") as f: logo_data = f.read() + # get small logo image image = Image(value=logo_data, format="png", width=300, height=55) - display(image) - - # print logo and adapter info + # get adapters and info adapters = [a for a in wgpu.gpu.enumerate_adapters()] adapters_info = [a.info for a in adapters] default_adapter_info = wgpu.gpu.request_adapter().info default_ix = adapters_info.index(default_adapter_info) - if len(adapters) > 0: - print("Available devices:") - + if len(adapters) < 1: + return + + # start HTML table + table_str = ("Available devices:" + "" + "" + "" + "" + "" + "" + "" + "") + + # parse each adapter that WGPU found for ix, adapter in enumerate(adapters_info): atype = adapter["adapter_type"] backend = adapter["backend_type"] driver = adapter["description"] device = adapter["device"] - if atype == "DiscreteGPU" and backend != "OpenGL": - charactor = chr(0x2705) - elif atype == "IntegratedGPU" and backend != "OpenGL": - charactor = chr(0x0001FBC4) + if atype in ("DiscreteGPU", "IntegratedGPU") and backend != "OpenGL": + charactor = chr(0x2705) # green checkmark + tooltip = "This adapter can be used with fastplotlib" + elif backend == "OpenGL": + charactor = chr(0x0000274C) # red x + tooltip = "This adapter cannot be used with fastplotlib" + elif device.startswith("llvmpipe") or atype == "CPU": + charactor = f"{chr(0x00002757)} limited" # red ! + tooltip = "CPU rendering support is limited and mainly for testing purposes" else: - charactor = chr(0x2757) + charactor = f"{chr(0x00002757)} unknown" # red ! + tooltip = "Unknown adapter type and backend" if ix == default_ix: default = " (default) " else: - default = " " + default = "" - output_str = f"{charactor}{default}| {device} | {atype} | {backend} | {driver}" - print(output_str) + # add row to HTML table + table_str += f"" + # add each element to this row + for s in [f"{charactor}{default}", device, atype, backend, driver]: + table_str += f"" + table_str += "" + + table_str += "
ValidDeviceTypeBackendDriver
{s}
" + + # display logo and adapters table + display(image) + display(HTML(table_str)) if GUI_BACKEND == "jupyter": From 64bb827cb09d6104fd243dd15bf954bc9aedc18f Mon Sep 17 00:00:00 2001 From: kushalkolar Date: Fri, 18 Oct 2024 02:05:36 -0400 Subject: [PATCH 2/2] black --- fastplotlib/utils/gui.py | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/fastplotlib/utils/gui.py b/fastplotlib/utils/gui.py index 5591d10f8..c9b2ad011 100644 --- a/fastplotlib/utils/gui.py +++ b/fastplotlib/utils/gui.py @@ -68,15 +68,17 @@ def _notebook_print_banner(): return # start HTML table - table_str = ("Available devices:" - "" - "" - "" - "" - "" - "" - "" - "") + table_str = ( + "Available devices:" + "
ValidDeviceTypeBackendDriver
" + "" + "" + "" + "" + "" + "" + "" + ) # parse each adapter that WGPU found for ix, adapter in enumerate(adapters_info): @@ -104,7 +106,7 @@ def _notebook_print_banner(): default = "" # add row to HTML table - table_str += f"" + table_str += f'' # add each element to this row for s in [f"{charactor}{default}", device, atype, backend, driver]: table_str += f""
ValidDeviceTypeBackendDriver
{s}