struct Capabilities Conforms to
OptionSet, Sendable, CustomStringConvertible, SetAlgebra, RawRepresentable, Equatable, ExpressibleByArrayLiteralCapability detection is exposed directly for diagnostics and tests:
import NumKong
// `capabilitiesEnabled` is what dispatch runs within: detected on this CPU AND compiled into the binary.
let enabled = try Device.cpu.capabilitiesEnabled
print(enabled) // like "serial,neon,neonhalf,neonfhm,neonsdot"
print(enabled.contains(.neon)) // `Capabilities` is an `OptionSet`
// The two raw axes, when you specifically mean one of them:
let onThisCpu = try Device.cpu.capabilitiesDetected
let inThisBinary = Device.cpu.capabilitiesCompiled
// Set up each thread that runs kernels:
try Device.cpu.configureThread(enabled)
// GPUs are devices too, by their runtime's own ordinal:
for ordinal in 0..<((try? Device.count(.metal)) ?? 0) {
print(try Device(kind: .metal, ordinal: ordinal).capabilitiesEnabled) // like "metal,apple9"
}Device.cpu is the host CPU, and Device(kind:ordinal:) any device Device.count(_:) counts, throwing an Error past the last one.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 runs within, both axes at once, which the library settles for the CPU as it loads, and on the CPU always contains .serial.
Every CPU kernel call passes Capabilities.cpus, which the library clamps to it, so the module keeps no mask of its own.configureThread(_:) sets per-thread state such as Intel AMX tiles for the given CPU capabilities, usually the enabled ones.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.
You usually do not need to branch on this in application code. The native layer still selects the best enabled kernel automatically.
CapabilitiesA set of capabilities of a CPU or a GPU, as a Device reports them.55struct Capabilities OptionSet, Sendable, CustomStringConvertible, SetAlgebra, RawRepresentable, Equatable, ExpressibleByArrayLiteralrawValuelet rawValue: UInt64 initinit(rawValue: UInt64) serialstatic let serial: Capabilities neonstatic let neon: Capabilities neonHalfstatic let neonHalf: Capabilities neonBFDotstatic let neonBFDot: Capabilities neonFHMstatic let neonFHM: Capabilities neonSDotstatic let neonSDot: Capabilities neonFP8static let neonFP8: Capabilities svestatic let sve: Capabilities sveHalfstatic let sveHalf: Capabilities sveSDotstatic let sveSDot: Capabilities sveBFDotstatic let sveBFDot: Capabilities sve2static let sve2: Capabilities smestatic let sme: Capabilities smeF64static let smeF64: Capabilities smeBI32static let smeBI32: Capabilities haswellstatic let haswell: Capabilities alderstatic let alder: Capabilities sierrastatic let sierra: Capabilities skylakestatic let skylake: Capabilities iceLakestatic let iceLake: Capabilities genoastatic let genoa: Capabilities turinstatic let turin: Capabilities sapphirestatic let sapphire: Capabilities diamondstatic let diamond: Capabilities sapphireAMXstatic let sapphireAMX: Capabilities graniteAMXstatic let graniteAMX: Capabilities diamondAMXstatic let diamondAMX: Capabilities rvvstatic let rvv: Capabilities rvvBF16static let rvvBF16: Capabilities rvvHalfstatic let rvvHalf: Capabilities rvvBBstatic let rvvBB: Capabilities v128static let v128: Capabilities v128Relaxedstatic let v128Relaxed: Capabilities powerVSXstatic let powerVSX: Capabilities loongsonASXstatic let loongsonASX: Capabilities cudastatic let cuda: Capabilities amperestatic let ampere: Capabilities adastatic let ada: Capabilities hopperstatic let hopper: Capabilities blackwellstatic let blackwell: Capabilities blackwellRTXstatic let blackwellRTX: Capabilities blackwellUltrastatic let blackwellUltra: Capabilities rocmstatic let rocm: Capabilities cdna3static let cdna3: Capabilities cdna4static let cdna4: Capabilities cdna5static let cdna5: Capabilities metalstatic let metal: Capabilities apple9static let apple9: Capabilities apple10static let apple10: Capabilities cpusEvery CPU capability, the bits below the first GPU vendor's, which every CPU kernel call passes, as the library clamps it to capabilitiesEnabled.static let cpus: Capabilities gpusEvery GPU capability.static let gpus: Capabilities anyEvery capability.static let any: Capabilities descriptionThe capability names, comma-separated, like "serial,haswell".var description: String { get } DeviceKindWhich runtime a device belongs to, as the nk_<kind>_* C functions name it.enum DeviceKind cpu | ||
|---|---|---|
cuda | ||
rocm | ||
metal |
Equatable, Hashable, SendableDeviceOne device NumKong 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.9struct 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.
Sendable, Equatablekindlet kind: DeviceKind ordinallet 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 kernel calls run within: capabilitiesDetected and capabilitiesCompiled at once.var capabilitiesEnabled: Capabilities { get throws } On the CPU the library settles it as it loads, and it always
contains serial.
configureThreadConfigures the current thread for capabilities, usually capabilitiesEnabled, e.g.func configureThread(_ capabilities: Capabilities) throws AMX tile state on x86. Must be called once per thread before using AMX operations.
Error on a GPU, which has no thread state to configure.