A CPU-GPU collaborative parallel computing method for edge detection of remote sensing images
By chunking data with the minimum parallel granularity of grid behavior and setting anchor marks in remote sensing image edge detection, forming a directional task queue, the thread organization and scheduling of CPU and GPU is optimized, load balancing problems are solved, and efficient Parallel computing significantly improves the computing speed.
Patent Information
- Application Number
- CN202210760820.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-06-29
- Publication Date
- 2025-01-03
- Estimated Expiration
- 2042-06-29
AI Technical Summary
The prior art is difficult to achieve load balancing in parallel computing of remote sensing image edge detection with CPU-GPU collaborative remote sensing image edge detection, resulting in instability and poor adaptability of computing resources, increasing communication competition and additional overhead.
By blocking the source raster data with the minimum parallel granularity of raster behavior, and anchor marking the first and last rows, forming a directional task queue, optimizing the thread organization and scheduling mode of the CPU and GPU, and adopting two-way tasks Scheduling and allocation method, dynamically adjust data division to achieve load balancing.
It improves load balancing between CPU and GPU, reduces data communication overhead, simplifies task scheduling, realizes efficient parallel computing, and significantly improves computing speed.
Smart Images

Figure CN115100227B_ABST
Abstract
Description
Technical Field
[0001] The invention relates to a CPU-GPU collaborative remote sensing image edge detection parallel computing method, belonging to the technical field of data processing. Background Art
[0002] The rapid development of earth observation technology has led to an explosive growth of multi-source heterogeneous geospatial data, and parallel computing technology plays an important role in large-scale, high-density geospatial data analysis. With the continuous development of high-performance computing hardware architecture, how to keep pace with the times and use new parallel computing technologies to break through the performance bottlenecks caused by data-intensive, computing-intensive and communication-intensive problems has become a research hotspot in the GIS field.
[0003] The calculation results of raster neighborhood analysis are usually only related to the focal raster and its neighborhood raster. It has less task dependence and stronger computational independence, and is the focus of many scholars' research on parallel efficiency improvement. In the early days, CPU computing nodes were used to perform parallel computing, but as demand increased, the parallel computing power of the CPU became increasingly difficult to meet the needs of large-scale parallel processing of massive geospatial data. With the advent and development of GPUs, their powerful numerical parallel computing capabilities have brought more significant parallel acceleration effects to analysis processes such as remote sensing image edge detection, unsupervised classification, digital terrain analysis, and regional spatiotemporal change simulation. At the same time, the CPU-GPU asynchronous parallel idea is adopted to efficiently coordinate the computing resources of the CPU and GPU to further improve the speed of numerical calculations with strong computational independence, such as raster neighborhood analysis.
[0004] However, in the parallel algorithm of raster neighborhood analysis, reasonable spatial data partitioning and task scheduling mechanisms are required to ensure efficient use of computing resources, that is, load balancing. For raster data, the most commonly used data partitioning methods are one-dimensional partitioning or two-dimensional partitioning, equal area partitioning method, and natural watershed partitioning method. The above partitioning methods focus on pre-segmenting the source raster data before numerical calculation and allocating it to each computing node. However, the computing power of each computing node is not consistent during actual operation, resulting in instability and poor adaptability. For this reason, an irregular data partitioning method is also produced that dynamically adjusts the data partitioning results by real-time monitoring of the computing power of each node, thereby realizing a more sophisticated load balancing strategy. However, the repeated communication in the process of finding the best load solution increases the communication competition between the CPU and GPU computing nodes, increases the additional overhead, and is not worth the loss. Summary of the invention
[0005] The technical problem to be solved by the present invention is to provide a parallel computing method for remote sensing image edge detection which can achieve both load balancing and efficient parallelism between CPU and GPU.
[0006] In order to solve the above technical problems, the technical solution proposed by the present invention is: a CPU-GPU collaborative remote sensing image edge detection parallel computing method, performing the following steps:
[0007] Step 1, parallel environment initialization;
[0008] Step 11, read the source raster data, obtain the number of raster rows, columns, pixel depth and pixel value type;
[0009] Step 12, setting parallel parameters, including the stream parallel granularity of the GPU computing end, the GPU thread organization mode, and the number of CPU computing threads of the CPU computing end;
[0010] Step 13, creating a directed task queue, dividing the source raster data into blocks with the number of raster rows as the minimum parallel granularity, and marking the first and last rows with anchor points, thereby forming a plurality of subtask queues with first anchor point marks and last anchor point marks;
[0011] Step 2: The CPU main thread initializes the GPU and optimizes GPU memory
[0012] Step 3, the CPU computing end and the GPU computing end respectively perform computing tasks;
[0013] On the GPU computing side, the CPU main thread initializes three GPU streams, starts from the first anchor mark of the corresponding subtask queue according to the stream parallel granularity, extracts data blocks in sequence from the middle of the subtask queue, fills them into each GPU stream, and performs calculations by the GPU;
[0014] At the CPU computing end, each CPU computing thread starts from the tail anchor mark of the corresponding subtask queue, traverses to the middle of the subtask queue to extract data blocks, and performs block calculation on the data blocks according to the number of CPU computing threads;
[0015] Step 4: Synchronize CPU and GPU;
[0016] The CPU main thread waits for the operations in each GPU stream to be completed, and at the same time, each CPU computing thread feeds back information to the main thread;
[0017] Step 5: Update the task queue. If the task queue is not empty, return to step 3; otherwise, exit the parallel environment and terminate the calculation.
[0018] The improvement of the above technical solution is that the calculations performed in the GPU computing end and the CPU computing end are both based on the edge detection algorithm of the Laplace operator.
[0019] The improvement of the above technical solution is: at the CPU computing end, each CPU computing thread is anchored to the tail anchor mark of the directed task queue in sequence.
[0020] The improvement of the above technical solution is: the block division process of the data block in each GPU stream in step 3 is as follows:
[0021] 1) Map the data block into a one-dimensional linear sequence;
[0022] 2) Set the organization mode (Grid, Block) of the thread grid in the GPU stream, where Grid represents the number of thread blocks contained in the thread grid in the GPU stream, and Block represents the number of threads contained in each thread block. Map all threads in the thread grid in the GPU stream into a one-dimensional linear sequence, and each thread has a unique number.
[0023] 3) Complete the cyclic allocation of the data block in sequence according to the thread number.
[0024] The beneficial effects brought by the present invention are as follows: the present invention divides the source raster data into blocks with the raster line as the minimum parallel granularity, and marks the first row and the last row with anchor points. Each raster line corresponds to a complete numerical calculation task, so a subtask queue with head and tail anchor points can be formed. The data partitioning method can fully consider the spatial characteristics of the raster data, establish a directional task queue to simplify the data communication process of the CPU task scheduler, improve the monitoring ability of each computing node, and reduce the additional overhead caused by frequent task scheduling, so as to achieve the purpose of high efficiency. In addition, in order to make full use of the multi-threaded advantage of the CPU, multiple tail anchor points can be set at the tail of the directional task queue according to the number of CPU computing threads opened up, and the data block can be further equally divided to form multiple data sub-blocks containing the same amount of data.
[0025] Then, the GPU and CPU computing threads will start from the anchor points at the head and tail of the directed task queue, extract tasks in the order of traversing the middle of the queue, and perform calculations in parallel. Based on the directed task queue, this task division method dynamically schedules the GPU and the GPU to perform bidirectional merge calculations from both ends of the queue. While ensuring extremely low data communication overhead during numerical calculations, it simplifies the termination conditions of parallel calculations, that is, the CPU and GPU execute tasks corresponding to the same data block. This ensures to a great extent that the CPU and GPU tend to start and end computing tasks at the same time, so as to achieve load balancing between CPU and GPU devices.
[0026] That is, by dividing the data in the task queue and allocating tasks to the GPU and CPU computing threads in both directions, the thread organization and scheduling mode within the CPU and GPU are optimized, achieving both load balancing and efficient parallelism between the CPU and GPU. BRIEF DESCRIPTION OF THE DRAWINGS
[0027] The present invention will be further described below in conjunction with the accompanying drawings.
[0028] Figure 1 It is a flowchart of a CPU-GPU collaborative remote sensing image edge detection parallel computing method according to an embodiment of the present invention.
[0029] Figure 2 It is a flowchart of a GPU in-stream computing process at a GPU computing end according to an embodiment of the present invention.
[0030] Figure 3 It is a remote sensing image of a data set according to an embodiment of the present invention, a local magnified image of the same scale, and a comparison image of the detection results.
[0031] Figure 4 It is a running time-speedup ratio diagram of the method in the embodiment of the present invention and other detection methods. DETAILED DESCRIPTION
[0032] Example
[0033] A CPU-GPU collaborative remote sensing image edge detection parallel computing method of this embodiment, such as Figure 1 As shown, perform the following steps:
[0034] Step 1, parallel environment initialization;
[0035] Step 11, read the source raster data, obtain the number of raster rows, columns, pixel depth and pixel value type;
[0036] Step 12, setting parallel parameters, including the stream parallel granularity of the GPU computing end, the GPU thread organization mode, and the number of CPU computing threads of the CPU computing end;
[0037] Step 13, creating a directed task queue, dividing the source raster data into blocks with the number of raster rows as the minimum parallel granularity, and marking the first and last rows with anchor points, thereby forming a plurality of subtask queues with first anchor point marks and last anchor point marks;
[0038] Step 2: The CPU main thread initializes the GPU and optimizes GPU memory
[0039] Step 3, the CPU computing end and the GPU computing end respectively perform computing tasks;
[0040] On the GPU computing side, the CPU main thread initializes three GPU streams, starts from the first anchor mark of the corresponding subtask queue according to the stream parallel granularity, extracts data blocks in sequence toward the middle of the subtask queue, fills them into each GPU stream, and performs calculations by the GPU;
[0041] At the CPU computing end, each CPU computing thread starts from the tail anchor mark of the corresponding subtask queue, traverses to the middle of the subtask queue to extract data blocks, and performs block calculation on the data blocks according to the number of CPU computing threads;
[0042] Step 4: Synchronize CPU and GPU;
[0043] The CPU main thread waits for the operations in each GPU stream to be completed, and at the same time, each CPU computing thread feeds back information to the main thread;
[0044] Step 5: Update the task queue. If the task queue is not empty, return to step 3; otherwise, exit the parallel environment and terminate the calculation.
[0045] The calculations performed in the GPU computing end and the CPU computing end in this embodiment are both based on the edge detection algorithm of the Laplace operator.
[0046] Edge detection based on Laplace operator is essentially a convolution operation between the set operator template and the image to be processed, which is a typical grid neighborhood analysis. The value of each pixel in the calculation result is only related to the value of the focal grid cell and its four adjacent grid cells. The calculation process is independent of each other and has strong parallel computing potential.
[0047] Edge detection is a means of image enhancement that can sharpen the contours of entities in an image to make it visually clearer. The Laplace operator is the simplest isotropic second-order differential operator in n-dimensional Euclidean space. It is defined as the divergence of the gradient and has rotation invariance. It is one of the edge detection operators. According to the properties of function differentials, for a two-dimensional image function f(x,y), the Laplace operator of the image can be defined as
[0048]
[0049] By taking the second-order derivative of the image f(x,y) in the x and y directions and substituting it into the formula, we can get the expression of the second-order Laplace operator:
[0050]
[0051] At the CPU computing end, each CPU computing thread is anchored to the tail anchor mark of the directed task queue in sequence.
[0052] The process of dividing the data blocks in each GPU stream in step 3 is as follows:
[0053] 1) Map the data block into a one-dimensional linear sequence;
[0054] 2) Set the organization mode (Grid, Block) of the thread grid in the GPU stream, where Grid represents the number of thread blocks contained in the thread grid in the GPU stream, and Block represents the number of threads contained in each thread block. Map all threads in the thread grid in the GPU stream into a one-dimensional linear sequence, and each thread has a unique number.
[0055] 3) Complete the cyclic allocation of the data block in sequence according to the thread number.
[0056] Among them, the GPU stream represents a GPU operation queue, and the operations in the queue will be executed in a specified order. The process of the GPU computing end when executing a computing task is as follows: (1) CTG: the CPU side copies the data memory to the GPU side; (2) K: the GPU side starts the kernel function to perform parallel computing according to the set thread organization mode; (3) GTC: the GPU side copies the calculation result memory back to the CPU side. When using multi-stream technology, each GPU stream will extract the corresponding number of rows of raster data from the directed task queue each time according to the set stream parallel granularity, and will fill the task in the order of CTG-K-GTC; the GPU memory copy engine and the kernel function execution engine will execute asynchronously according to the task filling order and the dependency relationship between tasks. This embodiment selects 3 streams for GPU computing tasks, and the GPU can perform a CTG and GTC operation while executing the K operation. The execution status of the computing task will be as follows Figure 2 shown.
[0057] In the hardware configuration of this embodiment, the CPU model is Intel Core i7-1165G7, quad-core eight-thread, main frequency 2.8GHz; GPU model is NVIDIA MX450, video memory size is 4GB, 13 stream multiprocessors; memory size is 16GB; software configuration, operating system is Windows 10 64x, file system is NTFS, OpenMP implementation product selects OpenMP 2.0, GDAL implementation product selects GDAL 3.2.0. The compilation environment is Visual Studio 2019, and the programming language is selected to run in the C++ environment. The panchromatic band remote sensing image of Nanjing and its surrounding areas taken by Landsat 8's land imager OLI and resampled (the location overview is shown in the figure), the data volume is 300MB, the grid size is 12542×12542, the imaging time is November 15, 2018, and the data source is https: / / glovis.usgs.gov. Set the number of CPU computing threads to 7, the GPU stream parallel granularity N to 40, the GPU thread organization mode to (104,256), perform edge detection based on the Laplace operator on the data set, and generate raster result data in GeoTIFF (*.tif) format. Figure 3The remote sensing image corresponding to the dataset, the large-scale effect of setting three windows, and the edge detection result image using this example method are shown. The results show that the corresponding pixels of traffic roads, building outlines, lake shorelines and other features in Nanjing and its surrounding areas are all assigned high values in the calculation results, and the edge detection effect is good.
[0058] In addition, the parallel computing results are interpolated with the edge detection results based on the Laplace operator in ArcMap, a professional software for geospatial data processing and analysis, and the resulting raster data in GeoTIFF (*.tif) format is generated. According to statistics, the total number of zero-valued pixels in the resulting raster is 12542×12542, indicating that the parallel computing results are highly consistent with the ArcMap calculation results, further verifying the correctness of the proposed asynchronous algorithm.
[0059] In addition, for the edge detection algorithm based on the Laplace operator, this embodiment will use the CPU-GPU asynchronous parallel algorithm and the serial, CPU parallel and GPU parallel algorithms to conduct efficiency comparison analysis, test the data set, and count the running time and acceleration ratio of each algorithm. Among them, for the CPU-GPU asynchronous parallel algorithm, the GPU stream parallel granularity is set to 40, and the GPU thread organization mode is (104,256); the total number of CPU threads opened is 8, of which the main thread is responsible for communicating with the GPU and monitoring the operating status of each computing node, and the remaining non-main threads are responsible for numerical calculations; the relevant parameters of the CPU and GPU parallel algorithms are consistent with the CPU-GPU asynchronous algorithm.
[0060] The results are as follows Figure 4 As shown, when calculating a data set with a data size of 300MB, the running time of the serial algorithm, CPU parallel algorithm, GPU parallel algorithm and CPU-GPU asynchronous parallel algorithm are 1.93 seconds, 0.37 seconds, 0.25 seconds and 0.19 seconds respectively, and the acceleration ratios are 1, 5.22, 7.62 and 10.31 respectively. It can be seen that the various parallel algorithms designed can achieve significant acceleration effects compared with the serial algorithms; GPU is better than CPU at parallel acceleration of data-intensive neighborhood analysis such as edge detection; compared with the GPU parallel algorithm, the CPU-GPU asynchronous parallel algorithm of this embodiment can bring a 35% performance improvement, which shows that this method can make more full use of computing resources.
Claims
1. A CPU-GPU collaborative remote sensing image edge detection parallel computing method, characterized in that Follow these steps: Step 1: Parallel environment initialization; Step 11, read the source raster data, obtain the number of raster rows, columns, pixel depth and pixel value type; Step 12: Set parallel parameters, including the stream parallel granularity of the GPU computing end, the GPU thread organization mode, and the number of CPU computing threads of the CPU computing end; Step 13, creating a directed task queue, dividing the source raster data into blocks with the number of raster rows as the minimum parallel granularity, and marking the first and last rows with anchor points, thereby forming a plurality of subtask queues with first anchor point marks and last anchor point marks; Step 2: The CPU main thread initializes the GPU and optimizes GPU memory Step 3: The CPU computing end and the GPU computing end perform computing tasks respectively; On the GPU computing side, the CPU main thread initializes three GPU streams, starts from the first anchor mark of the corresponding subtask queue according to the stream parallel granularity, extracts data blocks in sequence toward the middle of the subtask queue, fills them into each GPU stream, and performs calculations by the GPU; At the CPU computing end, each CPU computing thread starts from the tail anchor mark of the corresponding subtask queue, traverses to the middle of the subtask queue to extract data blocks, and performs block calculation on the data blocks according to the number of CPU computing threads; At the CPU computing end, each CPU computing thread is anchored to the tail anchor mark of the directed task queue in sequence; The process of dividing the data blocks in each GPU stream is as follows: 1) Map the data block into a one-dimensional linear sequence; 2) Set the organization mode of the thread grid in the GPU stream [Grid, Block], where Grid represents the number of thread blocks contained in the thread grid in the GPU stream, and Block represents the number of threads contained in each thread block. All threads in the thread grid in the GPU stream are mapped into a one-dimensional linear sequence, and each thread has a unique number. 3) Complete the cyclic allocation of the data block in sequence according to the thread number; Step 4: Synchronize CPU and GPU; The CPU main thread waits for the operations in each GPU stream to be completed, and at the same time, each CPU computing thread feeds back information to the main thread; Step 5: Update the task queue. If the task queue is not empty, return to step 3; otherwise, exit the parallel environment and terminate the calculation.
2. The CPU-GPU collaborative remote sensing image edge detection parallel computing method according to claim 1, characterized in that: The calculations performed in the GPU computing end and the CPU computing end are both based on the edge detection algorithm of the Laplace operator.
