npu-detect
v1.0.1
Published
Cross-platform NPU (Neural Processing Unit) detection for JavaScript — Node.js + Browser (WebNN)
Downloads
187
Maintainers
Readme
npu-detect
Cross-platform NPU (Neural Processing Unit) detection for JavaScript.
Works in Node.js (server-side, shells out to OS tools) and Browsers (client-side, via the WebNN API).
Why?
You can query CPU info with os.cpus() and GPU info with navigator.gpu — but there's no equivalent for NPUs. This library fills that gap.
Install
npm install npu-detectQuick Start
Node.js
const { detectNPU, hasNPU, npuSummary } = require('npu-detect');
// Full detection with details
const info = await detectNPU();
console.log(info);
// {
// detected: true,
// platform: 'darwin',
// devices: [{ name: 'Apple Neural Engine (ANE)', cores: 16, ... }],
// cpuHeuristic: { likely: true, vendor: 'Apple', npuName: 'Apple Neural Engine' },
// ...
// }
// Quick boolean
const has = await hasNPU(); // true
// One-liner summary
const summary = await npuSummary(); // "NPU detected: Apple Neural Engine (ANE)"Browser
import { detectNPU, hasNPU } from 'npu-detect/browser';
const info = await detectNPU({ benchmark: true });
console.log(info);
// {
// webnnSupported: true,
// npuAvailable: true,
// devices: {
// npu: { available: true, benchmark: { functional: true, execLatencyMs: 0.4 } },
// cpu: { available: true, ... },
// gpu: { available: true, ... },
// },
// ...
// }CLI
npx npu-detect
npx npu-detect --verbose
npx npu-detect --jsonHow It Works
Node.js Detection (per platform)
| Platform | Method |
|----------|--------|
| Linux | Checks /dev/accel/* devices, lspci for NPU-class hardware, lsmod for intel_vpu/amdxdna kernel modules, sysfs for NPU frequency |
| Windows | Queries Device Manager's "Neural processors" class via PowerShell (Get-PnpDevice), falls back to WMI |
| macOS | Uses ioreg to find AppleNeuralEngine, infers ANE core count and TOPS from chip model, reads powermetrics for ANE power (requires root) |
| All | CPU model string heuristic to identify known NPU-equipped processors (Intel Core Ultra, Snapdragon X, Ryzen AI, Apple M-series, etc.) |
Browser Detection
Uses the W3C Web Neural Network API (navigator.ml):
- Checks if
navigator.mlexists - Attempts
navigator.ml.createContext({ deviceType: 'npu' })— success means NPU is available - Optionally runs a minimal add-two-matrices computation graph to verify the device is functional
- Also probes
cpuandgpudevice types for comparison
Note: WebNN requires Chrome/Edge with the flag
chrome://flags/#web-machine-learning-neural-networkenabled, or Edge with--disable_webnn_for_npu=0for NPU specifically.
Supported NPU Hardware
| Vendor | NPU | Detection |
|--------|-----|-----------|
| Intel | AI Boost (Core Ultra / Meteor Lake, Arrow Lake, Lunar Lake) | Linux: intel_vpu module + /dev/accel/accel0. Windows: Device Manager. |
| AMD | XDNA / XDNA2 (Ryzen AI, Hawk Point, Strix Point) | Linux: amdxdna module. Windows: Device Manager. |
| Qualcomm | Hexagon (Snapdragon X Elite/Plus) | Windows: Device Manager. Browser: WebNN. |
| Apple | Neural Engine (M1–M4, A11–A19) | macOS: ioreg + chip identification. |
API Reference
Node.js (npu-detect)
detectNPU(options?): Promise<NPUDetectionResult>
Full detection. Options:
cpuHeuristic(boolean, defaulttrue) — also check CPU model stringverbose(boolean, defaultfalse) — include raw OS command output
hasNPU(): Promise<boolean>
Quick boolean — confirmed NPU present?
npuSummary(): Promise<string>
Human-readable one-liner.
Browser (npu-detect/browser)
detectNPU(options?): Promise<BrowserNPUDetectionResult>
Full browser detection. Options:
benchmark(boolean, defaultfalse) — run a test computation on each deviceprobeAll(boolean, defaulttrue) — also probe CPU and GPU
hasNPU(): Promise<boolean>
Quick boolean — NPU available via WebNN?
probeDevice(deviceType): Promise<{available, error?, context?}>
Low-level probe for a specific WebNN device type.
benchmarkDevice(deviceType): Promise<{functional, buildLatencyMs?, execLatencyMs?, error?}>
Run a minimal computation on a device and measure latency.
Caveats
- Linux: NPU detection requires the kernel module to be loaded and
/dev/accel/to be populated. Some sysfs paths require root. - Windows: PowerShell queries may be slow (~1-2s). The "NeuralProcessor" PnP class requires up-to-date drivers.
- macOS: Apple provides almost no public API for ANE introspection. Detection relies on
ioregand chip identification.powermetricsrequiressudo. - Browser: WebNN is still an emerging standard. NPU support requires specific browser flags and up-to-date GPU/NPU drivers.
- CPU Heuristic: The CPU model string check is a "best guess" — it tells you the CPU should have an NPU, not that it's accessible.
License
MIT
