A two-dimensional flood inundation simulation method based on GPU memory optimized access and related equipment
By optimizing the access and computation region partitioning on the GPU, the computational efficiency and resource utilization problems of traditional two-dimensional flood inundation simulation are solved, achieving efficient and stable flood inundation simulation results.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- GUANGDONG RES INST OF WATER RESOURCES & HYDROPOWER
- Filing Date
- 2026-04-02
- Publication Date
- 2026-07-31
AI Technical Summary
Traditional CPU implementations struggle to achieve high throughput or near real-time computation for two-dimensional flooding simulations on an engineering scale. GPU shallow water equation solvers suffer from low global memory access efficiency, high overhead for global reduction computation, complex data transmission and memory management, numerous invalid computations at wet and dry boundaries and in sparse regions, and low utilization of computational resources in irregular regions.
By constructing a two-dimensional structured mesh based on GPU memory optimization access, determining the effective computation region mask, dividing the shared memory into blocks, and utilizing GPU memory for local wave speed parallel computation and reduction, the data transmission and computation process is optimized, invalid computation is reduced, and bandwidth utilization and computational efficiency are improved.
It achieves efficient, stable and accurate two-dimensional flood inundation simulation, improves overall simulation efficiency, reduces the number of global memory reads, increases computational throughput and bandwidth utilization, and reduces synchronization overhead in the reduction process.
Smart Images

Figure CN122491092A_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of hydrodynamic numerical simulation technology, and in particular to a two-dimensional flood inundation simulation method and related equipment based on GPU memory optimized access. Background Technology
[0002] Two-dimensional shallow water equations are widely used to simulate processes such as flood evolution, dam-break wave propagation, urban flooding, and tsunamis. These problems are characterized by large computational domains, high grid resolution, and numerous time steps. Traditional CPU (Central Processing Unit) implementations are limited by thread parallelism and memory bandwidth, making it difficult to achieve high throughput or near real-time computation on an engineering scale. GPUs (Graphics Processing Units) offer high parallelism and high bandwidth, but updating shallow water equations within a finite volume requires frequent access to stencil data. Repeatedly reading stencils directly from global memory would cause bandwidth bottlenecks and performance degradation.
[0003] Among related technologies, GPU shallow water equation solvers have the following main shortcomings in large-scale grid computing: low global memory access efficiency, large overhead of global reduction calculation, complex data transmission and memory management, many invalid calculations in dry and wet boundaries and sparse regions, and low utilization of computing resources in irregular regions.
[0004] In summary, the technical problems existing in the relevant technologies need to be improved. Summary of the Invention
[0005] The embodiments of this application aim to at least partially solve one of the technical problems in the related art. Therefore, the main objective of the embodiments of this application is to propose a two-dimensional flood inundation simulation method and related equipment based on GPU memory optimized access, which can achieve efficient, stable, and accurate two-dimensional flood inundation simulation.
[0006] To achieve the above objectives, one aspect of this application proposes a two-dimensional flood inundation simulation method based on GPU memory optimization access, the method comprising the following steps: A two-dimensional structured grid is constructed based on the target raster data of the target watershed to obtain the target field; the target raster data includes ground elevation data, water depth data and flow velocity data, and the target field includes topographic field, water depth field and momentum field; Based on the effective calculation area in the ground elevation data, determine the effective calculation area mask; The two-dimensional structured mesh is logically divided to obtain several shared memory blocks, and an effective shared memory block is determined from the several shared memory blocks based on the effective computing region mask; The target field and the effective computation region mask corresponding to the effective shared memory block are copied to the GPU memory in a two-dimensional stepping manner; Within each time step, the first GPU kernel function in the GPU memory is used to perform parallel calculation of the local wave velocity of the full-field grid cells of the target field in the effective shared memory block, and parallel reduction is performed based on the parallel calculation results of the local wave velocity in the effective shared memory block to obtain the upper bound of the maximum wave velocity. Based on the upper bound of the maximum wave velocity, the global time step is calculated using the CFL condition. Combining the global time step, the second GPU kernel function in the GPU memory is used to solve the two-dimensional shallow water equation based on the effective shared memory block to obtain the conserved variables for the next time step; If the current time step reaches the preset simulation termination time, the two-dimensional flood inundation simulation results are sent back from the GPU memory to the host CPU memory at the output time interval; wherein, the two-dimensional flood inundation simulation results are determined based on the conserved variables in the next time step.
[0007] In some embodiments, the method further includes: If the current time step has not reached the preset simulation termination time, the target field in the effective shared memory block is updated based on the conserved variables of the next time step, and the process returns to the steps of performing parallel calculations of local wave velocities on the full-field grid cells of the target field in the effective shared memory block using the first GPU kernel function in the GPU memory at each time step, and performing parallel reduction to obtain the upper bound of the maximum wave velocity based on the parallel calculation results of the local wave velocity in the effective shared memory block, until the current time step reaches the preset simulation termination time, and the two-dimensional flooding simulation results are returned from the GPU memory to the host CPU memory according to the output time interval.
[0008] In some embodiments, copying the target field and the effective computation region mask corresponding to the effective shared memory block to the GPU memory in a two-dimensional step-by-step manner includes: The effective data in the target field and the effective computing region mask corresponding to the effective shared memory block are padded according to a preset alignment granularity to generate a row step length; Based on the row step size, the target field and the effective computation region mask corresponding to the effective shared memory block are copied from the host CPU memory to the GPU memory using cudaMemcpy2D or an equivalent mechanism.
[0009] In some embodiments, the step of performing parallel calculations of local wave velocities on the full-field grid cells of the target field in the effective shared memory block using the first GPU kernel function in the GPU memory at each time step, and performing parallel reduction based on the parallel calculation results of the local wave velocities in the effective shared memory block to obtain the upper bound of the maximum wave velocity, includes: Within each time step, the thread bundle in the first GPU kernel function is used to perform parallel calculation of the local wave velocity of the full-field grid cells of the target field in the effective shared memory block, so as to obtain the maximum local wave velocity corresponding to each thread bundle. Write the maximum local wave velocity corresponding to each thread bundle into the effective shared memory block, and perform block-level reduction on each maximum local wave velocity according to the first thread bundle in the effective shared memory block to obtain the block maximum wave velocity corresponding to each thread bundle; The maximum wave velocity of a block is selected from the maximum wave velocities of the blocks with the largest value as the upper bound of the maximum wave velocity.
[0010] In some embodiments, the effective shared memory block includes a Halo cooperative loading region that stores neighborhood data. The step of combining the global time step with the second GPU kernel function in the GPU memory to solve the two-dimensional shallow water equation based on the effective shared memory block to obtain the conserved variables for the next time step includes: The neighboring data in the Halo cooperative loading region is loaded using the second GPU kernel function, and the interface numerical flux of each grid cell in the effective shared memory block is calculated in combination with the neighboring data; Calculate the source term vector containing the rainfall replenishment term, topographic slope term, and friction term; Based on the global time step, and according to the source term vector and the interface numerical flux of each grid cell in the effective shared memory block, the conserved variable for the next time step is calculated.
[0011] In some embodiments, the method further includes: Based on the updated water depth data in the conserved variables at the next time step and the flow velocity data at the previous time step, the friction coefficient of each grid cell in the effective shared memory block is calculated. The momentum components of the momentum field in the effective shared memory block are semi-implicitly scaled according to each of the friction coefficients.
[0012] In some embodiments, the method further includes: Using the second GPU kernel function, dry and wet boundary processing is performed on the mesh cells in the effective shared memory block where the effective computation region mask is invalid or the water depth value is lower than a preset depth threshold, to obtain the dry and wet boundary processing result; When a completely dry block exists in the dry-wet boundary processing result, the exit operation is performed on the completely dry block through a thread collective judgment mechanism within the effective shared memory block.
[0013] To achieve the above objectives, another aspect of this application proposes a two-dimensional flood simulation device based on GPU memory optimization access, the device comprising the following modules: A two-dimensional structured mesh construction module is used to construct a two-dimensional structured mesh based on target raster data of the target watershed to obtain the target field; the target raster data includes ground elevation data, water depth data, and flow velocity data, and the target field includes topographic field, water depth field, and momentum field; The effective calculation area mask calculation module is used to determine the effective calculation area mask based on the effective calculation area in the ground elevation data; An effective shared memory block determination module is used to logically divide the two-dimensional structured mesh to obtain several shared memory blocks, and to determine the effective shared memory block from the several shared memory blocks based on the effective computing region mask; A two-dimensional step data copying module is used to copy the target field and the effective computing region mask corresponding to the effective shared memory block to the GPU memory in a two-dimensional step manner. The maximum wave velocity upper bound calculation module is used to perform parallel calculation of the local wave velocity of the full-field grid cells of the target field in the effective shared memory block using the first GPU kernel function in the GPU memory at each time step, and to perform parallel reduction based on the parallel calculation results of the local wave velocity in the effective shared memory block to obtain the maximum wave velocity upper bound. The global time step calculation module is used to calculate the global time step based on the maximum wave velocity upper bound and the CFL condition. The two-dimensional shallow water equation solving module is used to solve the two-dimensional shallow water equation by combining the global time step and using the second GPU kernel function in the GPU memory based on the effective shared memory block, so as to obtain the conserved variables for the next time step. The two-dimensional simulation result feedback module is used to feed back the two-dimensional flood inundation simulation results from the GPU memory to the host CPU memory at output time intervals if the current time step reaches the preset simulation termination time; wherein the two-dimensional flood inundation simulation results are determined based on the conserved variables in the next time step.
[0014] To achieve the above objectives, another aspect of this application provides an electronic device, which includes a memory and a processor. The memory stores a computer program, and the processor executes the computer program to implement the above-described method.
[0015] To achieve the above objectives, another aspect of the embodiments of this application proposes a computer-readable storage medium storing a computer program that, when executed by a processor, implements the above-described method.
[0016] To achieve the above objectives, another aspect of this application provides a computer program product, including a computer program that, when executed by a processor, implements the above-described method.
[0017] The embodiments of this application include at least the following beneficial effects: This application provides a two-dimensional flood simulation method and related equipment based on GPU memory optimized access. This scheme determines and deletes shared memory blocks that do not have effective computing regions based on an effective computing region mask, thereby reducing invalid computations and improving overall simulation efficiency. By reusing data through shared memory, the number of global memory reads can be significantly reduced and the effective bandwidth utilization rate can be improved. By copying the target field and effective computing region mask of the effective shared memory blocks to GPU memory in a two-dimensional step manner, the H2D / D2H transmission efficiency can be improved and the kernel function can be optimized. The system integrates access conditions; by utilizing the first GPU kernel function in the GPU memory to perform parallel calculations of the local wave velocity of the target field's full-field grid cells in the effective shared memory blocks, and performing parallel reduction based on the parallel calculation results of the local wave velocity in the effective shared memory blocks to obtain the upper bound of the maximum wave velocity, it can reduce the synchronization overhead and shared memory access overhead in the reduction process, improve the calculation efficiency of the maximum wave velocity and the overall computational throughput of subsequent time steps; by using the second GPU kernel function to solve the two-dimensional shallow water equation based on the effective shared memory blocks, it can efficiently obtain the conserved variables for the next time step, and finally achieve efficient, stable and accurate two-dimensional flood inundation simulation. Attached Figure Description
[0018] Figure 1 This is a flowchart illustrating the steps of a two-dimensional flood inundation simulation method based on GPU memory optimization access provided in this application embodiment; Figure 2 This is a schematic diagram of the overall process of a two-dimensional flood inundation simulation method based on GPU memory optimization access provided in an embodiment of this application; Figure 3 This is a schematic diagram of finite volume update and four-way flux Stencil provided in an embodiment of this application; Figure 4 This is a schematic diagram of shared memory block loading and Halo collaborative loading provided in an embodiment of this application; Figure 5 This is a schematic diagram of Warp Shuffle and block-level specification provided in an embodiment of this application; Figure 6This is a schematic diagram of the fast exit of the full dry block provided in the embodiments of this application; Figure 7 This is a schematic diagram of the dry and wet mask performing flux and source term updates provided in the embodiments of this application; Figure 8 This is a schematic diagram comparing the effective computation regions under different partitioning strategies provided in the embodiments of this application; Figure 9 This is the simulation result of urban-wide rainstorm and flooding provided in the embodiments of this application; Figure 10 These are the simulation results of localized urban rainstorms and floods provided in the embodiments of this application; Figure 11 This is a schematic diagram of the structure of a two-dimensional flood inundation simulation device based on GPU memory optimization access provided in an embodiment of this application; Figure 12 This is a schematic diagram of the hardware structure of the electronic device provided in the embodiments of this application. Detailed Implementation
[0019] To make the objectives, technical solutions, and advantages of this application clearer, the following detailed description is provided in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are merely illustrative of this application and are not intended to limit it. In the following description, when referring to the accompanying drawings, unless otherwise indicated, the same numbers in different drawings represent the same or similar elements. The embodiments described in the following exemplary embodiments do not represent all embodiments consistent with those of this application; they are merely examples of apparatuses and methods consistent with some aspects of the embodiments of this application as detailed in the appended claims.
[0020] It is understood that the terms “first,” “second,” etc., used in this application may be used herein to describe various concepts, but unless otherwise stated, these concepts are not limited by these terms. These terms are only used to distinguish one concept from another. For example, without departing from the scope of the embodiments of this application, first information may also be referred to as second information, and similarly, second information may also be referred to as first information. Depending on the context, the words “if,” “when,” or “in response to a determination” as used herein may be interpreted as “when…” or “when…” or “in response to a determination.”
[0021] As used in this application, the terms "at least one", "multiple", "each", "any", etc., "at least one" includes one, two or more, "multiple" includes two or more, "each" refers to each of the corresponding multiples, and "any" refers to any one of the multiples.
[0022] Unless otherwise defined, all technical and scientific terms used herein have the same meaning as commonly understood by one of ordinary skill in the art to which this application belongs. The terminology used herein is for the purpose of describing embodiments of this application only and is not intended to limit this application.
[0023] As an example, two-dimensional shallow water equations are widely used to simulate processes such as flood evolution, dam-break wave propagation, urban flooding, and tsunamis. These problems are characterized by large computational domains, high grid resolution, and numerous time steps. Traditional CPU implementations are limited by thread parallelism and memory bandwidth, making it difficult to achieve high throughput or near real-time computation on an engineering scale. GPUs offer high parallelism and high bandwidth, but updating the finite volume of shallow water equations requires frequent access to stencil data. Repeatedly reading stencils directly from global memory would cause bandwidth bottlenecks and performance degradation.
[0024] The following problems are typically faced by GPU shallow water equation solvers in large-scale meshes: First, repeated access to the stencil leads to a waste of global memory bandwidth; second, the calculation of the maximum wave velocity required for CFL control incurs reduction overhead; third, data transfer between the host and GPU memory and GPU memory layout management are complex in order to meet the requirements of merged access and two-dimensional data layout; fourth, dry and wet boundaries and sparse effective regions introduce a large amount of invalid computation; and fifth, for irregular research regions, since GPUs do not have branch prediction capabilities, NoData regions also need to participate in the computation, wasting GPU memory and computing power.
[0025] Therefore, designing efficient memory access modes (shared memory reuse, merge access, reduction optimization, and straddle copy) for neighborhood Stencil computing is key to improving overall performance.
[0026] In view of this, this application provides a two-dimensional flood simulation method and related equipment based on GPU memory optimized access. This method determines and deletes shared memory blocks that do not have valid computation regions based on an effective computation region mask, thereby reducing invalid computations and improving overall simulation efficiency. By reusing data in shared memory, it significantly reduces the number of global memory reads and improves effective bandwidth utilization. By copying the target field and effective computation region mask of the effective shared memory blocks to GPU memory in a two-dimensional step-by-step manner, it improves H2D / D2H transmission efficiency and enhances kernel function merging access. The question asks for the following conditions: By utilizing the first GPU kernel function in the GPU memory to perform parallel calculations of the local wave velocity in the full-field grid cells of the target field in the effective shared memory blocks, and performing parallel reduction based on the parallel calculation results of the local wave velocity in the effective shared memory blocks to obtain the upper bound of the maximum wave velocity, the synchronization overhead and shared memory access overhead in the reduction process can be reduced, thereby improving the calculation efficiency of the maximum wave velocity and the overall computational throughput of subsequent time steps; by using the second GPU kernel function to solve the two-dimensional shallow water equation based on the effective shared memory blocks, the conserved variables of the next time step can be obtained efficiently, ultimately achieving efficient, stable, and accurate two-dimensional flood inundation simulation.
[0027] This application provides a two-dimensional flood inundation simulation method based on GPU memory optimization access, relating to the field of hydrodynamic numerical simulation technology. This two-dimensional flood inundation simulation method based on GPU memory optimization access can be applied to a terminal, a server, or software running on either a terminal or a server. In some embodiments, the terminal can be a smartphone, tablet, laptop, desktop computer, smart speaker, smartwatch, or vehicle terminal, but is not limited to these. The server can be configured as an independent physical server, a server cluster or distributed system composed of multiple physical servers, or a cloud server providing basic cloud computing services such as cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communication, middleware services, domain name services, security services, CDN, and big data and artificial intelligence platforms. The server can also be a node server in a blockchain network. The software can be an application implementing a two-dimensional flood inundation simulation method based on GPU memory optimization access, but is not limited to the above forms.
[0028] This application can be used in a wide variety of general-purpose or special-purpose computer system environments or configurations. Examples include: personal computers, server computers, handheld or portable devices, tablet devices, multiprocessor systems, microprocessor-based systems, set-top boxes, programmable consumer electronics devices, network PCs, minicomputers, mainframe computers, and distributed computing environments including any of the above systems or devices. This application can be described in the general context of computer-executable instructions executed by a computer, such as program modules. Generally, program modules include routines, programs, objects, components, data structures, etc., that perform specific tasks or implement specific abstract data types. This application can also be practiced in distributed computing environments where tasks are performed by remote processing devices connected via a communication network. In distributed computing environments, program modules can reside in local and remote computer storage media, including storage devices.
[0029] Please see Figure 1 , Figure 1 This is an optional flowchart of a two-dimensional flood inundation simulation method based on GPU memory optimization access provided in an embodiment of this application. Figure 1 The method may include, but is not limited to, steps S101 to S108.
[0030] Step S101: Construct a two-dimensional structured grid based on the target grid data of the target watershed to obtain the target field; the target grid data includes ground elevation data, water depth data and flow velocity data, and the target field includes topographic field, water depth field and momentum field. Optionally, the target watershed is the area that needs to be studied, such as rivers, reservoirs, or watersheds.
[0031] Target raster data refers to data where the ground or water surface is divided into multiple small squares, with each square storing a numerical value. Specifically, target raster data includes ground elevation data, water depth data, and current velocity data. Ground elevation data represents the elevation of the ground in each raster cell within the target watershed; water depth data represents the water depth in each raster cell within the target watershed; and current velocity data represents the water flow velocity in each raster cell within the target watershed.
[0032] Two-dimensional structured meshes refer to two-dimensional planar meshes that are constructed based on grid cells and arranged in a regular and orderly manner.
[0033] The target field is the data field used for watershed numerical simulation, which includes the topographic field, water depth field, and momentum field. Specifically, the topographic field is a data field representing the distribution of topographic elevation in the watershed after mapping ground elevation data onto a two-dimensional structured grid; the water depth field is a data field representing the distribution of water depth in the watershed after mapping water depth data onto a two-dimensional structured grid; and the momentum field is a data stream representing the water flow motion state in the watershed after mapping flow velocity data onto a two-dimensional structured grid.
[0034] In the specific implementation, DEM (Digital Elevation Model) raster data, water depth raster data, and current velocity raster data are read, and a two-dimensional structured mesh is built based on the DEM raster data, water depth raster data, and current velocity raster data to obtain the topographic field, water depth field, and momentum field.
[0035] Step S102: Determine the effective calculation area mask based on the effective calculation area in the ground elevation data; The effective calculation area is the actual simulable area where there are valid values in the ground elevation data, i.e., the non-NoData area.
[0036] The effective computation area mask is a marker layer generated based on the effective computation area of ground elevation data to define the scope of numerical simulation calculations.
[0037] Step S103: Logically divide the two-dimensional structured mesh to obtain several shared memory blocks, and determine the effective shared memory blocks from the several shared memory blocks based on the effective computing region mask; Among them, shared memory partitioning refers to the grid block unit that can be computed in parallel in shared memory mode after logically dividing the two-dimensional structured grid.
[0038] For a valid shared memory block, it is a shared memory block containing a valid computing region obtained after filtering through a valid computing region mask.
[0039] In the specific implementation, the two-dimensional structured mesh is further subdivided into shared memory blocks (i.e. thread blocks), the coordinates of the shared memory blocks in the global computational mesh are stored, and based on the effective computational region mask, shared memory blocks that do not have effective computational regions are deleted to obtain effective shared memory blocks, thereby reducing the amount of computation and the amount of video memory occupied.
[0040] Step S104: Copy the target field and the effective computing region mask corresponding to the effective shared memory block to the GPU memory in a two-dimensional stepping manner; In some embodiments, step S104 may include: performing a padding operation on each row of valid data in the target field and valid computation region mask corresponding to the valid shared memory block according to a preset alignment granularity to generate a row step; based on the row step, copying the target field and valid computation region mask corresponding to the valid shared memory block from the host CPU memory to the GPU memory through cudaMemcpy2D or an equivalent mechanism.
[0041] cudaMemcpy2D is a function used for two-dimensional data copying between the CPU and GPU.
[0042] Optionally, the default alignment granularity is 32 single-precision floating-point numbers or its equivalent byte alignment granularity, so that the global memory addresses accessed by adjacent threads satisfy the merged access requirement.
[0043] Two-dimensional striding refers to an addressing mechanism for extracting or copying two-dimensional target data sub-blocks within a one-dimensional contiguously addressed physical storage space. The characteristics of two-dimensional striding are: the stride is determined based on the global row width of the source data grid; after continuously reading or writing a single row of valid data in a two-dimensional target data sub-block, the memory address pointer is offset by the stride to skip redundant memory areas in the source data grid that do not belong to the two-dimensional target data sub-block, thereby directly locating the starting physical address of the next row of the two-dimensional target data sub-block; by repeatedly executing single-row operations and address offsets, non-contiguous, skip-like extraction and transfer of two-dimensional target data sub-blocks in memory is achieved. For example, the two-dimensional striding method includes padding each row of valid data length nx with a preset alignment granularity to form the row stride, denoted as stride_nx, and completing the two-dimensional copy between the host and video memory through cudaMemcpy2D or an equivalent mechanism.
[0044] Specifically, each thread within the GPU thread block traverses the elements in the effective shared memory tile using a linear index, and loads the water depth, momentum, terrain, and effective computation area mask at the corresponding global coordinates in the video memory to the GPU for computation according to the global coordinate mapping relationship.
[0045] Step S105: In each time step, the first GPU kernel function in the GPU memory is used to perform parallel calculation of the local wave velocity of the full-field grid cells of the target field in the effective shared memory block, and parallel reduction is performed based on the parallel calculation result of the local wave velocity in the effective shared memory block to obtain the upper bound of the maximum wave velocity. In some embodiments, step S105 may include: in each time step, using the thread bundles in the first GPU kernel function to perform parallel calculations of the local wave velocity of the full-field grid cells of the target field in the effective shared memory block, to obtain the maximum local wave velocity corresponding to each thread bundle; writing the maximum local wave velocity corresponding to each thread bundle into the effective shared memory block, and performing block-level reduction on each maximum local wave velocity according to the first thread bundle in the effective shared memory block, to obtain the block maximum wave velocity corresponding to each thread bundle; selecting the block maximum wave velocity with the largest value from several block maximum wave velocities as the upper bound of the maximum wave velocity.
[0046] The first GPU kernel function is a parallel function that runs on the GPU to calculate local wave speeds.
[0047] The local wave velocity is the water wave velocity at each grid cell, which is a parameter used to determine the time step in hydrodynamic simulation.
[0048] Specifically, the parallel reduction of the first GPU kernel function includes: first, using the WarpShuffle instruction to find the maximum value of the local wave velocity in a Warp (Warp is a thread bundle), then writing the maximum value results obtained by each Warp into shared memory and having the first Warp complete the block-level reduction to output the maximum wave velocity of the block, and finally using the maximum value of the maximum wave velocity of all blocks as the upper bound of the maximum wave velocity.
[0049] The upper bound for the maximum wave velocity is the maximum value among all local wave velocities of all grid cells, used to determine the global time step of the numerical simulation. The global time step satisfies the CFL condition.
[0050] Step S106: Calculate the global time step based on the CFL condition according to the upper limit of the maximum wave velocity; The CFL condition (Courant-Friedrichs-Lewy condition) is the core criterion for ensuring computational stability in numerical simulations. The global time step is a uniform time step calculated based on the CFL condition, applicable to the simulation of the entire target watershed, within which all grid cells synchronously update their data.
[0051] Step S107: Combining the global time step, the second GPU kernel function in the GPU memory is used to solve the two-dimensional shallow water equation based on the effective shared memory block to obtain the conserved variables for the next time step. Optionally, the effective shared memory block includes a Halo cooperative loading region, which is an additional buffer set at the edge of the effective shared memory block to store the grid data of adjacent blocks. That is, the Halo cooperative loading region stores neighborhood data, which can solve the computational dependency problem at the block boundary.
[0052] Neighborhood data, which includes topography, water depth, flow velocity, and other data of the grid cells surrounding the grid cell, is used to calculate the numerical flux of the interface.
[0053] In some embodiments, step S107 may include: loading neighborhood data in the Halo collaborative loading region using a second GPU kernel function, and calculating the interface numerical flux of each grid cell in the effective shared memory block using the neighborhood data; calculating the source term vector including rainfall supply, terrain slope, and friction terms; and calculating the conserved variables for the next time step based on the source term vector and the interface numerical flux of each grid cell in the effective shared memory block, using the global time step.
[0054] The second GPU kernel function is a parallel function running on the GPU for solving the two-dimensional shallow water equations, serving as the computational vehicle for hydrodynamic numerical simulation. The operations performed by the second GPU kernel function include: Halo cooperative loading based on efficient shared memory blocks, calculating the interface numerical flux in the x and y directions of the grid cells, and updating conserved variables based on the interface numerical flux and source term vectors. Finally, it obtains the conserved variables (water depth and flow velocity) for the next time step, where the flow velocity is calculated from the momentum field and the water depth field.
[0055] The two-dimensional shallow water equation is the core governing equation for describing water movement within a watershed. It is derived based on the conservation of mass and momentum and is suitable for simulating water flow in shallow water environments.
[0056] For conserved variables, these mainly include data such as water depth and flow velocity.
[0057] In some embodiments, the method may further include: using a second GPU kernel function to perform dry and wet boundary processing on mesh cells whose effective computation region mask is invalid or whose water depth value is lower than a preset depth threshold in the effective shared memory block, to obtain the dry and wet boundary processing result; when there is a completely dry block in the dry and wet boundary processing result, an exit operation is performed on the completely dry block in the effective shared memory block through a thread collective judgment mechanism.
[0058] The second GPU kernel function also performs dry and wet boundary processing on grid cells in the effective shared memory block where the effective computation region mask is invalid or the water depth is below the threshold. Within the block, it uses a thread collective judgment mechanism to quickly exit all dry blocks to avoid invalid computation. For blocks with valid cells, it performs flux and source term calculation updates on all grid cells within the block.
[0059] In some embodiments, the method may further include: calculating the friction coefficient of each grid cell in the effective shared memory block based on the updated water depth data in the conserved variables of the next time step and the flow velocity data of the previous time step; and semi-implicitly scaling the momentum components of the momentum field in the effective shared memory block according to each friction coefficient.
[0060] In the specific implementation, the terrain slope term is calculated and superimposed in the update of the conserved variables, and the Manning friction term is semi-implicitly processed. The semi-implicit processing of the Manning friction term includes: calculating the friction coefficient K based on the updated water depth and the flow velocity of the previous time step only for the grid of the effective computational region, and semi-implicitly scaling the momentum component with a scaling factor of 1 / (1+dt·K).
[0061] Specifically, in calculating the conserved variables (water depth, flow velocity) for the next time step, the updated water depth is first calculated based on the interface numerical flux, topographic slope term, and the water depth of the previous time step; then, the friction coefficient K is calculated based on the updated water depth and the flow velocity of the previous time step, and the intermediate predicted momentum is calculated based on the interface numerical flux and topographic slope term. Furthermore, based on the friction coefficient K, the intermediate predicted momentum ( Semi-implicit scaling is performed to obtain the updated momentum components / flow velocity; finally, based on the updated momentum components / flow velocity and the updated water depth, the conserved variables for the next time step are constructed.
[0062] Furthermore, in the calculation of the conserved variables for the next time step, the rainfall replenishment term is an external input, a known value, which participates in the calculation of the conserved variables for the next time step. Specifically, the rainfall replenishment term simulates the amount of water entering the computational domain during rainfall, serving as a source term in the update of water depth and momentum, making the solution of the two-dimensional shallow water equations more consistent with real hydrophysical processes.
[0063] Step S108: If the current time step reaches the preset simulation termination time, the two-dimensional flood inundation simulation results are sent back from the GPU memory to the host CPU memory according to the output time interval; wherein, the two-dimensional flood inundation simulation results are determined based on the conserved variables in the next time step.
[0064] Among them, the two-dimensional flood inundation simulation results are the global grid water depth and flow velocity distribution calculated based on the conserved variables output at each time step.
[0065] In some embodiments, the method may further include: if the current time step has not reached the preset simulation termination time, updating the target field in the effective shared memory block based on the conserved variables of the next time step, and returning to the steps of performing parallel calculation of local wave velocity on the full-field grid cells of the target field in the effective shared memory block using the first GPU kernel function in the GPU memory in each time step, and performing parallel reduction to obtain the upper bound of the maximum wave velocity based on the parallel calculation results of the local wave velocity in the effective shared memory block, until the current time step reaches the preset simulation termination time, and then transferring the two-dimensional flooding simulation results from the GPU memory to the host CPU memory at the output time interval.
[0066] Steps S101 to S108 as illustrated in this embodiment determine and delete shared memory blocks that do not have valid computation regions based on the effective computation region mask, thereby reducing invalid computations and improving overall simulation efficiency. By reusing data in shared memory, the number of global memory reads can be significantly reduced, and the effective bandwidth utilization rate can be improved. By copying the target field and effective computation region mask of the effective shared memory blocks to the GPU memory in a two-dimensional step-by-step manner, the H2D / D2H transfer efficiency can be improved, and the kernel function merging access conditions can be improved. Furthermore, by utilizing the GPU memory… The first GPU kernel function in the memory performs parallel calculations of local wave velocities on the full-field grid cells of the target field in the effective shared memory blocks. Based on the parallel calculation results of local wave velocities in the effective shared memory blocks, it performs parallel reduction to obtain the upper bound of the maximum wave velocity. This reduces the synchronization overhead and shared memory access overhead in the reduction process, and improves the calculation efficiency of the maximum wave velocity and the overall computational throughput of subsequent time steps. The second GPU kernel function solves the two-dimensional shallow water equations based on the effective shared memory blocks, which can efficiently obtain the conserved variables for the next time step, and finally achieves efficient, stable and accurate two-dimensional flood inundation simulation.
[0067] To explain in detail the principles of the technical solution of this application, the overall process of this application will be described below with reference to some specific embodiments. It is easy to understand that the following is an explanation of the technical principles of this application and should not be regarded as a limitation of this application.
[0068] Please see Figure 2 , Figure 2 This is a schematic diagram of the overall process of a two-dimensional flood inundation simulation method based on GPU memory optimization access provided in an embodiment of this application, as shown below. Figure 2 As shown, the host is mainly responsible for data preparation, program loading, and result output, while the graphics processor is mainly responsible for specific parallel computing tasks and performs collaborative computing through CUDA. Figure 2The steps handled by the host computer include reading initial conditions, preprocessing basic data, allocating computing memory, loading the CUDA backend computing program, monitoring computing progress, receiving GPU computing data, and outputting computing results. The steps handled by the graphics processor include GPU memory allocation, straddle memory layout + 2D straddle copying, maximum wave velocity reduction, numerical flux calculation, shallow water equation time step progression, and determining completion status (loop control). In numerical simulations of fluid dynamics (such as shallow water equations), initial conditions typically include initial water depth, initial flow velocity, computational domain boundary conditions, physical parameters (such as gravitational acceleration, friction coefficient, etc.), and mesh information. In this embodiment, the initial conditions mainly consist of DEM raster data, water depth raster data, and flow velocity raster data. These initial conditions are the starting point of the numerical simulation, providing basic data for subsequent GPU parallel computing. Figure 2 In this process, the data is read in and preprocessed, and then allocated to GPU memory for high-performance computing.
[0069] Specifically, the overall process of a two-dimensional flood inundation simulation method based on GPU memory optimization access provided in this application embodiment includes, but is not limited to, the following steps S201-S207: Step S201: Read DEM raster data, water depth raster data and current velocity raster data, and establish a two-dimensional structured mesh based on DEM raster data, water depth raster data and current velocity raster data to obtain topographic field, water depth field and momentum field. Calculate the effective computational area mask based on the non-NoData (no data) area of DEM raster data. Step S202 further subdivides the two-dimensional structured mesh into shared memory blocks (i.e. thread blocks), stores the coordinates of the shared memory blocks in the global computational mesh, and deletes shared memory blocks that do not have effective computational regions based on the effective computational region mask, thereby obtaining effective shared memory blocks, thereby reducing the amount of computation and GPU memory usage.
[0070] The shared memory segmentation includes: the size of the shared memory tile is determined by the thread block size (Bx, By) as (Bx+2, By+2), and the area with an extra boundary width of 1 is the Halo area.
[0071] In this embodiment, when reading Digital Elevation Model (DEM) data, the original data is a global two-dimensional mesh matrix, in which only a portion of the area contains valid data. After performing block operations on the global two-dimensional mesh matrix, memory blocks without valid data are filtered and removed based on the effective computation area mask, retaining only the blocks containing valid data and loading them into the GPU memory as the basis for parallel computing. Furthermore, during the GPU parallel computing stage, dynamic wet / dry discrimination is further performed on the valid memory blocks already loaded into the memory: wet / dry boundary processing is performed on mesh cells with invalid effective computation area masks or water depths below a threshold, and within the block, a thread-based collective judgment mechanism quickly exits completely dry blocks to avoid invalid computation; for blocks containing valid cells, flux and source term calculations are performed on all mesh cells within that block for updates.
[0072] Step S203: The terrain field, water depth field, momentum field, and effective computation region mask corresponding to the effective shared memory blocks are written to the GPU memory in a two-dimensional stride manner. The two-dimensional stride manner includes padding each row of effective data length nx with a preset alignment granularity to form a row stride, denoted as stride_nx, and completing the two-dimensional copy between the host and the GPU memory through cudaMemcpy2D or an equivalent mechanism.
[0073] The alignment granularity is 32 single-precision floating-point numbers or their equivalent byte alignment granularity, which ensures that global memory addresses accessed by adjacent threads satisfy merged access.
[0074] Specifically, each thread within the GPU thread block traverses the elements in the effective shared memory tile using a linear index, and loads the water depth, momentum, terrain, and effective computation area mask at the corresponding global coordinates in the video memory to the GPU for computation according to the global coordinate mapping relationship.
[0075] Step S204: In each time step, the local wave velocity is calculated in parallel on the full-field mesh after deleting the non-valid computation region using the first GPU kernel function, and parallel reduction is performed to obtain the upper bound of the maximum wave velocity. Specifically, the parallel reduction of the first GPU kernel function includes: first, using the Warp Shuffle instruction to find the maximum value of the local wave velocity in the Warp, then writing the maximum value results obtained by each Warp into shared memory and having the first Warp complete the block-level reduction to output the maximum wave velocity of the block, and finally using the maximum value of the maximum wave velocity of all blocks as the upper bound of the maximum wave velocity.
[0076] Step S205: Calculate the global time step dt based on the upper bound of the maximum wave velocity and the CFL condition; Step S206: Explicit time-stepping is performed on the depth field and momentum field using the second GPU kernel function; the time step size is the global time step size dt calculated in step S205; the operations performed by the second GPU kernel function include Halo cooperative loading based on shared memory blocks, calculating the numerical flux in the x and y directions of the grid cells, and updating the conserved variables based on the numerical flux and source terms, ultimately obtaining the conserved variables (depth and velocity) for the next time step, where the velocity is calculated from the momentum field and depth field.
[0077] Furthermore, in the conservation variable update of step S206, the terrain slope term is calculated and superimposed, and the Manning friction term is semi-implicitly processed. The semi-implicit processing of the Manning friction term includes: calculating the friction coefficient K based on the updated water depth and the flow velocity of the previous time step only for the grid of the effective calculation area, and semi-implicitly scaling the momentum component with a scaling factor of 1 / (1+dt·K).
[0078] The second GPU kernel function also performs dry and wet boundary processing on grid cells with invalid masks or water depths below the threshold for effective computation regions, and quickly exits all dry blocks within the block through a thread collective judgment mechanism to avoid invalid computation; for blocks with effective cells, it performs flux and source term calculation updates on all grid cells within the block.
[0079] For the central type numerical flux at the grid cell interface, namely the interface numerical flux, it is a local Lax-Friedrichs flux. The flux wave velocity of the interface numerical flux is taken as the upper bound of the sum of the velocities of adjacent cells and the gravitational wave velocity. It is used to stably calculate the water exchange volume at the grid cell interface when solving the two-dimensional shallow water equation in parallel on the GPU, ensuring that the explicit time progression does not diverge and the numerical calculation is stable and reliable.
[0080] Step S207: Repeat steps S204 to S206 until the simulation termination time is reached, and transfer the simulated water depth and simulated flow velocity results from the video memory to the CPU memory and write them out according to the output time interval.
[0081] To address the aforementioned issues, the core technical solution of a two-dimensional flood inundation simulation method based on optimized GPU memory access provided in this application is as follows: (1) The conservative shallow water equation is discretized using a finite volume framework and explicitly updated using a central numerical flux (local Lax-Friedrichs / Rusanov flux); (2) Introduce shared memory block and Halo collaborative loading in the time-progression GPU kernel function: each thread block covers a computing core area and additionally loads a Halo area with a width of 1; the water depth h, x-direction flow velocity hu, y-direction flow velocity hv, terrain elevation z and effective computing area mask are cached in the shared memory at the same time. During the calculation, the neighboring cells are read from the shared memory to reduce the number of global memory accesses. (3) Based on the shared memory block strategy, combined with the effective computing region mask, the shared memory blocks that do not have an effective computing region are deleted to reduce the amount of computation and the amount of video memory occupied; (4) In both the maximum wave velocity calculation and time advancement, the Warp Shuffle reduction combined with shared memory is used to realize the block-level maximum value calculation, which is used for CFL time step control and the next wave velocity estimation. (5) By aligning the valid data nx with 32 floats, stride_nx is obtained. It is then used with cudaMemcpy2D to implement two-dimensional stride H2D / D2H copy, which makes the addresses of each row in the video memory aligned and easier to merge. The kernel function accesses the video memory through the stride index. (6) Perform dry and wet processing on meshes with invalid masks and water depths below the threshold tol_h, and use the thread collective decision primitive to quickly exit fully dry thread blocks to reduce invalid calculations; (7) In terms of source term processing, the central difference approximation of terrain slope is used to form the source term, and the Manning friction term is semi-implicitly updated to enhance stability. (8) Provide Python backend selection and scheduling at the system level, supporting backends such as CPU, CUDA C (NVRTC / CuPyRawKernel) and CUDA extensions (.pyd), and can be extended to multi-GPU partitions and Peer-to-Peer data transfer.
[0082] The governing equations and numerical algorithm for a two-dimensional flood inundation simulation method based on GPU memory optimization access provided in this application are as follows: I. Governing equations: Using the two-dimensional shallow water equation as the governing equation, the unknowns are water depth and unit width discharge: ; in, For conserved variables, Because of the water depth, The average flow velocities in the x and y directions are respectively. For the unit width flow rate in the x direction, Let be the unit width flow rate in the y-direction. The conservation form of the two-dimensional shallow water equation is: ; in, Let x be the flux vector in the x-direction. Let y be the flux vector in the y-direction. For the source term vector, t represents the terrain elevation, and t represents time.
[0083] The flux vector is taken as: ; The source terms include rainfall replenishment, terrain slope, and friction. Expressed as: ; in, Rainfall intensity (the increase in water depth per unit time). It is the acceleration due to gravity. Let be the bottom frictional stress in the x-direction. The base frictional stress is in the y-direction. Specifically, the rainfall replenishment term is based on rainfall intensity. Calculated; the terrain slope term is based on (The slope driving term of the terrain in the x-direction) and (The slope driving term of the terrain in the y-direction) is calculated; the friction term is based on... and Calculated.
[0084] In this embodiment, the friction term is handled semi-implicitly in the form of Manning; specifically, the equivalent coefficient of friction... Take as: ; in, This is the Manning roughness coefficient. When ( When the water depth threshold is used, define The momentum is set to zero to achieve dry-wet boundary stabilization.
[0085] II. Numerical Algorithm: The shallow water equations are solved using a finite volume discretization method on a two-dimensional structured mesh. (See also...) Figure 3 , Figure 3 This is a schematic diagram of finite volume update and four-way flux Stencil provided in the embodiments of this application. A schematic diagram of the two-dimensional structured mesh is shown below. Figure 3 As shown, each computational unit contains four interfaces: east, west, south, and north. Numerical flux needs to be solved for each interface. Let the grid step size be... , No. Each grid cell at time... The conserved variables are Then explicit time progression is expressed as: ; in, For the first Each grid cell at time... Conservative variables, For time step, and It is the step size of the mesh element in the x and y directions. and Let x be the interface numerical flux of the interface in the x-direction. and This represents the interface numerical flux in the y-direction. For the first The source term vector of each grid cell.
[0086] The interface numerical flux adopts the local Lax-Friedrichs (Rusanov) form. The interface is shown in the x-direction. For example: ; in, and Let x be the interface numerical flux in the x-direction corresponding to the conserved variables of the left and right units of the interface. These are the conserved variables (center values or equivalent reconstructed values) of the left and right units of the interface, respectively, with the upper bound of the wave velocity taken as... ,in, The water depth in the left-hand unit of the interface. The water depth in the right-hand unit of the interface; flux in the y direction Similarly, the upper bound of wave speed is taken as .
[0087] Topographic slope ( , Central difference method is used to obtain: ; The friction term employs semi-implicit scaling on the momentum component: first, the intermediate predicted momentum without friction is obtained. Then, the equivalent friction coefficient is introduced. For intermediate predicted momentum Perform semi-implicit scaling to obtain the momentum at the next time step. The time step is adaptively determined based on the CFL condition.
[0088] Calculate the local wave velocity for each effective element. ; Take the maximum wave velocity across the entire field. and order ; in, To prevent division by zero constants, the above algorithm corresponds to the GPU implementation: the maximum wave velocity is obtained through Warp Shuffle and block-level reduction, flux updates are performed in shared memory tiles, and terrain slope and friction terms are superimposed according to the above formula.
[0089] It should be noted that this embodiment is only a brief illustrative description of the overall process of a two-dimensional flood inundation simulation method based on GPU memory optimization access. Detailed descriptions of each step can be found in the relevant content of the foregoing embodiments, and will not be repeated here. It is understood that this application does not impose any limitations on this.
[0090] The solutions of this application embodiment will be further described below with reference to specific application examples: Example 1: Shared memory block loading of time-advanced kernel functions and Halo cooperative loading: Please see Figure 4 , Figure 4 This is a schematic diagram of shared memory block loading and Halo collaborative loading provided in the embodiments of this application, as shown below. Figure 4 As shown, the time-advancement kernel function processes the tile region in units of thread blocks. Let the dimension of the thread block be (Bx, By), and the dimension of the shared memory tile be (Bx+2, By+2). Within each thread block, each thread traverses the sm_size elements of the tile using a linear index k, loading the data at the corresponding global coordinates (gx, gy) into shared memory. To reduce read latency, the kernel function uses read-only cache hints to read the read-only array. After loading, threads synchronize to ensure consistency in shared memory, then calculate the throughput based on the neighbor data in shared memory and update the central unit.
[0091] Example 2, Maximum wave velocity calculation and CFL time step control: Please see Figure 5 , Figure 5 This is a schematic diagram of Warp Shuffle and block-level specification provided in the embodiments of this application, such as... Figure 5 As shown, the maximum wave velocity kernel function calculates the local wave velocity s for each effective grid cell and obtains the maximum value max(s) within a Warp using a shuffle instruction. The maximum value max(s) of each Warp is written to shared memory, and then the first Warp (warp0) performs block-level reduction, outputting the maximum wave velocity for each block. Further reduction of the block maximum value is performed on the Python side to obtain the upper bound of the global wave velocity, and dt is determined by the CFL condition.
[0092] Example 3: Rapid withdrawal of dry and wet masks and fully dry blocks: Please see Figure 6-7 , Figure 6 This is a schematic diagram of the fast exit of the entire dry block provided in the embodiments of this application. Figure 7This is a schematic diagram illustrating the flux and source term update of the dry and wet mask operation provided in the embodiments of this application, as shown below. Figure 6 and Figure 7 As shown, the mask is loaded synchronously during the shared memory loading phase, and the existence of any valid units is determined collectively by threads within the block. If there are no valid units in the entire block, zeros are written directly and the process exits quickly to avoid subsequent throughput and source item calculations. If there are valid units, throughput and source item calculations are performed to update the process.
[0093] Example 4, please refer to Figure 8 , Figure 8 This is a schematic diagram comparing the effective computation regions under different partitioning strategies provided in the embodiments of this application, such as... Figure 8 As shown, by using a shared memory partitioning strategy to increase the number of partitions and significantly eliminate invalid computational grids in irregular research areas, the computational load can be greatly reduced. Taking City A in Province G as an example, using 16×16 partitions can reduce the computational load by 58.2%.
[0094] Example 5: Simulation of rainstorm and flooding in a city in Guangdong Province: Please see Figure 9-10 , Figure 9 This is the simulation result of a city-wide rainstorm and flooding in an embodiment of this application. Figure 10 This is a simulation result of localized urban rainstorm and flooding provided in the embodiments of this application, such as... Figure 9 and Figure 10 As shown, taking City A in Province G as an example, the application method and effect of the model provided in this application are demonstrated. Figure 9 The results of the rainstorm and flood simulation were presented. Figure 10 The results of a local simulation are presented. The study area was characterized using a 4m high-precision DEM. Based on the proposed two-dimensional rapid flood inundation simulation method, the computational region was discretized into a two-dimensional unstructured grid. When a 10-year return period rainfall event was input to simulate flood inundation in the study area, this application demonstrated extremely high computational efficiency, simulating a 3-hour rainstorm and flood event (approximately 100 million computational grids) in just 200 seconds, meeting the needs for real-time flood forecasting and early warning.
[0095] In summary, this application provides a two-dimensional flood inundation simulation method based on GPU memory optimization access, specifically relating to the fields of hydrodynamic numerical simulation, computational fluid dynamics (CFD), and parallel computing technology, and particularly to a method for efficiently solving two-dimensional shallow water equations using a GPU under Python scheduling. This application employs a finite volume framework to discretize the water depth and momentum conservation equations, uses a central-type numerical flux (local Lax-Friedrichs / Rusanov flux) to achieve stable explicit time propagation, and introduces semi-implicit treatment of topographic slope and Manning friction terms to enhance stability. To overcome the GPU bandwidth bottleneck, a shared memory block and Halo collaborative loading mechanism for Stencil memory access is proposed: before computation, thread blocks collaboratively move water depth, momentum, terrain, and mask data from global memory to shared memory according to the computational core area + Halo area, reducing redundant memory access and improving memory merging rate; and adopts maximum wave velocity parallel reduction and block-level reduction based on Warp Shuffle to quickly obtain the upper bound of the full-field wave velocity required for CFL control; further, by using a 128-byte aligned row stride and cudaMemcpy2D for two-dimensional stride copying, the efficiency of data transmission and kernel function memory access is improved without changing the algorithm semantics. The two-dimensional flood inundation simulation system based on GPU memory optimized access provided in this application provides automatic backend selection and multi-GPU partition scheduling on the Python side, supports CPU, CUDA C (NVRTC / CuPy), and CUDA extension (.pyd) backends, and is suitable for efficient simulation of large-scale hydrodynamic processes such as dam breaks and flood evolution.
[0096] The two-dimensional flood simulation method based on optimized GPU memory access provided in this application has the following advantages compared with implementations that only use global memory access and have unoptimized reduction and transport layout: (1) By reusing Stencil neighborhood data through shared memory, the number of global memory reads is significantly reduced and the effective bandwidth utilization is improved (e.g., Figure 4 (as shown) (2) By reducing reduction synchronization and shared memory access overhead through Warp Shuffle and block-level reduction, the overall throughput of maximum wave speed computation and time stepping is improved (e.g., Figure 5 (as shown) (3) Improve H2D / D2H transmission efficiency and improve kernel function merge access conditions by stride alignment and two-dimensional stride copy; (4) Rapid exit via masking and full dry block reduces invalid computation, especially suitable for sparse wet region problems (such as...). Figure 6 and Figure 7 (as shown) (5) By using a shared memory partitioning strategy, the number of partitions is increased, significantly eliminating invalid computational grids in irregular research areas. Taking City A in Province G as an example, using 16×16 partitions can reduce the computational load by 58.2% (e.g., Figure 8 (as shown) (6) Implement automatic backend selection and scheduling on the Python side to facilitate project deployment and expansion.
[0097] Please see Figure 11 This application also provides a two-dimensional flood simulation device 1100 based on GPU memory optimized access, which can implement the above-mentioned method. The device includes the following modules: The two-dimensional structured mesh construction module 1101 is used to construct a two-dimensional structured mesh based on the target raster data of the target watershed to obtain the target field; the target raster data includes ground elevation data, water depth data and flow velocity data, and the target field includes topographic field, water depth field and momentum field. The effective calculation area mask calculation module 1102 is used to determine the effective calculation area mask based on the effective calculation area in the ground elevation data; The effective shared memory block determination module 1103 is used to logically divide the two-dimensional structured mesh to obtain several shared memory blocks, and determine the effective shared memory block from the several shared memory blocks based on the effective computing region mask; The two-dimensional step data copying module 1104 is used to copy the target field and the effective computing region mask corresponding to the effective shared memory block to the GPU memory in a two-dimensional step manner. The maximum wave velocity upper bound calculation module 1105 is used to perform parallel calculation of the local wave velocity of the full-field grid cells of the target field in the effective shared memory block using the first GPU kernel function in the GPU memory at each time step, and to perform parallel reduction based on the parallel calculation result of the local wave velocity in the effective shared memory block to obtain the maximum wave velocity upper bound. The global time step calculation module 1106 is used to calculate the global time step based on the CFL condition according to the upper limit of the maximum wave velocity. The two-dimensional shallow water equation solving module 1107 is used to combine the global time step and use the second GPU kernel function in the GPU memory to solve the two-dimensional shallow water equation based on the effective shared memory block to obtain the conserved variables for the next time step. The two-dimensional simulation result feedback module 1108 is used to feed back the two-dimensional flood inundation simulation results from the GPU memory to the host CPU memory at output time intervals if the current time step reaches the preset simulation termination time; wherein the two-dimensional flood inundation simulation results are determined based on the conserved variables in the next time step.
[0098] It is understood that the content of the above method embodiments is applicable to the present device embodiments. The specific functions implemented by the present device embodiments are the same as those of the above method embodiments, and the beneficial effects achieved are also the same as those achieved by the above method embodiments.
[0099] This application also provides an electronic device, which includes a memory and a processor. The memory stores a computer program, and the processor executes the computer program to implement the above-described method. This electronic device can be any smart terminal, including tablet computers, in-vehicle computers, etc.
[0100] It is understood that the content of the above method embodiments is applicable to this device embodiment. The specific functions implemented by this device embodiment are the same as those of the above method embodiments, and the beneficial effects achieved are also the same as those achieved by the above method embodiments.
[0101] Please see Figure 12 , Figure 12 The hardware structure of an electronic device according to another embodiment is illustrated. The electronic device includes: The processor 1201 can be implemented using a general-purpose CPU (Central Processing Unit), microprocessor, application-specific integrated circuit (ASIC), or one or more integrated circuits, and is used to execute relevant programs to implement the technical solutions provided in the embodiments of this application. The memory 1202 can be implemented as a read-only memory (ROM), a static storage device, a dynamic storage device, or a random access memory (RAM). The memory 1202 can store the operating system and other applications. When the technical solutions provided in the embodiments of this specification are implemented through software or firmware, the relevant program code is stored in the memory 1202 and is called and executed by the processor 1201 using the methods described in the embodiments of this application. The input / output interface 1203 is used to implement information input and output; The communication interface 1204 is used to enable communication and interaction between this device and other devices. Communication can be achieved through wired means (such as USB, network cable, etc.) or wireless means (such as mobile network, WIFI, Bluetooth, etc.). Bus 1205 transmits information between various components of the device (e.g., processor 1201, memory 1202, input / output interface 1203, and communication interface 1204); The processor 1201, memory 1202, input / output interface 1203 and communication interface 1204 are connected to each other within the device via bus 1205.
[0102] This application also provides a computer-readable storage medium storing a computer program that, when executed by a processor, implements the above-described method.
[0103] It is understood that the content of the above method embodiments is applicable to this storage medium embodiment. The specific functions implemented in this storage medium embodiment are the same as those in the above method embodiments, and the beneficial effects achieved are also the same as those achieved in the above method embodiments.
[0104] This application also provides a computer program product, including a computer program that, when executed by a processor, implements the above-described method.
[0105] It is understood that the content of the above method embodiments is applicable to the embodiments of this program product. The specific functions implemented by the embodiments of this program product are the same as those of the above method embodiments, and the beneficial effects achieved are also the same as those achieved by the above method embodiments.
[0106] Memory, as a non-transitory computer-readable storage medium, can be used to store non-transitory software programs and non-transitory computer-executable programs. Furthermore, memory may include high-speed random access memory, and may also include non-transitory memory, such as at least one disk storage device, flash memory device, or other non-transitory solid-state storage device. In some embodiments, memory may optionally include memory remotely located relative to the processor, and these remote memories can be connected to the processor via a network. Examples of such networks include, but are not limited to, the Internet, intranets, local area networks, mobile communication networks, and combinations thereof.
[0107] This application provides a two-dimensional flood simulation method and related equipment based on GPU memory optimized access. It identifies and deletes shared memory blocks lacking valid computation regions based on an effective computation region mask, thereby reducing invalid computations and improving overall simulation efficiency. By reusing data in shared memory, it significantly reduces the number of global memory reads and improves effective bandwidth utilization. Furthermore, by copying the target field and effective computation region mask of the effective shared memory blocks to GPU memory in a two-dimensional step-by-step manner, it improves H2D / D2H transmission efficiency and enhances kernel function merge access conditions. By utilizing the first GPU kernel function in GPU memory to perform parallel calculations of local wave velocities in the full-field grid cells of the target field in the effective shared memory blocks, and performing parallel reduction based on the parallel calculation results of local wave velocities in the effective shared memory blocks to obtain the upper bound of the maximum wave velocity, the synchronization overhead and shared memory access overhead in the reduction process can be reduced, thereby improving the calculation efficiency of the maximum wave velocity and the overall computational throughput of subsequent time steps. Utilizing the second GPU kernel function to solve the two-dimensional shallow water equations based on the effective shared memory blocks, the conserved variables for the next time step can be obtained efficiently, ultimately achieving efficient, stable, and accurate two-dimensional flood inundation simulation. The embodiments described in this application are for the purpose of more clearly illustrating the technical solutions of the embodiments of this application and do not constitute a limitation on the technical solutions provided by the embodiments of this application. Those skilled in the art will understand that with the evolution of technology and the emergence of new application scenarios, the technical solutions provided by the embodiments of this application are also applicable to similar technical problems.
[0108] Those skilled in the art will understand that the technical solutions shown in the figures do not constitute a limitation on the embodiments of this application, and may include more or fewer steps than shown, or combine certain steps, or different steps.
[0109] The device embodiments described above are merely illustrative. The units described as separate components may or may not be physically separate; that is, they may be located in one place or distributed across multiple network units. Some or all of the modules can be selected to achieve the purpose of this embodiment according to actual needs.
[0110] Those skilled in the art will understand that all or some of the steps in the methods disclosed above, as well as the functional modules / units in the systems and devices, can be implemented as software, firmware, hardware, or suitable combinations thereof.
[0111] The terms “first,” “second,” “third,” “fourth,” etc. (if present) in the specification and accompanying drawings of this application are used to distinguish similar objects and are not necessarily used to describe a specific order or sequence. It should be understood that such data can be interchanged where appropriate so that the embodiments of this application described herein can be implemented in orders other than those illustrated or described herein. Furthermore, the terms “comprising” and “having,” and any variations thereof, are intended to cover a non-exclusive inclusion; for example, a process, method, system, product, or apparatus that comprises a series of steps or units is not necessarily limited to those steps or units explicitly listed, but may include other steps or units not explicitly listed or inherent to such processes, methods, products, or apparatus.
[0112] It should be understood that in this application, "at least one (item)" means one or more, and "more than" means two or more. "And / or" is used to describe the relationship between related objects, indicating that three relationships can exist. For example, "A and / or B" can represent three cases: only A exists, only B exists, and both A and B exist simultaneously, where A and B can be singular or plural. The character " / " generally indicates that the preceding and following related objects are in an "or" relationship. "At least one (item) of the following" or similar expressions refer to any combination of these items, including any combination of single or plural items. For example, at least one (item) of a, b, or c can represent: a, b, c, "a and b", "a and c", "b and c", or "a and b and c", where a, b, and c can be single or multiple.
[0113] In the several embodiments provided in this application, it should be understood that the disclosed apparatus and methods can be implemented in other ways. For example, the apparatus embodiments described above are merely illustrative; for instance, the division of the units described above is only a logical functional division, and in actual implementation, there may be other division methods. For example, multiple units or components may be combined or integrated into another system, or some features may be ignored or not executed. Furthermore, the coupling or direct coupling or communication connection shown or discussed may be through some interfaces; the indirect coupling or communication connection between apparatuses or units may be electrical, mechanical, or other forms.
[0114] The units described above as separate components may or may not be physically separate. The components shown as units may or may not be physical units; that is, they may be located in one place or distributed across multiple network units. Some or all of the units can be selected to achieve the purpose of this embodiment according to actual needs.
[0115] Furthermore, the functional units in the various embodiments of this application can be integrated into one processing unit, or each unit can exist physically separately, or two or more units can be integrated into one unit. The integrated unit can be implemented in hardware or as a software functional unit.
[0116] If the integrated unit is implemented as a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of this application, in essence, or the part that contributes to the prior art, or all or part of the technical solution, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes multiple instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute all or part of the steps of the methods of the various embodiments of this application. The aforementioned storage medium includes various media capable of storing programs, such as USB flash drives, portable hard drives, read-only memory (ROM), random access memory (RAM), magnetic disks, or optical disks.
[0117] The preferred embodiments of the present application have been described above with reference to the accompanying drawings, but this does not limit the scope of the claims of the present application. Any modifications, equivalent substitutions, and improvements made by those skilled in the art without departing from the scope and substance of the embodiments of the present application shall be within the scope of the claims of the present application.
Claims
1. A method for two-dimensional flood inundation simulation based on GPU memory optimized access, characterized in that, The method includes the following steps: A two-dimensional structured grid is constructed based on the target raster data of the target watershed to obtain the target field; the target raster data includes ground elevation data, water depth data and flow velocity data, and the target field includes topographic field, water depth field and momentum field; Based on the effective calculation area in the ground elevation data, determine the effective calculation area mask; The two-dimensional structured mesh is logically divided to obtain several shared memory blocks, and an effective shared memory block is determined from the several shared memory blocks based on the effective computing region mask; The target field and the effective computation region mask corresponding to the effective shared memory block are copied to the GPU memory in a two-dimensional stepping manner; Within each time step, the first GPU kernel function in the GPU memory is used to perform parallel calculation of the local wave velocity of the full-field grid cells of the target field in the effective shared memory block, and parallel reduction is performed based on the parallel calculation results of the local wave velocity in the effective shared memory block to obtain the upper bound of the maximum wave velocity. Based on the upper bound of the maximum wave velocity, the global time step is calculated using the CFL condition. Combining the global time step, the second GPU kernel function in the GPU memory is used to solve the two-dimensional shallow water equation based on the effective shared memory block to obtain the conserved variables for the next time step; If the current time step reaches the preset simulation termination time, the two-dimensional flood inundation simulation results are sent back from the GPU memory to the host CPU memory at the output time interval; wherein, the two-dimensional flood inundation simulation results are determined based on the conserved variables in the next time step.
2. The method of claim 1, wherein, The method further includes: If the current time step has not reached the preset simulation termination time, the target field in the effective shared memory block is updated based on the conserved variables of the next time step, and the process returns to the steps of performing parallel calculations of local wave velocities on the full-field grid cells of the target field in the effective shared memory block using the first GPU kernel function in the GPU memory at each time step, and performing parallel reduction to obtain the upper bound of the maximum wave velocity based on the parallel calculation results of the local wave velocity in the effective shared memory block, until the current time step reaches the preset simulation termination time, and the two-dimensional flooding simulation results are returned from the GPU memory to the host CPU memory according to the output time interval.
3. The method of claim 1, wherein, The step of copying the target field and the effective computation region mask corresponding to the effective shared memory block to the GPU memory in a two-dimensional step manner includes: The effective data in the target field and the effective computing region mask corresponding to the effective shared memory block are padded according to a preset alignment granularity to generate a row step length; Based on the row step size, the target field and the effective computation region mask corresponding to the effective shared memory block are copied from the host CPU memory to the GPU memory using cudaMemcpy2D or an equivalent mechanism.
4. The method of claim 1, wherein, Within each time step, the first GPU kernel function in the GPU memory is used to perform parallel calculations of the local wave velocity of the full-field grid cells of the target field in the effective shared memory block, and parallel reduction is performed based on the parallel calculation results of the local wave velocity in the effective shared memory block to obtain the upper bound of the maximum wave velocity, including: Within each time step, the thread bundle in the first GPU kernel function is used to perform parallel calculation of the local wave velocity of the full-field grid cells of the target field in the effective shared memory block, so as to obtain the maximum local wave velocity corresponding to each thread bundle. Write the maximum local wave velocity corresponding to each thread bundle into the effective shared memory block, and perform block-level reduction on each maximum local wave velocity according to the first thread bundle in the effective shared memory block to obtain the block maximum wave velocity corresponding to each thread bundle; The maximum wave velocity of a block is selected from the maximum wave velocities of the blocks with the largest value as the upper bound of the maximum wave velocity.
5. The method of claim 1, wherein, The effective shared memory block includes a Halo cooperative loading region, which stores neighborhood data. Combining the global time step, the second GPU kernel function in the GPU memory solves the two-dimensional shallow water equation based on the effective shared memory block to obtain the conserved variables for the next time step, including: The neighboring data in the Halo cooperative loading region is loaded using the second GPU kernel function, and the interface numerical flux of each grid cell in the effective shared memory block is calculated in combination with the neighboring data; Calculate the source term vector containing the rainfall replenishment term, topographic slope term, and friction term; Based on the global time step, and according to the source term vector and the interface numerical flux of each grid cell in the effective shared memory block, the conserved variable for the next time step is calculated.
6. The method of claim 5, wherein, The method further includes: Based on the updated water depth data in the conserved variables at the next time step and the flow velocity data at the previous time step, the friction coefficient of each grid cell in the effective shared memory block is calculated. The momentum components of the momentum field in the effective shared memory block are semi-implicitly scaled according to each of the friction coefficients.
7. The method of claim 1, wherein, The method further includes: Using the second GPU kernel function, dry and wet boundary processing is performed on the mesh cells in the effective shared memory block where the effective computation region mask is invalid or the water depth value is lower than a preset depth threshold, to obtain the dry and wet boundary processing result; When a completely dry block exists in the dry-wet boundary processing result, the exit operation is performed on the completely dry block through a thread collective judgment mechanism within the effective shared memory block.
8. A two-dimensional flood inundation simulation device based on GPU memory optimized access, characterized in that, The device includes the following modules: A two-dimensional structured mesh construction module is used to construct a two-dimensional structured mesh based on target raster data of the target watershed to obtain the target field; the target raster data includes ground elevation data, water depth data, and flow velocity data, and the target field includes topographic field, water depth field, and momentum field; The effective calculation area mask calculation module is used to determine the effective calculation area mask based on the effective calculation area in the ground elevation data; An effective shared memory block determination module is used to logically divide the two-dimensional structured mesh to obtain several shared memory blocks, and to determine the effective shared memory block from the several shared memory blocks based on the effective computing region mask; A two-dimensional step data copying module is used to copy the target field and the effective computing region mask corresponding to the effective shared memory block to the GPU memory in a two-dimensional step manner. The maximum wave velocity upper bound calculation module is used to perform parallel calculation of the local wave velocity of the full-field grid cells of the target field in the effective shared memory block using the first GPU kernel function in the GPU memory at each time step, and to perform parallel reduction based on the parallel calculation results of the local wave velocity in the effective shared memory block to obtain the maximum wave velocity upper bound. The global time step calculation module is used to calculate the global time step based on the maximum wave velocity upper bound and the CFL condition. The two-dimensional shallow water equation solving module is used to solve the two-dimensional shallow water equation by combining the global time step and using the second GPU kernel function in the GPU memory based on the effective shared memory block, so as to obtain the conserved variables for the next time step. The two-dimensional simulation result feedback module is used to feed back the two-dimensional flood inundation simulation results from the GPU memory to the host CPU memory at output time intervals if the current time step reaches the preset simulation termination time; wherein the two-dimensional flood inundation simulation results are determined based on the conserved variables in the next time step.
9. An electronic device, comprising: The electronic device includes a memory and a processor, the memory storing a computer program, and the processor executing the computer program to implement the method according to any one of claims 1 to 7.
10. A computer program product comprising a computer program, characterized in that, When the computer program is executed by a processor, it implements the method of any one of claims 1 to 7.