cheatah
Module

gpu

cheatah-gpu v0.5.1-alpha — Biome Standard 0.6.3-alpha

Concepts

Functions

fn std::string_view backend_name(Backend backend) #

The lowercase name of a backend — for logs, a doctor report, or diagnostics.

Parameters
backend

the backend to name.

Returns

"metal" for Backend::metal, otherwise "vulkan".

Complexity

O(1).

Host allocation

none.

Unit testBackend.Name
Compile-run testsystests/test_backend_cr_query.purr
fn std::string_view active_backend_name() #

The name of the backend this binary was compiled for.

Returns

the active backend's name (see active_backend).

Complexity

O(1).

Host allocation

none.

Unit testBackend.Active
Compile-run testsystests/test_backend_cr_query.purr
fn std::optional< Backend > backend_from_name(std::string_view name) #

Parse a backend name — the optional pattern cheatah-gpu uses for fallible lookups: a missing value is an empty optional, never an exception or a sentinel.

Parameters
name

a backend name, "vulkan" or "metal" (case-sensitive).

Returns

the matching Backend, or std::nullopt when name is neither.

Complexity

O(1).

Host allocation

none.

Unit testBackend.FromName
Compile-run testsystests/test_backend_cr_query.purr
fn bool is_active(B backend) #

Whether backend is the one this binary was compiled for — a concept-constrained, compile-time comparison (the real interface gates backend-specific code on exactly this).

Parameters
backend

the backend to test.

Returns

true iff backend equals active_backend.

Complexity

O(1).

Host allocation

none.

Unit testBackend.IsActive
Compile-run testsystests/test_backend_cr_query.purr
fn bool & backend_warning_emitted() #

One-shot guard so the runtime backend notice is printed at most once per process.

Returns

a reference to the process-wide "already printed" flag.

Complexity

O(1).

Host allocation

none.

fn bool & backend_warning_silenced() #

User-controlled mute.

Once true, warn_backend_selection stays quiet.

Returns

a reference to the process-wide "silenced" flag.

Complexity

O(1).

Host allocation

none.

fn void silence_backend_warning(bool silence=true) #

Silence the runtime backend notice from here on.

The first notice is deliberately loud, but using (say) Vulkan on macOS on purpose is perfectly fine — call this, or set the environment variable CHEATAH_GPU_SILENCE_BACKEND_WARNING, or build with -DCHEATAH_GPU_NO_BACKEND_WARNING, to make it stop. This is a CHOICE the user owns, not a forced nag.

Parameters
silence

true to mute (the default), false to re-enable.

Complexity

O(1).

Host allocation

none.

Unit testBackend.Silence
Compile-run testsystests/test_backend_cr_warn.purr
fn bool warn_backend_selection(std::FILE *out=stderr) #

Print the runtime backend notice — at most once — if the build was auto-switched or is using a suboptimal backend.

Never silent by default: a suboptimal GPU API chosen behind the user's back is a performance bug. But the notice is dismissable — it is suppressed if silence_backend_warning was called, if CHEATAH_GPU_SILENCE_BACKEND_WARNING is set in the environment, or if built with CHEATAH_GPU_NO_BACKEND_WARNING — and the message itself says how. No-op when the selection is optimal. The switched/suboptimal message paths cannot run in an optimally-selected build; they are exercised by scripts/metal_gate.sh's backend auto-resolution stage, which compiles this header with the wrong backend forced for the platform and asserts the warning is raised.

Parameters
out

where to write the notice (defaults to stderr).

Returns

true iff a notice was printed by this call.

Complexity

O(1) — the constant-length notice; the first switched/suboptimal call also does one std::getenv lookup, linear in the process environment size.

Host allocation

none.

Unit testBackend.WarnSwitched
Compile-run testsystests/test_backend_cr_warn.purr

Constants & variables

var Backend active_backend #

The backend selected for THIS binary at compile time (see the CHEATAH_GPU_BACKEND_* macros).

var bool metal_available #

Whether native Metal can run on this platform (Apple only). Vulkan is assumed available everywhere.

var Backend requested_backend #

The backend the build REQUESTED (the platform default counts as a request), before auto-correction.

var bool backend_was_switched #

True iff the requested backend could not run here and was auto-switched to active_backend.

var bool backend_is_suboptimal #

True iff the active backend runs here but is not the platform's preferred (e.g. Vulkan on Apple).

Types

enum std::uint8_t Backend #

The native GPU API a build targets. Exactly one is active per binary, chosen at compile time.