Template matching method, device and equipment and computer readable storage medium

By performing prefix and suffix template matching in the GPU, combined with CUDA parallel computing and Reduce optimization, the problems of high hard disk resource consumption and low computing efficiency in the existing technology are solved, and efficient template matching is achieved, reducing hardware dependence and cost.

CN119091168APending Publication Date: 2024-12-06CETC CYBERSPACE SECURITY TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202411293088.0
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-09-14
Publication Date
2024-12-06

AI Technical Summary

Technical Problem

The existing fast template matching calculation method relies on parallel processing of CPU and GPU, resulting in high hard disk resource consumption, low computing efficiency and high deployment cost, which cannot meet the storage and processing needs of large-scale data.

Method used

By loading the random sequence to be detected in the GPU, performing prefix and suffix template matching, and using CUDA parallel computing and Reduce optimization algorithm, the matching process is directly completed in the GPU, avoiding the generation of a large number of intermediate files and reducing dependence on the hard disk and CPU.

Benefits of technology

It realizes template matching with low resource consumption and high computing efficiency, reduces I/O operations, reduces hardware configuration requirements, significantly improves computing speed and reduces costs.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119091168A_ABST
    Figure CN119091168A_ABST
Patent Text Reader

Abstract

The invention discloses a template matching method, device and equipment and a computer readable storage medium, which are applied to the technical field of computers, and comprise the following steps: loading a random sequence to be detected into a GPU (Graphics Processing Unit); executing the steps of prefix detection template matching, suffix matching and storage on each prefix detection template in the GPU until the execution times reach the prefix matching times, and ending the matching; the prefix detection template matching comprises the steps of matching a random sequence to be detected with a prefix detection template, and taking a successfully matched sequence as a target object; and suffix matching and storage comprise the steps of reserving the target objects with the same suffix sequence in the target objects as a matching result, and storing sequence information and position information of the matching result into the GPU. According to the method, a large number of intermediate files cannot be generated, a GPU memory can meet the storage requirement, hard disk resources are not needed for storage, the GPU is used for calculation and storage in the whole process, the calculation efficiency is improved, and calculation resource consumption and configuration requirements are reduced.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of computer technology, and in particular to a template matching method, device, equipment and computer-readable storage medium. Background Art

[0002] Overlapping template matching calculation is a random number duplication detection method, that is, by moving bit by bit, on a binary sequence with a data volume of n bits, the number of occurrences of a k-bit repeated sequence is found. These fixed-length binary sequences that repeat in an overlapping manner are called repeated codes, and the number of repeated code pairs in the sequence is one of the criteria for determining the randomness of the sequence.

[0003] At present, fast template matching calculation is mainly based on CUDA (parallel computing platform and programming model, used for general computing on graphics processing units), using CPU (Central Processing Unit / Processor, central processing unit) and GPU (Graphics Processing Unit, graphics processing unit) parallel processing calculation, prefix processing of all templates to generate a large number of intermediate files, and then subsequent suffix processing based on the intermediate files. Therefore, it is necessary to store the intermediate files. Due to the huge amount of intermediate files, for example, for 64-bit overlapping collisions of 10GB of data to be tested, 640GB of hard disk resources are required, and the limited GPU storage cannot meet the storage requirements, so a large amount of hard disk resources are required for storage, and there is also a certain dependence on the hard disk; and the parallel processing calculation of CPU and GPU is also highly dependent on both CPU and GPU, which has a high cost problem. Summary of the invention

[0004] In view of this, an object of the present invention is to provide a template matching method, which solves the problem of high cost caused by dependence on CPU and hard disk in the prior art.

[0005] In order to solve the above technical problems, the present invention provides a template matching method, comprising:

[0006] Obtaining a detection template length and a prefix detection template length, and calculating the number of prefix matches according to the prefix detection template length;

[0007] Loading the random sequence to be detected into the GPU; performing prefix detection template matching, suffix matching and saving steps on each prefix detection template in the GPU until the number of executions reaches the number of prefix matching times and the matching ends;

[0008] The prefix detection template matching includes: matching the random sequence to be detected with the prefix detection template, and taking the successfully matched sequence as the target object; the length of the target object is consistent with the length of the detection template;

[0009] The suffix matching and saving includes: retaining the target objects with the same suffix sequence in the target objects as matching results, and saving the sequence information and position information of the matching results in the GPU.

[0010] Optionally, matching the random sequence to be detected with the prefix detection template and taking the successfully matched sequence as the target object includes:

[0011] Dividing the random sequence to be detected into a plurality of sequence blocks;

[0012] CUDA parallel computing is used to match each of the sequence blocks with the prefix detection template to obtain the target object.

[0013] Optionally, using CUDA parallel computing to match each of the sequence blocks with the prefix detection template to obtain the target object includes:

[0014] Using CUDA parallel computing, matching each of the sequence blocks with the prefix detection template to obtain the number of successful matches in each of the sequence blocks;

[0015] The position information and sequence information of successful matches are obtained from the sequence blocks whose number of successful matches is not 0, and the target object is obtained according to the position information and sequence information.

[0016] Optionally, matching each of the sequence blocks with the prefix detection template to obtain the number of successful matches in each of the sequence blocks includes:

[0017] The shared memory of the GPU is used to recursively reduce and sum the number of successful matches in each byte block in each sequence block, so as to calculate the number of successful matches in each sequence block.

[0018] Optionally, the target objects with the same suffix sequence in the target objects are retained as matching results, including:

[0019] Calculate the bit value of each target object according to the sequence information of the target object;

[0020] Sort all the target objects from small to large or from large to small according to the bit value;

[0021] The target object with the same bit value as any adjacent object is retained as the matching result.

[0022] Optionally, the step of saving the sequence information and position information of the matching result to the GPU includes:

[0023] The total number of the matching results is calculated using a Reduce optimization algorithm, so that the GPU allocates corresponding memory to store the sequence information and position information of the matching results.

[0024] The present invention also provides a template matching device, comprising:

[0025] An acquisition module, used to acquire a detection template length and a prefix detection template length, and calculate the number of prefix matching times according to the prefix detection template length;

[0026] A data loading module is used to load the random sequence to be detected into the GPU; in the GPU, the steps of prefix detection template matching, suffix matching and saving are performed on each prefix detection template until the number of executions reaches the number of prefix matching times and the matching is completed;

[0027] A prefix matching module, used to perform the prefix detection template matching, including: matching the random sequence to be detected with the prefix detection template, and taking the successfully matched sequence as a target object; the length of the target object is consistent with the length of the detection template;

[0028] The suffix matching and saving module is used to perform the suffix matching and saving, including: retaining the target objects with the same suffix sequence in the target objects as matching results, and saving the sequence information and position information of the matching results to the GPU.

[0029] Optionally, the prefix matching module includes:

[0030] A segmentation unit, used for dividing the random sequence to be detected into a plurality of sequence blocks;

[0031] The parallel matching unit is used to match each of the sequence blocks with the prefix detection template by using CUDA parallel computing to obtain the target object.

[0032] The present invention also provides a template matching device, comprising:

[0033] Memory for storing computer programs;

[0034] A processor is used to implement the above-mentioned template matching method when executing the computer program.

[0035] The present invention also provides a computer-readable storage medium, in which computer-executable instructions are stored. When the computer-executable instructions are loaded and executed by a processor, the above-mentioned template matching method is implemented.

[0036] It can be seen that the present invention traverses each prefix detection template to perform prefix detection template matching and suffix matching on the random sequence to be detected, and directly obtains the final result of each prefix detection template matching, and does not generate a large number of intermediate files. The memory of the GPU can meet the storage requirements, and there is no need to use hard disk resources for storage, which reduces the consumption of computing resources; there is no need to store large files in other spaces, and I / O (Input output system) operations are reduced, thereby improving computing efficiency; the GPU is used throughout the process for computing and storage, and the dependence on hard disk, memory and CPU devices is extremely low, which reduces configuration requirements and saves costs.

[0037] In addition, the present invention also provides a template matching device, equipment and computer-readable storage medium, which also have the above-mentioned beneficial effects. BRIEF DESCRIPTION OF THE DRAWINGS

[0038] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are only embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on the provided drawings without paying creative work.

[0039] Figure 1 A flow chart of a template matching method provided by an embodiment of the present invention;

[0040] Figure 2 A flowchart of a reduce optimization calculation provided by an embodiment of the present invention;

[0041] Figure 3 An example flow chart of a template matching method provided in an embodiment of the present invention;

[0042] Figure 4 A schematic diagram of the structure of a template matching device provided by an embodiment of the present invention;

[0043] Figure 5 A schematic diagram of the structure of a template matching device provided by an embodiment of the present invention. DETAILED DESCRIPTION

[0044] In order to make the purpose, technical solution and advantages of the embodiments of the present invention clearer, the technical solution in the embodiments of the present invention will be clearly and completely described below in conjunction with the drawings in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.

[0045] At present, the fast overlapping template matching calculation is mainly implemented based on CUDA. The specific process is described as follows:

[0046] 1) Set initial parameters.

[0047] 2) Load the data to be tested into the GPU device, use the GPU device to perform CUDA parallel matching on the data, and obtain all the prefix frequency intermediate files, which store the data information and location information of all sequences with successful prefix matching. The GPU device sends all the generated intermediate files to the CPU device, and the CPU device sends the intermediate files to the hard disk for storage. The prefix frequency refers to the number of times a fixed prefix template (such as "1100011000") appears repeatedly in the entire sequence, which is the intermediate result obtained by prefix template matching.

[0048] 3) Using CUDA parallelism, the CPU takes out each intermediate file from the hard disk in turn and sends it to the GPU device. The GPU device performs radix sorting on the suffix data corresponding to the current prefix to obtain all collision sequences and their positions that meet the requirements.

[0049] 4) The GPU transmits the collision result (i.e., matching result) to the CPU, and uses the CPU to perform a longer collision determination search based on the known collision information.

[0050] From the above process, we can see that the existing methods have the following problems:

[0051] 1) High resource consumption: Because the prefix frequency intermediate file contains the data of successful prefix matching of all templates, the data volume is large, and the GPU cannot meet the storage requirements, so a large amount of hard disk resources are still required. For example, for a 64-bit overlap collision of 10GB data, 640GB of hard disk resources are required.

[0052] 2) Low computational efficiency: The process requires data transmission between the CPU, GPU, and hard disk, so a large number of I / O operations need to be inserted. I / O operations are very time-consuming operations, resulting in long computation time and low efficiency.

[0053] 3) High deployment cost: The computing process will be affected by devices such as the hard disk, CPU, and GPU, and its computing efficiency has an obvious barrel effect. If you want to achieve satisfactory results, the deployment cost is relatively high.

[0054] Based on the above problems, this application proposes a template matching method that can solve the above problems. For details, please refer to Figure 1 , Figure 1 A flow chart of a template matching method provided by an embodiment of the present invention. The method may include:

[0055] S101: Obtain a detection template length and a prefix detection template length, and calculate the number of prefix matching times according to the prefix detection template length.

[0056] This embodiment does not limit the detection template length and prefix detection template length. It can be understood that this embodiment divides the detection template into prefix and suffix, so the prefix detection template length must be smaller than the detection template length. For example, if the detection template length is 64 bits and the prefix detection template length is 8 bits, then the corresponding suffix length is 56 bits, and the prefix detection template is 00000000, 00000001, 00000010, ..., 11111111, a total of 2 8 The number of prefix matches is the number of prefix detection templates, that is, the number of prefix matches is 2. 8 . Generally, the detection template length is set according to the detection standard. For example, if the sequence randomness judgment standard is the value of a 64-bit repeated sequence, then the corresponding detection template length is 64 bits. At this time, in order to reduce the intermediate value and calculation efficiency between the prefix and suffix in each template in this embodiment, where the intermediate value refers to the sequence information of the successful match of the prefix detection template, the prefix detection template length can be 10 bits.

[0057] S102: Load the random sequence to be detected into the GPU; perform prefix detection template matching, suffix matching and saving steps on each prefix detection template in the GPU until the number of executions reaches the number of prefix matching times and the matching ends.

[0058] In this embodiment, the random sequence to be detected is loaded into the GPU. The random sequence to be detected generally has a large amount of data, such as a 10GB random sequence to be detected. The random sequence to be detected is loaded into the GPU, and the full process of template matching is executed on each prefix detection template in the GPU to obtain the matching results of each prefix detection template. When the number of executions reaches the number of prefix matching times, it means that all prefix detection templates have completed template matching. The full process of template matching includes prefix detection template matching, suffix matching and saving. Among them, prefix detection template matching includes: matching the random sequence to be detected with the prefix detection template, and taking the successfully matched sequence as the target object; the length of the target object is consistent with the length of the detection template; suffix matching and saving include: retaining the target object with the same suffix sequence in the target object as the matching result, and saving the sequence information and position information of the matching result to the GPU. This embodiment does not limit the order of each prefix detection template. Each prefix detection template can be performed synchronously, or it can also be performed sequentially. In order to calculate the speed, the CUDA parallel computing method can be used to simultaneously calculate the matching results of each prefix detection template and the random sequence to be detected. This embodiment does not limit the matching process of the prefix detection template. For example, the prefix detection template can be directly matched with the random sequence to be detected; or the random sequence to be detected can be divided into multiple blocks, and the random sequence in each block can be matched with the prefix detection template in parallel using the CUDA parallel computing method. This method can be applied to overlapping template matching or non-overlapping template matching.

[0059] Furthermore, in order to improve the calculation speed, the above-mentioned matching of the random sequence to be detected with the prefix detection template and taking the successfully matched sequence as the target object may specifically include:

[0060] Step 21: Divide the random sequence to be detected into several sequence blocks;

[0061] Step 22: Use CUDA parallel computing to match each sequence block with the prefix detection template to obtain the target object.

[0062] In this embodiment, the random sequence to be detected can be equally divided into several block sequence blocks, or the random sequence to be detected can be randomly divided into several block sequence blocks, so as to use CUDA parallel computing to determine the matching status of each block sequence block with the prefix detection template. If the match is successful, the target object exists in the block sequence block; if the match is unsuccessful, it means that the target object does not exist in the block sequence block.

[0063] Furthermore, in order to further improve the calculation speed, the above-mentioned CUDA parallel calculation is used to match each sequence block with the prefix detection template to obtain the target object, which may specifically include:

[0064] Step 221: using CUDA parallel computing, matching each sequence block with the prefix detection template to obtain the number of successful matches in each sequence block;

[0065] Step 222: Obtain the position information and sequence information of successful matches from the sequence blocks whose number of successful matches is not 0, and obtain the target object according to the position information and sequence information.

[0066] This embodiment calculates the number of successful matches with the prefix detection template in each block sequence block. If the number of successful matches with the prefix detection template 00000000 in block sequence block 5 is 10, then there are 10 sequences with a prefix part of 00000000 in block sequence block 5. The position information and sequence information of the successful match are determined as a target object. This embodiment improves the calculation speed by dividing the random sequence to be detected into sequence blocks and performing matching calculations in parallel; and based on the number of successful matches between the sequence blocks and the prefix detection template, the sequence blocks with a successful match number of 0 are filtered out to reduce the amount of subsequent calculation data.

[0067] Furthermore, in order to improve the matching speed, the target objects with the same suffix sequence in the above target objects are retained as matching results, which may specifically include:

[0068] Step 31: Calculate the bit value of each target object according to the sequence information of the target object;

[0069] Step 32: Sort all target objects from small to large or from large to small according to bit values;

[0070] Step 33: The target object having the same bit value as any adjacent object is retained as the matching result.

[0071] When the prefix parts of the target objects are exactly the same, the bit values ​​of the target objects can be calculated, and all target objects can be sorted according to the bit values. The target objects with the same bit values ​​are retained as the final matching results of the prefix detection template, and the position information and sequence information of the matching results are saved.

[0072] Furthermore, in order to improve the calculation efficiency of the number of times, the above uses CUDA parallel computing to match each sequence block with the prefix detection template to obtain the number of successful matches in each sequence block, which may specifically include:

[0073] The GPU's shared memory is used to recursively reduce and sum the number of successful matches in each byte block in each sequence block, and the number of successful matches in each sequence block is calculated.

[0074] Furthermore, in order to improve the calculation efficiency of the number of times, the above-mentioned storing the sequence information and position information of the matching results in the GPU may specifically include:

[0075] The Reduce optimization algorithm is used to calculate the total number of matching results, so that the GPU allocates corresponding memory to store the sequence information and position information of the matching results.

[0076] In this embodiment, the number of successful matches of each sequence block and the total number of successful matches of all sequence blocks in the entire random sequence to be detected can be calculated using the Reduce (Reduce() function accumulates the elements in the parameter sequence) optimization algorithm. For details, please refer to Figure 2 , the example calculates the prefix detection template matching results of two blocks respectively, and recursively reduces and sums the results of each round through the shared memory of the GPU. Compared with the general summation calculation method with a calculation complexity of n, the calculation complexity of this method is only log2n. When the total number is calculated, the GPU can allocate enough memory to store the sequence information and position information of the matching results under the prefix matching template.

[0077] The template matching method provided by the embodiment of the present invention is applied, by obtaining the detection template length and the prefix detection template length, and calculating the number of prefix matching according to the prefix detection template length; loading the random sequence to be detected into the GPU; performing the steps of prefix detection template matching, suffix matching and saving on each prefix detection template in the GPU until the number of executions reaches the number of prefix matching times, and the matching ends; wherein the prefix detection template matching includes: matching the random sequence to be detected with the prefix detection template, and taking the successfully matched sequence as the target object; the length of the target object is consistent with the length of the detection template; the suffix matching and saving includes: retaining the target object with the same suffix sequence in the target object as the matching result, and saving the sequence information and position information of the matching result to the GPU. This method will traverse each prefix detection template to perform prefix detection template matching and suffix matching on the random sequence to be detected, and directly obtain the final results of each prefix detection template matching. It will not generate a large number of intermediate files. The GPU memory can meet the storage requirements, and there is no need to use hard disk resources for storage, which reduces the consumption of computing resources; there is no need to store large files in other spaces, which reduces I / O operations and improves computing efficiency; the GPU is used for calculation and storage throughout the process, and the dependence on hard disks, memory and CPU devices is extremely low, which reduces configuration requirements. In addition, the parallelism in the statistical process of the number of successful matches is improved through Reduce optimization, and the computing power of the GPU is used more efficiently, while also reducing the consumption of some GPU resources. In addition, the intermediate values ​​are calculated in batches and overwritten and saved, so that the intermediate results of a large amount of data are always stored in the GPU, reducing a large number of I / O operations and hard disk resource consumption.

[0078] In order to make the present invention easier to understand, please refer to Figure 3 , Figure 3 An example flow chart of a template matching method provided in an embodiment of the present invention may specifically include:

[0079] Taking a 10GB random number sequence as an example, the specific calculation process is as follows:

[0080] 1) Input the 10GB random number sequence to be tested and load it into the GPU.

[0081] 2) Set the prefix detection template length to 10 bits and the detection template length to 64 bits, and traverse all prefix detection template matches. For example, the first prefix detection template is 0000000000, the second prefix detection template is 0000000001, and so on. Each prefix detection template needs to execute steps 3-7, that is, each prefix detection template executes in turn, for a total of 2 10 Prefix detection templates, a total of 2 10 Second-rate.

[0082] 3) Divide the input sequence into several Block sequence blocks so as to use CUDA for parallel computing. Then perform prefix matching and summation on the sequence data in each Block to obtain the number of successful prefix matching in each Block, sum1, sum2 to sumn.

[0083] 4) Filter out the blocks whose prefix matching results are not 0, and save the location information index and sequence information value of the target objects whose prefix matching is successful in these blocks.

[0084] 5) A 64-bit value is calculated based on the sequence information, and the prefix matching results (i.e., target objects) are sorted.

[0085] 6) Filter the target object according to the sorted result. If the 64-bit value of the target object is neither equal to the 64-bit value of the previous target object nor equal to the 64-bit value of the next target object, delete the target object.

[0086] 7) The result after screening is the matching result of the 64-bit detection template corresponding to the current prefix detection template. The matching result of the detection template with more than 64 bits can be expanded and calculated according to the previously saved position information.

[0087] 8) After steps 3-7 are repeated, the matching results of all 64-bit detection templates of the random number sequence can be obtained.

[0088] This method has the following advantages:

[0089] 1) Low resource consumption: No need to consume a lot of hard disk resources to save intermediate results.

[0090] 2) High computational efficiency: I / O operations are greatly reduced, and computational tasks are divided into multiple subtasks, which are more suitable for CUDA parallel implementation. For 64-bit overlapping collisions of 10GB data, the existing technology takes about 4200 seconds to complete the calculation, while this method only takes about 1600 seconds, which improves efficiency by 162.5%.

[0091] 3) Low configuration requirements: Users only need to provide a GPU that meets the requirements to achieve the best computing effect, without having to upgrade other existing hardware devices.

[0092] The following is an introduction to a template matching device provided in an embodiment of the present invention. The template matching device described below and the template matching method described above can be referred to in correspondence with each other.

[0093] Please refer to Figure 4 , Figure 4 A schematic diagram of the structure of a template matching device provided by an embodiment of the present invention may include:

[0094] An acquisition module 100 is used to acquire a detection template length and a prefix detection template length, and calculate the number of prefix matching times according to the prefix detection template length;

[0095] The data loading module 200 is used to load the random sequence to be detected into the GPU; in the GPU, the steps of prefix detection template matching, suffix matching and saving are performed on each prefix detection template until the number of executions reaches the number of prefix matching times and the matching is completed;

[0096] The prefix matching module 300 is used to perform the prefix detection template matching, including: matching the random sequence to be detected with the prefix detection template, and taking the successfully matched sequence as the target object; the length of the target object is consistent with the length of the detection template;

[0097] The suffix matching and saving module 400 is used to perform the suffix matching and saving, including: retaining the target objects with the same suffix sequence in the target objects as matching results, and saving the sequence information and position information of the matching results to the GPU.

[0098] Based on the above embodiment, the prefix matching module 300 may include:

[0099] A segmentation unit, used for dividing the random sequence to be detected into a plurality of sequence blocks;

[0100] The parallel matching unit is used to match each of the sequence blocks with the prefix detection template by using CUDA parallel computing to obtain the target object.

[0101] Based on the above embodiment, the parallel matching unit may include:

[0102] A times calculation unit, used for matching each of the sequence blocks with the prefix detection template by using CUDA parallel computing, and obtaining the times of successful matching in each of the sequence blocks;

[0103] The target object determination unit is used to obtain the position information and sequence information of the successful match from the sequence blocks whose number of successful matches is not 0, and obtain the target object according to the position information and sequence information.

[0104] Based on the above embodiment, the number calculation unit may include:

[0105] The times calculation subunit is used to use the shared memory of the GPU to recursively reduce and sum the times of successful matches in two byte blocks in each sequence block, so as to calculate the times of successful matches in each sequence block.

[0106] Based on the above embodiment, the suffix matching and saving module 400 may include:

[0107] A bit value calculation unit, configured to calculate a bit value of each target object according to the sequence information of the target object;

[0108] A sorting unit, used to sort all the target objects from small to large or from large to small according to the bit value;

[0109] The matching result determination unit is used to retain the target object having the same bit value as any adjacent object as the matching result.

[0110] Based on the above embodiment, the suffix matching and saving module 400 may include:

[0111] The storage unit is used to calculate the total number of the matching results by using the Reduce optimization algorithm, so that the GPU allocates corresponding memory to store the sequence information and position information of the matching results.

[0112] It should be noted that the order of the modules and units in the above template matching device can be changed without affecting the logic.

[0113] The template matching device provided by the embodiment of the present invention is applied, through the acquisition module 100, used to obtain the detection template length and the prefix detection template length, and calculate the prefix matching number according to the prefix detection template length; the data loading module 200 is used to load the random sequence to be detected into the GPU; the steps of prefix detection template matching, suffix matching and saving are performed on each prefix detection template in the GPU until the execution number reaches the prefix matching number and the matching is completed; the prefix matching module 300 is used to perform prefix detection template matching, including: matching the random sequence to be detected with the prefix detection template, and taking the successfully matched sequence as the target object; the length of the target object is consistent with the detection template length; the suffix matching and saving module 400 is used to perform suffix matching and saving, including: retaining the target object with the same suffix sequence in the target object as the matching result, and saving the sequence information and position information of the matching result to the GPU. This device will traverse each prefix detection template to perform prefix detection template matching and suffix matching on the random sequence to be detected, and directly obtain the final results of each prefix detection template matching. It will not generate a large number of intermediate files. The GPU memory can meet the storage requirements, and there is no need to use hard disk resources for storage, which reduces the consumption of computing resources; there is no need to store large files in other spaces, which reduces I / O operations and improves computing efficiency; the GPU is used for calculation and storage throughout the process, and the dependence on hard disks, memory and CPU devices is extremely low, which reduces configuration requirements. In addition, the parallelism in the statistical process of the number of successful matches is improved through Reduce optimization, and the computing power of the GPU is used more efficiently, while also reducing the consumption of some GPU resources. In addition, the intermediate values ​​are calculated in batches and overwritten and saved, so that the intermediate results of a large amount of data are always stored in the GPU, reducing a large number of I / O operations and hard disk resource consumption.

[0114] The following is an introduction to a template matching device provided in an embodiment of the present invention. The template matching device described below and the template matching method described above can be referred to in correspondence with each other.

[0115] Please refer to Figure 5 , Figure 5 A schematic diagram of the structure of a template matching device provided by an embodiment of the present invention may include:

[0116] A memory 10, used for storing computer programs;

[0117] The processor 20 is used to execute a computer program to implement the above template matching method.

[0118] The memory 10 , the processor 20 , and the communication interface 31 all communicate with each other via the communication bus 32 .

[0119] In the embodiment of the present invention, the memory 10 is used to store one or more programs, and the program may include program code, and the program code includes computer operation instructions. In the embodiment of the present invention, the memory 10 may store programs for implementing the following functions:

[0120] Obtain the detection template length and the prefix detection template length, and calculate the number of prefix matching times according to the prefix detection template length;

[0121] Load the random sequence to be detected into the GPU; perform prefix detection template matching, suffix matching and saving steps on each prefix detection template in the GPU until the number of executions reaches the number of prefix matching times and the matching ends;

[0122] The prefix detection template matching includes: matching the random sequence to be detected with the prefix detection template, and taking the successfully matched sequence as the target object; the length of the target object is consistent with the length of the detection template;

[0123] The suffix matching and saving includes: retaining the target objects with the same suffix sequence in the target objects as matching results, and saving the sequence information and position information of the matching results to the GPU.

[0124] In a possible implementation, the memory 10 may include a program storage area and a data storage area, wherein the program storage area may store an operating system and an application required for at least one function, etc.; the data storage area may store data created during use.

[0125] In addition, the memory 10 may include a read-only memory and a random access memory, and provide instructions and data to the processor. A portion of the memory may also include an NVRAM. The memory stores an operating system and operating instructions, executable modules or data structures, or a subset thereof, or an extended set thereof, wherein the operating instructions may include various operating instructions for implementing various operations. The operating system may include various system programs for implementing various basic tasks and processing hardware-based tasks.

[0126] The processor 20 may be a central processing unit (CPU), an application specific integrated circuit, a digital signal processor, a field programmable gate array or other programmable logic device, a microprocessor or any conventional processor, etc. The processor 20 may call a program stored in the memory 10 .

[0127] The communication interface 31 may be an interface of a communication module, and is used to connect to other devices or systems.

[0128] Of course, it should be noted that Figure 5The structure shown does not constitute a limitation on the template matching device in the embodiment of the present invention. In actual applications, the template matching device may include Figure 5 More or fewer components than shown, or combinations of certain components.

[0129] The computer-readable storage medium provided in the embodiment of the present invention is introduced below. The computer-readable storage medium described below and the template matching method described above can be referred to each other.

[0130] The present invention also provides a computer-readable storage medium, on which a computer program is stored. When the computer program is executed by a processor, the steps of the above-mentioned template matching method are implemented.

[0131] The computer-readable storage medium may include: a USB flash drive, a mobile hard disk, a read-only memory (ROM), a random access memory (RAM), a magnetic disk or an optical disk, and other media that can store program codes.

[0132] In this specification, each embodiment is described in a progressive manner, and each embodiment focuses on the differences from other embodiments. The same or similar parts between the embodiments can be referred to each other. For the device disclosed in the embodiment, since it corresponds to the method disclosed in the embodiment, the description is relatively simple, and the relevant parts can be referred to the method part.

[0133] Professionals may further appreciate that the units and algorithm steps of each example described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, computer software, or a combination of the two. In order to clearly illustrate the interchangeability of hardware and software, the composition and steps of each example have been generally described in the above description according to function. Whether these functions are performed in hardware or software depends on the specific application and design constraints of the technical solution. Professionals and technicians may use different methods to implement the described functions for each specific application, but such implementation should not be considered to be beyond the scope of the present invention.

[0134] Finally, it should be noted that, in this article, relationships such as first and second, etc. are used only to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Moreover, the terms "include", "comprises" or any other variations are intended to cover non-exclusive inclusion, so that a process, method, article or device that includes a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or device.

[0135] The above is a detailed introduction to a template matching method, device, equipment and computer-readable storage medium provided by the present invention. Specific examples are used in this article to illustrate the principles and implementation methods of the present invention. The description of the above embodiments is only used to help understand the method of the present invention and its core idea; at the same time, for a general technician in this field, according to the idea of ​​the present invention, there will be changes in the specific implementation method and application scope. In summary, the content of this specification should not be understood as a limitation on the present invention.

Claims

1. A template matching method, characterized in that: include: Obtaining a detection template length and a prefix detection template length, and calculating the number of prefix matches according to the prefix detection template length; Load the random sequence to be tested into the GPU; In the GPU, the steps of prefix detection template matching, suffix matching and saving are performed on each prefix detection template until the number of executions reaches the number of prefix matching times and the matching ends; The prefix detection template matching includes: matching the random sequence to be detected with the prefix detection template, and taking the successfully matched sequence as the target object; the length of the target object is consistent with the length of the detection template; The suffix matching and saving includes: retaining the target objects with the same suffix sequence in the target objects as matching results, and saving the sequence information and position information of the matching results in the GPU.

2. The template matching method according to claim 1, characterized in that: The step of matching the random sequence to be detected with the prefix detection template and taking the successfully matched sequence as a target object includes: Dividing the random sequence to be detected into a plurality of sequence blocks; CUDA parallel computing is used to match each of the sequence blocks with the prefix detection template to obtain the target object.

3. The template matching method according to claim 2, characterized in that: The using CUDA parallel computing to match each of the sequence blocks with the prefix detection template to obtain the target object includes: Using CUDA parallel computing, matching each of the sequence blocks with the prefix detection template to obtain the number of successful matches in each of the sequence blocks; The position information and sequence information of successful matches are obtained from the sequence blocks whose number of successful matches is not 0, and the target object is obtained according to the position information and sequence information.

4. The template matching method according to claim 3, characterized in that: The matching each of the sequence blocks with the prefix detection template to obtain the number of successful matches in each of the sequence blocks includes: The shared memory of the GPU is used to recursively reduce and sum the number of successful matches in each byte block in each sequence block, so as to calculate the number of successful matches in each sequence block.

5. The template matching method according to claim 1, characterized in that: The target objects with the same suffix sequence in the target objects are retained as matching results, including: Calculate the bit value of each target object according to the sequence information of the target object; Sort all the target objects from small to large or from large to small according to the bit value; The target object with the same bit value as any adjacent object is retained as the matching result.

6. The template matching method according to claim 1, characterized in that: The step of saving the sequence information and position information of the matching result to the GPU includes: The total number of the matching results is calculated using a Reduce optimization algorithm, so that the GPU allocates corresponding memory to store the sequence information and position information of the matching results.

7. A template matching device, characterized in that: include: An acquisition module, used to acquire a detection template length and a prefix detection template length, and calculate the number of prefix matching times according to the prefix detection template length; A data loading module is used to load the random sequence to be detected into the GPU; in the GPU, the steps of prefix detection template matching, suffix matching and saving are performed on each prefix detection template until the number of executions reaches the number of prefix matching times and the matching is completed; A prefix matching module, used to perform the prefix detection template matching, including: matching the random sequence to be detected with the prefix detection template, and taking the successfully matched sequence as a target object; the length of the target object is consistent with the length of the detection template; The suffix matching and saving module is used to perform the suffix matching and saving, including: retaining the target objects with the same suffix sequence in the target objects as matching results, and saving the sequence information and position information of the matching results to the GPU.

8. The template matching device according to claim 7, characterized in that: The prefix matching module includes: A segmentation unit, used for dividing the random sequence to be detected into a plurality of sequence blocks; The parallel matching unit is used to match each of the sequence blocks with the prefix detection template by using CUDA parallel computing to obtain the target object.

9. A template matching device, characterized in that: include: Memory for storing computer programs; A processor, configured to implement the template matching method according to any one of claims 1 to 6 when executing the computer program.

10. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores computer-executable instructions, and when the computer-executable instructions are loaded and executed by the processor, the template matching method according to any one of claims 1 to 6 is implemented.