dspk.runtime
Compute runtime choice.
Every call that runs on a device uses, in order: its runtime= argument, the runtime chosen with
set, the DSPK_RUNTIME environment variable, the first compiled-in runtime (GPUs first).
autotune |
Tunes the operations on this machine’s devices ahead of time, and compiles their kernels. |
available |
Names of the runtimes compiled into this build, in preference order (GPUs first). |
current |
The runtime calls use when they are not given runtime=. |
set |
Chooses the runtime of every later call that is not given runtime=. |
Functions
Section titled “Functions”autotune
Section titled “autotune”autotune( runtime: str | None = None, channels: Sequence[int] = [32, 64, 128, 384], samples: Sequence[int] = [8192, 32768, 131072, 524288],) -> dict[str, dict[str, float]]Tunes the operations on this machine’s devices ahead of time, and compiles their kernels.
An operation benchmarks its kernels the first time it meets a device and problem size, which can stall a first run. This does that work now, over a grid of common sizes, and saves the results for every later process. A size off the grid still tunes when it is first met.
Parameters
runtime:str, defaultNone
One runtime to tune; by default every runtime compiled in that can open a device here.channels:list of int, default[32, 64, 128, 384]
Channel counts to tune.samples:list of int, default[8192, 32768, 131072, 524288]
Samples per channel to tune.
Returns
dict— Per runtime tuned,{"sizes": int, "seconds": float}.
Raises
ValueError: Whenruntimeis not one of this build’s runtimes.
Examples
>>> import dspk>>> dspk.runtime.autotune(channels=[4], samples=[512], runtime="cpu")available
Section titled “available”available() -> list[str]Names of the runtimes compiled into this build, in preference order (GPUs first).
Returns
list of str— Runtime names, such as["cuda", "wgpu", "cpu"].
Examples
>>> import dspk>>> names = dspk.runtime.available()current
Section titled “current”current() -> strThe runtime calls use when they are not given runtime=.
The one chosen with set, else the DSPK_RUNTIME environment variable, else the first of
available().
Returns
str— A runtime name.
Raises
ValueError: WhenDSPK_RUNTIMEnames a runtime that is unknown or not compiled in.
set(name: str | None) -> NoneChooses the runtime of every later call that is not given runtime=.
Parameters
name:str or None
A runtime fromavailable()("cuda","hip","wgpu","cpu"), orNoneto go back to the default (DSPK_RUNTIME, else the first available).
Raises
ValueError: Whennameis unknown or not compiled into this build.
Examples
>>> import dspk>>> dspk.runtime.set("cpu")>>> dspk.runtime.current()'cpu'>>> dspk.runtime.set(None)