Particle index calculation method and device for CPU and GPU heterogeneous platforms
By adopting a multi-level particle index calculation method on a CPU+GPU heterogeneous platform, and through parallel accumulation at the block, warp and thread levels, the problems of data conflicts and low computational efficiency are solved, significantly reducing the particle index calculation time and improving calculation efficiency. efficiency.
Patent Information
- Application Number
- CN202410872065.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-07-01
- Publication Date
- 2024-09-03
- Estimated Expiration
- 2044-07-01
AI Technical Summary
On the CPU+GPU heterogeneous platform, the particle index calculation of the particle method has problems of data conflict and low calculation efficiency, which results in long calculation time, and the traditional method is inefficient and cannot effectively utilize the parallel computing power of the GPU.
A multi-level particle index calculation method is adopted to divide the grid units into block, warp and thread levels and perform accumulation operations in parallel to reduce data conflicts, optimize the calculation process and improve calculation efficiency.
It significantly reduces the particle index calculation time, improves the calculation efficiency on CPU and GPU heterogeneous platforms, reduces the calculation cost, and achieves more efficient particle method simulation.
Smart Images

Figure CN118394538B
Abstract
Description
Technical Field
[0001] The present invention mainly relates to the field of high performance computing technology, and in particular to a particle index calculation method and device for CPU and GPU heterogeneous platforms. Background Art
[0002] The operating airspace of spacecraft covers parts of the troposphere, stratosphere, mesosphere and thermosphere, and spans flow regions of different scales such as continuous flow, slip flow, transition flow and even free molecular flow. Traditional computational fluid dynamics methods are based on the continuous medium assumption and Fourier's law, and the governing equation is the Navier-Stokes equation. However, as the flight altitude of the spacecraft increases, the continuous medium assumption no longer holds. Therefore, traditional computational fluid dynamics methods cannot accurately simulate the external flow field of the spacecraft when the flight altitude reaches the transition flow region.
[0003] Therefore, particle methods such as the Direct Simulation Monte Carlo Method (DSMC) and the Unified Gas-Kinetic Wave-Particle (UGKWP) method have become important simulation methods in the design of reusable spacecraft. Since particle methods are highly data-dependent and often involve calculations at multiple spatial levels (such as velocity space and physical space), they are currently generally based on CPU architectures, and supercomputers are needed to simulate actual engineering problems.
[0004] Particle methods have large amounts of data and computation, and involve a large number of arithmetic operations. Although the CPU is powerful, it has a large number of logic units, and the proportion of arithmetic units is small. Therefore, when the CPU is used for the calculation of particle methods, there will be a lot of resource waste. When the amount of calculation is large, if a large-scale computing cluster is used, the computing cost will increase greatly, and supercomputers are expensive and have limited resources, so they cannot be popularized. The characteristics of particle simulation methods, which have more arithmetic operations and fewer logical operations, make the CPU+GPU heterogeneous parallel framework an effective solution. The main arithmetic operations are completed by the GPU, and a small amount of logical operations are completed on the CPU.
[0005] When implementing particle-based CFD simulation methods, it is necessary to divide the physical space of the entire flow field area into a series of grid units, and sample the parameters such as particle velocity, mass, and position in each unit grid. The movement and collision of particles will cause the number of particles in the grid unit to change frequently. When the sum of the parameters of the particles in this network unit cannot represent the physical quantity of the network unit, it is necessary to resample (resample) according to the physical quantity of the network unit to increase a part of the particles so that the total physical quantity of the particles can always represent the physical quantity of the unit. The physical quantity of each network unit is different from the number of particles, so the number of particles that need to be resampled is also different.
[0006] When executing the above process on a CPU+GPU heterogeneous framework, since each thread on the GPU processes the sampling (resample) process in a grid unit and writes it in the same particle array (called the "particle" array), and each thread of the GPU runs in parallel without data exchange, different threads will write to the particle array concurrently. In order to avoid different threads operating on the same memory area and causing data conflicts, each thread on the GPU needs to accumulate the number of newly sampled particles in the corresponding grid unit in sequence before the sampling (resample) process, in order to determine the starting index of the newly sampled particles in each network unit, and then determine the memory area operated by each thread based on the number of samples in each grid unit.
[0007] When executing serially on the CPU, there is no need to consider data conflicts; on CPU and GPU heterogeneous platforms, the generally used methods are inefficient and slow in calculation. Summary of the invention
[0008] In view of the technical problems existing in the prior art, the present invention proposes a particle index calculation method and device for CPU and GPU heterogeneous platforms.
[0009] To achieve the above purpose, the technical solution adopted by the present invention is as follows:
[0010] On the one hand, the present invention provides a particle index calculation method for CPU and GPU heterogeneous platforms, comprising:
[0011] The physical space of the entire flow field area simulated by the particle method running on the current GPU is divided into dataSize grid cells;
[0012] To be processed dataSize The resampled particle number array in the grid cells is divided into blockSize block data block;
[0013] Calculate the cumulative array within each block of data;
[0014] Take out the last data in the cumulative array of each block data block to perform inter-block calculation between block data blocks, and obtain the inter-block calculation result between block data blocks;
[0015] The inter-block calculation results between block data blocks are added to the data of the corresponding block data block's intra-block accumulation array in sequence to obtain the overall final accumulation result.
[0016] Furthermore, the intra-block cumulative array of each block data block is calculated, including:
[0017] The data in the block data block is divided into blocks of size Warp data block;
[0018] Execute the accumulation in each warp data block in parallel to obtain the intra-block accumulation array of each warp data block;
[0019] Take out the last data in the intra-block accumulation array of each warp data block for inter-warp block accumulation;
[0020] The inter-warp accumulation results are sequentially added to the data of the intra-block accumulation array of the corresponding warp data block to obtain the intra-block accumulation array of each block data block.
[0021] The accumulation within each warp data block includes: all warp data blocks contain the same number of threads, and thread-level accumulation within each warp data block is performed in parallel to obtain an intra-block accumulation array of each warp data block at the thread level.
[0022] Furthermore, the last data in the block accumulation array of each block data block is taken out to perform inter-block calculation between block data blocks, including:
[0023] Take out the last data in the cumulative array of each block data block, the total amount of data is , forming a block-block data block;
[0024] The data in the block-block data block is processed in blocks, and the data in the block-block data block is divided into block-warp data blocks of size warpSize;
[0025] Perform the accumulation in each block-warp data block in parallel to obtain the block accumulation array of each block-warp data block;
[0026] Take out the last data in the intra-block accumulation array of each block-warp data block and perform inter-block accumulation of the block-warp data block;
[0027] The inter-block accumulation results of each block-warp data block are added to the data of the intra-block accumulation array of the corresponding block-warp data block in sequence to obtain the final result of the overall calculation of the block-block data block, that is, the inter-block calculation result between block data blocks.
[0028] The accumulation within each block-warp data block includes: all block-warp data blocks contain the same number of threads, and thread-level accumulation within each block-warp data block is performed in parallel to obtain an intra-block accumulation array of each block-warp data block at the thread level.
[0029] On the other hand, the present invention provides a particle index calculation device for CPU and GPU heterogeneous platforms, comprising:
[0030] The first module is used to divide the physical space of the entire flow field area simulated by the particle method running on the current GPU into dataSize grid cells;
[0031] The second module is used to process dataSize The resampled particle number array in the grid cells is divided into blockSize block data block;
[0032] The third module is used to calculate the intra-block cumulative array of each block data block;
[0033] The fourth module is used to take out the last data in the block accumulation array of each block data block to perform inter-block calculation between block data blocks, and obtain the inter-block calculation results between block data blocks;
[0034] The fifth module is used to add the inter-block calculation results between block data blocks to the data of the block accumulation array of the corresponding block data block in sequence to obtain the overall final accumulation result.
[0035] In another aspect, the present invention provides a computer device, including a memory and a processor, wherein the memory stores a computer program, and when the processor executes the computer program, the following steps are implemented:
[0036] The physical space of the entire flow field area simulated by the particle method running on the current GPU is divided into dataSize grid cells;
[0037] To be processed dataSize The resampled particle number array in the grid cells is divided into blockSize block data block;
[0038] Calculate the cumulative array within each block of data;
[0039] Take out the last data in the cumulative array of each block data block to perform inter-block calculation between block data blocks, and obtain the inter-block calculation result between block data blocks;
[0040] The inter-block calculation results between block data blocks are added to the data of the corresponding block data block's intra-block accumulation array in sequence to obtain the overall final accumulation result.
[0041] In another aspect, the present invention provides a computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements the following steps:
[0042] The physical space of the entire flow field area simulated by the particle method running on the current GPU is divided into dataSize grid cells;
[0043] To be processed dataSize The resampled particle number array in the grid cells is divided into blockSize block data block;
[0044] Calculate the cumulative array within each block of data;
[0045] Take out the last data in the cumulative array of each block data block to perform inter-block calculation between block data blocks, and obtain the inter-block calculation result between block data blocks;
[0046] The inter-block calculation results between block data blocks are added to the data of the corresponding block data block's intra-block accumulation array in sequence to obtain the overall final accumulation result.
[0047] Compared with the prior art, the technical effects of the present invention are:
[0048] According to the characteristics of CPU and GPU heterogeneous platforms, the present invention proposes a multi-level particle index calculation method, which is a thread-warp-block multi-parallel level particle index calculation method, which solves the problems of data conflict and inefficient particle index calculation when particle methods are implemented on CPU+GPU heterogeneous architecture.
[0049] The present invention can reduce the calculation time of the particle index calculation part in the particle method running on the CPU and GPU heterogeneous platforms by 4 to 5 times. BRIEF DESCRIPTION OF THE DRAWINGS
[0050] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on the structures shown in these drawings without paying creative work.
[0051] Figure 1 This is a flow chart of a particle index calculation method for CPU and GPU heterogeneous platforms provided by an embodiment;
[0052] Figure 2 It is a block diagram of a particle index calculation device on a CPU and GPU heterogeneous platform provided by an embodiment;
[0053] Figure 3 This is a schematic diagram of block-level data segmentation in one embodiment;
[0054] Figure 4 is a schematic diagram of thread level accumulation in one embodiment;
[0055] Figure 5 This is a schematic diagram of inter-warp calculation and overall calculation within a block in one embodiment;
[0056] Figure 6 This is a schematic diagram of block-to-block calculation and overall calculation in one embodiment;
[0057] Figure 7 It is a diagram showing the optimization effect of a comparative embodiment. DETAILED DESCRIPTION
[0058] The following will be combined with the drawings in the embodiments of the present invention to clearly and completely describe the technical solutions in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.
[0059] In one embodiment of the present invention, referring to Figure 1 , provides a particle index calculation method for CPU and GPU heterogeneous platforms, including:
[0060] The physical space of the entire flow field area simulated by the particle method running on the current GPU is divided into dataSize grid cells;
[0061] To be processed dataSize The resampled particle number array in the grid cells is divided into blockSize block data block;
[0062] Calculate the cumulative array within each block of data;
[0063] Take out the last data in the cumulative array of each block data block to perform inter-block calculation between block data blocks, and obtain the inter-block calculation result between block data blocks;
[0064] The inter-block calculation results between block data blocks are added to the data of the corresponding block data block's intra-block accumulation array in sequence to obtain the overall final accumulation result.
[0065] It can be understood that the entire flow field area simulated by the particle method currently running on the GPU can be the external flow field area of a spacecraft, a continuous flow area, a slip flow area or a transition flow area, or even a flow area of different scales such as a free molecular flow.
[0066] When executing kernel functions on a CPU and GPU heterogeneous platform (the main arithmetic operations are completed by the GPU, and a small amount of logical operations are completed on the CPU), it is necessary to set the kernel function parameters " " parameter, that is, the number of threads in the block data block (block). Thread is the smallest execution unit at the GPU software logic level, but the GPU chip schedules concurrent threads in units of threads (warp). Each warp contains 32 threads, and the thread number starts from 0.
[0067] The physical space of the entire flow field area simulated by the particle method running on the current GPU is divided into a series of grid cells. Assume that there is grid cells.
[0068] Each thread on the GPU needs to process the resampling of particles in a grid unit, so it is necessary to accumulate the number of resampled particles in each grid unit to determine the memory address processed by each thread and specify the kernel function parameter " The parameters are (or ). According to the GPU programming model, each thread has two numbers, namely the global number and block data block number .
[0069] Will The total data of grid units is divided into blocks, and the size of each data block is , called block data block. dataSize The resampled particle number array in the grid cells is divided into blockSize The block data block.
[0070] First, calculate the cumulative array within each block data block, specifically, including:
[0071] The data in the block data block is divided into blocks of size Warp data block;
[0072] Accumulation within each warp data block is performed in parallel to obtain an intra-block accumulation array of each warp data block, wherein the accumulation within each warp data block includes: all warp data blocks contain the same number of threads, and thread-level accumulation within each warp data block is performed in parallel to obtain an intra-block accumulation array of each warp data block at the thread level.
[0073] Take out the last data in the intra-block accumulation array of each warp data block for inter-warp block accumulation;
[0074] The inter-warp accumulation results are sequentially added to the data of the intra-block accumulation array of the corresponding warp data block to obtain the intra-block accumulation array of each block data block.
[0075] Next, the last data in the cumulative array of each block is taken out to perform inter-block calculations between block data blocks, including:
[0076] Take out the last data in the cumulative array of each block data block, the total amount of data is , forming a block-block data block;
[0077] The data in the block-block data block is processed in blocks, and the data in the block-block data block is divided into block-warp data blocks of size warpSize;
[0078] Performing accumulation in each block-warp data block in parallel to obtain an intra-block accumulation array of each block-warp data block, wherein the accumulation in each block-warp data block includes: the block-warp data blocks all contain the same number of threads, performing thread-level accumulation in each block-warp data block in parallel to obtain an intra-block accumulation array of each block-warp data block at the thread level;
[0079] Take out the last data in the intra-block accumulation array of each block-warp data block and perform inter-block accumulation of the block-warp data block;
[0080] The inter-block accumulation results of each block-warp data block are added to the data of the intra-block accumulation array of the corresponding block-warp data block in sequence to obtain the final result of the overall calculation of the block-block data block, that is, the inter-block calculation result between block data blocks.
[0081] Reference Figure 2 An embodiment provides a particle index calculation device for CPU and GPU heterogeneous platforms, mainly including:
[0082] The first module is used to divide the physical space of the entire flow field area simulated by the particle method running on the current GPU into dataSize grid cells;
[0083] The second module is used to process dataSize The resampled particle number array in the grid cells is divided into blockSize block data block;
[0084] The third module is used to calculate the intra-block cumulative array of each block data block;
[0085] The fourth module is used to take out the last data in the block accumulation array of each block data block to perform inter-block calculation between block data blocks, and obtain the inter-block calculation results between block data blocks;
[0086] The fifth module is used to add the inter-block calculation results between block data blocks to the data of the block accumulation array of the corresponding block data block in sequence to obtain the overall final accumulation result.
[0087] The third module includes a Warp-level data block module, a Warp internal calculation module, a Warp block calculation module, and a block data block internal overall calculation module. The Warp-level data block module is used to block the data in the block data block and divide the data in the block data block into blocks of size Warp data blocks; the internal calculation module of the Warp is used to execute the accumulation in each warp data block in parallel to obtain the intra-block accumulation array of each warp data block; the inter-warp block calculation module is used to take out the last data in the intra-block accumulation array of each warp data block to perform inter-warp block accumulation; the internal overall calculation module of the block data block is used to add the results of each warp block accumulation to the data of the intra-block accumulation array of the corresponding warp data block in sequence to obtain the intra-block accumulation array of each block data block.
[0088] The fourth module includes a block-block data block module, a block-warp data block module, a block-warp data block internal calculation module and a block-block data block overall calculation module. The block-block data block module is used to accumulate the last data in the array in each block data block taken out. The total amount of data is to form a block-block data block; the block-warp data block module is used to process the data in the block-block data block in blocks, and divide the data in the block-block data block into block-warp data blocks of size warpSize; the block-warp data block internal calculation module is used to execute the accumulation in each block-warp data block in parallel to obtain the block accumulation array of each block-warp data block; the block-warp data block inter-block calculation module is used to take out the last data in the block accumulation array of each block-warp data block to perform block-warp data block inter-block accumulation; the block-block data block overall calculation module is used to add the inter-block accumulation results of each block-warp data block to the data of the block accumulation array of the corresponding block-warp data block in sequence to obtain the final result of the overall calculation of the block-block data block, that is, the inter-block calculation result between block data blocks.
[0089] The block-level data segmentation, block-inter-block calculation and overall calculation are three major parts. The block-level data segmentation also includes further segmentation of data within the block data block, namely warp-level data segmentation; warp data block internal calculation (thread level) and warp-inter-block calculation, and then block internal overall calculation. Block-inter-block calculation also includes block-block data segmentation, which further includes block-warp data segmentation and block-block inter-block calculation, and then block-block overall calculation.
[0090] The third module of the present invention includes further block processing of the data in the block data block, that is, warp-level data blocking; performing warp block internal calculation (thread level) and warp block inter-calculation on the warp data block, and then performing overall calculation within the block.
[0091] According to the architectural characteristics of the GPU, when the amount of data is large, due to the limited hardware resources on the chip, not all block data blocks can be executed concurrently at the same time. Instead, a part of the block data blocks will be calculated first. If the calculation of this part of the block data blocks is completed, the uncalculated block data blocks will be scheduled to continue calculation. The order of scheduling and allocation of block data blocks is determined by the hardware and cannot be accurately determined. Therefore, there should be no data dependency between block data blocks.
[0092] According to this feature, the resampled particle number array in the grid unit to be processed is divided into The block data block first completes the accumulation of the data in the block data block. Figure 3 This is a schematic diagram of block-level data segmentation in one embodiment. Figure 3 In the example, multiple block data blocks are included, where block 1 represents the first block data block and block 2 represents the second block data block. The parameter in the function is the thread number in the block data block. Indicates the first data in the block data block. It represents the sum of the first and second data in the block data block, and so on. Indicates the sum from the first data to the last data in the block data block.
[0093] If the single-level algorithm is used and data is no longer divided into blocks, the total number of operations for the data in a single block is
[0094] ;
[0095] when When the typical value is 512, the total number of calculations for the data in a single block is 131328.
[0096] In order to reduce the amount of calculation, an embodiment of the present invention proposes that for any block data block, a method for calculating the intra-block accumulation array of the block data block includes:
[0097] The data in the block data block is divided into blocks of size Warp data block;
[0098] Execute the accumulation in each warp data block in parallel to obtain the intra-block accumulation array of each warp data block;
[0099] Take out the last data in the intra-block accumulation array of each warp data block for inter-warp block accumulation;
[0100] The inter-warp accumulation results are sequentially added to the data of the intra-block accumulation array of the corresponding warp data block to obtain the intra-block accumulation array of each block data block.
[0101] because The block data blocks are further divided into indivual When performing the accumulation operation within each warp data block, each warp data block needs to process The number of accumulation operations in each warp data block is:
[0102] ;
[0103] when When the typical value is 512, the total number of calculations in the entire block data block is 9064 times. Compared with single-level blocking, the amount of calculation has been greatly reduced.
[0104] In order to further reduce the amount of calculation, Specifically, for the accumulation within each warp data block, the warp data blocks all contain the same number of threads, and the thread-level accumulation within each warp data block is performed in parallel to obtain the block accumulation array of each warp data block at the thread level.
[0105] Figure 4 : is a schematic diagram of thread level accumulation in one embodiment, assuming that a warp data block contains 10 threads, that is, Figure 4 When calculating the accumulation within the warp data block, a loop is required times, the number of threads for each call is .
[0106] In a single block, the amount of calculation for this part is:
[0107] ;
[0108] After completing the in-block accumulation calculation of each warp data block, take out the last data in the in-block accumulation array of each warp data block, for a total of After accumulating these data, the warp block calculation is completed.
[0109] Figure 5 This is a schematic diagram of inter-warp calculation and internal block calculation in an embodiment. The amount of calculation in this part is:
[0110] ;
[0111] The results of each warp block accumulation are added to the data of the corresponding warp data block in the block accumulation array in turn to obtain the block accumulation array of each block data block. The schematic diagram of this part is also shown in Figure 5 The amount of calculation for this part is .
[0112] Combining the above two parts, the total computational effort of the entire third module is:
[0113] ;
[0114] when When the typical value is 512, the total amount of calculation in the block data block is 2679.
[0115] In the fourth module, the last data in the block accumulation array of each block data block is taken out to perform block calculation between block data blocks, and the block calculation results between block data blocks are obtained and stored in the intermediate transition array. Middle, intermediate transition array The size is .
[0116] On the GPU, there is no data dependency between blocks, so inter-block data calculations can only be performed through global memory and global thread number (idx). Similar to the intra-block calculations in the third module, inter-block calculations can also be divided into two parts: multi-level block division of data and overall calculation. The final accumulated data is stored in the intermediate transition array. middle.
[0117] The amount of data that needs to be processed for inter-block calculations between block data blocks in the fourth module is In order to improve the computing efficiency, the data to be processed in the block-by-block computing is also divided into blocks. Specifically:
[0118] First, add the last data in the array to the block of each block of data taken out, and the total amount of data is , forming block-block data blocks.
[0119] In order to further improve the computational efficiency, all data blocks in the block-block data block are divided into block-warp data blocks of warpSize size.
[0120] To achieve this, the kernel function needs to be assigned thread thread.
[0121] According to the characteristics of GPU architecture, there is no storage resource sharing and data dependency between block data blocks, so the global thread number (set as idx) is used to calculate the data index of the left value and the right value. Initially, each thread indexes the last data in the block data block. The last data in the cumulative array of each block data block is the cumulative value of all data in the corresponding block data block. For example, the data indexed by the first thread thread is , which is actually the accumulated value from the first data (idx=0) to the last data (idx=blkSize-1) in the first block data block; similarly, the data indexed by the second thread thread It is the cumulative value of the first data (idx=blkSize) to the last data (idx=2blkSize-1) in the second block data block, such as Figure 6 As shown in FIG. 1 , a schematic diagram of block-by-block calculation and overall calculation in one embodiment is shown in FIG. The variable in the function is the global thread number idx.
[0122] After completing the above memory allocation, all data blocks in the block-block data block are divided into block-warp data blocks of warpSize size. Each warpSize thread thread will be divided into a group, and each group of threads thread will execute Figure 4 The data accumulation at the thread level shown in the figure is to perform the thread level accumulation in each block-warp data block in parallel to obtain the intra-block accumulation array of each block-warp data block at the thread level. Then, the last data in the intra-block accumulation array of each block-warp data block is taken out to perform the block-warp block accumulation operation, and finally the block-warp data block accumulation results are added to the data of the corresponding block-warp data block intra-block accumulation array in turn to obtain the final result of the overall calculation of the block-block data block, that is, the inter-block calculation result between block data blocks. Figure 6 As shown, the first thread called by the kernel function stores , which is the cumulative value of the first blkSize data. The second thread stores , which is the accumulated value of the first 2blkSize data, and writes the data in each thread in parallel for the overall calculation of the subsequent fifth module.
[0123] The overall process of block-level calculation in the fourth module is the same as that of block-level data segmentation in the third module, except that:
[0124] (a) The amount of data processed in the third module is , which is the total number of grids for the problem being calculated; the amount of data processed in the fourth module is , that is, only the last data in each data block is processed, and there is an intermediate transition array after accumulation middle.
[0125] (b) The data processed in the third module is continuous. Each block processes the data in the same block. Adjacent threads in the same block process adjacent data. The array index of the left value is the same as the array index of the right value. The thread number tid in the block can be used. In the fourth module, the data span processed by adjacent threads is , there is no data dependency between blocks, so it is necessary to use the global thread number idx to calculate the data index of the left and right values respectively.
[0126] In the fifth module, the intermediate transition array The data in is added to the data of the accumulation array in the corresponding block data block in turn to obtain the overall final accumulation result.
[0127] For the calculation problem with a grid size of dataSize, after the third module, each element in the first block has been accumulated, and the second block stores the accumulated value within this data block. Figure 6 middle, That is, the value of the first data in the second block data block, That is, the sum of the first two data in this data block, and so on. Therefore, each element in this data block should be added with the cumulative value of the previous block data block to get the cumulative result of the data in this data block in the total data. Each data in block data block 1 (counting from 0) is consistent with the intermediate transition array The first element in Add, block data block 2 is added to the intermediate transition array The second element in Add them together to get the final cumulative result.
[0128] Reference Figure 7 , is a diagram showing the optimization effect of a comparative embodiment. Figure 7The first column is the total data processed, i.e., dataSize. The second column is the time required to perform particle index calculation on the CPU, the third column is the calculation time required to execute the "block single-level algorithm" on the CPU / GPU heterogeneous platform, the fourth column is the calculation time required to execute the "warp-block double-level algorithm" on the CPU / GPU heterogeneous platform, and the fifth column is the calculation time required to execute the "thread-warp-block multi-level algorithm" on the CPU / GPU heterogeneous platform, i.e., the particle index calculation method for CPU and GPU heterogeneous platforms proposed in the present invention. The data used in the test is integer (int) data, and the unit of calculation time is second (s). It can be seen that the present invention can reduce the calculation time of the particle index calculation part in the particle method running on the CPU and GPU heterogeneous platforms by 4 to 5 numbers.
[0129] On the other hand, the present invention provides a computer device, including a memory and a processor, the memory storing a computer program, and the processor implementing the steps of the particle index calculation method for CPU and GPU heterogeneous platforms provided in any of the above embodiments when executing the computer program. The computer device may be a server. The computer device includes a processor, a memory, a network interface and a database connected via a system bus. Among them, the processor of the computer device is used to provide computing and control capabilities. The memory of the computer device includes a non-volatile storage medium and an internal memory. The non-volatile storage medium stores an operating system, a computer program and a database. The internal memory provides an environment for the operation of the operating system and the computer program in the non-volatile storage medium. The database of the computer device is used to store sample data. The network interface of the computer device is used to communicate with an external terminal via a network connection.
[0130] On the other hand, the present invention provides a computer-readable storage medium having a computer program stored thereon. When the computer program is executed by a processor, the steps of the particle index calculation method for CPU and GPU heterogeneous platforms provided in any of the above embodiments are implemented.
[0131] Those of ordinary skill in the art can understand that all or part of the processes in the above-mentioned embodiment methods can be implemented by instructing the relevant hardware through a computer program, and the computer program can be stored in a non-volatile computer-readable storage medium. When the computer program is executed, it can include the processes of the embodiments of the above-mentioned methods. Among them, any reference to memory, storage, database or other media used in the embodiments provided in this application may include non-volatile and / or volatile memory. Non-volatile memory may include read-only memory (ROM), programmable ROM (PROM), electrically programmable ROM (EPROM), electrically erasable programmable ROM (EEPROM) or flash memory. Volatile memory may include random access memory (RAM) or external cache memory. By way of illustration and not limitation, RAM is available in many forms, such as static RAM (SRAM), dynamic RAM (DRAM), synchronous DRAM (SDRAM), double data rate SDRAM (DDRSDRAM), enhanced SDRAM (ESDRAM), synchronous link (Synchlink) DRAM (SLDRAM), memory bus (Rambus) direct RAM (RDRAM), direct memory bus dynamic RAM (DRDRAM), and memory bus dynamic RAM (RDRAM), etc.
[0132] Matters not covered by the present invention are known technologies.
[0133] The technical features of the above embodiments may be combined arbitrarily. To make the description concise, not all possible combinations of the technical features in the above embodiments are described. However, as long as there is no contradiction in the combination of these technical features, they should be considered to be within the scope of this specification.
[0134] The above-described embodiments only express several implementation methods of the present application, and the descriptions thereof are relatively specific and detailed, but they cannot be understood as limiting the scope of the invention. It should be pointed out that, for a person of ordinary skill in the art, several modifications and improvements can be made without departing from the concept of the present application, and these all belong to the protection scope of the present application. Therefore, the protection scope of the present application shall be subject to the attached claims.
[0135] The above description is only a preferred embodiment of the present invention and is not intended to limit the present invention. For those skilled in the art, the present invention may have various modifications and variations. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present invention shall be included in the protection scope of the present invention.
Claims
1. A particle index calculation method for CPU and GPU heterogeneous platforms, characterized in that: include: The physical space of the entire flow field area simulated by the particle method running on the current GPU is divided into dataSize grid cells; To be processed dataSize The resampled particle number array in the grid cells is divided into blockSize block data block; Calculate the cumulative array within each block of data, including: The data in the block data block is divided into blocks of size Warp data block; Execute the accumulation in each warp data block in parallel to obtain the intra-block accumulation array of each warp data block; Take out the last data in the intra-block accumulation array of each warp data block for inter-warp block accumulation; The inter-warp accumulation results are sequentially added to the data of the intra-block accumulation array of the corresponding warp data block to obtain the intra-block accumulation array of each block data block; Take out the last data in the cumulative array of each block data block to perform inter-block calculation between block data blocks, and obtain the inter-block calculation results between block data blocks, including: Take out the last data in the cumulative array of each block data block, the total amount of data is , forming a block-block data block; The data in the block-block data block is processed in blocks, and the data in the block-block data block is divided into block-warp data blocks of size warpSize; Perform the accumulation in each block-warp data block in parallel to obtain the block accumulation array of each block-warp data block; Take out the last data in the intra-block accumulation array of each block-warp data block and perform inter-block accumulation of the block-warp data block; The inter-block accumulation results of each block-warp data block are sequentially added to the data of the intra-block accumulation array of the corresponding block-warp data block to obtain the final result of the overall calculation of the block-block data block, that is, the inter-block calculation result between the block data blocks; The inter-block calculation results between block data blocks are added to the data of the corresponding block data block's intra-block accumulation array in sequence to obtain the overall final accumulation result.
2. The particle index calculation method for CPU and GPU heterogeneous platforms according to claim 1, characterized in that: The accumulation within each warp data block includes: all warp data blocks contain the same number of threads, and thread-level accumulation within each warp data block is performed in parallel to obtain an intra-block accumulation array of each warp data block at the thread level.
3. The particle index calculation method for CPU and GPU heterogeneous platforms according to claim 1, characterized in that: The accumulation within each block-warp data block includes: all block-warp data blocks contain the same number of threads, and thread-level accumulation within each block-warp data block is performed in parallel to obtain an intra-block accumulation array of each block-warp data block at the thread level.
4. A particle index calculation device for CPU and GPU heterogeneous platforms, characterized in that: include: The first module is used to divide the physical space of the entire flow field area simulated by the particle method running on the current GPU into dataSize grid cells; The second module is used to process dataSize The resampled particle number array in the grid cells is divided into blockSize block data block; The third module is used to calculate the intra-block cumulative array of each block data block, wherein the third module includes: Warp-level data block module is used to process the data in the block data block into blocks of size Warp data block; The internal calculation module of the warp is used to perform the accumulation in each warp data block in parallel to obtain the intra-block accumulation array of each warp data block; Warp block calculation module, used to take out the last data in the block accumulation array of each warp data block to perform warp block accumulation; The overall calculation module within the block data block is used to add the results of the inter-warp accumulation to the data of the block accumulation array of the corresponding warp data block in sequence to obtain the block accumulation array of each block data block; The fourth module is used to take out the last data in the block accumulation array of each block data block to perform inter-block calculation between block data blocks to obtain the inter-block calculation results between block data blocks, wherein the fourth module includes: The block-block data block module is used to accumulate the last data in the array in each block of data blocks taken out. The total amount of data is , forming a block-block data block; The block-warp data block module is used to process the data in the block-block data block by blocks, and divide the data in the block-block data block into block-warp data blocks of size warpSize; The block-warp data block internal calculation module is used to perform the accumulation in each block-warp data block in parallel to obtain the block accumulation array of each block-warp data block; A block-warp data block inter-block calculation module is used to take out the last data in the intra-block accumulation array of each block-warp data block to perform block-warp data block inter-block accumulation; The block-block data block overall calculation module is used to sequentially add the inter-block accumulation results of each block-warp data block to the data of the intra-block accumulation array of the corresponding block-warp data block to obtain the final result of the block-block data block overall calculation, that is, the inter-block calculation result between block data blocks; The fifth module is used to add the inter-block calculation results between block data blocks to the data of the block accumulation array of the corresponding block data block in sequence to obtain the overall final accumulation result.
5. The particle index calculation device for CPU and GPU heterogeneous platforms according to claim 4, characterized in that: In the internal computing module of the warp, all warp data blocks contain the same number of threads, and the thread-level accumulation within each warp data block is executed in parallel to obtain the block accumulation array of each warp data block at the thread level.
6. The particle index calculation device for CPU and GPU heterogeneous platforms according to claim 5, characterized in that: In the internal computing module of the block-warp data block, the accumulation within each block-warp data block includes: the block-warp data blocks all contain the same number of threads, and the thread-level accumulation within each block-warp data block is executed in parallel to obtain the block-level accumulation array of each block-warp data block at the thread level.
