C# · Runtime Dispatch

Runtime Dispatch

using StringZilla; 6.0.0-rc.1 · 91a27bdd

A Device is the host CPU or one GPU, by its runtime’s own ordinal, and reports capability bitmasks with the serial fallback at bit 0. Every call of this binding dispatches to the best kernel among the CPU’s enabled capabilities; a GPU device only reports its masks here.

Device cpu = Device.Cpu;
ulong enabled = cpu.CapabilitiesEnabled;                      // what dispatch uses
Console.WriteLine(Sz.CapabilitiesName(enabled));              // like "serial,neon,neonaes,neonsha"
ulong gpus = Device.Count(DeviceKind.Metal);                  // throws StatusException without a Metal GPU
ulong metal = new Device(DeviceKind.Metal, 0).CapabilitiesEnabled;
Console.WriteLine(Sz.Version);
  • Device.Cpu is the host CPU, which every build has, and new Device(kind, ordinal) is device ordinal of DeviceKind.Cuda, Rocm or Metal.
  • Device.Count(kind) is how many devices of kind the process sees: one CPU, or the GPUs its runtime counts.
  • CapabilitiesDetected is what the device can execute, from CPUID or HWCAP on the CPU.
  • CapabilitiesCompiled is what this binary contains for devices of that kind, from the ISA probes at build time.
  • CapabilitiesEnabled is what dispatch uses, both axes at once, and on the CPU always contains serial.
  • ConfigureThread(capabilities) prepares the calling thread for the kernels of capabilities, usually CapabilitiesEnabled, once per thread that runs them.
  • Sz.CapabilitiesName(capabilities) spells a mask as comma-separated capability names.

Reach for CapabilitiesEnabled unless you specifically mean one of the raw axes. CapabilitiesDetected describes the machine and says nothing about whether a kernel was compiled in, so a build whose ISA probes failed still reports your CPU’s full feature set while containing no SIMD kernels at all. A StatusException reports misuse: sz_missing_gpu_k for a GPU kind without devices or an ordinal past the last one, and sz_missing_kernel_k for ConfigureThread on a GPU, which keeps no thread state.

API

StructDeviceOne device StringZilla can run kernels on: the host CPU, or a GPU by its runtime's own ordinal, the one cudaSetDevice or hipSetDevice takes, or the position in Metal's device list.3
StringZilla.cs:707 ↗
struct Device

Prefer CapabilitiesEnabled unless you specifically mean one of the raw axes: CapabilitiesDetected describes the device and says nothing about whether a kernel was compiled into this binary, so selecting on it alone claims support for code that may not exist. Every call of this binding dispatches over the CPU's enabled set; a GPU device only reports its masks here.

DeviceDevice ordinal of kind .
StringZilla.cs:719 ↗
Device(DeviceKind kind, ulong ordinal = 0);
ConfigureThreadPrepares the calling thread for the kernels of capabilities , usually CapabilitiesEnabled; call it once on every thread that runs them.
StringZilla.cs:792 ↗
void ConfigureThread(ulong capabilities);
CountHow many devices of kind the process sees: one CPU, or the GPUs its runtime counts.
StringZilla.cs:730 ↗
ulong Count(DeviceKind kind);