Skip to content

gpu info upon notebook import #410

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Feb 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .github/workflows/pypi-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,14 @@ jobs:
runs-on: ubuntu-latest

steps:
- name: Install git-lfs
run: |
sudo apt install --no-install-recommends -y git-lfs
- uses: actions/checkout@v3
- name: fetch git lfs files
run: |
git lfs fetch --all
git lfs pull
- name: Set up Python
uses: actions/setup-python@v3
with:
Expand Down
2 changes: 2 additions & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
recursive-include fastplotlib/utils/colormaps/ *
include fastplotlib/VERSION
recursive-include fastplotlib/assets/ *

11 changes: 11 additions & 0 deletions fastplotlib/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from .layouts import Plot, GridPlot
from .graphics import *
from .graphics.selectors import *
from .utils import _notebook_print_banner, config

from wgpu.gui.auto import run

Expand All @@ -13,6 +14,16 @@
else:
from .widgets import ImageWidget

from wgpu.backends.wgpu_native import enumerate_adapters

adapters = [a.request_adapter_info() for a in enumerate_adapters()]

if len(adapters) < 1:
raise IndexError(
"No WGPU adapters found, fastplotlib will not work."
)

_notebook_print_banner()

with open(Path(__file__).parent.joinpath("VERSION"), "r") as f:
__version__ = f.read().split("\n")[0]
Expand Down
3 changes: 3 additions & 0 deletions fastplotlib/assets/egg.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions fastplotlib/assets/fastplotlib_face_logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
16 changes: 16 additions & 0 deletions fastplotlib/layouts/_frame/_ipywidget_toolbar.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from itertools import product
from math import copysign
from functools import partial
from pathlib import Path
from typing import *


Expand All @@ -17,10 +18,12 @@
BoundedIntText,
Play,
jslink,
Image,
)

from ...graphics.selectors import PolygonSelector
from ._toolbar import ToolBar
from ...utils import config


class IpywidgetToolBar(HBox, ToolBar):
Expand Down Expand Up @@ -92,6 +95,19 @@ def __init__(self, plot):
self._record_button,
]

if config.party_parrot:
gif_path = Path(__file__).parent.parent.parent.joinpath("assets", "egg.gif")
with open(gif_path, "rb") as f:
gif = f.read()

image = Image(
value=gif,
format="png",
width=35,
height=25,
)
widgets.append(image)

if hasattr(self.plot, "_subplots"):
positions = list(product(range(self.plot.shape[0]), range(self.plot.shape[1])))
values = list()
Expand Down
14 changes: 14 additions & 0 deletions fastplotlib/utils/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1,15 @@
from dataclasses import dataclass


from .functions import *
from ._gpu_info import _notebook_print_banner


@dataclass
class _Config:
party_parrot: bool


config = _Config(
party_parrot=False
)
66 changes: 66 additions & 0 deletions fastplotlib/utils/_gpu_info.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
from pathlib import Path

from wgpu.backends.wgpu_native import enumerate_adapters
from wgpu.utils import get_default_device

try:
ip = get_ipython()
from ipywidgets import Image
from wgpu.gui.jupyter import JupyterWgpuCanvas
except (NameError, ModuleNotFoundError, ImportError):
NOTEBOOK = False
else:
from IPython.display import display
if ip.has_trait("kernel") and (JupyterWgpuCanvas is not False):
NOTEBOOK = True
else:
NOTEBOOK = False


def _notebook_print_banner():
if NOTEBOOK is False:
return

logo_path = Path(__file__).parent.parent.joinpath("assets", "fastplotlib_face_logo.png")

with open(logo_path, "rb") as f:
logo_data = f.read()

image = Image(
value=logo_data,
format="png",
width=300,
height=55
)

display(image)

# print logo and adapter info
adapters = [a for a in enumerate_adapters()]
adapters_info = [a.request_adapter_info() for a in adapters]

ix_default = adapters_info.index(get_default_device().adapter.request_adapter_info())

if len(adapters) > 0:
print("Available devices:")

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)
else:
charactor = chr(0x2757)

if ix == ix_default:
default = " (default) "
else:
default = " "

output_str = f"{charactor}{default}| {device} | {atype} | {backend} | {driver}"
print(output_str)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy