.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "_gallery/other/gpu_selection.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end ` to download the full example code. .. rst-class:: sphx-glr-example-title .. _sphx_glr__gallery_other_gpu_selection.py: GPU selection ============= Demonstrate how a specific GPU can be selected, or how a GPU can be selected using a power preference. .. GENERATED FROM PYTHON SOURCE LINES 9-47 .. code-block:: Python import wgpu import pygfx as gfx # You can express whether you prefer a "high-performance" (default) or "low-power" device. # Note that the power preference is ignored if select_adapter() is used. gfx.renderers.wgpu.select_power_preference("high-performance") # Get a list of all adapters from wgpu adapters = wgpu.gpu.enumerate_adapters_sync() # Show the options print("Available adapters:") for a in adapters: print(a.summary) # The best way to select an adapter is highly dependent on the use-case. # Here we prefer a Geforce GPU, but fallback to the default if its not available. adapters_geforce = [a for a in adapters if "geforce" in a.summary.lower()] if adapters_geforce: gfx.renderers.wgpu.select_adapter(adapters_geforce[0]) # Draw a cube cube = gfx.Mesh( gfx.box_geometry(200, 200, 200), gfx.MeshPhongMaterial(color="#336699"), ) if __name__ == "__main__": disp = gfx.Display() disp.show(cube) # Show what adapter was selected wgpu.diagnostics.pygfx_adapter_info.print_report() .. _sphx_glr_download__gallery_other_gpu_selection.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: gpu_selection.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: gpu_selection.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: gpu_selection.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_ .. only:: html Interactive example ------------------- Try this example in your browser using Pyodide. Might not work with all examples and all devices. Check the output and your browser's console for details. .. raw:: html