Data structure optimization method, cardiac electrophysiology simulation method, device, equipment and medium
By dividing, fusing, and sorting the three-dimensional cardiac tissue model in cardiac electrophysiology simulation into blocks, constructing a one-dimensional cell sequence, and using a position index table, the problems of thread resource waste and low memory access efficiency are solved, thereby improving the efficiency of GPU parallel computing and simulation speed.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2025-06-17
- Publication Date
- 2026-03-27
AI Technical Summary
Existing technologies in cardiac electrophysiology simulations suffer from problems such as wasted thread resources and low memory access efficiency due to block data structures, making it difficult to simultaneously achieve both computational efficiency and resource utilization.
We employ a block partitioning and fusion strategy based on a 3D cardiac tissue model to eliminate empty blocks, sort and fuse sparse blocks according to the effective number of cells, construct a 1D cell sequence, and optimize memory access strategy by combining a location index table.
It significantly improves GPU parallel efficiency, reduces memory access latency, enhances cache utilization efficiency and overall simulation speed, and is suitable for various cardiac electrophysiological models.
Smart Images

Figure CN120708921B_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The present application relates to the technical field of cardiac electrophysiology simulation, and in particular to a data structure optimization method, a cardiac electrophysiology simulation method, a device, equipment and a medium. BACKGROUND
[0002] In distributed computing, I / O performance directly affects the overall throughput and resource utilization efficiency of the system. An efficient I / O optimization method can significantly improve computing performance. As the core device of parallel computing, the performance of a GPU (Graphics Processing Unit) is highly dependent on the memory access mode. Sequential memory access (i.e., accessing data with consecutive addresses) can fully trigger the memory coalescing access mechanism in the GPU, thereby reducing access delay and improving memory bandwidth utilization. In contrast, non-coalescing access generates multiple memory transactions, which severely restricts performance.
[0003] In addition, spatial locality is also a key optimization point in GPU programming. Reasonably arranging memory data so that data accessed by neighboring threads are stored in adjacent locations can improve cache hit rate and reduce data loading delay, thereby further improving computing efficiency.
[0004] In cardiac electrophysiology simulation, the main computational load is concentrated on the high-frequency update of the membrane potential and ion channels of each cell in the effective myocardial region, and the electrical coupling between cells also needs to be considered. To improve efficiency, existing methods usually unfold the sparse three-dimensional heart structure into a one-dimensional array, exclude the cavity positions, and record the original 3D position information through indexing, so that threads only calculate effective cells and try to use sequential memory access. However, when processing coupled voltages, the spatial locality is difficult to maintain due to the row-major or column-major arrangement, affecting memory access efficiency.
[0005] Another method preserves the local structure through three-dimensional block division, and after removing completely empty blocks, the internal data of each block is unfolded again. Although this scheme can enhance locality, it inevitably retains some invalid cells, causing waste of GPU thread resources and affecting computing density and scheduling efficiency.
[0006] In summary, existing technologies have to make a trade-off between ensuring sequential memory access and spatial locality, and it is difficult to simultaneously consider both computing efficiency and resource utilization. Therefore, there is an urgent need for a new data layout and access strategy that takes both into account and is suitable for parallel computing of sparse three-dimensional structures. SUMMARY
[0007] The present application provides a data structure optimization method, a cardiac electrophysiology simulation method, a device, equipment and a medium to solve the problem of thread resource waste and low memory access efficiency caused by block data structure in cardiac electrophysiology simulation.
[0008] In a first aspect, the present application provides a data structure optimization method, comprising:
[0009] constructing a three-dimensional heart tissue model and saving the coordinate positions of each cell in the three-dimensional heart tissue model;
[0010] dividing and unfolding the three-dimensional heart tissue model according to the thread bundle size M of the GPU to obtain a plurality of cell blocks; wherein the cell blocks include dense blocks, sparse blocks and empty blocks, the dense block refers to all cells therein are valid cells, the sparse block refers to part of the cells therein are valid cells, and the empty block refers to no valid cells therein;
[0011] removing all empty blocks and sorting the remaining cell blocks in descending order according to the number of valid cells;
[0012] fusing and removing the empty blocks of the cell blocks sorted in descending order to obtain each fused cell block;
[0013] one-dimensional unfolding each fused cell block to obtain a one-dimensional cell sequence;
[0014] constructing a position index table according to the coordinate positions of each cell in the one-dimensional cell sequence.
[0015] Further, the fused cell blocks sorted in descending order are fused, specifically including:
[0016] traversing each cell block in turn, for the i-th cell block, if the number of valid cells in the i-th cell block is less than M, then the valid cells in the j-th cell block are inserted into the i-th cell block to obtain the i-th cell block after one insertion; wherein the number of valid cells in the 1st to i-1th cell blocks that have been traversed is greater than or equal to M, i
[0017] If the number of valid cells in the i-th cell block after one insertion is less than M and the number of valid cells in the j-th cell block is equal to 0, then the valid cells in the j-1th cell block are inserted into the i-th cell block after one insertion to obtain the i-th cell block after two insertions; and so on, until the number of valid cells in the i-th cell block after multiple insertions is greater than or equal to M;
[0018] If the number of valid cells in the i-th cell block after one insertion is greater than or equal to M and the number of valid cells in the j-th cell block is equal to 0, then the i+1th cell block is traversed, if the number of valid cells in the i+1th cell block is less than M, then the valid cells in the j-1th cell block are inserted into the i+1th cell block to obtain the i+1th cell block after one insertion;
[0019] If the number of effective cells in the ith cell block after one insertion is greater than or equal to M and the number of effective cells in the jth cell block is greater than 0, then the (i+1)th cell block is traversed, and if the number of effective cells in the (i+1)th cell block is less than M, then the remaining effective cells in the jth cell block are inserted into the (i+1)th cell block to obtain the (i+1)th cell block after one insertion;
[0020] In this way, until i=j, the fusion processing of all cell blocks is completed.
[0021] Further, the thread bundle size M of the GPU is equal to 32.
[0022] In a second aspect, the present application further provides a cardiac electrophysiology simulation method, comprising:
[0023] obtaining a one-dimensional cell sequence and a position index table of a three-dimensional cardiac tissue model; wherein the one-dimensional cell sequence and the position index table are obtained by using the data structure optimization method described above;
[0024] loading a cardiac electrophysiology model and initializing state variables of each cell in the one-dimensional cell sequence;
[0025] updating the cell state according to the state variables of each cell, the position index table and the cardiac electrophysiology model.
[0026] Further, updating the cell state according to the state variables of each cell, the position index table and the cardiac electrophysiology model specifically comprises:
[0027] storing the initial value of the state variable of each cell in the global memory;
[0028] reading the state variable of the cell from the global memory and loading it into the register;
[0029] in the register, continuously performing N time step cell ion channel dynamics calculation according to the state variable of the cell; at the Nth time step, calculating the potential diffusion term based on the position index table; wherein N>1;
[0030] calculating the cell membrane potential at the Nth time step according to the cardiac electrophysiology simulation model, the cell ion channel dynamics calculation result at the Nth time step and the potential diffusion term, and realizing cell state updating;
[0031] writing the calculation result of N time steps and the state variable of the cell into the global memory;
[0032] repeating the steps of reading the cell state variable from the global memory, performing calculation in the register and writing the calculation result into the global memory until the simulation ends.
[0033] Further, according to the state variable of the cell, a cycle-unfold strategy is adopted to continuously perform cell ion channel dynamics calculation for N time steps.
[0034] Further, the specific expression of the cardiac electrophysiological simulation model is as follows:
[0035]
[0036] Wherein, C m represents the membrane capacitance per unit area; V represents the cell membrane potential; represents the potential diffusion term, i.e. the electrical signal propagation in the cardiac tissue, represents the divergence operator, D represents the diffusion coefficient, represents the gradient operator; I ion represents the total ion current, g represents the ion channel gating variable, and t represents time; I stim represents the external stimulation current.
[0037] In a third aspect, the present application further provides a data structure optimization device, comprising:
[0038] A construction and saving unit is configured to construct a three-dimensional cardiac tissue model and save the coordinate positions of each cell in the three-dimensional cardiac tissue model.
[0039] A block division unit is configured to divide and unfold the three-dimensional cardiac tissue model according to the thread bundle size M of a GPU to obtain a plurality of cell blocks; wherein the cell blocks include dense blocks, sparse blocks and empty blocks, the dense blocks refer to all cells therein being valid cells, the sparse blocks refer to part of the cells therein being valid cells, and the empty blocks refer to no valid cells therein.
[0040] A rejection and sorting unit is configured to reject all empty blocks and sort the remaining cell blocks in descending order according to the number of valid cells.
[0041] A fusion and rejection unit is configured to fuse and reject empty blocks for the cell blocks sorted in descending order to obtain fused cell blocks.
[0042] An unfolding unit is configured to one-dimensionally unfold the fused cell blocks to obtain a one-dimensional cell sequence.
[0043] A construction unit is configured to construct a position index table according to the coordinate positions of each cell in the one-dimensional cell sequence.
[0044] In a fourth aspect, the present application further provides an electronic device comprising a memory, a processor and a computer program / instruction stored in the memory, wherein the processor executes the computer program / instruction to implement the data structure optimization method or the cardiac electrophysiological simulation method of the present application.
[0045] In a fifth aspect, the present application also provides a computer readable storage medium having stored thereon computer programs / instructions which, when executed by a processor, implement the data structure optimization method or the cardiac electrophysiology simulation method of the present application as described above.
[0046] The present application has the following beneficial effects:
[0047] The present application divides the three-dimensional heart tissue model into blocks according to the thread bundle size of the GPU, so that the cell block size matches the thread bundle size of the GPU; and in combination with cell block fusion processing, the sparse blocks are effectively merged, the problem of empty thread scheduling caused by sparse data is avoided, the waste of thread resources is avoided, and the parallel efficiency and overall computing throughput of the GPU are significantly improved.
[0048] The present application rearranges the three-dimensional cell structure into a one-dimensional linear high-density cell sequence through the cell block fusion mechanism and the empty block rejection, and in combination with the coordinate axis sequence unfolding and the original coordinate position indexing mechanism, the locality and order of data in the GPU are improved, the cache utilization efficiency is improved, the memory access delay is reduced, and thus the overall simulation speed is improved, especially in the voltage coupling calculation (i.e., the potential diffusion term).
[0049] The fusion mechanism and the position indexing reconstruction mechanism of the present application are data-driven and do not depend on specific model structures, are suitable for a variety of mainstream cardiac electrophysiology models (such as Luo-Rudy, Ten Tusscher, O'Hara-Rudy Dynamic, etc.), can adapt to various kinetic parameters and cell network structures without modifying the core logic, are easy to integrate into existing simulation systems, and are also convenient for extension to more dimensional models or more complex coupling mechanisms. BRIEF DESCRIPTION OF DRAWINGS
[0050] In order to more clearly illustrate the technical solutions of the present application, the following will briefly introduce the drawings needed in the embodiment description. Obviously, the drawings in the following description are only one embodiment of the present application, and other drawings can also be obtained by those skilled in the art without creative labor.
[0051] Figure 1 The data structure optimization method flowchart in the embodiment of the present application;
[0052] Figure 2 The block division, rejection, fusion and one-dimensional unfolding processing schematic diagram in the embodiment of the present application; wherein, SM is the abbreviation of Streaming Multiprocessors, which means streaming multiprocessor; SP is the abbreviation of Streaming processor, which means streaming processor.
[0053] Figure 3 The flow chart of the cardiac electrophysiology simulation method is shown in the embodiment of the present application.
[0054] Figure 4 The structure block diagram of the data structure optimization device is shown in the embodiment of the present application.
[0055] Figure 5 The structure block diagram of the electronic device is shown in the embodiment of the present application. DETAILED DESCRIPTION
[0056] The technical solutions in the present application will be described clearly and completely in combination with the drawings in the embodiments of the present application. Obviously, the described embodiments are only a part of the embodiments of the present application, rather than all the embodiments. Based on the embodiments in the present application, all other embodiments obtained by those skilled in the art without creative work fall within the scope of protection of the present application.
[0057] The technical solutions of the present application will be described in detail in combination with specific embodiments. The following specific embodiments can be combined with each other, and the same or similar concepts or processes can not be described in some embodiments.
[0058] Embodiment one
[0059] In order to solve the problem of waste of thread resources and insufficient memory access efficiency caused by the block data structure in the GPU parallel calculation of cardiac electrophysiology simulation, the present application provides a data structure optimization method, which adopts a three-dimensional blocking strategy to divide the cardiac tissue model in space, so as to isolate invalid areas and improve the initial data organization efficiency. For the sparse block containing empty cells, a block fusion strategy based on density analysis is proposed, which fuses multiple sparse blocks into a high-density cell block (i.e. dense block) with compact structure and no empty cells. This way effectively reduces the generation of idle threads, improves the utilization rate of thread scheduling, avoids invalid calculation, enhances the continuity of data structure, improves the order and spatial locality of memory access, significantly improves the cache hit rate, reduces the access delay, and improves the overall simulation performance.
[0060] Meanwhile, the present application also introduces a position index mechanism, which maintains the original three-dimensional coordinate mapping relationship for each valid cell during the fusion and one-dimensional expansion process, ensures the correctness of the coupling term and the adjacency relationship during simulation calculation, and further ensures the accuracy of simulation calculation.
[0061] Figure 1 The flow chart of the data structure optimization method provided by the present application is shown. As shown in Figure 1 The data structure optimization method comprises the following steps:
[0062] A1: Construct a three-dimensional heart tissue model, and save the coordinate positions of each cell in the three-dimensional heart tissue model.
[0063] As shown in the following figure, when constructing the three-dimensional heart tissue model, a three-dimensional coordinate system is constructed, so that the coordinate positions of each cell in the three-dimensional heart tissue model in the three-dimensional coordinate system can be obtained. Saving the coordinate positions of each cell ensures the correct adjacency relationship between cells during coupling item simulation calculation, and further ensures the accuracy of simulation calculation. Figure 2
[0064] A2: According to the thread bundle size M of the GPU, the three-dimensional heart tissue model is divided into blocks and unfolded to obtain a plurality of cell blocks.
[0065] According to the thread bundle size M of the GPU, the three-dimensional heart tissue model is divided into blocks, so that the size of the cell block matches the thread bundle size M of the GPU, and then the computing unit of the GPU efficiently schedules the thread bundle, fully utilizes the resources, and improves the parallelism.
[0066] In this embodiment, the thread bundle size M of the GPU is equal to 32, and the three-dimensional heart tissue model is divided into blocks according to (4, 4, 2), so that the number of cells in each cell block obtained is exactly equal to 32, which is equal to the thread bundle size M of the GPU. The heart tissue structure divided into blocks (i.e. cell blocks) is unfolded along the coordinate axes in turn to obtain the cell blocks. As shown in the following figure, the cell blocks are unfolded along the Z-Y-X axes in turn. Figure 2
[0067] The cell block includes three types, namely dense block, sparse block and empty block. The dense block refers to all cells in it are effective cells; the sparse block refers to part of the cells in it are effective cells, that is, part of the cells are effective cells and part of the cells are empty cells; the empty block refers to no effective cell in it, that is, all cells are empty cells. The effective cell refers to the cell directly participating in the generation, conduction and related physiological function simulation of the cardiac electrical signal in the cardiac electrophysiology simulation, that is, the cell with characteristic electrophysiological behavior which is explicitly modeled in the cardiac electrophysiology simulation. The empty cell refers to the cell which is not defined or not endowed with characteristic electrophysiological behavior.
[0068] A3: Remove all empty blocks, and only keep dense blocks and sparse blocks, and then sort the remaining cell blocks in descending order according to the number of effective cells, to avoid waste of GPU resources.
[0069] A4: Fuse and remove the empty blocks of the cell blocks sorted in descending order to obtain the fused cell blocks.
[0070] In the specific embodiments of the present application, the fusion processing is performed on the cell blocks sorted in descending order, which specifically includes:
[0071] The effective cells in the jth cell block are inserted into the empty cells of the ith cell block to obtain the ith cell block after one insertion.
[0072] The effective cell number in the 1st to (i-1)th cell block that has been traversed is greater than or equal to M, that is, the 1st to (i-1)th cell block that has been traversed is a dense block, i < j, the effective cell number of the (j+1)th to Eth cell block is 0, that is, the (j+1)th to Eth cell block is an empty block, and E represents the number of cell blocks in descending order.
[0073] If the effective cell number in the ith cell block after one insertion is less than M and the effective cell number in the jth cell block is equal to 0, the effective cells in the (j-1)th cell block are inserted into the empty cells of the ith cell block after one insertion to obtain the ith cell block after two insertions; and the process is repeated until the effective cell number in the ith cell block after multiple insertions is greater than or equal to M.
[0074] If the effective cell number in the ith cell block after one insertion is greater than or equal to M and the effective cell number in the jth cell block is equal to 0, the (i+1)th cell block is traversed, if the effective cell number in the (i+1)th cell block is less than M, the effective cells in the (j-1)th cell block are inserted into the empty cells of the (i+1)th cell block to obtain the (i+1)th cell block after one insertion; and it is judged whether the effective cell number in the (i+1)th cell block after one insertion is greater than or equal to M.
[0075] If the effective cell number in the ith cell block after one insertion is greater than or equal to M and the effective cell number in the jth cell block is greater than 0, the (i+1)th cell block is traversed, if the effective cell number in the (i+1)th cell block is less than M, the remaining effective cells in the jth cell block are inserted into the empty cells of the (i+1)th cell block to obtain the (i+1)th cell block after one insertion;
[0076] The process is repeated until i=j, and the fusion processing of all cell blocks is completed. The sparse blocks containing empty cells are effectively merged by the sparse block fusion mechanism.
[0077] For example, the 1st cell block is traversed, if the effective cell number in the 1st cell block is less than 32, the effective cells in the Eth cell block are inserted into the empty cells of the 1st cell block to obtain the 1st cell block after one insertion.
[0078] If the number of effective cells in the first cell block after the first insertion is less than 32 and the number of effective cells in the Eth cell block is equal to 0, the effective cells in the (E-1)th cell block are inserted into the empty cells of the first cell block after the first insertion to obtain the first cell block after the second insertion; and the process is repeated until the number of effective cells in the first cell block after the multiple insertions is greater than or equal to 32.
[0079] If the number of effective cells in the first cell block after the first insertion is greater than or equal to 32 and the number of effective cells in the Eth cell block is equal to 0, the second cell block is traversed, and if the number of effective cells in the second cell block is less than 32, the effective cells in the (E-1)th cell block are inserted into the empty cells of the second cell block to obtain the second cell block after the first insertion; and it is judged whether the number of effective cells in the second cell block after the first insertion is greater than or equal to 32, if yes, the third cell block is traversed, and if no, the effective cell insertion process is continued on the second cell block.
[0080] If the number of effective cells in the first cell block after the first insertion is greater than or equal to 32 and the number of effective cells in the Eth cell block is greater than 0, the second cell block is traversed, and if the number of effective cells in the second cell block is less than 32, the remaining effective cells in the Eth cell block are inserted into the empty cells of the second cell block to obtain the second cell block after the first insertion.
[0081] The empty block generated by the fusion process is removed, and only the continuous effective cell block is retained.
[0082] A5: One-dimensional expansion is performed on each cell block after fusion to obtain a one-dimensional cell sequence.
[0083] In this embodiment, each cell block after fusion is sequentially expanded along the Z-Y-X axis into a one-dimensional data structure. This data structure fully takes into account the GPU memory sequential access and spatial limitations, significantly improving the cache hit rate and data loading efficiency.
[0084] A6: A position index table is constructed according to the coordinate positions of each cell in the one-dimensional cell sequence to ensure the correctness of the coupling term and the adjacency relationship during simulation calculation.
[0085] The position index table records the coordinate positions of each effective cell in the three-dimensional heart tissue model, ensuring the correctness of the adjacency relationship between cells during coupling term calculation, and further ensuring the accuracy of the coupling term calculation.
[0086] Compared with the traditional block division structure, the present application saves about 26% of the empty thread calculation overhead, improves the GPU parallel execution efficiency; under the premise of ensuring the accuracy of the coupling term calculation, the overall simulation speed of the system is significantly improved, and it is suitable for large-scale three-dimensional heart electrophysiology simulation and other high-computing-intensive tasks.
[0087] Embodiment Two
[0088] Figure 3 A flow chart of a cardiac electrophysiology simulation method provided by the present application is shown. As shown, the cardiac electrophysiology simulation method comprises the following steps: Figure 3
[0089] B1: obtaining a one-dimensional cell sequence of a three-dimensional cardiac tissue model and a position index table thereof; wherein the one-dimensional cell sequence and the position index table thereof are obtained by using the data structure optimization method in Embodiment One of the present application.
[0090] B2: loading a cardiac electrophysiology model and initializing state variables of each cell in the one-dimensional cell sequence.
[0091] In this embodiment, the specific expression of the cardiac electrophysiology simulation model is as follows:
[0092]
[0093] wherein C m represents a membrane capacitance per unit area, unit: μF / cm 2 ; V represents a cell membrane potential, unit: mV; represents a potential diffusion term (i.e. a coupling term), i.e. an electrical signal propagation in the cardiac tissue, represents a divergence operator, D represents a diffusion coefficient, represents a gradient operator; I ion represents a total ion current, g represents an ion channel gating variable (i.e. a state variable of a cell), and t represents time; I stim represents an external stimulation current.
[0094] According to formula (1), the parameters of the cardiac electrophysiology simulation model include a cell membrane voltage, a cell ion channel state, and ion concentration parameters, etc. The cell ion channel state is described by a plurality of cell state variables, and I ion (V, g, t) is calculated according to the plurality of cell state variables. Before simulation calculation, each cell state variable is initialized.
[0095] In this embodiment, the state variables of the cell include a depolarization-related current, a repolarization-related current, and an ion balance-related current; the depolarization-related current includes a fast sodium current and an L-type calcium current; the repolarization-related current includes a transient outward potassium current, a fast delayed rectifier potassium current, a slow delayed rectifier potassium current, and an inward rectifier potassium current; and the ion balance-related current includes a sodium-calcium exchange current, a sodium-potassium pump current, a calcium pump current, a potassium pump current, a background sodium current, and a background calcium current.
[0096] In step B2, simulation parameters such as total simulation time, single time step step size dt, etc. are also set.
[0097] B3: update the cell state according to the state variable of each cell, the position index table and the cardiac electrophysiology model.
[0098] According to formula (1), the calculation of the cardiac electrophysiology simulation model mainly includes two items, that is, I ion (V, g, t) and I ion (V, g, t) is a current item reflecting the dynamics of ion channels in cells, which changes rapidly and needs to be updated at a high frequency; It is a term for describing the voltage diffusion coupling between cells (i.e. coupling term), which changes relatively slowly over time, and the update frequency is relatively low.
[0099] In traditional cardiac electrophysiology simulation, I ion (V, g, t) and are updated and global memory is accessed at each time step, resulting in a large number of redundant global memory read and write operations, which seriously restricts the simulation efficiency; the ion channel state of the myocardial cell is loaded from the global memory, L2 cache, L1 cache, and finally to the register for calculation, but almost every cell state variable only participates in one calculation and is then released, resulting in a very low cache hit rate, which limits the performance optimization effect of the cache mechanism and shared memory. In addition, a large number of global memory read and write operations lead to an imbalance between I / O and computing load, and thus the computing unit spends most of the time waiting for I / O operations. Therefore, the high-frequency access of global memory I / O becomes a performance bottleneck, significantly affecting the efficiency of simulation calculation, especially in large-scale simulation tasks, frequent memory access consumes a large amount of bandwidth, thereby limiting the throughput of the calculation process.
[0100] Based on the above technical problems, the present application controls the update frequency based on a full assessment of the smoothness of the time variation of and the controllability of the error, that is, the update of I ian (V, g, t) is performed at each of the consecutive N time steps, and the update of is performed only at the Nth time step, and global memory read and write access is performed once every N time steps, without the need for separate global memory access at each time step, significantly reducing the number of global memory access, reducing memory bandwidth pressure, and reducing access delay and waiting time of the GPU computing core.
[0101] The number N of consecutive time steps is greater than 1 and is determined according to the load of the GPU memory and computing core, and N is usually 3-5. For H100 Tensor Core GPU, N is 5.
[0102] In a specific embodiment of the present invention, updating the cell state based on the state variables of each cell, the location index table, and the cardiac electrophysiological model specifically includes:
[0103] B3.1: Store the initial values of the state variables of each cell in global memory.
[0104] On the GPU device side, a global memory allocation is performed for a cell state array, a temporary computation cache, and a potential diffusion term buffer. The initial values of the state variables of each cell are stored in the cell state array for easy access by the GPU computing core.
[0105] The kernel function (kemel) is launched on the GPU to execute steps B3.2 to B3.6 in parallel on all cardiomyocytes. The GPU has a large number of computing cores, making it suitable for handling large-scale parallel tasks. The kernel function can perform calculations independently for each cardiomyocyte, achieving fine-grained parallelization and significantly accelerating the overall computation process.
[0106] B3.2: Read the cell's state variables from global memory and load them into a register.
[0107] B3.3: In the register, cell ion channel dynamics calculations are performed continuously for N time steps based on the cell's state variables; at the Nth time step, the potential diffusion term is calculated based on the position index table.
[0108] The cell ion channel dynamics calculation is performed continuously for N time steps, that is, the cell ion channel state is calculated N times in N*dt, without reading or writing to global memory, and the N times are completed using a cell state variable read from global memory. ion The calculation of (V, g, t) enables high-frequency updates of the current term in the cardiac electrophysiology simulation model; at the last time step of every N time steps (i.e., the Nth time step), the potential diffusion term is calculated. That is, the potential diffusion term is performed every N time steps. The update realizes the potential diffusion term. The low-frequency update; then the I calculated at the Nth time step ion (V,g,t) and Substitute into formula (1) to calculate the cell membrane potential at the Nth time step; finally, write the calculation results of the Nth time step into the global memory, that is, only one read and write operation is performed on the global memory every N time steps.
[0109] The N time step continuous calculation strategy of the application significantly reduces the global memory access times while ensuring the calculation accuracy, effectively reduces the memory bandwidth pressure, and improves the memory access efficiency; the calculation of multiple time steps is performed after reading data from the global memory each time, which improves the calculation density and calculation efficiency, and significantly reduces the GPU waiting delay caused by waiting for I / O response.
[0110] After adopting the N time step continuous calculation strategy, the data resides in the register for a longer time, and the reuse rate is higher, so that the effective calculation amount (i.e. calculation density) generated by unit data is significantly improved. At the same time, in the specific embodiments of the application, the loop unrolling strategy is adopted to continuously perform the cell ion channel dynamics calculation of N time steps, which effectively reduces the branch judgment and loop overhead, and improves the instruction parallelism and calculation throughput of the GPU calculation core. Experiments show that the overall simulation speed can be improved by more than 2 times.
[0111] The application realizes the reduction of the calculation resources required for equivalent simulation accuracy without sacrificing numerical stability and accuracy. Compared with the traditional method, about 50% of the GPU calculation resources can be saved or the equivalent simulation time can be shortened by more than half, effectively reducing the hardware cost and energy consumption in the process of simulation platform construction and operation, and having significant engineering application value.
[0112] B3.4: Calculate the cell membrane potential of the Nth time step according to the cardiac electrophysiological simulation model, the cell ion channel dynamics calculation result of the Nth time step and the potential diffusion term, and realize the cell state update.
[0113] B3.5: Write the calculation results of N time steps and the state variables of the cell into the global memory.
[0114] B3.6: Determine whether the simulation time reaches the set total simulation time, if not, go to step B3.2; if yes, the simulation is ended.
[0115] The application significantly reduces the I / O bottleneck caused by data loading in the simulation calculation process through the N time step continuous calculation strategy, improves the effective calculation amount corresponding to unit memory access, effectively reduces the idle time of the GPU calculation core, and improves the overall operation efficiency of the GPU; at the same time, the instruction parallelism and kernel throughput are further improved through the loop unrolling strategy. The application is particularly suitable for large-scale three-dimensional cardiac tissue electrophysiological simulation tasks, can realize more than 2 times performance improvement, has good scalability and engineering practical value, and provides a feasible path for realizing real-time cardiac electrophysiological simulation with high precision and low delay.
[0116] Example three
[0117] Figure 4A structural block diagram of a data structure optimization apparatus is shown. As shown in Figure 4 The data structure optimization apparatus comprises a construction and storage unit, a block division unit, a rejection and sorting unit, a fusion and rejection unit, an expansion unit and a construction unit.
[0118] The construction and storage unit is configured to construct a three-dimensional heart tissue model and store coordinate positions of cells in the three-dimensional heart tissue model.
[0119] The block division unit is configured to divide and expand the three-dimensional heart tissue model according to a thread bundle size M of a GPU to obtain a plurality of cell blocks, wherein the cell blocks comprise dense blocks, sparse blocks and empty blocks, the dense blocks refer to blocks in which all cells are valid cells, the sparse blocks refer to blocks in which part of the cells are valid cells, and the empty blocks refer to blocks in which there are no valid cells.
[0120] The rejection and sorting unit is configured to reject all empty blocks and sort the remaining cell blocks in descending order according to the number of valid cells.
[0121] The fusion and rejection unit is configured to fuse and reject empty blocks of the cell blocks sorted in descending order to obtain fused cell blocks.
[0122] The expansion unit is configured to expand the fused cell blocks in one dimension to obtain a one-dimensional cell sequence.
[0123] The construction unit is configured to construct a position index table according to the coordinate positions of the cells in the one-dimensional cell sequence.
[0124] In some embodiments of the present application, the data structure optimization apparatus can be combined with the data structure optimization method in Embodiment One of the present application, and vice versa.
[0125] Embodiment Four
[0126] The present application also provides an electronic device, as shown in Figure 5 The electronic device comprises a memory, a processor and computer programs / instructions stored in the memory, and the processor executes the computer programs / instructions to implement the data structure optimization method or the cardiac electrophysiology simulation method in the embodiments of the present application.
[0127] Although not shown, the electronic device includes a processor that can perform various appropriate operations and processes according to programs and / or data stored in a read-only memory (ROM) or loaded from a storage section into a random access memory (RAM). The processor can be one multi-core processor or can include a plurality of processors. In some embodiments, the processor can include a general-purpose main processor and one or more special-purpose co-processors, such as a central processing unit, a graphics processing unit (GPU), a neural processing unit (NPU), a digital signal processor (DSP), and the like. In the RAM, various programs and data required for device operations are also stored. The processor, the ROM, and the RAM are connected to each other through a bus. An input / output (I / O) interface is also connected to the bus.
[0128] The above processor and memory are used together to execute programs / instructions stored in the memory, which, when executed by a computer, can implement the methods, steps, or functions described in the above embodiments.
[0129] Although not shown, the embodiments of the present application also provide a computer-readable storage medium having stored thereon computer programs / instructions, which, when executed by a processor, implement the data structure optimization method or the cardiac electrophysiology simulation method in the embodiments of the present application.
[0130] The readable storage medium includes permanent and non-permanent, removable and non-removable media, which can be implemented by any method or technology to store information. The information can be computer-readable instructions, data structures, program modules, or other data. Examples of computer storage media include, but are not limited to, phase-change memory (PRAM), static random access memory (SRAM), dynamic random access memory (DRAM), other types of random access memory (RAM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), flash memory or other memory technologies, compact disc read-only memory (CD-ROM), digital versatile disc (DVD) or other optical storage, magnetic cassette, disk storage or other magnetic storage devices, or any other non-transmission medium that can be used to store information accessible by a computing device. According to the definition herein, computer-readable media do not include transitory media, such as modulated data signals and carriers.
[0131] While the preferred embodiments of the application have been described, additional variations and modifications can be made to these embodiments by those skilled in the art once they have the benefit of the present disclosure without departing from the spirit and scope of the application. Accordingly, it is intended that the appended claims include all such variations and modifications as fall within the scope of the present application. It is apparent that those skilled in the art can modify and adapt the present application in various ways without departing from the spirit and scope of the present application. It is therefore intended that the present application encompass all such modifications and variations as fall within the scope of the claims and their equivalents.
Claims
1. A method of data structure optimization, characterized by, The optimization method comprises: constructing a three-dimensional heart tissue model and saving coordinate positions of each cell in the three-dimensional heart tissue model; dividing and unfolding the three-dimensional heart tissue model according to a thread bundle size M of a GPU to obtain a plurality of cell blocks; wherein the cell blocks comprise dense blocks, sparse blocks and empty blocks, the dense blocks refer to all cells in the dense blocks being valid cells, the sparse blocks refer to part of cells in the sparse blocks being valid cells, and the empty blocks refer to no valid cell in the empty blocks; removing all empty blocks and sorting the remaining cell blocks in descending order according to the number of valid cells; fusing and removing the empty blocks of the cell blocks sorted in descending order to obtain fused cell blocks; one-dimensionally unfolding the fused cell blocks to obtain a one-dimensional cell sequence; constructing a position index table according to the coordinate positions of each cell in the one-dimensional cell sequence; wherein the fusion processing of the cell blocks sorted in descending order comprises: iterating each cell block in turn, and for the i th cell block, if the number of valid cells in the i th cell block is less than M, inserting the valid cells in the j th cell block into the i th cell block to obtain the i th cell block after first insertion; wherein the number of valid cells in the 1 st to i-1 th cell blocks that have been iterated is greater than or equal to M, i < j, the number of valid cells in the j+1 th to E th cell blocks is 0, and E represents the number of cell blocks sorted in descending order; if the number of valid cells in the i th cell block after first insertion is less than M and the number of valid cells in the j th cell block is equal to 0, inserting the valid cells in the j-1 th cell block into the i th cell block after first insertion to obtain the i th cell block after second insertion; and so on until the number of valid cells in the i th cell block after multiple insertions is greater than or equal to M; if the number of valid cells in the i th cell block after first insertion is greater than or equal to M and the number of valid cells in the j th cell block is equal to 0, iterating the i+1 th cell block, if the number of valid cells in the i+1 th cell block is less than M, inserting the valid cells in the j-1 th cell block into the i+1 th cell block to obtain the i+1 th cell block after first insertion; if the number of valid cells in the i th cell block after first insertion is greater than or equal to M and the number of valid cells in the j th cell block is greater than 0, iterating the i+1 th cell block, if the number of valid cells in the i+1 th cell block is less than M, inserting the remaining valid cells in the j th cell block into the i+1 th cell block to obtain the i+1 th cell block after first insertion; and so on until i=j, completing the fusion processing of all cell blocks.
2. The data structure optimization method of claim 1, wherein, The thread bundle size M of the GPU is equal to 32.
3. A method of cardiac electrophysiology simulation, characterized by, The simulation method comprises: obtaining a one-dimensional cell sequence and a position index table of a three-dimensional heart tissue model; wherein the one-dimensional cell sequence and the position index table are obtained by using the data structure optimization method according to any one of claims 1-2; loading a cardiac electrophysiological model and initializing state variables of each cell in the one-dimensional cell sequence; Updating the cell state according to the state variable of each cell, the position index table and the cardiac electrophysiology model.
4. The cardiac electrophysiology simulation method of claim 3, wherein, Updating the cell state according to the state variable of each cell, the position index table and the cardiac electrophysiology model, specifically comprising: storing the initial value of the state variable of each cell in the global memory; reading the state variable of the cell from the global memory and loading it into the register; in the register, continuously performing N time step cell ion channel dynamics calculation according to the state variable of the cell; at the Nth time step, calculating the potential diffusion term based on the position index table; wherein N>1; calculating the cell membrane potential at the Nth time step according to the cardiac electrophysiology simulation model, the cell ion channel dynamics calculation result at the Nth time step and the potential diffusion term, and realizing the cell state update; writing the calculation result of N time steps and the state variable of the cell into the global memory; repeating the steps of reading the cell state variable from the global memory, performing calculation in the register and writing the calculation result into the global memory until the simulation ends.
5. The cardiac electrophysiology simulation method of claim 4, wherein, According to the state variable of the cell, the N time step cell ion channel dynamics calculation is continuously performed by using the loop unrolling strategy.
6. The cardiac electrophysiology simulation method of claim 3, wherein, The specific expression of the cardiac electrophysiology simulation model is: ; wherein, represents the membrane capacitance per unit area; represents the cell membrane potential; represents the potential diffusion term, i.e. the propagation of the electrical signal in the cardiac tissue, represents the divergence operator, represents the diffusion coefficient, represents the gradient operator; represents the sum of the ionic currents, represents the ion channel gating variable, represents time; represents the applied stimulus current.
7. A data structure optimization apparatus, characterized by, The optimization device comprises: a construction and saving unit configured to construct a three-dimensional cardiac tissue model and save the coordinate positions of each cell in the three-dimensional cardiac tissue model; a block division unit configured to divide and expand the three-dimensional cardiac tissue model according to the thread bundle size M of the GPU to obtain a plurality of cell blocks; wherein the cell blocks include dense blocks, sparse blocks and empty blocks, the dense block refers to all cells therein being valid cells, the sparse block refers to part of the cells therein being valid cells, and the empty block refers to no valid cells therein; a rejection and sorting unit configured to reject all empty blocks and sort the remaining cell blocks in descending order according to the number of valid cells; a fusion and rejection unit configured to fuse and reject empty blocks for the cell blocks sorted in descending order to obtain fused cell blocks; an expansion unit configured to one-dimensionally expand the fused cell blocks to obtain a one-dimensional cell sequence; a construction unit configured to construct a position index table according to the coordinate positions of each cell in the one-dimensional cell sequence; wherein the fusion processing for the cell blocks sorted in descending order specifically comprises: traversing each cell block in turn, for the ith cell block, if the number of valid cells in the ith cell block is less than M, inserting the valid cells in the jth cell block into the ith cell block to obtain the ith cell block after the first insertion; wherein the number of valid cells in the first to i-1th cell blocks that have been traversed is greater than or equal to M, i If the number of effective cells in the i-th cell block after the first insertion is less than M and the number of effective cells in the j-th cell block is equal to 0, the effective cells in the j-1-th cell block are inserted into the i-th cell block after the first insertion to obtain the i-th cell block after the second insertion; and the process is repeated until the number of effective cells in the i-th cell block after the multiple insertions is greater than or equal to M; If the number of effective cells in the i-th cell block after the first insertion is greater than or equal to M and the number of effective cells in the j-th cell block is equal to 0, the i+1-th cell block is traversed, and if the number of effective cells in the i+1-th cell block is less than M, the effective cells in the j-1-th cell block are inserted into the i+1-th cell block to obtain the i+1-th cell block after the first insertion; If the number of effective cells in the i-th cell block after the first insertion is greater than or equal to M and the number of effective cells in the j-th cell block is greater than 0, the i+1-th cell block is traversed, and if the number of effective cells in the i+1-th cell block is less than M, the remaining effective cells in the j-th cell block are inserted into the i+1-th cell block to obtain the i+1-th cell block after the first insertion; The process is repeated until i=j, and the fusion processing of all cell blocks is completed.
8. An electronic device, comprising: A computer program product comprising a memory, a processor, and computer programs / instructions stored on the memory, the processor executing the computer programs / instructions to implement the data structure optimization method of any one of claims 1-2 or the cardiac electrophysiology simulation method of any one of claims 3-6.
9. A computer-readable storage medium, characterized in that, A computer program product comprising a memory, a processor, and computer programs / instructions stored on the memory, the processor executing the computer programs / instructions to implement the data structure optimization method of any one of claims 1-2 or the cardiac electrophysiology simulation method of any one of claims 3-6.
Citation Information
Patent Citations
Heart electrophysiology simulation method based on GPU
CN111091912A