struct Capabilities Conforms to
OptionSet, Sendable, CustomStringConvertible, SetAlgebra, RawRepresentable, Equatable, ExpressibleByArrayLiteralEvery call runs on the CPU and dispatches to the best kernel of Device.cpu.capabilitiesEnabled, a Capabilities OptionSet:
import StringZilla
// `enabled` is what dispatch uses: detected on this CPU AND compiled into the binary.
let cpu = Device.cpu
print(try cpu.capabilitiesEnabled) // like "serial,neon,neonaes,neonsha"
print(try cpu.capabilitiesEnabled.contains(.neon)) // `Capabilities` is an `OptionSet`
// The two raw axes, when you specifically mean one of them:
let onThisCpu = try cpu.capabilitiesDetected
let inThisBinary = cpu.capabilitiesCompiled
// Prepare each thread that runs kernels:
try cpu.configureThread(cpu.capabilitiesEnabled)capabilitiesDetected is what the device can execute, from CPUID or HWCAP on the CPU.capabilitiesCompiled is what this binary contains for devices of its 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(_:) prepares the calling thread for the kernels of its argument, once per thread that runs them.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 Device is the host CPU or one GPU of a runtime, named by that runtime’s own ordinal:
let gpus = try Device.count(.metal) // throws without a Metal device
let gpu = try Device(kind: .metal, ordinal: 0) // throws past the last one
print(try gpu.capabilitiesEnabled) // like "metal"configureThread(_:) throws a StringZilla.Error on a GPU, which keeps no thread state of its own: this package only reports GPU capabilities. .cpus, .gpus and .any group the CPU capabilities, the GPU ones, and all of them.
CapabilitiesA set of capabilities of a CPU or a GPU, as a Device reports them.29struct Capabilities OptionSet, Sendable, CustomStringConvertible, SetAlgebra, RawRepresentable, Equatable, ExpressibleByArrayLiteralrawValuelet rawValue: UInt64 initinit(rawValue: UInt64) serialstatic let serial: Capabilities westmerestatic let westmere: Capabilities goldmontstatic let goldmont: Capabilities haswellstatic let haswell: Capabilities skylakestatic let skylake: Capabilities iceLakestatic let iceLake: Capabilities neonstatic let neon: Capabilities neonAESstatic let neonAES: Capabilities neonSHAstatic let neonSHA: Capabilities svestatic let sve: Capabilities sve2static let sve2: Capabilities sve2AESstatic let sve2AES: Capabilities rvvstatic let rvv: Capabilities rvvCryptostatic let rvvCrypto: Capabilities v128static let v128: Capabilities v128Relaxedstatic let v128Relaxed: Capabilities loongsonASXstatic let loongsonASX: Capabilities powerVSXstatic let powerVSX: Capabilities cudastatic let cuda: Capabilities hopperstatic let hopper: Capabilities blackwellstatic let blackwell: Capabilities rocmstatic let rocm: Capabilities metalstatic let metal: Capabilities cpusEvery CPU capability, the bits below the first GPU vendor's.static let cpus: Capabilities gpusEvery GPU capability.static let gpus: Capabilities anyEvery capability.static let any: Capabilities descriptionThe capability names, comma-separated, like "serial,neon".var description: String { get } DeviceKindWhich runtime a device belongs to, as the sz_<kind>_* C functions name it.enum DeviceKind cpu | ||
|---|---|---|
cuda | ||
rocm | ||
metal |
Equatable, Hashable, SendableDeviceOne device StringZilla knows: 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.9struct Device Every call of this module runs on the CPU and dispatches over its capabilitiesEnabled, so a
GPU device only reports its capabilities here. 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.
Sendable, Equatablekindordinallet ordinal: Int cpuThe host CPU, which every build has.static let cpu: Device initDevice ordinal of kind.countHow many devices of kind the process sees: one CPU, or the GPUs its runtime counts.capabilitiesDetectedWhat this device runs, whether or not this binary holds kernels for it.var capabilitiesDetected: Capabilities { get throws } capabilitiesCompiledWhat this binary holds kernels for on devices of this kind, whether or not this one runs.var capabilitiesCompiled: Capabilities { get } capabilitiesEnabledWhat this device's calls run: capabilitiesDetected and capabilitiesCompiled at once.var capabilitiesEnabled: Capabilities { get throws } On the CPU it always contains serial.
configureThreadConfigures the current thread for capabilities, usually capabilitiesEnabled.func configureThread(_ capabilities: Capabilities) throws Call it once on every thread that runs kernels.
Error on a GPU, which has no thread state to configure.