Memory Scheduling for Quantum Circuit Simulation on Consumer GPUs

    This article examines how to run state-vector quantum circuit simulation on consumer GPUs with limited memory. It covers capacity tiering between GPU memory, host memory, storage, and cloud resources; block-based streaming scheduling; gate-window merging to reduce host-device transfers; deferred layout scheduling to reuse matrix multiplication and avoid immediate physical restoration; and explicit transfers overlapped with computation. It also provides practical parameters, monitoring metrics, boundaries, and the relationship between local consumer-GPU simulation and HPC or cloud execution.

    1. The Core Problem: The Memory Wall in Quantum Circuit Simulation

    Before a quantum algorithm runs on real quantum hardware, it usually needs functional validation, noise modeling, and debugging on classical computers. State-vector simulation is one of the most common approaches, but its memory requirement grows exponentially with the number of qubits: each additional qubit doubles the required storage capacity. For a complex-valued state vector, 30 qubits require about 8 GiB, 32 qubits require about 32 GiB, and 35 qubits require about 256 GiB. With double buffering or additional workspace, peak usage rises further. Consumer GPUs typically have only 8 GiB to 16 GiB of memory, so even moderately complex circuits can exhaust GPU memory.

    This creates a structural conflict. On one hand, developers want to move algorithm validation down to personal workstations or ordinary lab machines and reduce dependence on large supercomputing nodes. On the other hand, the exponential scale of state vectors keeps exceeding single-GPU memory capacity. The traditional response is to “buy a larger GPU” or “use a supercomputer,” but this raises the barrier and slows rapid iteration. A more practical engineering direction is not to fight the exponential law, but to use capacity tiering, block scheduling, and data movement optimization to turn the constraint that data “must all reside in GPU memory at the same time” into “data resides in batches according to the computation rhythm.”

    The problem can therefore be split into three subproblems: first, how to partition the full quantum state into controllable data blocks; second, how to reduce round trips between host memory and GPU memory; third, how to overlap computation and transfer so that insufficient GPU memory does not turn into bandwidth thrashing.

    2. Capacity Tiering: GPU Memory as Workspace, Host Memory as the Large Resident Pool

    When GPU memory is insufficient, the most intuitive approach is to let host memory assist the GPU. But “automatic managed memory” does not equal high performance. When compute kernels access non-resident data by page, the system may trigger frequent page faults, page migration, and bandwidth contention, causing severe bandwidth thrashing. Especially with small-grained, random access patterns, the effective throughput of automatic migration can be far lower than explicit bulk transfers. A more reliable engineering approach is to plan data placement actively: keep only a fixed-size working buffer and a small number of hot blocks in GPU memory, keep the full state vector resident in large host memory, and load blocks in batches according to gate-window dependencies.

    A practical capacity tiering model is:

    • GPU memory tier: stores the current compute block, prefetch blocks, matrix multiplication temporary results, and metadata cache. Usage should be controlled at 60% to 80% of total GPU memory to leave headroom for drivers and temporary allocations.
    • Host memory tier: stores the full state vector, checkpoints, and cold blocks. Capacity should be at least 1.5 to 2 times the size of the state vector to support double buffering and write-back.
    • Local high-speed storage tier: used for very large state checkpoints, cross-session recovery, and cloud elastic scaling, and not on the high-frequency compute path.
    • Cloud elastic tier: when local GPU memory and host memory are still insufficient, chunked states or checkpoints can be placed in cloud object storage services, such as Baidu AI Cloud object storage where available, and restored on general-purpose GPU compute instances as needed. Monitoring and alerting capabilities can be used to track GPU memory peaks, transfer throughput, and task duration.

    The core of capacity tiering is not “where to put data,” but “making data appear in the right place at the right time.” GPU memory is the high-speed workspace, host memory is the capacity pool, and storage is the recovery point. The scheduler must know the logical location, physical location, and next use time of each data block.

    3. Block-Based Streaming Scheduling: Partition the Full State and Load by Dependency

    The basic unit of block-based streaming scheduling is the “state block.” A high-dimensional quantum state is partitioned along a set of qubit axes into several blocks, each of which can independently complete part of the gate operations. When a gate involves cross-block qubits, the operation is completed through inter-block exchange or temporary concatenation. The scheduler maintains a fixed-size GPU memory pool, scans the circuit in topological order, computes the gate dependency window for each block, and prefetches the next batch of blocks in advance.

    Block size needs to balance three factors: if blocks are too small, transfer count and metadata overhead increase; if blocks are too large, the GPU workspace is insufficient and prefetching and double buffering become ineffective; when blocks are medium-to-large, transfer efficiency is higher and consecutive gates can be covered. In engineering practice, the following constraint can be used for estimation:

    1. B = min(
    2. GPU workspace budget / (buffer count * bytes per block),
    3. host memory budget / total blocks,
    4. optimal transfer granularity per transfer
    5. )

    The buffer count is usually 2 to 4: one for current computation, one for prefetching, and one for write-back or temporary results. The scheduler should use explicit bulk transfers as much as possible instead of relying on automatic paging. During transfer, copy large blocks sequentially, merge small requests, reduce the number of concurrent streams, and avoid multiple streams contending for interconnect bandwidth at the same time.

    The benefit of block streaming comes from “turning random page faults into sequential movement.” When a compute kernel accesses the current block, that block is already fully resident in GPU memory. When computation ends, the next block has already entered GPU memory through prefetching. In this way, insufficient GPU memory is no longer a fatal error, but only a waiting item in the scheduling queue.

    4. Gate Windows: Merge Multiple Round Trips into One Load and Multiple Computations

    Blocking alone is not enough. If a data block is moved in and out for every quantum gate, the number of transfers grows linearly with the number of gates. The core idea of the gate-window mechanism is to analyze circuit topology in advance and combine consecutive operations on the same batch of data blocks into one window. Within the window, data is loaded once, multiple gates are executed consecutively, and write-back or block switching happens after the window ends.

    Gate windows can be constructed by scanning in topological order: maintain the block set and gate set involved in the current window; if the next gate acts only on blocks within the window and the window size does not exceed budget, continue merging; when a cross-window dependency appears, the block set expands too much, or workspace is insufficient, split the window. In this way, traditional gate-by-gate streaming may cause dozens of round trips for the same data block, while gate windows can merge consecutive gates and significantly reduce round trips. In some regular circuits, the reduction can reach an order of magnitude.

    Window size is not better when larger. If the window is too large, more blocks must reside in the workspace at the same time, and prefetch benefits decrease. If the window is too small, transfer count rises again. It is recommended to use dual thresholds based on “GPU memory usage of the block set in the window” and “number of gates in the window,” and to record window hit rate, average window length, and transferred bytes as tuning references.

    5. Deferred Layout Scheduling: Reuse Matrix Multiplication After Axis Permutation Without Immediate Physical Restoration

    Quantum gates are usually represented as small matrix multiplications acting on several qubit axes. In a high-dimensional state tensor, the target qubit axis may not be in the matrix row position, and direct computation causes non-contiguous access. The traditional approach is to first permute the target axis into the row position, perform computation, and then move data back to restore the layout. But “restoration” itself creates a large amount of unnecessary reverse movement within GPU memory.

    The idea of deferred layout scheduling is: before computation, temporarily permute the qubit axes that need computation into the matrix row position and reuse mature general matrix multiplication units; after computation, do not immediately restore physical layout, but record the block’s current physical axis order and logical axis order in a software metadata table. If subsequent gates can continue computation under the current layout, reuse it directly. Only when the next operation requires a different axis order and cannot be completed through view mapping does the system trigger actual layout materialization.

    This decouples “physical movement” from “logical view”: the physical arrangement of a data block in GPU memory can temporarily remain in a non-standard order, and the scheduler maps logical to physical through metadata. The benefit is reduced reverse data movement in GPU memory and higher matrix multiplication unit utilization. The cost is more complex metadata management, including block lifecycle, axis-order consistency, materialization during window switching, and defragmentation.

    A simplified pseudocode example is as follows:

    1. function simulate(circuit, state_blocks, mem_pool):
    2. windows = build_gate_windows(circuit)
    3. meta = BlockMetaTable()
    4. for win in windows:
    5. for chunk_id in win.chunks:
    6. buf = mem_pool.reserve(chunk_id)
    7. explicit_copy_to_device(state_blocks[chunk_id], buf)
    8. for gate in win.gates_for(chunk_id):
    9. view = meta.permute_axis_view(buf, gate.target_axis)
    10. launch_matmul(view, gate.matrix)
    11. meta.commit_layout(buf, view.physical_order)
    12. if meta.needs_materialize(chunk_id):
    13. meta.materialize(buf)
    14. explicit_copy_to_host(buf, state_blocks[chunk_id])
    15. mem_pool.release(chunk_id)
    16. return meta.materialize_all(state_blocks)

    There are three key points in this pseudocode: build_gate_windows merges consecutive gates; permute_axis_view only establishes a logical view and records physical order; needs_materialize triggers actual layout materialization only when crossing windows or when output requires it. This can defer or eliminate a large amount of the overhead of “restore immediately after computation.”

    6. Explicit Transfers and Computation Overlap: Avoid Bandwidth Thrashing

    The core of explicit transfer is “bulk, sequential, and predictable.” Compared with automatic managed memory, explicit bulk copies let the scheduler know transfer timing, transfer size, and dependencies, so transfers can overlap with computation. A double-buffered or multi-buffered pipeline is recommended:

    1. The current block executes gate-window computation in GPU memory.
    2. The next block is prefetched into a spare buffer through explicit copy.
    3. Computation and copy are synchronized through events or dependency queues to avoid read-write conflicts.
    4. After the current block finishes computation, it is written back to host memory while the buffer is released for subsequent prefetching.
    5. If host-to-device bandwidth is sufficient, prefetch depth can be increased, but the number of concurrent streams should be limited to avoid bandwidth contention.

    The performance model can be simplified as:

    1. total time ≈ compute time + non-overlapped transfer time + metadata overhead
    2. transfer count ≈ number of gate windows × block switches per window
    3. effective bandwidth ≈ transferred bytes / actual transfer time

    During tuning, priority should be given to reducing “non-overlapped transfer time”: increase transfer granularity, prefetch earlier, reduce window switches, and merge small copies. Next, reduce “metadata overhead”: cache axis-order mappings, reduce frequent lookups, and submit layout changes in batches. Only after that should compute-kernel occupancy be improved. If the order is reversed, a false impression may appear that “computation is fast but waiting for data.”

    7. Practical Parameters and Monitoring Metrics on Consumer GPUs

    On consumer GPUs with 8 GiB to 16 GiB of memory, it is recommended to control the GPU workspace at 1 GiB to 4 GiB, start with block sizes from tens of MiB to hundreds of MiB, and use 2 to 3 buffers. Host memory should be at least 1.5 times the size of the state vector; if checkpoints are needed, it should be increased further. For 30-qubit-class states, host memory pressure is already noticeable; for 32 qubits and above, block partitioning, gate windows, and checkpoint recovery should be used together.

    Recommended monitoring metrics include:

    • GPU memory peak and workspace hit rate;
    • Number of resident blocks, prefetch depth, and buffer utilization;
    • Number of host-device transfers, transferred bytes, and effective bandwidth;
    • Number of gate windows, average window length, and window hit rate;
    • Matrix multiplication unit utilization and number of layout materializations;
    • Metadata lookup time and defragmentation time;
    • Total task time and number of checkpoint recoveries.

    These metrics help determine whether the bottleneck is capacity, bandwidth, or scheduling overhead. If GPU memory peak is close to the limit but transfer count is not high, reduce block size or lower prefetch depth. If transfer count is high while compute units are idle, increase gate windows or merge small copies. If layout materialization occurs too often, optimize the axis-order reuse strategy.

    8. Relationship with the HPC Ecosystem: Lower the Barrier Without Replacing Supercomputers

    Block streaming and deferred layout do not eliminate exponential memory growth. States above 35 qubits may still require hundreds of GiB of memory and higher interconnect bandwidth. Their value lies in turning a validation workflow that “must depend on large supercomputing nodes” into an elastic path of “local small-scale tuning + cloud or HPC large-scale execution.” Developers can complete circuit correctness checks, gate-window tuning, and small-qubit-scale performance evaluation on consumer GPUs. As scale increases, the same set of chunked states, checkpoints, and scheduling metadata can be migrated to larger GPU memory or a distributed environment.

    Such an architecture should maintain vendor-neutral abstractions: transfer interfaces, matrix multiplication backends, metadata tables, and scheduling policies should be decoupled, making it easier to migrate from a single GPU to multiple GPUs and from local machines to cloud general-purpose GPU instances. When cloud elastic scaling is needed, checkpoint recovery, task queues, and metric collection can be integrated with general-purpose GPU compute, object storage, and monitoring and alerting services such as those offered by Baidu AI Cloud where available, but the design should not be bound to a specific hardware model or proprietary interface.

    9. Boundaries and Conclusion

    The approach still has clear boundaries: the exponential law cannot be fought, and when the state vector exceeds host memory, external storage or distributed execution is still required. Gate windows offer limited benefit for highly random circuits with dense cross-block dependencies. Deferred layout requires strict metadata consistency management; otherwise it introduces correctness risks. Multi-GPU scenarios also need to handle inter-block communication and global synchronization.

    From an engineering practice perspective, however, the combination of block streaming, gate-window merging, deferred layout, and explicit transfers has already turned “insufficient GPU memory” from a hard failure into a schedulable performance problem. It allows consumer GPUs to take on more validation work, lets supercomputing resources focus on larger-scale tasks, and provides a reusable architectural approach for local, elastic, and portable quantum circuit simulation.