Routes compute operations to the backend registered for a given Device.
Holds one IBackend slot per Device variant (currently
CPU and GPU). register_backend transfers ownership via
std::unique_ptr; for_device returns a non-owning reference
valid for the lifetime of the process. Every higher-level op in the
Lucid engine fetches its backend through this class — the dispatcher is
the single seam between device-agnostic op code and device-specific
compute libraries.
See Also
IBackend — abstract per-device interface.
CpuBackend::register_self — installs the CPU backend.
GpuBackend::register_self — installs the GPU backend.
Notes
Thread safety: register_backend is called exactly once per
device at process startup, before any worker threads exist. After
that, for_device is read-only and safe to call concurrently
from any thread.
The internal storage is a fixed-size std::array indexed by the
Device enum value; kNumDevices must match the number of
Device variants (currently CPU=0, GPU=1).
Static methods
3Returns the backend registered for device d.
The returned reference is non-owning and remains valid for the entire process lifetime; callers must not delete it.
See Also
register_backend — installer counterpart.
Parameters
dDeviceReturns
IBackend&Reference to the singleton backend instance for d.
Notes
Behaviour is undefined if no backend has been registered for d
— register_backend must have been called for that device
before any tensor compute occurs. noexcept; safe to call
concurrently after initialisation.
Dispatcher & instance()Returns the Meyers-singleton dispatcher instance.
Constructed on first call and destroyed at program exit per the standard C++11 magic-statics guarantee.
Returns
Dispatcher&The process-wide dispatcher.
Registers (or replaces) the backend for device d.
Transfers ownership of be into the dispatcher. Any backend
previously stored at that slot is destroyed.
Parameters
dDevicebestd::unique_ptr<IBackend>Notes
Called exactly once per Device during process
initialisation (typically from CpuBackend::register_self
and GpuBackend::register_self, invoked by
BackendInit.cpp). Not thread-safe — must complete before any
worker threads start issuing for_device calls.