A GPU memory allocation method and apparatus for simulating quantum programs
By using a GPU memory allocation method in a distributed computing cluster to dynamically plan quantum state storage, the problem of low efficiency in CPU-simulated quantum computing is solved, thus improving quantum computing performance.
Patent Information
- Application Number
- CN202210720765.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-06-23
- Publication Date
- 2026-11-17
- Estimated Expiration
- 2042-06-23
AI Technical Summary
In existing technologies, as the number of qubits increases, the number of quantum states and operands that need to be stored when the CPU simulates quantum computing grows exponentially. Due to the limitations of the CPU's parallel computing capabilities and memory, the simulation efficiency is low.
A distributed computing cluster GPU memory allocation method is adopted. By acquiring hardware parameters and GPU status information, a quantum state storage scheme is dynamically planned. Combined with the data transfer performance between GPUs, the storage and allocation of quantum states on multiple GPUs are optimized.
It improves the computational performance of complex quantum circuits, expands the qubit size for GPU simulations, and increases computational speed.
Smart Images

Figure CN117311956B_ABST
Abstract
Description
Technical Field
[0001] This invention belongs to the field of quantum computing technology, and in particular to a GPU memory allocation method and apparatus for simulating quantum programs. Background Technology
[0002] In the field of quantum computing, as the complexity of research problems gradually increases, the demand for quantum computers is also growing. However, the actual manufacturing of physical quantum computers is difficult and costly, and existing quantum computer resources are limited, making it difficult to meet actual social needs. Therefore, using CPUs to simulate the actual computation process of quantum computers based on the principles of quantum computing to address the challenges of meeting the demand for quantum computers has become a key technology under research.
[0003] However, in quantum computing, as the number of qubits increases, the number of superimposed quantum states grows exponentially. Therefore, when using a CPU to perform full-amplitude simulation, the number of quantum states that need to be stored and the number of operations that need to be performed also grow exponentially. However, the number of threads that can run in parallel on each CPU and the CPU's memory are limited, which limits the number of qubits that the CPU can simulate and affects the simulation efficiency. This is a problem that urgently needs to be solved. Summary of the Invention
[0004] The purpose of this invention is to provide a GPU memory allocation method and apparatus for simulating quantum programs, in order to overcome the shortcomings of the prior art. It can provide a dynamic planning quantum state storage scheme that combines the data transfer performance between GPUs, thereby improving the computational performance of complex quantum circuits.
[0005] One embodiment of this application provides a GPU memory allocation method for simulating a quantum program, the method comprising:
[0006] Obtain the hardware parameter information of the distributed computing cluster and initialize the GPU status information of the computing cluster;
[0007] Determine the number of qubits in the quantum program to be simulated, and obtain the number of quantum states to be simulated and the maximum number of quantum state operations through a preset calculation method;
[0008] Based on the hardware parameter information, GPU status information, number of quantum states, and maximum number of quantum state operations, the GPU memory allocation scheme for the quantum program to be simulated is determined.
[0009] Optionally, initializing the GPU state information of the computing cluster includes:
[0010] The number of nodes in the computing cluster, the number of GPUs per node, and the computing performance parameters of each GPU are obtained, wherein the computing performance parameters are determined by the number of cores and the maximum number of parallel threads per GPU.
[0011] The system communicates with each GPU and obtains the current free memory of each GPU as well as the data transfer rate between the GPUs.
[0012] Optionally, the preset calculation method includes one of the following: full amplitude simulation calculation method, partial amplitude simulation calculation method, and single amplitude simulation calculation method.
[0013] Optionally, determining the GPU memory allocation scheme for the quantum program to be simulated based on the hardware parameter information, GPU state information, number of quantum states, and maximum number of quantum state operations includes:
[0014] Determine whether a target GPU exists, wherein the maximum number of parallel threads of the target GPU is not less than the maximum number of quantum state operations;
[0015] If not, then it is further determined whether the current free memory of all GPUs in the computing cluster can realize all quantum state simulations;
[0016] If the current free memory of all GPUs in the computing cluster can realize the simulation of all quantum states, then the GPU memory allocation scheme of the quantum program to be simulated is determined according to the execution time corresponding to the current free memory occupancy mode of all quantum states on the GPUs.
[0017] Optionally, the method further includes:
[0018] If the target GPU exists, determine whether the current free memory of the target GPU can realize all the quantum state simulations;
[0019] If so, all quantum states are stored in the free memory of the target GPU to achieve GPU memory allocation for the quantum program to be simulated.
[0020] Optionally, the method further includes:
[0021] If the current free memory of the target GPU is insufficient to simulate all quantum states, then the step of further determining whether the current free memory of all GPUs in the computing cluster can simulate all quantum states continues.
[0022] Optionally, the method further includes:
[0023] If the current free memory of all GPUs in the computing cluster is insufficient to simulate all quantum states, an error message will be output and displayed.
[0024] Optionally, determining the GPU memory allocation scheme for the quantum program to be simulated based on the execution time corresponding to the current free memory usage mode of all quantum states on the GPU includes:
[0025] The first execution time, in which all quantum states are evenly distributed across the free memory of each GPU, and the second execution time, in which all quantum states first occupy the free memory of a single GPU before occupying the free memory of other GPUs, are calculated respectively. The first and second execution times are determined based on the data transfer rate between the GPUs, the computational performance parameters, the hardware parameter information, and the number of quantum states.
[0026] The GPU memory allocation scheme for the quantum program to be simulated is determined based on the first execution time and the second execution time.
[0027] Optionally, determining the GPU memory allocation scheme for the quantum program to be simulated based on the first execution time and the second execution time includes:
[0028] If the first execution time is not greater than the second execution time, then all quantum states are evenly distributed among the current free memory of all GPUs in the computing cluster;
[0029] If the first execution time is greater than the second execution time, then all quantum states will be used to fill the free memory of a single GPU before using other GPUs.
[0030] Another embodiment of this application provides a GPU memory allocation device for simulating a quantum program, the device comprising:
[0031] The acquisition module is used to acquire hardware parameter information of the distributed computing cluster and initialize the GPU status information of the computing cluster.
[0032] The first determining module is used to determine the number of qubits of the quantum program to be simulated, and to obtain the number of quantum states to be simulated and the maximum number of quantum state operations through a preset calculation method;
[0033] The second determining module is used to determine the GPU memory allocation scheme of the quantum program to be simulated based on the hardware parameter information, GPU state information, number of quantum states and maximum number of quantum state operations.
[0034] Optionally, the obtaining module includes:
[0035] The acquisition unit is used to acquire the number of nodes in the computing cluster, the number of GPUs per node, and the computing performance parameters of each GPU, wherein the computing performance parameters are determined by the number of cores and the maximum number of parallel threads per GPU.
[0036] The acquisition unit is used to communicate with each GPU and acquire the current free memory of each GPU and the data transfer rate between the GPUs.
[0037] Optionally, the second determining module includes:
[0038] The first judgment unit is used to determine whether a target GPU exists, wherein the maximum number of parallel threads of the target GPU is not less than the maximum number of quantum state operations;
[0039] The second judgment unit is used to further determine, if not, whether the current free memory of all GPUs in the computing cluster can realize all quantum state simulations;
[0040] The first determining unit is configured to determine the GPU memory allocation scheme for the quantum program to be simulated based on the execution time corresponding to the current free memory occupancy mode of all quantum states on the GPUs if the current free memory of all GPUs in the computing cluster can realize the simulation of all quantum states.
[0041] Optionally, the second determining module further includes:
[0042] The third judgment unit is used to determine whether the current free memory of the target GPU can realize all the quantum state simulations if the target GPU exists.
[0043] A storage unit is used to store all the quantum states in the free memory of the target GPU if the conditions are met, so as to realize the GPU memory allocation of the quantum program to be simulated.
[0044] Optionally, the second determining module further includes:
[0045] The output unit is used to output and display an error message if the current free memory of all GPUs in the computing cluster is insufficient to simulate all quantum states.
[0046] Optionally, the first determining unit includes:
[0047] The computing subunit is used to calculate the first execution time when all quantum states are evenly distributed across the free memory of each GPU and the second execution time when all quantum states first occupy the free memory of a single GPU and then occupy the free memory of other GPUs. The first execution time and the second execution time are determined based on the data transfer rate between the GPUs, the computing performance parameters, the hardware parameter information, and the number of quantum states.
[0048] A determination subunit is used to determine the GPU memory allocation scheme for the quantum program to be simulated based on the first execution time and the second execution time.
[0049] Optionally, the second determining module further includes:
[0050] The return unit is used to continue executing the step of further determining whether the current free memory of all GPUs in the computing cluster can realize all quantum state simulations if the current free memory of the target GPU cannot realize all quantum state simulations.
[0051] Optionally, the determining subunit includes:
[0052] The equalization unit is used to evenly distribute all quantum states into the current free memory of all GPUs in the computing cluster if the first execution time is not greater than the second execution time.
[0053] The sub-unit is prioritized to be fully occupied. If the first execution time is greater than the second execution time, all quantum states will be prioritized to fill the free memory of a single GPU before occupying other GPUs.
[0054] Another embodiment of this application provides a storage medium storing a computer program, wherein the computer program is configured to execute the method described in any of the preceding claims when running.
[0055] Another embodiment of this application provides an electronic device including a memory and a processor, wherein the memory stores a computer program and the processor is configured to run the computer program to perform the method described in any of the preceding claims.
[0056] Compared with existing technologies, this invention first obtains the hardware parameter information of the distributed computing cluster and initializes the GPU state information of the computing cluster to determine the number of qubits of the quantum program to be simulated. It then obtains the number of quantum states to be simulated and the maximum number of quantum state operations through a preset calculation method. Based on the hardware parameter information, GPU state information, number of quantum states, and maximum number of quantum state operations, it determines the GPU memory allocation scheme for the quantum program to be simulated. This invention can provide a dynamic planning quantum state storage scheme that combines the data transfer performance between GPUs, thereby improving the computational performance of complex quantum circuits. Attached Figure Description
[0057] Figure 1 This is a hardware structure block diagram of a computer terminal for a GPU memory allocation method for simulating a quantum program, provided in an embodiment of the present invention.
[0058] Figure 2 This is a flowchart illustrating a GPU memory allocation method for simulating a quantum program, provided in an embodiment of the present invention.
[0059] Figure 3 A schematic diagram of the overall framework of a GPU memory allocation method for simulating a quantum program provided in an embodiment of the present invention;
[0060] Figure 4 This is a schematic diagram of a GPU memory allocation device for simulating a quantum program, provided in an embodiment of the present invention. Detailed Implementation
[0061] The embodiments described below with reference to the accompanying drawings are exemplary and are only used to explain the present invention, and should not be construed as limiting the present invention.
[0062] The present invention first provides a GPU memory allocation method for simulating quantum programs. This method can be applied to electronic devices, such as computer terminals, specifically ordinary computers, quantum computers, etc.
[0063] The following detailed explanation uses a computer terminal as an example. Figure 1 This is a hardware structure block diagram of a computer terminal for a GPU memory allocation method to simulate a quantum program, provided as an embodiment of the present invention. Figure 1 As shown, a computer terminal may include one or more ( Figure 1 Only one is shown in the diagram. A processor 102 (which may include, but is not limited to, a microprocessor MCU or a programmable logic device FPGA, etc.) and a memory 104 for storing data are also shown. Optionally, the computer terminal may further include a transmission device 106 for communication functions and an input / output device 108. Those skilled in the art will understand that... Figure 1The structure shown is for illustrative purposes only and does not limit the structure of the computer terminal described above. For example, the computer terminal may also include components that are more complex than those described above. Figure 1 The more or fewer components shown, or having the same Figure 1 The different configurations shown.
[0064] The memory 104 can be used to store software programs and modules for application software, such as the program instructions / modules corresponding to a GPU memory allocation method for simulating a quantum program in this embodiment of the application. The processor 102 executes various functional applications and data processing by running the software programs and modules stored in the memory 104, thereby implementing the above-described method. The memory 104 may include high-speed random access memory, and may also include non-volatile memory, such as one or more magnetic storage devices, flash memory, or other non-volatile solid-state memory. In some instances, the memory 104 may further include memory remotely located relative to the processor 102, and these remote memories can be connected to a computer terminal via a network. Examples of such networks include, but are not limited to, the Internet, corporate intranets, local area networks, mobile communication networks, and combinations thereof.
[0065] The transmission device 106 is used to receive or send data via a network. Specific examples of the network described above may include a wireless network provided by a communication provider for the computer terminal. In one example, the transmission device 106 includes a Network Interface Controller (NIC), which can connect to other network devices via a base station to communicate with the Internet. In another example, the transmission device 106 may be a Radio Frequency (RF) module, used for wireless communication with the Internet.
[0066] It's important to note that a true quantum computer has a hybrid structure, comprising two main parts: a classical computer responsible for performing classical computations and control, and a quantum device responsible for running quantum programs to achieve quantum computation. A quantum program is a sequence of instructions written in a quantum language such as QRunes that can run on a quantum computer, supporting operations on quantum logic gates and ultimately enabling quantum computing. Specifically, a quantum program is a sequence of instructions that operates on quantum logic gates according to a specific timing order.
[0067] In practical applications, due to limitations in the development of quantum device hardware, quantum computing simulations are often required to verify quantum algorithms, quantum applications, and so on. Quantum computing simulation is the process of simulating the execution of a quantum program corresponding to a specific problem using a virtual architecture (i.e., a quantum virtual machine) built with the resources of a regular computer. Typically, it is necessary to construct a quantum program corresponding to a specific problem. The quantum program referred to in this embodiment of the invention is a program written in a classical language that represents qubits and their evolution, wherein qubits, quantum logic gates, etc., related to quantum computing all have corresponding classical code representations.
[0068] Quantum circuits, also known as quantum logic circuits, are a common manifestation of quantum programming and are the most widely used general-purpose quantum computing model. They represent circuits that operate on qubits under an abstract concept. They consist of qubits, circuits (timelines), and various quantum logic gates. Finally, the results are often read out through quantum measurement operations.
[0069] Unlike traditional circuits that use metal wires to transmit voltage or current signals, in quantum circuits, the circuits can be seen as being connected by time. That is, the state of a quantum bit evolves naturally over time, following the instructions of the Hamiltonian operator until it encounters a logic gate and is operated on.
[0070] A quantum program corresponds to a single quantum circuit. The quantum program described in this invention refers to this single quantum circuit, where the total number of qubits in the single quantum circuit is the same as the total number of qubits in the quantum program. This can be understood as follows: a quantum program can consist of a quantum circuit, measurement operations on the qubits within the quantum circuit, registers for storing measurement results, and control flow nodes (jump instructions). A single quantum circuit can contain dozens, hundreds, or even thousands of quantum logic gate operations. The execution of a quantum program is the process of executing all the quantum logic gates in a specific timing order. It should be noted that the timing order refers to the chronological sequence in which individual quantum logic gates are executed.
[0071] It's important to note that in classical computing, the most basic unit is the bit, and the most fundamental control mode is the logic gate. Circuit control can be achieved through combinations of logic gates. Similarly, the way to process qubits is through quantum logic gates. Quantum logic gates enable the evolution of quantum states and are the foundation of quantum circuits. Quantum logic gates include single-qubit gates, such as Hadamard gates (H-gates), Pauli-X gates (X-gates), Pauli-Y gates (Y-gates), Pauli-Z gates (Z-gates), RX gates, RY gates, RZ gates, etc.; and multi-qubit quantum logic gates, such as CNOT gates, CR gates, iSWAP gates, Tofoli gates, etc. Quantum logic gates are generally represented using unitary matrices, which are not only matrix forms but also operations and transformations. The effect of a quantum logic gate on a quantum state is generally calculated by left-multiplying the unitary matrix by the matrix corresponding to the right vector of the quantum state.
[0072] As those skilled in the art will understand, in classical computers, the basic unit of information is the bit, which has two states: 0 and 1. The most common physical implementation uses high and low voltage levels to represent these states. In quantum computing, the basic unit of information is the qubit, which also has two states: |0> and |1>. However, it can exist in a superposition of these two states, expressed as |φ> = a|0> + b|1>, where a and b are complex numbers representing the amplitudes (probability amplitudes) of the |0> and |1> states, respectively. This is not possible with classical bits. After measurement, the state of a qubit collapses to a definite state (eigenstate, here |0> or |1>), where the probability of collapsing to |0> is |a|. 2 The probability of collapsing to |1> is |b|. 2 , |a| 2 +|b| 2 =1, |> is the Dirac notation.
[0073] A quantum state refers to the state of a qubit (or quantum bit). Its eigenstates are represented in binary form in quantum algorithms (or quantum programs). For example, a set of qubits q0, q1, and q2, representing the 0th, 1st, and 2nd qubits respectively, ordered from most significant bit to least significant bit as q2q1q0, has a quantum state of 2q1q ... 3 A quantum state is a superposition of 8 eigenstates. The 8 eigenstates (definite states) are: |000>, |001>, |010>, |011>, |100>, |101>, |110>, and |111>. Each eigenstate corresponds to a qubit. For example, in the |000> state, 000 corresponds to q2q1q0 from the highest to the lowest bit. In short, a quantum state is a superposition of eigenstates. When the probability amplitude of other states is 0, the state is in one of the definite eigenstates.
[0074] In quantum computing, the number of superimposed quantum states increases exponentially with the increase of qubits. Current technologies employ memory allocation schemes using CPUs, single GPUs, or evenly distributed quantum states across multiple GPUs. When using a CPU for simulation, the limited parallel computing capability of the CPU results in low performance for simulating large numbers of qubits. Using a single GPU, the parallel computing capability and memory size of the GPU limit the size of the qubits that can be simulated and the computation time. When evenly distributing quantum states across multiple GPUs, the quantum states are stored evenly across the global memory of multiple GPUs. For multi-quantum gate operations, frequent data transfers across GPUs are required, which can severely degrade computational performance when hardware performance is insufficient.
[0075] This application combines quantum computing principles, GPU parallel computing, and communication technology to realize a GPU memory allocation method for simulating quantum programs. This method expands the qubit size of GPU simulation computing and improves the computing speed, which has important practical significance for solving the demand problems of quantum computers.
[0076] See Figure 2 , Figure 2 A flowchart illustrating a GPU memory allocation method for simulating a quantum program, provided as an embodiment of the present invention, may include the following steps:
[0077] S201: Obtain the hardware parameter information of the distributed computing cluster and initialize the GPU status information of the computing cluster.
[0078] Specifically, the hardware parameters of the computing cluster, such as GPU memory frequency and memory bus width, are obtained. The bandwidth can then be calculated by multiplying the GPU memory frequency by the memory bus width, where the bus width represents the number of data bits transmitted at a time, and the bandwidth represents the number of data bits transmitted per second. Initializing the GPU state information of the computing cluster may include:
[0079] Step 1: Obtain the number of nodes in the computing cluster, the number of GPUs per node, and the computing performance parameters of each GPU, wherein the computing performance parameters are determined by the number of cores and the maximum number of parallel threads per GPU.
[0080] Specifically, the number of nodes is the core of a multi-node cluster, while the number of GPUs and cores are the core of multi-GPU allocation. Multi-GPU allocation is based on the amount of data to be allocated and the number of GPUs. A GPU can have multiple processors, typically 82 to 128. Each processor supports a series of parallel threads, which are logically divided into GPU cores. For example, the RTX 3090 has over 10,000. Logically, each core can handle 32 parallel threads simultaneously. The computing performance of each GPU can be determined by the number of GPU cores, the number of parallel threads per core, the base frequency, memory frequency, memory bandwidth, and memory size. The maximum number of parallel threads for a GPU is the number of cores (i.e., hardware-level SMs; software-level Cores are 64 to 512 times the number of hardware-level cores) multiplied by the number of threads allowed per core. However, this total number of threads is not executed simultaneously but in batches. Typically, each software core has 32 threads in a batch (represented by `wrap`), but in actual execution, 16 threads may be executed at a time, followed by the remaining 16. The maximum number of parallel threads and the actual number of parallel threads are not the same. The maximum is what is allowed and can be handled at the logical level, but in actual execution, the maximum number of parallel threads needs to be executed step by step. For example, a SM may logically allow a maximum number of parallel threads of more than 1,500, and there are 82 SMs, each with 128 logical cores, for a total of more than 10,000 logical cores. Each logical core can run 32 threads in parallel (wrap), but in reality, only 16 threads are executed at the same time.
[0081] Step 2: Establish communication connections between the GPUs and obtain the current free memory of each GPU and the data transfer rate between the GPUs.
[0082] Specifically, GPUs can be directly connected, or existing connections can be established. Peer-to-Peer technology enables direct communication between GPUs. While individual GPUs can communicate with each other via CPU, PCIe, or network interface card (NIC) relays, not every two GPUs can communicate directly. This is because direct communication requires the same memory address allocation method. Peer-to-Peer technology enables unified addressing and provides directionality, allowing for collaborative computation between GPUs. By connecting the GPUs, Peer-to-Peer communication can be achieved between any two GPUs (when there are more than one GPU), and the data transfer rate between GPUs can be obtained (or calculated) (or not obtained, as the default cross-GPU data transfer rate is within an acceptable range).
[0083] S202: Determine the number of qubits in the quantum program to be simulated, and obtain the number of quantum states to be simulated and the maximum number of quantum state operations through a preset calculation method.
[0084] Specifically, by determining the number of qubits in the quantum program to be simulated, the number of quantum states is determined. For example, if the quantum program to be simulated is a quantum circuit containing 10 qubits, then the number of quantum states is 2^32. 10 The maximum number of quantum state operands is the number of quantum states divided by 2.
[0085] The preset calculation method includes one of the following: full amplitude simulation calculation method, partial amplitude simulation calculation method, and single amplitude simulation calculation method.
[0086] For example, in full-amplitude simulation computing, the memory required increases exponentially with the number of qubits; configuring 10 qubits requires 16Kbytes of memory. Furthermore, full-amplitude simulation quantum computing can employ a serial computing method, such as breaking down a large computational task and distributing it evenly across multiple computing nodes, performing serial computation simultaneously on each node. The full-amplitude simulation computing method can include: obtaining the quantum program to be simulated to each computing node, where the quantum program can be stored in a linked list; configuring and initializing the quantum states stored on each computing node based on the number of qubits required to execute the quantum program and the number of computing nodes; traversing the linked list of the quantum program within each computing node; and executing the quantum operation instructions stored in the current node for each traversed quantum program node, until all nodes in the linked list have been traversed, thus completing the full-amplitude quantum computing simulation.
[0087] S203: Determine the GPU memory allocation scheme for the quantum program to be simulated based on the hardware parameter information, GPU status information, number of quantum states, and maximum number of quantum state operations.
[0088] For details, see Figure 3 , Figure 3 This is a schematic diagram of the overall framework of a GPU memory allocation method for simulating a quantum program, provided by an embodiment of the present invention. Based on the hardware parameter information, GPU state information, number of quantum states, and maximum number of quantum state operations, the GPU memory allocation scheme for the quantum program to be simulated is determined, which may include:
[0089] Determine if a target GPU exists, wherein the maximum number of parallel threads of the target GPU is not less than the maximum number of quantum state operations; if not, further determine whether the current free memory of all GPUs in the computing cluster can realize the simulation of all quantum states; if the current free memory of all GPUs in the computing cluster can realize the simulation of all quantum states, determine the GPU memory allocation scheme of the quantum program to be simulated based on the execution time corresponding to the current free memory occupancy mode of all quantum states on the GPU.
[0090] Specifically, determining the GPU memory allocation scheme for the quantum program to be simulated based on the execution time corresponding to the current free memory usage of all quantum states on the GPU can include:
[0091] 1. Calculate the first execution time when all quantum states are evenly distributed across the free memory of each GPU and the second execution time when all quantum states first occupy the free memory of a single GPU before occupying the free memory of other GPUs, wherein the first execution time and the second execution time are determined based on the data transfer rate between the GPUs, the computing performance parameters, the hardware parameter information, and the number of quantum states.
[0092] 2. Determine the GPU memory allocation scheme for the quantum program to be simulated based on the first execution time and the second execution time.
[0093] Specifically, if the first execution time is not greater than the second execution time, then all quantum states are evenly distributed among the current free memory of all GPUs in the computing cluster;
[0094] If the first execution time is greater than the second execution time, then all quantum states will be used to fill the free memory of a single GPU before using other GPUs.
[0095] It should be noted that execution time can fluctuate even for the same program, depending on GPU hardware parameters, inter-GPU data transfer rate, and the number of quantum states (or maximum quantum state operands). Analyzing the GPU's memory frequency and bandwidth helps determine the speed of cross-GPU data transfer. This analysis should also consider the total number of threads, distributing threads across multiple GPUs to reduce time and increase cross-GPU read time (while also taking into account the reduction in data read). Key factors include GPU memory frequency, memory bandwidth, inter-GPU data transfer rate, total number of quantum states (or maximum quantum state operands), and the number of GPUs allocated (the more GPUs N allocated to the total data, the more data needs to be read across GPUs; on average, (N-1) / N data needs to be read).
[0096] If the target GPU exists, it is determined whether the current free memory of the target GPU can realize the simulation of all quantum states; if so, all quantum states are stored in the free memory of the target GPU to realize GPU memory allocation for the quantum program to be simulated.
[0097] If the current free memory of the target GPU is insufficient to simulate all quantum states, then the step of further determining whether the current free memory of all GPUs in the computing cluster can simulate all quantum states continues.
[0098] If the current free memory of all GPUs in the computing cluster is insufficient to simulate all quantum states, an error message will be output and displayed.
[0099] For example, based on the size of the qubits, the system analyzes the amount of data required to store the full-amplitude quantum states and checks whether the available memory on the currently idle GPUs meets the memory allocation scheme. If the number of quantum states is less than the number of GPU parallel operation threads, the data is directly allocated to a single GPU. Otherwise, the system analyzes whether the computational performance of evenly distributing the quantum states across multiple GPUs is higher than that of prioritizing full GPU memory, considering memory copy speed, and selects the scheme with the optimal computational performance. For the case where the quantum states are distributed across multiple GPUs, the system further analyzes whether copying the data to the GPU performing the operation beforehand is better than the default operation method, considering inter-GPU data transfer performance and the waiting time during thread parallelism, and selects the optimal method. After the quantum logic gate operation is completed, the system returns the processing result to the caller and releases the GPU resources occupied.
[0100] For example, if the number of qubits is b, the memory required to store one quantum state is m, the number of GPU cores is core, the number of parallel threads is w, the memory frequency is r, the bandwidth is width, the available free memory per GPU is f, the total available free memory is F, the number of GPUs used across GPUs is count, and the data transfer rate between GPUs is v, then the overall memory allocation rules are as follows:
[0101] First, determine if condition 2 is met. b-1 If the value is less than or equal to (core × w) ÷ 2, then further check if the condition 2 is met. b If ×m≤f, then all quantum states are stored on a single GPU. If 2 b-1 If the value is greater than (core × w) ÷ 2, then further determine whether the condition 2 is met. b If ×m≤F, it indicates insufficient memory, and the process exits immediately. If it is satisfied, further check if (count-1)×(r×width)÷(count) is satisfied. 2 ×v 2If ≥ 1, then all quantum states will first occupy the free memory of a single GPU before occupying other GPUs; otherwise, all quantum states will be evenly distributed among the current free memory of all GPUs in the computing cluster. b If ×m>f, then proceed to further determine whether condition 2 is satisfied. b The steps for ×m≤F.
[0102] As can be seen, this invention first obtains the hardware parameter information of the distributed computing cluster, initializes the GPU state information of the computing cluster, determines the number of qubits of the quantum program to be simulated, and obtains the number of quantum states to be simulated and the maximum number of quantum state operations through a preset calculation method. Based on the hardware parameter information, GPU state information, number of quantum states and maximum number of quantum state operations, the GPU memory allocation scheme of the quantum program to be simulated is determined. It can provide a quantum state storage scheme that combines the data transfer performance between GPUs to improve the computing performance of complex quantum circuits.
[0103] See Figure 4 , Figure 4 This is a schematic diagram of the structure of a GPU memory allocation device for simulating a quantum program, provided in an embodiment of the present invention. Figure 2 The process shown can include:
[0104] The module 401 is used to obtain hardware parameter information of the distributed computing cluster and initialize the GPU status information of the computing cluster.
[0105] The first determining module 402 is used to determine the number of qubits of the quantum program to be simulated, and to obtain the number of quantum states to be simulated and the maximum number of quantum state operations through a preset calculation method;
[0106] The second determining module 403 is used to determine the GPU memory allocation scheme of the quantum program to be simulated based on the hardware parameter information, GPU status information, number of quantum states and maximum number of quantum state operations.
[0107] Specifically, the obtaining module includes:
[0108] The acquisition unit is used to acquire the number of nodes in the computing cluster, the number of GPUs per node, and the computing performance parameters of each GPU, wherein the computing performance parameters are determined by the number of cores and the maximum number of parallel threads per GPU.
[0109] The acquisition unit is used to communicate with each GPU and acquire the current free memory of each GPU and the data transfer rate between the GPUs.
[0110] Specifically, the second determining module includes:
[0111] The first judgment unit is used to determine whether a target GPU exists, wherein the maximum number of parallel threads of the target GPU is not less than the maximum number of quantum state operations;
[0112] The second judgment unit is used to further determine, if not, whether the current free memory of all GPUs in the computing cluster can realize all quantum state simulations;
[0113] The first determining unit is configured to determine the GPU memory allocation scheme for the quantum program to be simulated based on the execution time corresponding to the current free memory occupancy mode of all quantum states on the GPUs if the current free memory of all GPUs in the computing cluster can realize the simulation of all quantum states.
[0114] Specifically, the second determining module further includes:
[0115] The third judgment unit is used to determine whether the current free memory of the target GPU can realize all the quantum state simulations if the target GPU exists.
[0116] A storage unit is used to store all the quantum states in the free memory of the target GPU if the conditions are met, so as to realize the GPU memory allocation of the quantum program to be simulated.
[0117] Specifically, the second determining module further includes:
[0118] The return unit is used to continue executing the step of further determining whether the current free memory of all GPUs in the computing cluster can realize all quantum state simulations if the current free memory of the target GPU cannot realize all quantum state simulations.
[0119] Specifically, the second determining module further includes:
[0120] The output unit is used to output and display an error message if the current free memory of all GPUs in the computing cluster is insufficient to simulate all quantum states.
[0121] Specifically, the first determining unit includes:
[0122] The computing subunit is used to calculate the first execution time when all quantum states are evenly distributed across the free memory of each GPU and the second execution time when all quantum states first occupy the free memory of a single GPU and then occupy the free memory of other GPUs. The first execution time and the second execution time are determined based on the data transfer rate between the GPUs, the computing performance parameters, the hardware parameter information, and the number of quantum states.
[0123] A determination subunit is used to determine the GPU memory allocation scheme for the quantum program to be simulated based on the first execution time and the second execution time.
[0124] Specifically, the determining subunit includes:
[0125] The equalization unit is used to evenly distribute all quantum states into the current free memory of all GPUs in the computing cluster if the first execution time is not greater than the second execution time.
[0126] The sub-unit is prioritized to be fully occupied. If the first execution time is greater than the second execution time, all quantum states will be prioritized to fill the free memory of a single GPU before occupying other GPUs.
[0127] Compared with existing technologies, this invention first obtains the hardware parameter information of the distributed computing cluster and initializes the GPU state information of the computing cluster to determine the number of qubits of the quantum program to be simulated. It then obtains the number of quantum states to be simulated and the maximum number of quantum state operations through a preset calculation method. Based on the hardware parameter information, GPU state information, number of quantum states, and maximum number of quantum state operations, it determines the GPU memory allocation scheme for the quantum program to be simulated. This invention can provide a dynamic planning quantum state storage scheme that combines the data transfer performance between GPUs, thereby improving the computational performance of complex quantum circuits.
[0128] This invention also provides a storage medium storing a computer program, wherein the computer program is configured to execute the steps in any of the method embodiments described above when running.
[0129] Specifically, in this embodiment, the storage medium can be configured to store a computer program for performing the following steps:
[0130] S201: Obtain the hardware parameter information of the distributed computing cluster and initialize the GPU status information of the computing cluster;
[0131] S202: Determine the number of qubits in the quantum program to be simulated, and obtain the number of quantum states to be simulated and the maximum number of quantum state operations through a preset calculation method;
[0132] S203: Determine the GPU memory allocation scheme for the quantum program to be simulated based on the hardware parameter information, GPU status information, number of quantum states, and maximum number of quantum state operations.
[0133] Specifically, in this embodiment, the storage medium may include, but is not limited to, USB flash drives, read-only memory (ROM), random access memory (RAM), portable hard drives, magnetic disks, or optical disks, and other media capable of storing computer programs.
[0134] This invention also provides an electronic device, including a memory and a processor, wherein the memory stores a computer program and the processor is configured to run the computer program to perform the steps in any of the method embodiments described above.
[0135] Specifically, the aforementioned electronic device may further include a transmission device and an input / output device, wherein the transmission device is connected to the aforementioned processor, and the input / output device is connected to the aforementioned processor.
[0136] Specifically, in this embodiment, the processor can be configured to perform the following steps via a computer program:
[0137] S201: Obtain the hardware parameter information of the distributed computing cluster and initialize the GPU status information of the computing cluster;
[0138] S202: Determine the number of qubits in the quantum program to be simulated, and obtain the number of quantum states to be simulated and the maximum number of quantum state operations through a preset calculation method;
[0139] S203: Determine the GPU memory allocation scheme for the quantum program to be simulated based on the hardware parameter information, GPU status information, number of quantum states, and maximum number of quantum state operations.
[0140] The above description, based on the embodiments shown in the figures, details the structure, features, and effects of the present invention. The above description is only a preferred embodiment of the present invention, but the present invention is not limited to the scope of implementation shown in the figures. Any changes made in accordance with the concept of the present invention, or equivalent embodiments modified to have equivalent changes, that do not exceed the spirit covered by the specification and figures, should be within the protection scope of the present invention.
Claims
1. A GPU memory allocation method for simulating a quantum program, characterized in that, The method includes: Obtain the hardware parameter information of the distributed computing cluster and initialize the GPU status information of the computing cluster; Determine the number of qubits in the quantum program to be simulated, and obtain the number of quantum states to be simulated and the maximum number of quantum state operations through a preset calculation method; Based on the hardware parameter information, GPU status information, number of quantum states, and maximum number of quantum state operations, the GPU memory allocation scheme for the quantum program to be simulated is determined, including: when there is no target GPU with a maximum number of parallel threads not less than the maximum number of quantum state operations, and the current free memory of all GPUs in the computing cluster can realize the simulation of all quantum states, the GPU memory allocation scheme for the quantum program to be simulated is determined based on the execution time corresponding to the current free memory occupancy mode of all quantum states on the GPU; the execution time corresponding to the occupancy mode includes: the first execution time when all quantum states are evenly distributed across the free memory of each GPU, and the execution time after all quantum states first fill the free memory of a single GPU. The second execution time occupies the free memory of other GPUs, wherein the first execution time and the second execution time are determined based on the data transfer rate between the GPUs, the computing performance parameters, the hardware parameter information, and the number of quantum states; the GPU memory allocation scheme for the quantum program to be simulated is determined based on the execution time corresponding to the current free memory occupancy mode of all quantum states on the GPUs, including: if the first execution time is not greater than the second execution time, then all quantum states are evenly distributed among the current free memory of all GPUs in the computing cluster; if the first execution time is greater than the second execution time, then all quantum states are given priority to fill the free memory of a single GPU before occupying other GPUs.
2. The method according to claim 1, characterized in that, The initialization of the GPU state information of the computing cluster includes: The number of nodes in the computing cluster, the number of GPUs per node, and the computing performance parameters of each GPU are obtained, wherein the computing performance parameters are determined by the number of cores and the maximum number of parallel threads per GPU. The system communicates with each GPU and obtains the current free memory of each GPU as well as the data transfer rate between the GPUs.
3. The method according to claim 2, characterized in that, The preset calculation method includes one of the following: full amplitude simulation calculation method, partial amplitude simulation calculation method, and single amplitude simulation calculation method.
4. The method according to claim 1, characterized in that, The method further includes: If the target GPU exists, determine whether the current free memory of the target GPU can realize all the quantum state simulations; If so, all quantum states are stored in the free memory of the target GPU to achieve GPU memory allocation for the quantum program to be simulated.
5. The method according to claim 4, characterized in that, The method further includes: If the current free memory of the target GPU is insufficient to simulate all quantum states, then it is determined whether the current free memory of all GPUs in the computing cluster is sufficient to simulate all quantum states.
6. The method according to claim 5, characterized in that, The method further includes: If the current free memory of all GPUs in the computing cluster is insufficient to simulate all quantum states, an error message will be output and displayed.
7. A GPU memory allocation device for simulating quantum programs, characterized in that, The device includes: The acquisition module is used to acquire hardware parameter information of the distributed computing cluster and initialize the GPU status information of the computing cluster. The first determining module is used to determine the number of qubits of the quantum program to be simulated, and to obtain the number of quantum states to be simulated and the maximum number of quantum state operations through a preset calculation method; The second determining module is used to determine the GPU memory allocation scheme for the quantum program to be simulated based on the hardware parameter information, GPU status information, number of quantum states, and maximum number of quantum state operations. This includes: when there is no target GPU and the current free memory of all GPUs in the computing cluster can realize the simulation of all quantum states, determining the GPU memory allocation scheme for the quantum program to be simulated based on the execution time corresponding to the current free memory occupancy method of all quantum states on the GPU; the maximum number of parallel threads of the target GPU is not less than the maximum number of quantum state operations; the execution time corresponding to the occupancy method includes: the first execution time when all quantum states are evenly distributed across the free memory of each GPU and the execution time when all quantum states preferentially occupy a single GPU. The second execution time is determined by first executing the first quantum state and then using the free memory of other GPUs. The first and second execution times are determined based on the data transfer rate between the GPUs, computational performance parameters, hardware parameter information, and the number of quantum states. The GPU memory allocation scheme for the quantum program to be simulated is determined based on the execution time corresponding to the current free memory usage of all quantum states on the GPUs. If the first execution time is not greater than the second execution time, then all quantum states are evenly distributed among the current free memory of all GPUs in the computing cluster. If the first execution time is greater than the second execution time, then all quantum states are prioritized to fill the free memory of a single GPU before using the free memory of other GPUs.
8. A storage medium, characterized in that, The storage medium stores a computer program, wherein the computer program is configured to execute the method described in any one of claims 1 to 6 when it is run.
9. An electronic device comprising a memory and a processor, characterized in that, The memory stores a computer program, and the processor is configured to run the computer program to perform the method as described in any one of claims 1 to 6.
Citation Information
Patent Citations
Apparatus and method for specifying quantum operation parallelism for quantum control processor
CN112990470A
Large-scale quantum circuit simulation method based on cooperation of CPU and GPU
CN114595820A
