Beyond the Transistor

Emulator and hardware

Understand what the cpu-backend build does on your CPU, which results transfer to a physical card, and how to check which backend you ran on.

Every result in this guide comes from the toolkit’s CPU emulator, the cpu-backend build. This page explains what the emulator does, so you can judge which conclusions carry over to a physical card.

What the emulator is

The emulator is two small Rust files in the toolkit source. Since toolkit 2.5.0 there is one per card generation: src/qant_driver_import/gen2/backend_cpu.rs simulates Gen2 cards and src/qant_driver_import/gen2p/backend_cpu.rs simulates Gen2+ cards. Together they replace the Q.ANT driver with CPU code. Its header comment describes it as a lightweight simulation backend that is “intentionally minimal and not fully featured” but “sufficient for validating toolkit integrations”.

The rest of the toolkit is the same in both builds. The Python wrapper, the argument checks and the Rust core that builds layers from primitives all run unchanged. Only the lowest layer, the calls to the driver, is swapped out. How the toolkit is built shows all the layers in one diagram.

Simulated devices

The emulator in toolkit 2.5.0 reports six NPUs. Each one only accepts the operations its generation supports:

Device IDsSimulatesCapabilitiesSerial
0, 1, 2Gen2Mul, NonLin, MemHandlingcpu_backend_0 and so on
10, 11, 12Gen2+Dftcpu_backend_gen2p_10 and so on

If you leave out device_id, or pass -1, the toolkit picks the first NPU that supports the operation. So a linear layer runs on device 0 and a DFT on device 10. If you pick a device that can’t run the operation, you get an error such as NPU10 does not support MULTIPLICATION or NPU0 does not support DFT. Any other ID, such as 3, fails with Could not acquire NPU3.

get_capabilities(device_id) in the info module returns what a device supports. get_available_npus() takes an optional list of capabilities and returns only the devices that have all of them.

What the emulator does

Driver functionWhat the emulator does
Element-wise multiplyMultiplies the two inputs in bfloat16.
Batched matrix-vector multiplyMultiplies each pair of elements in bfloat16 and adds the products in float32, then rounds the sum to bfloat16.
Scaled periodic nonlinearityComputes an exact cosine, u.cos() * v in bfloat16.
Discrete Fourier transform (Gen2+)Runs an exact FFT with the rustfft library, with every step computed in bfloat16. Against NumPy’s FFT we measured errors of 0.2% to 1.4%, growing with the transform size.
init_npu, release_npuDoes nothing and reports success.
Device IDChecks that the device exists and supports the operation, then runs the same CPU code on every device of that generation.
get_available_npusReturns the six simulated devices as a list of (id, serial) pairs.
get_driver_infoReturns cpu-backend;commit:none; for Gen2 devices and cpu-backend-gen2p;commit:none; for Gen2+ devices.
get_sensor_infoReturns fixed constants, for example 35.0 for every temperature and 1.8 for voltage_1v8.
get_version_infoReturns empty strings.
get_perf_counterReturns 0.0 for both counters.
setup_loggingFails with logging not available for cpu-backend.

What a physical card does differently

A physical NPU computes the multiplications, the nonlinearity and, on Gen2+, the Fourier transform optically. The toolkit documentation describes the nonlinearity as tcos, a 2π-periodic function with values between -1 and 1 that is similar to a cosine but has “the cosine-related shape of the periodic optical nonlinearity”. The emulator uses an exact cosine in its place.

An analog optical computation also adds noise. The Fourier network example trains with Gaussian noise for this reason, so that its weights tolerate the noise of a physical device.

We have no access to a card. We can’t tell you how large the noise is, how far tcos departs from a cosine, or how fast a card runs.

What emulator results tell you

Emulator results are useful for some questions and not others.

QuestionCan the emulator answer it?
Does my code call the API correctly, with the right shapes and dtypes?Yes. The argument checks are the same in both builds.
How much does bfloat16 rounding change my model’s output?Partly. Inputs and outputs are bfloat16 in both builds, so that rounding transfers. How a card computes internally may differ.
Does my model’s algorithm work, for example a KAN layer learning a function?Yes, for an ideal cosine and no noise.
How accurate is my model on a card?No. The card’s tcos and noise are missing.
How fast is my model on a card?No. The emulator computes with simple loops on the CPU.
Does my multi-device code scale?Partly. The emulator reports three Gen2 devices, so you can test that your code spreads work across them, but every device runs on the same CPU, so you can’t measure any speedup.

Check which backend you ran on

Call get_driver_info and look for the cpu-backend prefix:

import qant_native_computing_toolkit as q

info = q.info.get_driver_info()
print(info)

On the emulator this prints cpu-backend;commit:none;. You can also check get_available_npus(). The emulator’s serials start with cpu_backend, while a card returns its real serial number.

To record which backend produced a result, save the output of get_driver_info next to your results.

Reproduce the emulator in your browser

This site includes a NumPy version of the emulator’s KAN layer arithmetic that runs in your browser. It matched the real emulator bit for bit on 40 of 40 random layers and on a full trained network. Use it to try KAN layers without installing anything:

Like the emulator, these pages compute an exact cosine. They show the same algorithm behaviour and bfloat16 effects, and the same limits apply.

What’s next