A parallelized nearest neighbor search device and method based on Kd-Tree
By splitting the Kd-Tree search process into parallelized downward search and upward backtracking modules, the problem of not being able to fully utilize parallel resources in existing technologies is solved, and efficient processing of LiDAR point cloud data is achieved.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2023-02-24
- Publication Date
- 2026-04-03
AI Technical Summary
Existing Kd-Tree search methods cannot fully utilize the parallel resources of modern computing platforms, resulting in low efficiency in processing LiDAR point cloud data.
The search process of Kd-Tree is split into two independent processes: downward search and upward backtracking. These processes are designed to be processed in parallel by multiple modules. A state module is used to record the node state and search path, and a shared FIFO memory is used to reduce storage space usage.
It improves the search speed and processing efficiency of LiDAR point cloud data, makes full use of the parallel resources of multi-core processors, and solves the problem of single-process serial operation.
Smart Images

Figure CN116226424B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of parallel search technology, and more specifically to a parallel search device and method for nearest neighbor points based on Kd-Tree. Background Technology
[0002] With the development of remote sensing mapping and autonomous driving in recent years, LiDAR, as a sensor with relatively low environmental sensitivity, capable of active measurement and acquiring high-precision 3D point cloud data day and night, has attracted much attention. Compared with traditional camera image data, LiDAR point cloud data has the characteristics of high sampling rate, high precision, discrete spatial distribution, and huge data volume. A common 32-line LiDAR can generate 1.2 million 3D point clouds per second. Such a large amount of point cloud data has become a bottleneck for subsequent processing and applications such as point cloud segmentation, registration, and recognition. Choosing an appropriate spatial indexing method can quickly and efficiently realize the storage, querying, calculation, and operation of massive point cloud data. In current mainstream research and applications, Kd-trees, octrees, and voxel grids are commonly used to establish spatial indexes for LiDAR point cloud data.
[0003] Kd-Tree is a tree-like data structure for storing instances in a k-dimensional space for fast retrieval. Proposed by Bentley in 1975, it is primarily used for range searches and nearest neighbor searches of key data in multidimensional spaces. A Kd-Tree is a special type of balanced binary tree that continuously bisects the entire k-dimensional space into several local spaces. During the search, it continuously performs branching decisions, selecting local subspaces, thus avoiding a global space search and accelerating the search for neighboring points. Its average time complexity is O(n log n). The data output by LiDAR is a three-dimensional point cloud, so the dimension used to organize the point cloud using Kd-Tree is also 3.
[0004] While Kd-Tree's inherent characteristics allow it to perform well in point cloud organization and management, the rapid development of modern computing platforms in recent years, the dominance of multi-core processors, and the growing attention to heterogeneous computing have provided ample parallel resources for improving application performance, making program parallelization a mainstream approach. However, existing Kd-Tree search methods rely on recursive search, which prevents full utilization of parallel resources in practical applications. Summary of the Invention
[0005] The purpose of this invention is to overcome the above-mentioned deficiencies in the prior art and provide a parallel search device and method for nearest neighbor points based on Kd-Tree.
[0006] The first objective of this invention can be achieved by adopting the following technical solution:
[0007] A parallelized nearest neighbor search device based on Kd-Tree, the device comprising a control module, M search modules, N backtracking modules, and a state module, wherein M = 1, 2, ..., N = 1, 2, ...;
[0008] The control module receives the node data to be matched and writes the node data into the search FIFO memory. At the same time, it controls the M search modules and N backtracking modules to search for the nearest points of the node data to be matched.
[0009] The M search modules read the data of the nodes to be matched from the search FIFO memory, read the relevant running status of the nodes from the status module according to the sequence number of the nodes to be matched, read the Kd-Tree nodes from the Kd-Tree memory according to the relevant running status of the nodes, and perform a downward search operation until the leaf node of the Kd-Tree is found. According to the status of the search operation completion, the results are written into the search FIFO memory and the backtracking FIFO memory respectively.
[0010] The N backtracking modules read the data of the nodes to be matched from the backtracking FIFO memory, read the relevant running status of the nodes from the status module according to the sequence number of the nodes to be matched, perform an upward backtracking operation in the Kd-Tree until the root node of the Kd-Tree is found, and write the results into the search FIFO memory, the backtracking FIFO memory and the output node memory respectively according to the status of the backtracking operation.
[0011] The status module receives the node sequence number to be matched from M search modules or N backtracking modules, and transmits the corresponding node-related running status information back to the corresponding module. The node-related running status includes Kd-Tree node position, nearest neighbor distance, nearest neighbor node, current segmentation dimension, searched nodes, and Kd-Tree search path stack area.
[0012] Furthermore, the Kd-Tree is a data structure that stores instance points in a k-dimensional space to enable fast retrieval of the Kd-Tree. The Kd-Tree construction process is as follows:
[0013] S11. Using the current instance point as the tree node in the Kd-Tree, calculate the modulo between the depth of the current instance point and the data dimension k to obtain the current segmentation dimension;
[0014] S12. Sort the k-dimensional data according to the current segmentation dimension, and use the median data after sorting as the value of the current tree node.
[0015] S13. Using the median as the dividing point, the data less than the median is taken as the left subtree of the current tree node, and the data greater than the median is taken as the right subtree of the current tree node.
[0016] S14. Repeat S11 to S13 until all instance point data are organized and stored in a Kd-Tree manner.
[0017] Furthermore, the neighbor search process for the node data to be matched in the control module is as follows:
[0018] S21. Starting from the root node of the Kd-Tree, search downwards;
[0019] S22. If the value of the current dimension of the node to be searched is less than the value of the corresponding dimension of the current Kd-Tree node, then search the left subtree; otherwise, search the right subtree and push the current node onto the stack.
[0020] S23. Repeat step S22 until the current Kd-Tree node is a leaf node, then execute step S24.
[0021] S24. Pop the node from the stack to get the current node, mark the current node as visited, calculate the Euclidean distance between the current node and the target point, and if it is less than the nearest neighbor distance, update the nearest neighbor node and the nearest neighbor distance.
[0022] S25. Calculate the distance between the target point and the parent node in the corresponding dimension. If it is less than the nearest distance, start step S22 from the sibling node that has never been visited.
[0023] S26. Repeat steps S24-S25 until the current node is the root node, and output the final nearest point to the target array.
[0024] Furthermore, the Kd-Tree memory storage method is as follows:
[0025] The Kd-Tree is stored in memory with contiguous addresses. The root node is at address 1. For a node at address i, its left child is stored at address i×2, and its right child is stored at address i×2+1. The level of the current node in the Kd-Tree is obtained by calculating the highest 1 in the binary representation of the node address. Storing the Kd-Tree with contiguous addresses and determining the distribution of the left and right child nodes in the address space allows other modules to access Kd-Tree nodes in O(1) time complexity.
[0026] Furthermore, the control module polls the idle flag regions of the search FIFO and backtrack FIFO memories. If the idle flag of the corresponding search FIFO or backtrack FIFO is set to 0, it indicates that there is data waiting to be processed in the search FIFO or backtrack FIFO, and the control module generates a start signal to the corresponding search FIFO or backtrack FIFO. The control module starts the corresponding working module according to the state of the FIFO memory. When there are multiple search modules or backtrack modules, the control module will also balance the load according to the working status.
[0027] Furthermore, the processing procedure of the search module is as follows:
[0028] S31. Retrieve the data of the node to be matched from the search FIFO memory, transmit the sequence number of the node to be matched in the node data to the status module to obtain the node-related running status information, and obtain the current node from the Kd-Tree memory through the Kd-Tree node position of the node-related running status.
[0029] S32. Push the current node's index in the Kd-Tree into the search path stack area related to the node's running status;
[0030] S33. Determine whether the current node is a leaf node of the Kd-Tree. If it is a leaf node, add the sequence number corresponding to the current node to the end of the backtracking FIFO memory and then exit the remaining steps. Otherwise, execute step S34.
[0031] S34. Compare the value of the dimension corresponding to the node to be matched with the value of the dimension corresponding to the current node. If it is less than the value of the current node, update the position of the Kd-Tree node related to the node's running status to the position of the left child node; otherwise, update it to the position of the right child node.
[0032] S35. Add the node number to be matched to the end of the search FIFO memory.
[0033] Furthermore, the processing procedure of the backtracking module is as follows:
[0034] S41. Retrieve the data of the node to be matched from the backtracking FIFO memory, transmit the sequence number of the node to be matched in the node data to the status module to obtain the node-related running status, retrieve the current node from the Kd-Tree search path stack area of the node-related running status, and mark the current node as visited.
[0035] S42. Calculate the Euclidean distance between the current node and the node to be matched. If it is less than the nearest neighbor distance in the running state, update the nearest neighbor distance to the Euclidean distance and update the nearest neighbor node to the current node.
[0036] S43. If the current node is the root node of the Kd-Tree, transfer the nearest neighbor node in the running state to the output node memory, and then exit to execute the remaining steps; otherwise, execute step S44.
[0037] S44. Calculate the distance between the node to be matched and the parent node of the current node in the corresponding dimension. Compare the distance with the nearest neighbor distance. If the distance is less than the nearest neighbor distance in the running state, update the current node to an unvisited sibling node and add the node to be matched to the end of the search FIFO memory. Otherwise, add the node to be matched to the end of the backtracking FIFO memory.
[0038] The original Kd-Tree search process is split into two parts: downward search and upward backtracking. These are designed as independently operating search and backtracking modules, so that the entire search process can be completed by M search modules and N backtracking modules, thereby accelerating the search.
[0039] Furthermore, the number of search modules M and the number of backtracking modules N are set according to the required parallelism, and the M search modules and N backtracking modules share a single search FIFO memory and a backtracking FIFO memory.
[0040] Sharing a single search FIFO memory and a backtracking FIFO memory effectively reduces the required memory size. Furthermore, nodes are retrieved from the top of the FIFO memory and pushed in from the bottom, ensuring accurate node access during parallel operation of multiple modules without affecting overall parallel performance.
[0041] Furthermore, the node-related operating status of the state module has its own separate copy for each input node to be matched, and its access to and writing to the node-related operating status of other nodes to be matched do not interfere with each other.
[0042] The node-related operational status is a part that needs to be accessed during both downward searching and upward backtracking in the entire search process. To avoid the situation where multiple modules read and write simultaneously, leading to a decrease in parallel performance, a separate space is allocated in the status module for each node to be matched. If the search device has K nodes to be matched, then K spaces are allocated to store the node-related operational status.
[0043] The second objective of this invention can be achieved by adopting the following technical solution:
[0044] A search method for a Kd-Tree-based parallelized nearest neighbor search device includes the following steps:
[0045] T1. The control module receives the node to be matched, adds it to the search FIFO memory, and simultaneously polls to check the idle status of the search FIFO memory and the backtrack FIFO memory. If they are not empty, a start signal is sent to the corresponding module.
[0046] T2. After receiving the start signal from the control module, the search module communicates with the status module to obtain relevant node information and begins to perform a downward search operation, adding the results to the search FIFO memory and the backtracking FIFO memory respectively.
[0047] T3. After receiving the start signal from the control module, the backtracking module communicates with the status module to obtain relevant node information and begins to perform the upward backtracking operation, adding the results to the search FIFO memory, backtracking FIFO memory or output node memory respectively.
[0048] The present invention has the following advantages and effects compared with the prior art:
[0049] This invention proposes a parallelized nearest neighbor search device based on Kd-Tree. The search process in Kd-Tree nearest neighbor is divided into a downward search process and an upward backtracking process, designed as modules. A state module records the state of the node to be matched during the Kd-Tree search process, and a stack structure records the search path. This allows the Kd-Tree search process to be repeatedly entered and exited, breaking down the original continuous search process into multi-step discrete processes. The entire search process can be processed in parallel by M search modules and N backtracking modules, thereby accelerating the search, improving data processing speed and efficiency, and solving the problem that existing technologies can only run serially in a single process. Furthermore, the M search modules and N backtracking modules share a unique search FIFO memory and a backtracking FIFO memory, reducing storage space usage without affecting parallel performance. Attached Figure Description
[0050] The accompanying drawings, which are included to provide a further understanding of the invention and form part of this application, illustrate exemplary embodiments of the invention and, together with their description, serve to explain the invention and do not constitute an undue limitation thereof. In the drawings:
[0051] Figure 1 This is a schematic diagram of the architecture of a Kd-Tree-based parallel search device for nearest neighbor points provided in an embodiment of the present invention;
[0052] Figure 2 This is a schematic diagram of a Kd-Tree node storage method based on node sequence number provided in an embodiment of the present invention;
[0053] Figure 3This is a schematic diagram of a Kd-Tree node storage method based on node values provided in an embodiment of the present invention;
[0054] Figure 4 This is a schematic diagram of a parallelized search device provided in an embodiment of the present invention;
[0055] Figure 5 This is a schematic diagram of a parallelized search device based on the Zynq platform provided in an embodiment of the present invention. Detailed Implementation
[0056] To make the objectives, technical solutions, and advantages of the embodiments of the present invention clearer, the technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present invention, not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of the present invention.
[0057] Example 1
[0058] See Figure 1 This is a schematic diagram of the architecture of a Kd-Tree-based parallel neighbor search device shown in this embodiment. This device is applied to a lidar point cloud matching scenario and is used to perform neighbor search processing on lidar point cloud data. The following description, in conjunction with the accompanying drawings, describes a Kd-Tree-based parallel neighbor search device provided in this application embodiment.
[0059] like Figure 1 As shown, this device includes one control module, one search module, one backtracking module, and one status module. The control module receives the node data to be matched and writes the node data into the search FIFO memory. At the same time, it controls the search module and the backtracking module to search for the nearest neighbor of the node data to be matched.
[0060] The search module reads the data of the nodes to be matched from the search FIFO memory, reads the relevant running status of the nodes from the status module according to the sequence number of the nodes to be matched, performs a downward search operation in the Kd-Tree until the leaf node of the Kd-Tree is found, and writes the results into the search FIFO memory and the backtracking FIFO memory respectively according to the status of the search operation.
[0061] The backtracking module reads the data of the node to be matched from the backtracking FIFO memory, reads the relevant running status of the node from the status module according to the node number to be matched, performs an upward backtracking operation in the Kd-Tree until the root node of the Kd-Tree is found, and writes the results into the search FIFO memory, the backtracking FIFO memory and the output node memory respectively according to the status of the backtracking operation completion.
[0062] The status module receives the node number to be matched from the search module or the backtracking module, and transmits the corresponding node-related running status information back to the corresponding module. The node-related running status includes the Kd-Tree node position, nearest neighbor distance, nearest neighbor node, current segmentation dimension, searched nodes, and Kd-Tree search path stack area.
[0063] In this embodiment, the search device runs on an Ubuntu 20.04 LTS system on a PC and is implemented in a single-threaded manner. The search FIFO memory and the backtracking FIFO memory are implemented using data structure queues, hereinafter referred to as the search node queue and the backtracking node queue. The state module is implemented using an array of data structures, hereinafter referred to as the state array. A corresponding state structure is allocated for each node to be matched. The search path stack area in the node-related running state structure is implemented using a data structure stack. The searched nodes in the state structure are implemented using the unordered_map library of the STL library. All data structures are implemented using space allocated by the Linux system on the PC memory.
[0064] See Figure 2 In this embodiment, the Kd-Tree is a data structure that stores instance points in a k-dimensional space for fast retrieval. Its construction process is as follows:
[0065] S11. Using the current instance point as the tree node in the Kd-Tree, calculate the modulo between the depth of the current instance point and the data dimension k to obtain the current segmentation dimension;
[0066] S12. Sort the k-dimensional data according to the current segmentation dimension, and use the median data after sorting as the value of the current tree node.
[0067] S13. Using the median as the dividing point, the data less than the median is taken as the left subtree of the current tree node, and the data greater than the median is taken as the right subtree of the current tree node.
[0068] S14. Repeat S11 to S13 until all instance point data are organized and stored in a Kd-Tree manner.
[0069] In this embodiment, the search for Kd-Tree neighbor points of the node data to be matched in the control module is implemented in a stack manner, as follows:
[0070] S21. Starting from the root node of the Kd-Tree, search downwards;
[0071] S22. If the value of the current dimension of the node to be searched is less than the value of the corresponding dimension of the current Kd-Tree node, then search the left subtree; otherwise, search the right subtree and push the current node onto the stack.
[0072] S23. Repeat step S22 until the current Kd-Tree node is a leaf node, then execute step S24.
[0073] S24. Pop the node from the stack to get the current node, mark the current node as visited, calculate the Euclidean distance between the current node and the target point, and if it is less than the nearest neighbor distance, update the nearest neighbor node and the nearest neighbor distance.
[0074] S25. Calculate the distance between the target point and the parent node in the corresponding dimension. If it is less than the nearest distance, start step S22 from the sibling node that has never been visited.
[0075] S26. Repeat steps S24-S25 until the current node is the root node, and output the final nearest point to the target array.
[0076] See Figure 3 In this embodiment, the Kd-Tree is stored in an array. The Kd-Tree is stored in the array with consecutive addresses. The node number of the root node is 1, and the corresponding memory address is also 1. For a node with address i, its left child node is stored at address i×2, and its right child node is stored at address i×2+1. By calculating the highest position of 1 in the binary representation of the node address, the level of the current node in the Kd-Tree can be obtained. For a node in the m-th level, the m-th bit of its node number in binary representation is 1, and all bits greater than m are 0.
[0077] In this embodiment, the search module processes the following steps:
[0078] S31. Take out the data of the node to be matched from the head of the search node queue, read the node-related running status information from the status array according to the node to be matched number in the node data, and read the current node from the Kd-Tree array through the Kd-Tree node position of the node-related running status.
[0079] S32. Push the current node's index in the Kd-Tree into the search path stack related to the node's running status;
[0080] S33. Determine whether the current node is a leaf node of the Kd-Tree. If it is a leaf node, add the index corresponding to the current node to the tail of the backtracking node queue and then exit the remaining steps. Otherwise, execute step S34.
[0081] S34. Compare the value of the dimension corresponding to the node to be matched with the value of the dimension corresponding to the current node. If it is less than the value of the current node, update the Kd-Tree node position i of the node's related running status to the left child node position 2i. Otherwise, update it to the right child node position 2i+1.
[0082] S35. Add the node number to be matched to the tail of the search node queue.
[0083] In this embodiment, the processing procedure of the backtracking module is as follows:
[0084] S41. Take out the data of the node to be matched from the head of the backtracking node queue, read the node-related running status from the status array according to the node to be matched number in the node data, take out the current node from the Kd-Tree search path stack area of the node-related running status, and mark the current node as visited.
[0085] S42. Calculate the Euclidean distance between the current node and the node to be matched. If it is less than the nearest neighbor distance in the running state, update the nearest neighbor distance to the Euclidean distance and update the nearest neighbor node to the current node.
[0086] S43. If the current node is the root node of the Kd-Tree, transfer the nearest neighbor node in the running state to the output array, and then exit to execute the remaining steps; otherwise, execute step S44.
[0087] S44. Calculate the distance between the node to be matched and the parent node of the current node in the corresponding dimension. Compare the distance with the nearest neighbor distance. If it is less than the nearest neighbor distance in the running state, update the current node to an unvisited sibling node and add the node to be matched to the tail of the search node queue. Otherwise, add the node to be matched to the tail of the backtracking node queue.
[0088] Example 2
[0089] This embodiment discloses a parallelized nearest neighbor search device based on Kd-Tree, such as... Figure 4 The device comprises one control module, M search modules, N backtracking modules, and one status module.
[0090] The control module receives the node data to be matched and writes the node data into the search FIFO memory. At the same time, it controls the search module and the backtracking module to search for the nearest points of the node data to be matched.
[0091] M search modules read the data of the nodes to be matched from the search FIFO memory, read the relevant running status of the nodes from the status module according to the node number, perform a downward search operation in the Kd-Tree until the leaf node of the Kd-Tree is found, and write the results into the search FIFO memory and the backtracking FIFO memory respectively according to the status of the search operation.
[0092] N backtracking modules read the data of the node to be matched from the backtracking FIFO memory, read the relevant running status of the node from the status module according to the node to be matched sequence number, perform an upward backtracking operation in the Kd-Tree until the root node of the Kd-Tree is found, and write the results into the search FIFO memory, backtracking FIFO memory and output node memory respectively according to the status of the backtracking operation completion.
[0093] The status module receives the node numbers to be matched from M search modules or N backtracking modules, and transmits the corresponding node-related running status information back to the corresponding module. The node-related running status includes Kd-Tree node position, nearest neighbor distance, nearest neighbor node, current segmentation dimension, searched nodes, and Kd-Tree search path stack area.
[0094] In this embodiment, the search device runs on an Ubuntu 20.04 LTS system on a PC equipped with an 8-core, 16-thread AMD R7-5800X CPU, and is implemented using a multi-threaded approach. Each search module or backtracking module is implemented by an independent thread, and the total number of modules does not exceed the number of logical CPU cores of the PC.
[0095] In this embodiment, M=8 and N=8 are set to make full use of all the cores of the PC to achieve the effect of accelerating the operation.
[0096] In this embodiment, the search FIFO memory and the backtracking FIFO memory are implemented using data structure queues, hereinafter referred to as the search node queue and the backtracking node queue. The state module is implemented using an array of data structure bodies, hereinafter referred to as the state array. A corresponding state structure is allocated for each node to be matched. The search path stack area in the node-related running state structure is implemented using a data structure stack. The searched nodes in the state structure are implemented using the unordered_map library of the STL library. All data structures are implemented using space allocated on the PC memory of the Ubuntu 20.04 LTS system.
[0097] In this embodiment, M search threads and N backtracking threads run in parallel and are controlled by a control thread. They continuously retrieve node data from the search node queue and the backtracking node queue to perform search and backtracking operations until both the search node queue and the backtracking node queue are empty.
[0098] Example 3
[0099] This specific example demonstrates a parallelized nearest-neighbor search device and method based on a Kd-Tree. Figure 5 As shown, the device can be deployed on the Zynq platform and applied to neighbor point matching of laser 3D point clouds. It includes one control module, M search modules, N backtracking modules and one status module.
[0100] The control module receives the node data to be matched and writes the node data into the search FIFO memory. At the same time, it controls the search module and the backtracking module to search for the nearest points of the node data to be matched.
[0101] M search modules read the data of the nodes to be matched from the search FIFO memory, read the relevant running status of the nodes from the status module according to the node number, perform a downward search operation in the Kd-Tree until the leaf node of the Kd-Tree is found, and write the results into the search FIFO memory and the backtracking FIFO memory respectively according to the status of the search operation.
[0102] N backtracking modules read the data of the node to be matched from the backtracking FIFO memory, read the relevant running status of the node from the status module according to the node to be matched sequence number, perform an upward backtracking operation in the Kd-Tree until the root node of the Kd-Tree is found, and write the results into the search FIFO memory, backtracking FIFO memory and output node memory respectively according to the status of the backtracking operation completion.
[0103] The status module receives the node numbers to be matched from M search modules or N backtracking modules, and transmits the corresponding node-related running status information back to the corresponding module. The node-related running status includes Kd-Tree node position, nearest neighbor distance, nearest neighbor node, current segmentation dimension, searched nodes, and Kd-Tree search path stack area.
[0104] In this embodiment, the Zynq platform includes a PS (Processing System) end and a PL (Programmable Logic) end. The PS end includes an ARM-CPU core and a DDR controller, while the PL end is an FPGA implementation based on the Zynq SoC chip. The PS end and the PL end communicate through the AXI bus.
[0105] The search FIFO memory, backtracking FIFO memory, and node status module deployed on the PL can be BRAM (Block Memory) memory in the PL for fast reading and writing of node-related data.
[0106] The quantities of M and N can be arbitrarily allocated according to the logic resources of the FPGA of the Zynq SoC chip. In this embodiment, M=8 and N=8 are set.
[0107] M search modules and N backtracking modules send signals to the FIFO controller to obtain node data stored in the BRAM search FIFO memory and backtracking FIFO memory.
[0108] The search module and the backtracking module send signals to the stack controller to obtain node-related running status data stored in the BRAM.
[0109] The searched nodes in the status module are queried by traversing the entire searched node BRAM through the FPGA.
[0110] M search modules and N backtracking modules run in parallel, controlled by a control module. They continuously retrieve node data from the search queue and backtracking queue to perform search and backtracking operations until both the search queue and the backtracking queue are empty.
[0111] In this embodiment, the PS end constructs the target point cloud into a Kd-Tree and stores it in the DDR of the PS end. At the same time, the nodes to be matched are also stored in the DDR in the form of an array.
[0112] The PS terminal sends a signal to the control module on the PL terminal via the AXI4 bus to initiate the search process.
[0113] The control module on the PL side reads the nodes to be matched and the Kd-Tree array in the DDR through AXI-DMA and stores them in the PL side BRAM.
[0114] The above embodiments are preferred embodiments of the present invention, but the embodiments of the present invention are not limited to the above embodiments. Any changes, modifications, substitutions, combinations, or simplifications made without departing from the spirit and principle of the present invention shall be considered equivalent substitutions and shall be included within the protection scope of the present invention.
Claims
1. A parallelized nearest neighbor search device based on Kd-Tree, characterized in that, The device includes a control module, M search modules, N backtracking modules, and a status module, where M = 1, 2, ..., N = 1, 2, ...; The control module receives the node data to be matched and writes the node data into the search FIFO memory. At the same time, it controls the M search modules and N backtracking modules to search for the nearest points of the node data to be matched. The M search modules read the data of the nodes to be matched from the search FIFO memory, read the relevant running status of the nodes from the status module according to the sequence number of the nodes to be matched, and read the Kd-Tree nodes from the Kd-Tree memory according to the relevant running status of the nodes, and perform a downward search operation until the leaf node of the Kd-Tree is found. According to the status of the search operation completion, the results are written into the search FIFO memory and the backtracking FIFO memory respectively. The N backtracking modules read the data of the nodes to be matched from the backtracking FIFO memory, read the relevant running status of the nodes from the status module according to the sequence number of the nodes to be matched, perform an upward backtracking operation in the Kd-Tree until the root node of the Kd-Tree is found, and write the results into the search FIFO memory, the backtracking FIFO memory and the output node memory respectively according to the status of the backtracking operation. The status module receives the node sequence number to be matched from M search modules or N backtracking modules, and transmits the corresponding node-related running status information back to the corresponding module. The node-related running status includes Kd-Tree node position, nearest neighbor distance, nearest neighbor node, current segmentation dimension, searched nodes, and Kd-Tree search path stack area.
2. The parallelized nearest neighbor search device based on Kd-Tree according to claim 1, characterized in that, The Kd-Tree is a data structure that stores instance points in a k-dimensional space to facilitate fast retrieval within the Kd-Tree. The Kd-Tree construction process is as follows: S11. Take the current instance point as the tree node in the Kd-Tree and calculate the modulo between the depth of the current instance point and the data dimension k to obtain the current segmentation dimension; S12. Sort the k-dimensional data according to the current segmentation dimension, and use the median data after sorting as the value of the current tree node. S13. Using the median as the dividing point, the data less than the median is taken as the left subtree of the current tree node, and the data greater than the median is taken as the right subtree of the current tree node. S14. Repeat S11 to S13 until all instance point data are organized and stored in a Kd-Tree manner.
3. The parallelized nearest neighbor search device based on Kd-Tree according to claim 1, characterized in that, The neighbor search process for the node data to be matched in the control module is as follows: S21. Starting from the root node of the Kd-Tree, search downwards; S22. If the value of the current dimension of the node to be searched is less than the value of the corresponding dimension of the current Kd-Tree node, then search the left subtree; otherwise, search the right subtree and push the current node onto the stack. S23. Repeat step S22 until the current Kd-Tree node is a leaf node, then execute step S24. S24. Pop the node from the stack to get the current node, mark the current node as visited, calculate the Euclidean distance between the current node and the target point, and if it is less than the nearest neighbor distance, update the nearest neighbor node and the nearest neighbor distance. S25. Calculate the distance between the target point and the parent node in the corresponding dimension. If it is less than the nearest distance, start step S22 from the sibling node that has never been visited. S26. Repeat steps S24-S25 until the current node is the root node, and output the final nearest point to the target array.
4. The parallelized nearest neighbor search device based on Kd-Tree according to claim 2, characterized in that, The Kd-Tree memory storage method is as follows: Kd-Tree is stored in memory with consecutive addresses. The root node is at address 1. For a node at address i, the left child of node i is stored at address i×2, and the right child of node i is stored at address i×2+1. By calculating the highest 1 in the binary representation of the node address, the level of the current node in the Kd-Tree can be obtained.
5. The parallelized nearest neighbor search device based on Kd-Tree according to claim 1, characterized in that, The control module polls the idle flag area of the search FIFO memory and the backtrack FIFO memory. If the idle flag of the corresponding search FIFO memory or backtrack FIFO memory is set to 0, it indicates that there is data waiting to be processed in the search FIFO memory or backtrack FIFO memory. The control module then generates a start signal to the corresponding search FIFO memory or backtrack FIFO memory.
6. The parallelized nearest neighbor search device based on Kd-Tree according to claim 1, characterized in that, The processing procedure of the search module is as follows: S31. Retrieve the data of the node to be matched from the search FIFO memory, transmit the sequence number of the node to be matched in the node data to the status module to obtain the node-related running status information, and obtain the current node from the Kd-Tree memory through the Kd-Tree node position of the node-related running status. S32. Push the current node's index in the Kd-Tree into the search path stack area related to the node's running status; S33. Determine whether the current node is a leaf node of the Kd-Tree. If it is a leaf node, add the sequence number corresponding to the current node to the end of the backtracking FIFO memory and then exit the remaining steps. Otherwise, execute step S34. S34. Compare the value of the dimension corresponding to the node to be matched with the value of the dimension corresponding to the current node. If it is less than the value of the current node, update the position of the Kd-Tree node related to the node's running status to the position of the left child node; otherwise, update it to the position of the right child node. S35. Add the node number to be matched to the end of the search FIFO memory.
7. The parallelized nearest neighbor search device based on Kd-Tree according to claim 1, characterized in that, The processing procedure of the backtracking module is as follows: S41. Retrieve the data of the node to be matched from the backtracking FIFO memory, transmit the sequence number of the node to be matched in the node data to the status module to obtain the node-related running status, retrieve the current node from the Kd-Tree search path stack area of the node-related running status, and mark the current node as visited. S42. Calculate the Euclidean distance between the current node and the node to be matched. If it is less than the nearest neighbor distance in the running state, update the nearest neighbor distance to the Euclidean distance and update the nearest neighbor node to the current node. S43. If the current node is the root node of the Kd-Tree, transfer the nearest neighbor node in the running state to the output node memory, and then exit to execute the remaining steps; otherwise, execute step S44. S44. Calculate the distance between the node to be matched and the parent node of the current node in the corresponding dimension. Compare the distance in the corresponding dimension with the nearest neighbor distance. If it is less than the nearest neighbor distance in the running state, update the current node to an unvisited sibling node and add the node to be matched to the end of the search FIFO memory. Otherwise, add the node to be matched to the end of the backtracking FIFO memory.
8. The parallelized nearest neighbor search device based on Kd-Tree according to claim 1, characterized in that, The number of search modules M and the number of backtracking modules N are set according to the required parallelism. The M search modules and N backtracking modules share a single search FIFO memory and a backtracking FIFO memory.
9. The parallelized nearest neighbor search device based on Kd-Tree according to claim 1, characterized in that, The node-related operating status of the state module has its own separate copy for each input node to be matched, and its access to and writing to the node-related operating status of other nodes to be matched do not interfere with each other.
10. A search method for a Kd-Tree-based parallelized nearest neighbor search apparatus according to any one of claims 1-9, characterized in that, The search method includes the following steps: T1. The control module receives the node to be matched, adds it to the search FIFO memory, and simultaneously polls to check the idle status of the search FIFO memory and the backtrack FIFO memory. If they are not empty, a start signal is sent to the corresponding module. T2. After receiving the start signal from the control module, the search module communicates with the status module to obtain relevant node information and begins to perform a downward search operation, adding the results to the search FIFO memory and the backtracking FIFO memory respectively. T3. After receiving the start signal from the control module, the backtracking module communicates with the status module to obtain relevant node information and begins to perform the upward backtracking operation, adding the results to the search FIFO memory, backtracking FIFO memory or output node memory respectively.
Citation Information
Patent Citations
Parallel breadth-first search method based on shared memory system structure
CN106033442A
Three-dimensional Kriging algorithm collaborative acceleration technology based on CUDA and OpenMP
CN113360187A