A GPU Monte Carlo acceleration method based on stack processing
By designing a storage stack operation in the Monte Carlo method, the problem of long calculation time of the Monte Carlo method is solved, the GPU Monte Carlo calculation speed is significantly improved, and the computational efficiency in radiotherapy is improved.
Patent Information
- Application Number
- CN202411714025.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-11-27
- Publication Date
- 2025-10-03
- Estimated Expiration
- 2044-11-27
AI Technical Summary
The Monte Carlo method takes too long to calculate in radiotherapy, which limits its application and promotion in clinical treatment plan dose calculation.
Through carefully designed storage stack operations, including creating different storage stacks according to different particles and data blocks in the simulation calculation process, performing pop operations to keep the particle types consistent, balancing the difference in the number of particles between storage stacks, adding a new batch of particles and merging idle data blocks, the parallelism of the push operation is improved.
The calculation speed of GPU Monte Carlo has been greatly improved, increasing the speed by two to three times, reducing thread idling caused by differences in particle types and data blocks, and improving calculation efficiency.
Smart Images

Figure CN119623220B_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of medical physics, and in particular to a GPU Monte Carlo acceleration method based on stack processing. Background Art
[0002] In radiotherapy, accurately determining the absorbed dose produced by radiation is one of the foundations for ensuring the effectiveness of radiotherapy. The Monte Carlo method is a computational method recognized as the most effective for simulating particle migration and is now widely used in medical physics. However, its long computational time limits its application and promotion in clinical treatment plan dose calculations. GPU general computing can handle a large number of computing tasks simultaneously due to its large number of cores and has powerful parallel computing capabilities. The Monte Carlo method, also known as the statistical simulation method, refers to the use of random numbers to solve many computational problems, or more commonly, the use of pseudo-random numbers to solve computational problems. The working principle is continuous sampling and gradual approximation. Therefore, GPU general computing provides a powerful way to establish a fast Monte Carlo dose calculation platform. Summary of the Invention
[0003] The embodiment of the present application discloses a GPU Monte Carlo acceleration method based on stack processing. Through carefully designed storage stack operations, the calculation speed of GPU Monte Carlo is greatly improved, which is two to three times faster than traditional methods.
[0004] The present application discloses a GPU Monte Carlo acceleration method based on stack processing, which is applied to electronic devices. The method includes:
[0005] Create different storage stacks according to different particles and different data blocks in the simulation calculation process;
[0006] Performing a pop operation on the storage stack according to a rule to keep the particle type consistent in each simulation;
[0007] balancing the difference in the number of particles between the storage stacks in different data blocks;
[0008] Adding a new batch of particles to the storage stack generated in the late stage of the simulation during the batch simulation calculation;
[0009] If there are idle threads in all the data blocks at the end of the simulation, the data blocks are merged.
[0010] As an optional implementation, creating different storage stacks according to different particles and different data blocks in the simulation calculation process includes:
[0011] Create different storage stacks according to different particles in the simulation calculation process;
[0012] Create different storage stacks according to different data blocks in the simulation calculation process;
[0013] The different particles include photons, electrons and positrons; the number of storage stacks is the number of data blocks.
[0014] As an optional implementation, performing a pop operation on the storage stack according to a rule to keep the particle type consistent in each simulation includes:
[0015] Counting the total number of particles in the storage stack based on a certain time interval;
[0016] Determine a corresponding pop threshold value according to the size of the storage stack;
[0017] If the size of the storage stack exceeds the popping threshold, the particle type corresponding to the storage stack is processed first.
[0018] As an optional implementation manner, balancing the difference in the number of particles between the storage stacks in different data blocks includes:
[0019] Determining a corresponding balance threshold according to the size of the storage stack;
[0020] If the difference between the maximum total number of particles and the minimum total number of particles in the storage stack is greater than the balance threshold, sorting the storage stack according to the total number of particles in the storage stack;
[0021] determining a first storage stack and a corresponding second storage stack according to the total number of particles in the storage stack;
[0022] pairing the first storage stack with the second storage stack;
[0023] determining a transferred number of the particles according to a difference between the total number of the particles in the first storage stack and the total number of the particles in the second storage stack;
[0024] A portion of the particles in the first storage stack is transferred to the second storage stack.
[0025] As an optional embodiment, the step of adding a new batch of particles to the storage stack generated in the later stage of the batch simulation calculation process includes:
[0026] Determining a corresponding supplement threshold according to the size of the storage stack;
[0027] If the minimum total number of particles in the storage stack is less than the replenishment threshold, the next batch of particles is immediately simulated and calculated, and the next batch of particles is replenished into the storage stack.
[0028] As an optional embodiment, before replenishing the next batch of particles into the storage stack, the method further includes:
[0029] determining particle energies of the particles in the storage stack;
[0030] The particles are sorted according to their energy.
[0031] As an optional implementation manner, if idle threads exist in all the data blocks in the later stage of simulation, merging the data blocks includes:
[0032] If idle threads exist in all the data blocks at the end of the simulation, determining the first data block and the corresponding second data block;
[0033] pairing the first data block with the second data block;
[0034] transferring all the particles of the second data block to the first data block;
[0035] Delete the second data block.
[0036] The present application discloses a GPU Monte Carlo acceleration device based on stack processing, the device comprising:
[0037] A creation module is used to create different storage stacks according to different particles and different data blocks in the simulation calculation process;
[0038] A popping module, configured to perform a popping operation on the storage stack according to a rule, so as to keep the particle types consistent in each simulation;
[0039] a balancing module, configured to balance the difference in the number of particles between the storage stacks in different data blocks;
[0040] A replenishment module, for replenishing a new batch of particles into the storage stack generated in the late stage of the simulation during the batch simulation calculation process;
[0041] The merging module is used to merge the data blocks if there are idle threads in all the data blocks in the later stage of simulation.
[0042] An embodiment of the present application discloses an electronic device, including a memory and a processor, wherein a computer program is stored in the memory. When the computer program is executed by the processor, the processor implements any one of the stack processing-based GPU Monte Carlo acceleration methods disclosed in the embodiment of the present application.
[0043] An embodiment of the present application discloses a computer-readable storage medium that stores a computer program, wherein when the computer program is executed by a processor, it implements any one of the stack processing-based GPU Monte Carlo acceleration methods disclosed in the embodiment of the present application.
[0044] Compared with the related art, the embodiments of the present application have the following beneficial effects:
[0045] An embodiment of the present application provides a GPU Monte Carlo acceleration method based on stack processing, which creates different storage stacks according to different particles and different data blocks in the simulation calculation process, performs pop operations on the storage stacks according to rules, keeps the particle types consistent in each simulation, balances the difference in the number of particles between storage stacks in different data blocks, adds a new batch of particles to the storage stacks generated in the later stage of the simulation during the batch simulation calculation process, and merges the data blocks if there are idle threads in all data blocks in the later stage of the simulation. In the implementation of the embodiment of the present application, different storage stacks are created for different particles in the simulation calculation process, which improves the parallelism of the push operation and reduces the simulation branches caused by the particle type. Different storage stacks are created for different data blocks, which greatly improves the parallelism of the push operation. A set of pop rules are established to make the particle types of each simulation as similar as possible, reducing the waiting caused by different particle types. A set of balancing rules between storage stacks is established to greatly reduce thread idling caused by the difference in the number of particles in the storage stacks in different data blocks. A set of storage stack replenishment rules is established to avoid thread idling in the later stage of each batch due to batch simulation. When replenishing particles to the storage stack, the particles are first sorted by energy, so that particles with similar energy are more easily assigned to the same warp, reducing the waiting caused by uneven particle lifespan. A set of storage stack merging rules is established to reduce thread idling in the later stage of the simulation. Through carefully designed storage stack operations, the calculation speed of GPU Monte Carlo is greatly improved, which is two to three times faster than traditional methods. BRIEF DESCRIPTION OF THE DRAWINGS
[0046] In order to more clearly illustrate the technical solutions in the embodiments of the present application, the following briefly introduces the drawings required for use in the embodiments. Obviously, the drawings described below are only some embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without creative work.
[0047] Figure 1 This is a flowchart of a GPU Monte Carlo acceleration method based on stack processing disclosed in an embodiment of the present application;
[0048] Figure 2 is a schematic diagram of a process for balancing the difference in the number of particles between storage stacks in different data blocks disclosed in an embodiment of the present application;
[0049] Figure 3This is a schematic diagram of the process of adding a new batch of particles to the storage stack generated in the late stage of the simulation during the batch simulation calculation disclosed in the embodiment of the present application;
[0050] Figure 4 This is a schematic diagram of the structure of a GPU Monte Carlo accelerator based on stack processing disclosed in an embodiment of the present application;
[0051] Figure 5 This is a schematic structural diagram of an electronic device disclosed in an embodiment of the present application. DETAILED DESCRIPTION
[0052] The following will be combined with the drawings in the embodiments of this application to clearly and completely describe the technical solutions in the embodiments of this application. Obviously, the embodiments described are only part of the embodiments of this application, not all of the embodiments. Based on the embodiments in this application, all other embodiments obtained by ordinary technicians in this field without making creative efforts are within the scope of protection of this application.
[0053] It should be noted that the terms "including," "having," and any variations thereof in the embodiments and drawings of this application are intended to cover non-exclusive inclusions. For example, a process, method, system, product, or apparatus comprising a series of steps or units is not limited to the listed steps or units, but may optionally include steps or units not listed, or may optionally include other steps or units inherent to the process, method, product, or apparatus.
[0054] It is understood that the terms "first," "second," etc., used herein may be used to describe various elements, but these elements are not limited by these terms. These terms are only used to distinguish a first element from another element. For example, a first storage stack may be referred to as a second storage stack, and similarly, a second storage stack may be referred to as a first storage stack, without departing from the scope of this application. Both the first storage stack and the second storage stack are storage stacks, but they are not the same storage stack.
[0055] The present invention discloses a GPU Monte Carlo acceleration method based on stack processing. Through carefully designed storage stack operations, the GPU Monte Carlo calculation speed is greatly improved, with a speed increase of two to three times compared to traditional methods. The following details each method.
[0056] See also Figure 1 , Figure 1 This is a flowchart of a GPU Monte Carlo acceleration method based on stack processing disclosed in an embodiment of the present application. Figure 1 The described GPU Monte Carlo acceleration method based on stack processing is applicable to electronic devices. Figure 1 As shown, the GPU Monte Carlo acceleration method may include the following steps:
[0057] Step S101 : creating different storage stacks according to different particles and different data blocks in the simulation calculation process.
[0058] In GPU computing, threads in the same warp execute the same instruction stream. If there are branches during the execution process, the threads executing different branches need to wait for each other, which affects the computing efficiency. The Monte Carlo method is a random algorithm with a large number of branches. Different storage stacks are created for different particles in the simulation calculation process, which improves the parallelism of the push operation and reduces the simulation branches caused by the type of particles. The number of GPU threads is limited, and only the number of data blocks multiplied by the number of threads is simulated at the same time. The other particles are stored in the particle storage stack. The push operation is an atomic operation and can only be serial, which affects the computing efficiency.
[0059] Among them, a warp is a fixed-size thread group in GPU computing, and a thread is the smallest unit of GPU work. Usually 32 threads form a warp. Threads in the same warp execute the same instruction stream, that is, the thread operations in the same warp are completely synchronized. These threads are executed in parallel on the GPU, sharing the same instruction stream but processing different data. This mechanism is also called a single instruction multiple data model or a single instruction multiple thread model. The GPU scheduling unit schedules in units of warps rather than single threads, which means that the entire warp will be assigned to a processor for parallel execution. If all threads in the warp take the same branch path, they will continue to execute synchronously. However, if the threads have different paths on the branch, the warp will execute each path, but not all threads will be active on each path, which may lead to decreased efficiency because even if some threads are idling, the entire warp must wait for the path to complete. For example, to simulate the effect of sunlight passing through a forest, each ray of light can be thought of as a thread. Suppose you need to trace one million rays, that is, start one million threads. When these threads are started on the GPU, they are automatically grouped. Each group contains 32 threads, that is, a warp, and there will be a total of about 31,250 warps. Since the threads in each warp execute the same instructions, these one million rays will be processed in parallel efficiently. When one warp is calculating whether a ray of light intersects with the leaves, other warps may be processing the interaction of other rays with tree trunks or the ground. Suppose that most of the threads in a warp calculate rays that do not intersect with the leaves, but a few threads calculate rays that intersect with the leaves. In this case, the entire warp will execute along the path that intersects with the leaves, even if most of the threads are actually idling, which may result in reduced efficiency.
[0060] A data block is a function that encapsulates a piece of data and can be called and executed elsewhere in the simulation computing program. A data block is composed of multiple threads. The number of data blocks can include the number of data blocks specified in the simulation computing program, and the number of threads can include the number of threads in each data block.
[0061] In some embodiments, different storage stacks are created according to different particles in the simulation calculation process, which improves the parallelism of the push operation and reduces the simulation branches caused by the particle types. Different storage stacks are created according to different data blocks in the simulation calculation process, which greatly improves the parallelism of the push operation. Different particles can include: photons, electrons and positrons, and the number of storage stacks created depends on the number of data blocks.
[0062] Step S102: Pop the storage stack according to the rules to keep the particle types consistent in each simulation.
[0063] As a data structure, a storage stack is a linear table with restricted operations. The restriction is that insertion and deletion operations are only allowed at one end of the table. This end is called the top of the stack, and the other end is called the bottom of the stack. It stores data according to the first-in-last-out principle. The first data entered is pushed to the bottom of the stack, and the last data is at the top of the stack. When data needs to be read, data is popped from the top of the stack. Inserting new data into a storage stack is also called pushing the stack, which is to put the new data on top of the stack data to make it the new top data. Deleting data from a storage stack is also called popping the stack, which is to delete the top data of the stack so that the adjacent data becomes the new top data of the stack.
[0064] As an optional implementation, the total number of particles in the storage stack is counted based on a certain time interval, and the corresponding popping threshold is determined according to the size of the storage stack. Furthermore, if the size of the storage stack exceeds the popping threshold, the particle type corresponding to the storage stack is prioritized, and a set of popping rules is established to ensure that the particle types simulated each time are the same as much as possible, thereby reducing the waiting caused by different particle types. For example, assuming that a data block photon storage stack reaches the popping threshold, all data blocks will select photons for popping, and all simulated data will be photons. There will be no situation where some data blocks simulate photons while other data blocks simulate electrons.
[0065] Step S103 , balancing the difference in the number of particles between storage stacks in different data blocks.
[0066] All threads in each data block execute in parallel on the GPU, sharing the same instruction stream but processing different data. If all threads take the same branch path, they will continue to execute synchronously. However, if the threads have different paths on the branch, each path will be executed, but not all threads will be active on every path, because even if some threads are idling, they must wait for the path to complete. Each data block simulates particles equal to the number of threads at the same time. When the number of particles in the storage stack in the data block is less than the number of threads, it is inevitable that some threads will be idling. After a long simulation time, the number of particles in the storage stacks in different data blocks will be significantly different, resulting in some data blocks' storage stacks being empty, while other data blocks' storage stacks still have a considerable number of particles. At this time, the threads in the data blocks of the space-time storage stack are idling, affecting efficiency.
[0067] As an implementation method, a set of inter-storage stack balancing rules is established to greatly reduce thread idling caused by differences in the number of particles in storage stacks within different data blocks. The number of particles in the storage stack is counted at regular intervals. When the difference between the maximum and minimum number of particles in a storage stack exceeds a certain threshold, an inter-storage stack balancing operation is triggered, and some particles from a storage stack with more particles are transferred to a storage stack with fewer particles.
[0068] Step S104: adding a new batch of particles to the storage stack generated in the late stage of the batch simulation calculation process.
[0069] Due to memory limitations, particles can only be divided into multiple batches for GPU simulation. The conventional approach is to write a loop to wait until one batch of particles is simulated before starting the next batch. However, due to the large difference in particle lifespans mentioned above, a large number of threads will idle in the later stages of the simulation. Therefore, the size of the GPU's video memory is very important to the computational efficiency of the present invention. Larger video memory can increase the number of parallel threads and the size of the storage stack, thereby improving efficiency.
[0070] The Monte Carlo method is a numerical calculation method based on random numbers, which is often used to simulate the multiple scattering and single scattering processes of particles. In the multiple scattering process, the particle collides with the atoms or molecules in the medium multiple times, which changes the direction and energy of the particle. The initial position and initial energy of the particle in the medium are determined. According to the properties of the medium and the probability of interaction between the particle and the medium, an interaction process is randomly selected. According to the selected interaction process, the scattering angle and energy loss of the particle in the process are calculated, the position and energy of the particle are updated, and the above steps are repeated until the specified number of simulations is reached or other termination conditions are met. In the single scattering process, the particle collides with an atom or molecule in the medium once, which changes the direction and energy of the particle. The initial position and initial energy of the particle in the medium are determined. According to the properties of the medium and the probability of interaction between the particle and the medium, an interaction process is randomly selected. According to the selected interaction process, the scattering angle and energy loss of the particle in the process are calculated, and the position and energy of the particle are updated.
[0071] The Monte Carlo method is also the most commonly used method for studying random problems. In the simulation calculation process, the issue of the number of samplings is involved. It is generally believed that the more sampling times, the better. However, the more sampling times, the greater the computational workload, which will eventually make the analysis impossible. Therefore, in the simulation calculation process, we also hope that the number of samplings is as small as possible.
[0072] To this end, a set of storage stack replenishment rules is established to avoid idling threads in the later stages of each batch due to batch simulation. The number of particles in the storage stack is counted at regular intervals. When the minimum number of particles in the storage stack is less than a certain threshold, the simulation of the next batch of particles begins immediately, thus avoiding thread idling.
[0073] Step S105: If there are idle threads in all data blocks in the later stage of simulation, the data blocks are merged.
[0074] As an implementation method, if there are idle threads in all data blocks in the later stage of simulation, the first data block and the corresponding second data block are determined. However, in the later stage of simulation, as the number of sampling times of the Monte Carlo method increases, the number of particles in all data blocks is less than the number of threads, and idling threads will inevitably occur, affecting efficiency.
[0075] In some embodiments, a set of storage stack merging rules is established to reduce thread idling in the later stages of the simulation. The first data block is paired with the second data block, all particles in the second data block are transferred to the first data block, and the second data block is deleted. At this time, the storage stack merging rules are triggered to transfer particles in some data blocks to other data blocks, and the empty data blocks are canceled, thereby reducing thread idling in the data blocks that are still running. For example, specifically, the i-th data block is paired with the i+number of data blocks / 2 data blocks, all particles in the i+number of data blocks / 2 data blocks are transferred to the i-th data block, and then the i+number of data blocks / 2 data blocks are canceled. In this way, the number of data blocks is halved, the average number of particles in the data blocks is increased, and computational efficiency is improved.
[0076] In the embodiment of the present application, different storage stacks are created according to different particles and different data blocks in the simulation calculation process, and the storage stack is popped according to the rules to keep the particle type consistent in each simulation, balance the difference in the number of particles between the storage stacks in different data blocks, and add a new batch of particles to the storage stack generated in the late simulation during the batch simulation calculation process. If there are idle threads in all data blocks in the late simulation, the data blocks are merged, and different storage stacks are created for different particles in the simulation calculation process, thereby improving the parallelism of the stacking operation and reducing the simulation branches caused by the particle type. Different data blocks are divided into Do not create different storage stacks, which greatly improves the parallelism of the push operation, establish a set of pop rules, and make the particle types of each simulation as similar as possible to reduce the waiting caused by different particle types, establish a set of storage stack balance rules, and greatly reduce the thread idling caused by the difference in the number of particles in the storage stacks in different data blocks, establish a set of storage stack supplement rules to avoid the thread idling in the later stage of each batch due to batch simulation, and establish a set of storage stack merging rules to reduce the thread idling in the later stage of simulation. Through carefully designed storage stack operations, the calculation speed of GPU Monte Carlo is greatly improved, which is two to three times faster than traditional methods.
[0077] Figure 2 This is a flow chart of balancing the difference in the number of particles between storage stacks in different data blocks disclosed in an embodiment of the present application, which also includes the following steps:
[0078] Step S201: determining a corresponding balance threshold according to the size of the storage stack.
[0079] The number of GPU threads is limited, and only the number of data blocks multiplied by the number of threads is simulated at the same time. The other particles are stored in the particle storage stack. Whether the number of particles between storage stacks is balanced depends on the number of particles in the storage stack. Therefore, before judging whether the storage stack meets the trigger condition, the status of the storage stack needs to be determined.
[0080] Step S202 : If the difference between the maximum total number of particles and the minimum total number of particles in the storage stack is greater than the balance threshold, the storage stack is sorted according to the total number of particles in the storage stack.
[0081] As an optional implementation, the difference between the maximum total number of particles and the minimum total number of particles in the storage stack compared to the size of the storage stack determines whether to trigger the inter-storage stack balancing operation. Compared with the balance threshold, if the difference between the maximum total number of particles and the minimum total number of particles in the storage stack is greater than the balance threshold, the next inter-storage stack balancing operation is triggered. If the difference between the maximum total number of particles and the minimum total number of particles in the storage stack is less than the balance threshold, the original working state is maintained. The difference between the maximum total number of particles and the minimum total number of particles in the storage stack compared to the balance threshold is the triggering condition for the inter-storage stack balancing operation.
[0082] Step S203 : determining a first storage stack and a corresponding second storage stack according to the total number of particles in the storage stack.
[0083] After a long simulation, the number of particles in the storage stacks of different data blocks will vary significantly, resulting in some data blocks' storage stacks being empty while others still have a large number of particles. Therefore, the inter-stack balancing operation is to transfer some particles from the storage stack with a large number of particles to the storage stack with a small number of particles. This is the transfer of the number of particles between the two storage stacks. To do this, it is necessary to determine the storage stack with a large number of particles as the first storage stack and the storage stack with a small number of particles as the second storage stack.
[0084] Specifically, after all storage stacks are sorted by the number of particles, it is possible to accurately determine which storage stacks have a larger number of particles and which storage stacks have a smaller number of particles.
[0085] Step S204: Pair the first storage stack with the second storage stack.
[0086] In some embodiments, after determining which storage stacks have a larger number of particles and which storage stacks have a smaller number of particles by sorting all storage stacks by the number of particles, accurate rules are required to pair the first storage stack and the second storage stack in pairs in order to keep the degree to which the first storage stack has a larger number of particles consistent with the degree to which the second storage stack has a smaller number of particles. Specifically, in actual simulation calculations, the i-th storage stack and the i-th to-last storage stack after sorting by the number of particles are usually paired, where the i-th storage stack is the first storage stack and the i-th to-last storage stack is the second storage stack.
[0087] Step S205 : determining the number of particles to be transferred according to the difference between the total number of particles in the first storage stack and the total number of particles in the second storage stack.
[0088] In some embodiments, the difference between the total number of particles in the first storage stack and the total number of particles in the second storage stack is an important determinant for determining the number of particles transferred. The number of particles transferred between the first storage stack and the second storage stack is an important parameter for the balancing operation between the storage stacks. Specifically, in actual simulation calculations, the number of n / 2 particles in the i-th storage stack is usually determined as the number of particles transferred, where n is the difference in the number of particles between the i-th storage stack and the i-th to last storage stack.
[0089] Step S206 , transferring some particles from the first storage stack to the second storage stack.
[0090] After determining the number of particles to be transferred between the first storage stack and the second storage stack, n / 2 particles of the i-th storage stack are transferred to the i-th storage stack from the end, where n is the difference in the number of particles between the i-th storage stack and the i-th storage stack from the end.
[0091] In an embodiment of the present application, the total number of particles in a storage stack is counted based on a certain time interval, and a corresponding balance threshold is determined based on the size of the storage stack. If the difference between the maximum total number of particles and the minimum total number of particles in the storage stack is greater than the balance threshold, the storage stacks are sorted based on the total number of particles in the storage stacks, a first storage stack and a corresponding second storage stack are determined based on the total number of particles in the storage stacks, the first storage stack and the second storage stack are paired, and the number of particles to be transferred is determined based on the difference between the total number of particles in the first storage stack and the total number of particles in the second storage stack, and some particles from the first storage stack are transferred to the second storage stack. This solves the problem of idling threads in data blocks in empty storage stacks due to significant differences in the number of particles in storage stacks in different data blocks in the later stages of the simulation, thereby improving the efficiency of the simulation calculation.
[0092] See also Figure 3 , Figure 3 This is a schematic diagram of a process for adding a new batch of particles to a storage stack generated in the later stages of a batch simulation process disclosed in an embodiment of the present application. In one embodiment, if the minimum total number of particles in the storage stack is less than a replenishment threshold, the next batch of particles is immediately simulated and calculated. Before adding the next batch of particles to the storage stack, the following steps are also included:
[0093] Step S301: determining a corresponding supplement threshold according to the size of the storage stack.
[0094] The number of GPU threads is limited, and only the number of data blocks multiplied by the number of threads can be simulated at the same time. The remaining particles are stored in the particle storage stack. Whether the number of particles in the storage stack needs to be replenished depends on the size of the storage stack. Therefore, before determining whether the storage stack meets the trigger condition, the status of the storage stack needs to be determined.
[0095] Step S302: determining the particle energy of the particles in the storage stack.
[0096] In some embodiments, particle lifetime is positively correlated with particle energy. Particle lifetime refers to the time it takes for a particle to be transported to the next collision. Particle lifetime is a statistic that reflects the characteristics of a large number of particles.
[0097] Step S303: sort the particles according to their energy.
[0098] As an optional implementation, when replenishing particles to the storage stack, the particles are first sorted by energy. For example, the flux is used as the particle source, and the incident particles are sampled. Each sampling is a batch of incident particles. The incident particles are sorted by energy. The GPU Monte Carlo simulates the behavior of the particles in the patient's body. The status of the storage stack in each data block is counted at intervals. According to the storage stack status and the popping rules of the present invention, the type of particles popped each time is determined. According to the storage stack status, when the trigger condition is met, the storage stack balancing operation is performed. According to the storage stack status, when the trigger condition is met, the storage stack replenishment operation is performed. According to the storage stack status, when the trigger condition is met, the storage stack merging operation is performed. The simulation ends and the dose distribution in the patient's body is output.
[0099] In step S304 , if the minimum total number of particles in the storage stack is less than the replenishment threshold, the next batch of particles is immediately simulated and calculated, and the next batch of particles is replenished into the storage stack.
[0100] In some embodiments, the minimum total number of particles in the storage stack compared to the size of the storage stack determines whether to trigger a storage stack replenishment operation. Compared with the replenishment threshold, if the minimum total number of particles in the storage stack is greater than the replenishment threshold, the next storage stack replenishment operation is triggered. If the minimum total number of particles in the storage stack is less than the replenishment threshold, the original working state is maintained. The size of the minimum total number of particles in the storage stack compared to the replenishment threshold is the triggering condition for the storage stack replenishment operation.
[0101] See also Figure 4 , Figure 4 This is a schematic diagram of the structure of a GPU Monte Carlo acceleration device disclosed in an embodiment of the present application. The device can be applied to electronic devices. Figure 4 As shown, the GPU Monte Carlo acceleration device 400 may include: a creation module 401, a pop module 402, a balance module 403, a supplement module 404 and a merging module 405.
[0102] A creation module 401 is used to create different storage stacks for different particles and different data blocks in the simulation calculation process;
[0103] A pop module 402 is used to perform a pop operation on the storage stack according to the rules to keep the particle types consistent in each simulation;
[0104] A balancing module 403 is used to balance the difference in the number of particles between storage stacks in different data blocks;
[0105] A replenishment module 404 is used to replenish a new batch of particles into the storage stack generated in the late stage of the batch simulation calculation process;
[0106] The merging module 405 is configured to merge data blocks if idle threads exist in all data blocks in the later stage of simulation.
[0107] In one embodiment, the creation module 401 further includes a first creation unit and a second creation unit:
[0108] A first creation unit is used to create different storage stacks according to different particles in the simulation calculation process;
[0109] The second creating unit is used to create different storage stacks according to different data blocks in the simulation calculation process.
[0110] In one embodiment, the pop module 402 further includes a counting unit, a first determining unit, and a processing unit:
[0111] A statistical unit, used to count the total number of particles in the storage stack based on a certain time interval;
[0112] A first determining unit, configured to determine a corresponding popping threshold according to the size of the storage stack;
[0113] The processing unit is configured to give priority to processing the particle type corresponding to the storage stack if the size of the storage stack exceeds a popping threshold.
[0114] In one embodiment, the balancing module 403 further includes a second determining unit, a first sorting unit, a third determining unit, a first pairing unit, a fourth determining unit, and a first transferring unit:
[0115] A second determining unit, configured to determine a corresponding balance threshold according to the size of the storage stack;
[0116] a first sorting unit, configured to sort the storage stack according to the total number of particles in the storage stack if a difference between the maximum total number of particles and the minimum total number of particles in the storage stack is greater than a balance threshold;
[0117] a third determining unit, configured to determine a first storage stack and a corresponding second storage stack according to the total number of particles in the storage stack;
[0118] a first pairing unit, configured to pair the first storage stack with the second storage stack;
[0119] a fourth determining unit, configured to determine the number of particles to be transferred according to a difference between the total number of particles in the first storage stack and the total number of particles in the second storage stack;
[0120] The first transfer unit is used to transfer some particles from the first storage stack to the second storage stack.
[0121] In one embodiment, the supplementing module 404 further includes a fifth determining unit and a supplementing unit:
[0122] a fifth determining unit, configured to determine a corresponding supplement threshold value according to a size of the storage stack;
[0123] The replenishment unit is used to immediately simulate and calculate the next batch of particles and replenish the next batch of particles into the storage stack if the minimum total number of particles in the storage stack is less than the replenishment threshold.
[0124] In one embodiment, the supplement module 404 further includes a sixth determining unit, a second sorting unit, and an allocating unit:
[0125] a sixth determining unit, configured to determine particle energies of particles in the storage stack;
[0126] a second sorting unit, for sorting particles according to particle energy;
[0127] The distribution unit is used to distribute particles with similar particle energies into the same warp yarn.
[0128] In one embodiment, the merging module 405 further includes a seventh determining unit, a second pairing unit, a second transferring unit, and a deleting unit:
[0129] a seventh determining unit, configured to determine the first data block and the corresponding second data block if idle threads exist in all data blocks in the later stage of the simulation;
[0130] a second pairing unit, configured to pair the first data block with the second data block;
[0131] a second transfer unit, configured to transfer all particles of the second data block to the first data block;
[0132] The deleting unit is used to delete the second data block.
[0133] See also Figure 5 , Figure 5 This is a schematic diagram of the structure of an electronic device disclosed in an embodiment of the present application. Figure 5 As shown, the electronic device 500 may include:
[0134] A memory 501 storing executable program code;
[0135] a processor 502 coupled to the memory 501;
[0136] Among them, the processor 502 calls the executable program code stored in the memory 501 to execute any one of the GPU Monte Carlo acceleration methods based on stack processing disclosed in the embodiments of the present application.
[0137] An embodiment of the present application discloses a computer-readable storage medium storing a computer program, wherein when the computer program is executed by the processor, the processor implements any one of the stack processing-based GPU Monte Carlo acceleration methods disclosed in the embodiment of the present application.
[0138] The embodiments of the present application disclose a computer program product, including a computer program, and the computer program can be executed by a processor to implement the methods described in the above embodiments.
[0139] It should be understood that the references to "one embodiment" or "an embodiment" throughout the specification mean that the specific features, structures, or characteristics associated with the embodiment are included in at least one embodiment of the present application. Therefore, the references to "in one embodiment" or "in an embodiment" throughout the specification do not necessarily refer to the same embodiment. In addition, these specific features, structures, or characteristics may be combined in any suitable manner in one or more embodiments. Those skilled in the art should also be aware that the embodiments described in the specification are all optional embodiments, and the actions and modules involved are not necessarily required for the present application.
[0140] In the various embodiments of the present application, it should be understood that the size of the serial numbers of the above-mentioned processes does not necessarily mean the order of execution. The order of execution of each process should be determined by its function and internal logic, and should not constitute any limitation on the implementation process of the embodiments of the present application.
[0141] The units described above as separate components may or may not be physically separate, and the components shown as units may or may not be physical units, i.e., they may be located in one place or distributed across multiple network units. Some or all of these units may be selected based on actual needs to achieve the objectives of this embodiment.
[0142] In addition, the functional units in the embodiments of the present application may be integrated into a single processing unit, or each unit may exist physically separately, or two or more units may be integrated into a single unit. The aforementioned integrated units may be implemented in the form of hardware or software functional units.
[0143] If the above-mentioned integrated unit is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a computer-accessible memory. Based on this understanding, the technical solution of the present application, or the part that contributes to the prior art, or all or part of the technical solution, can be embodied in the form of a software product. The computer software product is stored in a memory and includes several requests for causing a computer device (which can be a personal computer, server, or network device, etc., specifically a processor in the computer device) to execute some or all of the steps of the above-mentioned methods in various embodiments of the present application.
[0144] Those skilled in the art will appreciate that all or part of the steps in the various methods of the above embodiments can be completed by instructing related hardware through a program. The program can be stored in a computer-readable storage medium, including a read-only memory (ROM), a random access memory (RAM), a programmable read-only memory (PROM), an erasable programmable read-only memory (EPROM), a one-time programmable read-only memory (OTPROM), an electronically erasable programmable read-only memory (EEPROM), a compact disc read-only memory (CD-ROM), or other optical disc storage, magnetic disk storage, magnetic tape storage, or any other computer-readable medium capable of carrying or storing data.
[0145] The above is a detailed introduction to a GPU Monte Carlo acceleration method based on stack processing disclosed in an embodiment of the present application. Specific examples are used herein to illustrate the principles and implementation methods of the present application. The description of the above embodiments is only used to help understand the method and core idea of the present application. At the same time, for those skilled in the art, according to the ideas of the present application, there may be changes in the specific implementation methods and application scopes. In summary, the contents of this specification should not be understood as limiting the present application.
Claims
1. A GPU Monte Carlo acceleration method based on stack processing, characterized in that: Applied to electronic equipment, the method includes: Create different storage stacks according to different particles and different data blocks in the simulation calculation process; Performing a pop operation on the storage stack according to a rule to keep the particle type consistent in each simulation; balancing the difference in the number of particles between the storage stacks in different data blocks; Adding a new batch of particles to the storage stack at a later stage of the simulation during batch simulation calculation; If there are idle threads in all the data blocks at the end of the simulation, then merge the data blocks; The step of performing a pop operation on the storage stack according to a rule to keep the particle types consistent in each simulation includes: Counting the total number of particles in the storage stack based on a certain time interval; Determine a corresponding pop threshold value according to the size of the storage stack; If the size of the storage stack exceeds the popping threshold, the particle type corresponding to the storage stack is processed first; The balancing of the difference in the number of particles between the storage stacks in different data blocks includes: Determining a corresponding balance threshold according to the size of the storage stack; If the difference between the maximum total number of particles and the minimum total number of particles in the storage stack is greater than the balance threshold, sorting the storage stack according to the total number of particles in the storage stack; determining a first storage stack and a corresponding second storage stack according to the total number of particles in the storage stack; pairing the first storage stack with the second storage stack; determining a transferred number of the particles according to a difference between the total number of the particles in the first storage stack and the total number of the particles in the second storage stack; transferring a portion of the particles in the first storage stack to the second storage stack; If idle threads exist in all the data blocks in the later stage of the simulation, merging the data blocks includes: If idle threads exist in all the data blocks at the end of the simulation, determining the first data block and the corresponding second data block; pairing the first data block with the second data block; transferring all the particles of the second data block to the first data block; Delete the second data block.
2. The GPU Monte Carlo acceleration method based on stack processing according to claim 1, characterized in that: The process of creating different storage stacks according to different particles and different data blocks in the simulation calculation process includes: Create different storage stacks according to different particles in the simulation calculation process; Create different storage stacks according to different data blocks in the simulation calculation process; The different particles include photons and electrons; the number of storage stacks is the number of data blocks.
3. The GPU Monte Carlo acceleration method based on stack processing according to claim 1, characterized in that: The step of adding a new batch of particles to the storage stack generated in the late stage of the batch simulation calculation process includes: Determining a corresponding supplement threshold according to the size of the storage stack; If the minimum total number of particles in the storage stack is less than the replenishment threshold, the next batch of particles is immediately simulated and calculated, and the next batch of particles is replenished into the storage stack.
4. The GPU Monte Carlo acceleration method based on stack processing according to claim 3, characterized in that: Before immediately simulating and calculating the next batch of particles if the minimum total number of particles in the storage stack is less than the replenishment threshold and replenishing the next batch of particles into the storage stack, the method further includes: determining particle energies of the particles in the storage stack; The particles are sorted according to their energy.
5. A GPU Monte Carlo acceleration device based on stack processing, characterized in that: The method according to any one of claims 1 to 4 is applied, wherein the device comprises: A creation module is used to create different storage stacks according to different particles and different data blocks in the simulation calculation process; A popping module, configured to perform a popping operation on the storage stack according to a rule, so as to keep the particle types consistent in each simulation; a balancing module, configured to balance the difference in the number of particles between the storage stacks in different data blocks; A replenishment module, for replenishing a new batch of particles into the storage stack generated in the late stage of the simulation during the batch simulation calculation process; The merging module is used to merge the data blocks if there are idle threads in all the data blocks in the later stage of simulation.
6. An electronic device, characterized in that: It includes a memory and a processor, wherein a computer program is stored in the memory, and when the computer program is executed by the processor, the processor implements a GPU Monte Carlo acceleration method based on stack processing as described in any one of claims 1 to 4.
7. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, a GPU Monte Carlo acceleration method based on stack processing is implemented as described in any one of claims 1 to 4.
Citation Information
Patent Citations
GPU acceleration Monte Carlo simulation method and device for human body model, equipment and medium
CN118446877A
GPU parallel acceleration Monte Carlo method for magnetofluid microstructure simulation
CN118502962A