GPU Monte Carlo acceleration method based on stack processing

By adopting the stack-based GPU Moncara acceleration method in radiation therapy, the problem of the Monte Carlo method being calculated for too long is solved, and a significant calculation speed is achieved, which is suitable for the promotion of dose calculation of clinical treatment plan.

CN119623220AActive Publication Date: 2025-03-14GUANGZHOU RAYDOSE MEDICAL TECH CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202411714025.8
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-11-27
Publication Date
2025-03-14
Estimated Expiration
2044-11-27

AI Technical Summary

Technical Problem

When the Monte Carlo method is used to calculate the radiation absorption dose in radiation therapy, the calculation time is too long, which limits its application and promotion in the calculation of doses of clinical treatment plans.

Method used

The GPU Moncara acceleration method based on stack processing is adopted to improve the computing speed of GPU Moncara by creating storage stacks of different particles and data blocks.

Benefits of technology

Compared with traditional methods, the GPU Moncara acceleration method based on stack processing can significantly improve the computing speed, increasing the speed by two to three times.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119623220A_ABST
    Figure CN119623220A_ABST
Patent Text Reader

Abstract

The embodiment of the invention discloses a stack processing-based GPU Monte Carlo acceleration method. The method comprises the following steps of: respectively creating different storage stacks for different particles and different data blocks in a simulation calculation process; according to the rule, performing a stack-out operation on the storage stack, and keeping the particle types of each simulation consistent; balancing the difference of the number of particles among the storage stacks in different data blocks; supplementing a new batch of particles into an idle thread in a storage stack generated in a simulation later period in a batch simulation calculation process; if idle threads exist in all the data blocks in the later simulation period, the data blocks are merged. According to the embodiment of the invention, the calculation speed of the GPU Monte Carlo is greatly improved through well-designed storage stack operation, and compared with a traditional method, the speed is improved by two to three times.
Need to check novelty before this filing date? Find Prior Art

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, due to the long operation time, its application and promotion in clinical treatment plan dose calculation is limited. GPU general computing can handle a large number of computing tasks at the same time 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 method of using random numbers to solve many computing problems, or more commonly using pseudo-random numbers to solve computing 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 embodiment discloses a GPU Monte Carlo acceleration method based on stack processing, which is applied to electronic devices. The method includes: Different storage stacks are created 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 generated in the late stage of the simulation during batch simulation calculation; If there are idle threads in all the data blocks at the end of the simulation, the data blocks are merged.

[0005] As an optional implementation manner, the 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, electrons and positrons; the number of storage stacks is the number of data blocks.

[0006] 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: Counting the total number of particles in the storage stack based on a certain time interval; Determine a corresponding stack popping threshold according to the size of the storage stack; If the size of the storage stack exceeds the stack popping threshold, the particle type corresponding to the storage stack is processed preferentially.

[0007] As an optional implementation manner, balancing 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; Determine 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 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; A portion of the particles in the first storage stack is transferred to the second storage stack.

[0008] As an optional implementation, 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.

[0009] As an optional implementation, before replenishing the next batch of particles into the storage stack, the method further includes: determining a particle energy of the particles in the storage stack; The particles are sorted according to their energies.

[0010] As an optional implementation manner, if there are idle threads in all the data blocks in the later stage of simulation, merging the data blocks includes: If there are idle threads 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.

[0011] The present application embodiment discloses a GPU Monte Carlo acceleration device based on stack processing, the device comprising: A creation module is used to create different storage stacks according to different particles and different data blocks in the simulation calculation process; A pop module, used for performing a pop operation on the storage stack according to a rule, so as to keep the particle type consistent in each simulation; A balancing module, used for balancing the difference in the number of particles between the storage stacks in different data blocks; A replenishment module, used 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.

[0012] An embodiment of the present application discloses an electronic device, including a memory and a processor, wherein the memory stores a computer program, and when the computer program is executed by the processor, the processor implements any one of the GPU Monte Carlo acceleration methods based on stack processing disclosed in the embodiment of the present application.

[0013] An embodiment of the present application discloses a computer-readable storage medium storing a computer program, wherein when the computer program is executed by a processor, any one of the GPU Monte Carlo acceleration methods based on stack processing disclosed in the embodiment of the present application is implemented.

[0014] Compared with the related art, the embodiments of the present application have the following beneficial effects: 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 a pop operation on the storage stack according to the rules, keeps the type of particles consistent for 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 stack 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 implementing the embodiments of the present application, different storage stacks are created for different particles in the simulation calculation process, so as to improve the parallelism of the stack push operation and reduce the simulation branches caused by the particle types. Different storage stacks are created for different data blocks, so as to greatly improve the parallelism of the stack push operation. A set of pop rules are established to make the particle types of each simulation as similar as possible, so as to reduce the waiting caused by different particle types. A set of storage stack balance rules are established to greatly reduce the thread idling caused by the difference in the number of particles in the storage stacks in different data blocks. A set of storage stack supplement rules are established to avoid the idling of threads in the later stage of each batch due to batch simulation. When supplementing 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 are established to reduce the thread idling in the later stage of the simulation. Through the carefully designed storage stack operation, the calculation speed of GPU Monte Carlo is greatly improved, which is two to three times faster than the traditional method. BRIEF DESCRIPTION OF THE DRAWINGS

[0015] In order to more clearly illustrate the technical solutions in the embodiments of the present application, the drawings required for use in the embodiments will be briefly introduced below. 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 paying creative work.

[0016] Figure 1 It is a flowchart of a GPU Monte Carlo acceleration method based on stack processing disclosed in an embodiment of the present application; Figure 2 It 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; Figure 3 It is a schematic diagram of the process of supplementing a new batch of particles into a storage stack generated in the late stage of the simulation in the batch simulation calculation process disclosed in the embodiment of the present application; Figure 4 It is a structural schematic diagram of a GPU Monte Carlo acceleration device based on stack processing disclosed in an embodiment of the present application; Figure 5 It is a structural schematic diagram of an electronic device disclosed in an embodiment of the present application. DETAILED DESCRIPTION

[0017] The following will be combined with the drawings in the embodiments of the present application to clearly and completely describe the technical solutions in the embodiments of the present application. Obviously, the described embodiments are only part of the embodiments of the present application, not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of this application.

[0018] It should be noted that the terms "including" and "having" and any variations thereof in the embodiments of the present application and the accompanying drawings are intended to cover non-exclusive inclusions. For example, a process, method, system, product or device including 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 these processes, methods, products or devices.

[0019] It is understood that the terms "first", "second", etc. used in this application may be used herein 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, without departing from the scope of this application, 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. Both the first storage stack and the second storage stack are storage stacks, but they are not the same storage stack.

[0020] The embodiment of the present application discloses a GPU Monte Carlo acceleration method based on stack processing, which greatly improves the GPU Monte Carlo calculation speed by a well-designed storage stack operation, and is two to three times faster than the traditional method. Detailed descriptions are given below.

[0021] See also Figure 1 , Figure 1 : 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: Step S101, creating different storage stacks according to different particles and different data blocks in the simulation calculation process.

[0022] In GPU computing, threads in the same warp execute the same instruction stream. If there are branches during the execution process, 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 computing process to improve the parallelism of the push operation and reduce 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.

[0023] 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 is scheduled 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 of light, which means you start one million threads. When these threads are started on the GPU, they are automatically grouped, each group containing 32 threads, or one warp, for a total of about 31,250 warps. Since the threads in each warp execute the same instructions, the one million rays of light are efficiently processed in parallel. While one warp is calculating whether a ray of light intersects with a leaf, other warps may be processing the interaction of other rays with tree trunks or the ground. Suppose most of the rays calculated by threads in a warp do not intersect with the leaves, but rays calculated by several threads do intersect with the leaves. In this case, the entire warp will execute along the path that intersects with the leaves, even though most of the threads are actually idling, which may result in reduced efficiency.

[0024] 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.

[0025] In some embodiments, different storage stacks are created according to different particles in the simulation calculation process, which improves the parallelism of the stacking 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 stacking operation. Different particles may include: photons, electrons and positrons, and the number of storage stacks created depends on the number of data blocks.

[0026] Step S102, performing a pop operation on the storage stack according to the rules to keep the particle types consistent in each simulation.

[0027] 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 putting the new data on top of the data on the top of the stack to make it the new top data. Deleting data from a storage stack is also called popping the stack, which is deleting the top data to make its adjacent data the new top data.

[0028] As an optional implementation, the total number of particles in the storage stack is counted based on a certain time interval, and the corresponding pop threshold is determined according to the size of the storage stack. Furthermore, if the size of the storage stack exceeds the pop threshold, the particle type corresponding to the storage stack is given priority, and a set of pop rules is established to make the particle types simulated each time as similar as possible, thereby reducing the waiting caused by different particle types. For example, assuming that a data block photon storage stack reaches the pop threshold, all data blocks select photons for popping, and all simulated are photons. There will be no situation where some data blocks simulate photons while other data blocks simulate electrons.

[0029] Step S103, balancing the difference in the number of particles between storage stacks in different data blocks.

[0030] 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 each 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 the storage stacks of some data blocks being empty, while the storage stacks of other data blocks still have quite a lot of particles. At this time, the threads in the data blocks of the space-time storage stack are idling, affecting efficiency.

[0031] As an implementation method, a set of storage stack balancing rules is established to greatly reduce thread idling caused by the difference in the number of particles in storage stacks in different data blocks. The number of particles in the storage stack is counted at regular intervals. When the difference between the maximum number of particles and the minimum number of particles in the storage stack is greater than a certain threshold, the storage stack balancing operation is triggered to transfer some particles of the storage stack with more particles to the storage stack with fewer particles.

[0032] Step S104, adding a new batch of particles to the storage stack generated in the late stage of the simulation during the batch simulation calculation process.

[0033] Due to memory limitations, particles can only be divided into multiple batches to enter GPU simulation. The conventional approach is to write a loop to wait for one batch of particles to be 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 memory is very important to the computational efficiency of the present invention. A larger memory can increase the number of parallel threads and the size of the storage stack, thereby improving efficiency.

[0034] The Monte Carlo method is a numerical calculation method based on random numbers, which is often used to simulate 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, determines the initial position and initial energy of the particle in the medium, and randomly selects an interaction process according to the properties of the medium and the probability of the particle interacting with the medium. 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, determines the initial position and initial energy of the particle in the medium, and randomly selects an interaction process according to the properties of the medium and the probability of the particle interacting with the medium. 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.

[0035] The Monte Carlo method is also the most commonly used method to study random problems. In the simulation calculation process, the issue of sampling times is involved. It is generally believed that the more sampling times, the better. However, the more sampling times, the greater the calculation workload, which will eventually make the analysis impossible. Therefore, in the simulation calculation process, we also hope that the sampling times are as small as possible.

[0036] To this end, a set of storage stack supplement rules is established to avoid idling of threads in the later stage 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 is started immediately to avoid idling of threads.

[0037] Step S105: If there are idle threads in all data blocks in the later stage of simulation, the data blocks are merged.

[0038] 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.

[0039] In some embodiments, a set of storage stack merging rules is established to reduce thread idling in the later stage of simulation. The first data block is paired with the second data block, all particles of 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 cancelled, thereby reducing the situation of 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 cancelled. In this way, the number of data blocks is halved and the average number of particles in the data blocks is increased, thereby increasing the computing efficiency.

[0040] 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 a pop operation is performed on the storage stack according to the rules to keep the particle type consistent for 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 stage of the simulation during the batch simulation calculation. If there are idle threads in all data blocks in the late stage of the 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 stack push operation and reducing the simulation branches caused by the particle type. Different data blocks are divided into Don't create different storage stacks, which greatly improves the parallelism of the push operation, establish a set of pop rules, try to make the particle types of each simulation the same, reduce the waiting caused by different particle types, establish a set of storage stack balance rules, 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 idling of threads in the later stage of each batch due to batch simulation, establish a set of storage stack merging rules to reduce the idling of threads in the later stage of simulation, and through carefully designed storage stack operations, greatly improve the calculation speed of GPU Monte Carlo, which is two to three times faster than traditional methods.

[0041] Figure 2 : 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, and further includes the following steps: Step S201, determining a corresponding balance threshold according to the size of the storage stack.

[0042] 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, it is necessary to determine the status of the storage stack.

[0043] 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.

[0044] 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 balancing operation between storage stacks. 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 balancing operation between storage stacks 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 continues to be 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 balancing operation between storage stacks.

[0045] Step S203: determining a first storage stack and a corresponding second storage stack according to the total number of particles in the storage stack.

[0046] 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 lot 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. For this purpose, it is necessary to determine the storage stack with a larger number of particles as the first storage stack, and the storage stack with a smaller number of particles as the second storage stack.

[0047] Specifically, after all storage stacks are sorted according to 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.

[0048] Step S204: pair the first storage stack with the second storage stack.

[0049] 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 ith storage stack and the ith-to-last storage stack sorted by the number of particles are usually paired, where the ith storage stack is the first storage stack and the ith-to-last storage stack is the second storage stack.

[0050] 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.

[0051] 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 determining factor in 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.

[0052] Step S206, transferring some particles in the first storage stack to the second storage stack.

[0053] After determining the number of particles to be transferred between the first storage stack and the second storage stack, n / 2 particles of the ith storage stack are transferred to the ith-to-last storage stack, where n is the difference in the number of particles between the ith storage stack and the ith-to-last storage stack.

[0054] In an embodiment of the present application, the total number of particles in the storage stack is counted based on a certain time interval, and the corresponding balance threshold is determined 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, the storage stack is sorted according to the total number of particles in the storage stack, and a first storage stack and a corresponding second storage stack are determined according to the total number of particles in the storage stack, and the first storage stack is paired with the second storage stack. The number of particles to be transferred is determined 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, and some particles of the first storage stack are transferred to the second storage stack, which solves the problem of thread idling of data blocks in an empty storage stack caused by significant differences in the number of particles in storage stacks in different data blocks in the later stage of simulation, thereby improving the efficiency of simulation calculations.

[0055] See also Figure 3 , Figure 3 This is a flow chart of replenishing a new batch of particles into a storage stack generated in the late stage of a batch simulation calculation 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 the replenishment threshold, the next batch of particles is immediately simulated and calculated, and before replenishing the next batch of particles into the storage stack, the following steps are also included: Step S301, determining a corresponding supplement threshold according to the size of the storage stack.

[0056] The number of GPU threads is limited, and only the number of data blocks multiplied by the number of threads particles are simulated at the same time. The other 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 judging whether the storage stack meets the trigger condition, the status of the storage stack needs to be determined.

[0057] Step S302, determining the particle energy of the particles in the storage stack.

[0058] 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.

[0059] Step S303, sorting the particles according to their energy.

[0060] As an optional implementation, when replenishing particles to the storage stack, the particles are first sorted by energy. For example, flux is used as the particle source, and the incident particles are sampled. Each sampling is a batch of incident particles, and the incident particles are sorted by energy. GPU Monte Carlo simulates the behavior of particles in the patient's body, and 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 to be popped each time is determined. According to the storage stack status, when the trigger condition is met, a balancing operation between storage stacks is performed. According to the storage stack status, when the trigger condition is met, a storage stack replenishment operation is performed. According to the storage stack status, when the trigger condition is met, a storage stack merging operation is performed. The simulation ends and the dose distribution in the patient's body is output.

[0061] 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.

[0062] 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 the 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 continues to be 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.

[0063] See also Figure 4 , Figure 4 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.

[0064] A creation module 401 is used to create different storage stacks for different particles and different data blocks in the simulation calculation process; 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; A balancing module 403 is used to balance the difference in the number of particles between storage stacks in different data blocks; A replenishment module 404 is used to replenish 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 405 is used to merge data blocks if there are idle threads in all data blocks in the later stage of simulation.

[0065] In one embodiment, the creation module 401 further includes a first creation unit and a second creation unit: A first creation unit is used to create different storage stacks according to different particles in the simulation calculation process; The second creating unit is used to create different storage stacks according to different data blocks in the simulation calculation process.

[0066] In one embodiment, the stack popping module 402 further includes a statistical unit, a first determining unit, and a processing unit: A statistical unit, used to count the total number of particles in the storage stack based on a certain time interval; A first determining unit, configured to determine a corresponding stack popping threshold according to a size of a storage stack; The processing unit is used to give priority to processing the particle type corresponding to the storage stack if the size of the storage stack exceeds the stack popping threshold.

[0067] 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: A second determining unit, configured to determine a corresponding balance threshold according to the size of the storage stack; A first sorting unit, configured to sort the storage stack according to the total number of particles in 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 a balance threshold; 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; A first pairing unit, configured to pair the first storage stack with the second storage stack; 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; The first transfer unit is used to transfer some particles of the first storage stack to the second storage stack.

[0068] In one embodiment, the supplementing module 404 further includes a fifth determining unit and a supplementing unit: a fifth determining unit, configured to determine a corresponding supplementary threshold value according to a size of the storage stack; 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.

[0069] In one embodiment, the supplement module 404 further includes a sixth determining unit, a second sorting unit, and an allocating unit: a sixth determining unit, configured to determine particle energies of particles in the storage stack; A second sorting unit is used to sort the particles according to particle energy; The distribution unit is used to distribute particles with similar particle energies into the same warp yarn.

[0070] 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: a seventh determining unit, configured to determine the first data block and the corresponding second data block if there are idle threads in all data blocks in the later stage of the simulation; A second pairing unit, configured to pair the first data block with the second data block; A second transfer unit, used for transferring all particles of the second data block to the first data block; The deleting unit is used to delete the second data block.

[0071] See also Figure 5 , Figure 5 Schematic diagram of the structure of an electronic device disclosed in the embodiment of the present application. Figure 5 As shown, the electronic device 500 may include: A memory 501 storing executable program codes; a processor 502 coupled to the memory 501; 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.

[0072] 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 GPU Monte Carlo acceleration methods based on stack processing disclosed in the embodiment of the present application.

[0073] 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.

[0074] It should be understood that the "one embodiment" or "an embodiment" mentioned throughout the specification means that the specific features, structures or characteristics related to the embodiment are included in at least one embodiment of the present application. Therefore, "in one embodiment" or "in an embodiment" appearing throughout the specification does not necessarily refer to the same embodiment. In addition, these specific features, structures or characteristics can be combined in one or more embodiments in any suitable manner. 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.

[0075] 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 execution order 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.

[0076] The units described above as separate components may or may not be physically separated, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed on multiple network units. Some or all of the units may be selected according to actual needs to achieve the purpose of the solution of this embodiment.

[0077] In addition, each functional unit in each embodiment of the present application may be integrated into one processing unit, or each unit may exist physically separately, or two or more units may be integrated into one unit. The above-mentioned integrated unit may be implemented in the form of hardware or in the form of software functional units.

[0078] 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, in essence, 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, which is stored in a memory and includes several requests for a computer device (which can be a personal computer, server or network device, etc., specifically a processor in a computer device) to perform some or all of the steps of the above-mentioned methods of various embodiments of the present application.

[0079] A person skilled in the art can understand 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, and the program can be stored in a computer-readable storage medium, and the storage medium includes 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 (CD-ROM) or other optical disc storage, magnetic disk storage, magnetic tape storage, or any other computer-readable medium that can be used to carry or store data.

[0080] 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 in this article 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 of ordinary skill in the art, according to the idea of ​​the present application, there will be changes in the specific implementation method and application scope. In summary, the content of this specification should not be understood as a limitation on the present application.

Claims

1. A GPU Monte Carlo acceleration method based on stack processing, characterized in that: Applied to electronic equipment, the method comprises: Different storage stacks are created 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, the data blocks are merged.

2. The GPU Monte Carlo acceleration method based on stack processing according to claim 1, characterized in that: The method 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, electrons and positrons; 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 performing a pop operation on the storage stack according to the rule to keep the particle type consistent in each simulation includes: Counting the total number of particles in the storage stack based on a certain time interval; Determine a corresponding stack popping threshold according to the size of the storage stack; If the size of the storage stack exceeds the stack popping threshold, the particle type corresponding to the storage stack is processed preferentially.

4. The GPU Monte Carlo acceleration method based on stack processing according to claim 1, characterized in that: The balancing 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; Determine 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 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; A portion of the particles in the first storage stack is transferred to the second storage stack.

5. The GPU Monte Carlo acceleration method based on stack processing according to claim 1, characterized in that: The method of replenishing a new batch of particles into 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.

6. The GPU Monte Carlo acceleration method based on stack processing according to claim 5, 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 a particle energy of the particles in the storage stack; The particles are sorted according to their energies.

7. The GPU Monte Carlo acceleration method based on stack processing according to claim 1, characterized in that: If there are idle threads in all the data blocks in the later stage of simulation, merging the data blocks includes: If there are idle threads 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.

8. A GPU Monte Carlo acceleration device based on stack processing, characterized in that: 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 pop module, used for performing a pop operation on the storage stack according to a rule, so as to keep the particle type consistent in each simulation; A balancing module, used for balancing the difference in the number of particles between the storage stacks in different data blocks; A replenishment module, used 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.

9. 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 7.

10. 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 7.

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