Beyond the Transistor

Run work on several NPUs in parallel

Multiply ten large matrices by a vector, first on one NPU in a single process, then with one worker process per NPU using shared memory.

Tested on the toolkit 2.5.0 CPU emulator on 18 November 2026 with three emulated NPUs. The test passed in 1.08 seconds. First tested on 2.3.1 on 8 October 2026 with one emulated NPU.

A server can hold several Q.ANT cards. This example shows one way to use them together. It runs the same batch of matrix-vector products twice: once in a single process on one device, and once with a pool of worker processes, each linked to its own device.

This example is a plain Python script, not a notebook.

Objectives

  • List the available NPUs and address each one by its device ID.
  • Run a toolkit operation in several processes at once.
  • Share large arrays between processes without copying them.

Before you begin

  1. Install the toolkit. The CPU emulator works for this example. Since toolkit 2.5.0 it reports three NPUs that can multiply, but they all run on the same CPU, so it can’t show a real speed-up.

  2. Check that Python can import the toolkit:

    python -c "import qant_native_computing_toolkit as q; print(q.generic.get_available_npus())"

    On the 2.5.0 emulator this prints six devices, from (0, 'cpu_backend_0') to (12, 'cpu_backend_gen2p_12'). On a server with cards it lists each NPU.

  3. Get the examples repository:

    git clone --recurse-submodules https://github.com/Q-ANT-GmbH/qant_native_computing_toolkit_examples.git
    cd qant_native_computing_toolkit_examples/python/parallel_execution
  4. Install the example’s dependencies:

    pip install -r requirements.txt

    This example needs only numpy, ml_dtypes and pytest.

Run the example

Run the script:

python matrix_vector_multiplication.py

How it works

The workload

The script creates ten bfloat16 matrices of 2,000 by 2,000 values and one vector of 2,000 values. Each job multiplies one matrix by the vector with native.linear_fprop.

Find the devices

The script asks get_available_npus for the devices that can multiply and starts one worker for each:

npu_ids = [
    id
    for (id, _) in qant.generic.get_available_npus(
        [qant.generic.QantDeviceCapability.Mul]
    )
]
n_npus = len(npu_ids)
print(f"Found {n_npus} NPUs")

The capability filter matters since toolkit 2.5.0. Without it the list would also include Gen2+ devices, which can only run the DFT. In 2.4.0 and older, get_available_npus() returned a dictionary and the script used its keys.

Single process on one device

The baseline runs all ten jobs one after another on device 0:

qant.generic.init_npu(0)
results_singleproc = [multiply_matrix_vector_single(task) for task in task_args]
qant.generic.release_npu(0)

One process per device

For the parallel run, the script copies the matrices and the vector into multiprocessing.shared_memory blocks once. A comment in the script explains why: otherwise the cost of pickling the arrays for each worker is the bottleneck.

It then starts a ProcessPoolExecutor with one worker per NPU. To link each worker to a device, it collects the worker process IDs and maps each one to a device ID. Each worker rebuilds NumPy views on the shared memory and calls the toolkit with its own device:

pid = os.getpid()
wid = pid_to_wid[pid]
print(f"Worker[{wid}] with pid {pid} solves a job")

return qant.native.linear_fprop(vector, matrices[matrix_id], device_id=wid)

Expected output

On the toolkit 2.5.0 CPU emulator, the script printed:

Found 3 NPUs
Worker[0 with pid ...] solves a job
...
--------------------
worker pids: [485, 486, 487]
Worker[0] with pid 485 solves a job
...
execution time single NPU 0.2
execution time multi NPU 0.1

Each “solves a job” line appears ten times in each run. Your process IDs will differ.

MeasureToolkit 2.3.1, one emulated NPUToolkit 2.5.0, three emulated NPUs
NPUs found13
Single-process time0.1 seconds0.2 seconds
Multi-process time0.2 seconds0.1 seconds

With three emulated devices, three worker processes share the jobs, so the parallel run finished first on our machine. That speed-up comes from using more CPU cores, not from more cards.

Run the tests

The example includes a test that runs main() and checks that both approaches give the same results within an absolute tolerance of 0.001:

python -m pytest -v test_matrix_vector_parallel.py

On the 2.5.0 emulator the test passed in 1.08 seconds.

What’s next