FPGA-based data processing method, device, equipment and storage medium
By pre-defining multiple algorithm cores and cache structures on the FPGA, the problem of excessive resource consumption of hash algorithms in different application scenarios is solved, flexibly adjusting performance and resource reuse is achieved, and processing efficiency is improved.
Patent Information
- Application Number
- CN202210869578.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-07-22
- Publication Date
- 2024-10-29
- Estimated Expiration
- 2042-07-22
AI Technical Summary
When implementing hash algorithms on existing FPGAs, although the multi-stage pipeline method improves throughput, it consumes huge amounts of FPGA register resources, making it difficult to flexibly adjust performance in different application scenarios, and is not conducive to resource reuse.
By pre-defining multiple algorithm cores on the FPGA, adjusting the number of cores according to application scenario requirements, and using FIFO cache and multi-level cache structures to achieve parallel processing and orderly calling of data, reducing resource consumption.
On the premise of meeting the bandwidth requirements of the processing algorithm, it effectively reduces the consumption of FPGA resources, improves processing efficiency and resource reusability, and is suitable for different application scenarios.
Smart Images

Figure CN115098040B_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of data security technology, and in particular to a data processing method, device, electronic device and storage medium based on PFGA. Background Art
[0002] Field Programmable Gate Array (FPGA) is a product further developed on the basis of programmable devices such as PAL and GAL. It appears as a semi-custom circuit in the field of application-specific integrated circuits (ASIC), which not only solves the shortcomings of custom circuits, but also overcomes the shortcomings of the limited number of gate circuits of the original programmable devices. Implementing hash algorithms on FPGAs using hardware programming languages can effectively improve the bandwidth of hash algorithm operations.
[0003] However, in different application scenarios, the bandwidth requirements for hash algorithm operation are different, and even the bandwidth requirements range widely. Currently, hash algorithm can be implemented through multi-stage pipeline. Although this method can improve the throughput of hash algorithm, it consumes a lot of FPGA register resources. Summary of the invention
[0004] The purpose of the embodiments of the present application is to provide a data processing method, apparatus, device and storage medium based on FPGA, so as to balance the algorithm performance and the consumption of FPGA resources.
[0005] In a first aspect, an embodiment of the present application provides a data processing method based on FPGA, wherein the FPGA includes multiple algorithm cores, wherein the number of algorithm cores is pre-set, each algorithm core includes a processing algorithm, and multiple algorithm cores can process data in parallel; the method includes: receiving data to be processed; determining a target algorithm core that is in an idle state; processing the data to be processed using the processing algorithm in the target algorithm core; obtaining a processing result output by the target algorithm core, and storing the processing result.
[0006] The embodiment of the present application predefines multiple algorithm cores according to the requirements of different application scenarios, and processes the data to be processed in parallel through the multiple algorithm cores, thereby reducing the consumption of FPGA resources as much as possible while meeting the bandwidth requirements of the processing algorithm.
[0007] In any embodiment, the FPGA further includes a first-in first-out queue FIFO buffer, the FIFO buffer including an algorithm core identifier in an idle state;
[0008] Identify algorithm cores that are in idle state, including:
[0009] The algorithm core corresponding to the algorithm core identifier in the idle state written earliest in the FIFO buffer is used as the target algorithm core.
[0010] The embodiment of the present application utilizes a FIFO buffer to store algorithm cores in an idle state, and when data that needs to be processed arrives, the algorithm core that first enters the FIFO buffer is selected to process the data, thereby enabling orderly calling of the algorithm cores.
[0011] In any embodiment, a plurality of algorithm cores are pre-divided into a plurality of algorithm groups, each algorithm group corresponds to a first-level cache; storing the processing result includes: storing the processing result in the first-level cache of the corresponding algorithm group.
[0012] The embodiment of the present application improves the efficiency of data writing by predividing multiple algorithm cores into multiple algorithm groups, each algorithm group corresponding to a first-level cache.
[0013] In any embodiment, the processing results are stored in the first-level cache of the corresponding algorithm group, including: obtaining the write status of an algorithm core that belongs to the same algorithm group as the target algorithm core and has a higher priority than the target algorithm core; if the write status is idle, the processing results are stored in the first-level cache of the corresponding algorithm group.
[0014] In the embodiment of the present application, since a cache has only one external write interface, only one algorithm core is allowed to call the write interface at the same time. When the processing results are written into the first-level cache, they are written according to the priority order of each algorithm core so that the processing results can be written in order.
[0015] In any embodiment, the FPGA further includes a secondary cache; the method further includes: acquiring a non-empty primary cache, and storing the processing result in the non-empty primary cache into the secondary cache.
[0016] The embodiment of the present application writes the processing result twice, which greatly reduces the judgment of the types of result situations and reduces the fan-out of the FPGA.
[0017] In any embodiment, after determining that the target algorithm core is in an idle state, the method also includes: storing the data to be processed in a random access memory RAM block corresponding to the target algorithm core, and generating a start signal; using the processing algorithm in the target algorithm core to process the data to be processed, including: calling the processing algorithm in the corresponding target algorithm core according to the start signal to process the data to be processed.
[0018] In the embodiment of the present application, a RAM block is allocated in advance for each algorithm core to store the data to be processed, so that the target algorithm core can quickly obtain the data to be processed, thereby improving the processing efficiency of the data to be processed.
[0019] In any embodiment, the processing algorithm is a hash algorithm. The embodiment of the present application can be applied to a variety of hash algorithms, and the corresponding hash algorithm can be selected according to project needs, that is, it is only necessary to instantiate the algorithm core using the corresponding hash algorithm before processing the data, thereby realizing the reuse of the FPGA framework.
[0020] In the second aspect, an embodiment of the present application provides a data processing device based on FPGA, which includes multiple algorithm cores, wherein the number of algorithm cores is pre-set, each algorithm core includes a processing algorithm, and multiple algorithm cores can process data in parallel; the device includes: a data receiving module for receiving data to be processed; an algorithm core determination module for determining a target algorithm core that is in an idle state; a data processing module for processing the data to be processed using the processing algorithm in the target algorithm core; and a result storage module for obtaining the processing result output by the target algorithm core and storing the processing result.
[0021] In a third aspect, an embodiment of the present application provides an electronic device, comprising: a processor, a memory and a bus, wherein the processor and the memory communicate with each other through the bus; the memory stores program instructions that can be executed by the processor, and the processor calls the program instructions to execute the method of the first aspect.
[0022] In a fourth aspect, an embodiment of the present application provides a non-transitory computer-readable storage medium, including: the non-transitory computer-readable storage medium stores computer instructions, and the computer instructions enable a computer to execute the method of the first aspect.
[0023] Other features and advantages of the present application will be described in the following description, and partly become apparent from the description, or be understood by practicing the embodiments of the present application. The purpose and other advantages of the present application can be realized and obtained by the structures specifically pointed out in the written description, claims, and drawings. BRIEF DESCRIPTION OF THE DRAWINGS
[0024] In order to more clearly illustrate the technical solutions of the embodiments of the present application, the drawings required for use in the embodiments of the present application will be briefly introduced below. It should be understood that the following drawings only show certain embodiments of the present application and therefore should not be regarded as limiting the scope. For ordinary technicians in this field, other related drawings can be obtained based on these drawings without paying creative work.
[0025] Figure 1 A flowchart of the SM3 algorithm provided for comparison;
[0026] Figure 2A schematic diagram of a data processing method based on FPGA provided in an embodiment of the present application;
[0027] Figure 3 An algorithm core connection relationship diagram provided in an embodiment of the present application;
[0028] Figure 4 A flow chart of a data processing method provided in an embodiment of the present application;
[0029] Figure 5 Another algorithm core connection relationship diagram provided in an embodiment of the present application;
[0030] Figure 6 A schematic diagram of the structure of a data processing device based on FPGA provided in an embodiment of the present application;
[0031] Figure 7 A schematic diagram of the physical structure of an electronic device provided in an embodiment of the present application. DETAILED DESCRIPTION
[0032] The following embodiments of the technical solution of the present application are described in detail in conjunction with the accompanying drawings. The following embodiments are only used to more clearly illustrate the technical solution of the present application, and are therefore only used as examples, and cannot be used to limit the scope of protection of the present application.
[0033] Unless otherwise defined, all technical and scientific terms used herein have the same meaning as commonly understood by technicians in the technical field to which this application belongs; the terms used herein are only for the purpose of describing specific embodiments and are not intended to limit this application; the terms "including" and "having" in the specification and claims of this application and the above-mentioned figure descriptions and any variations thereof are intended to cover non-exclusive inclusions.
[0034] In the description of the embodiments of the present application, the technical terms "first", "second", etc. are only used to distinguish different objects, and cannot be understood as indicating or implying relative importance or implicitly indicating the number, specific order or primary and secondary relationship of the indicated technical features. In the description of the embodiments of the present application, the meaning of "multiple" is more than two, unless otherwise clearly and specifically defined.
[0035] Reference to "embodiments" herein means that a particular feature, structure, or characteristic described in conjunction with the embodiments may be included in at least one embodiment of the present application. The appearance of the phrase in various locations in the specification does not necessarily refer to the same embodiment, nor is it an independent or alternative embodiment that is mutually exclusive with other embodiments. It is explicitly and implicitly understood by those skilled in the art that the embodiments described herein may be combined with other embodiments.
[0036] In the description of the embodiments of the present application, the term "and / or" is only a description of the association relationship of the associated objects, indicating that there may be three relationships. For example, A and / or B can represent: A exists alone, A and B exist at the same time, and B exists alone. In addition, the character " / " in this article generally indicates that the associated objects before and after are in an "or" relationship.
[0037] In the description of the embodiments of the present application, the term "multiple" refers to more than two (including two). Similarly, "multiple groups" refers to more than two groups (including two groups), and "multiple pieces" refers to more than two pieces (including two pieces).
[0038] In the description of the embodiments of the present application, the technical terms "center", "longitudinal", "lateral", "length", "width", "thickness", "up", "down", "front", "back", "left", "right", "vertical", "horizontal", "top", "bottom", "inside", "outside", "clockwise", "counterclockwise", "axial", "radial", "circumferential", etc. indicate orientations or positional relationships based on the orientations or positional relationships shown in the accompanying drawings, which are only for the convenience of describing the embodiments of the present application and simplifying the description, and do not indicate or imply that the referred device or element must have a specific orientation, be constructed and operated in a specific orientation, and therefore should not be understood as a limitation on the embodiments of the present application.
[0039] In the description of the embodiments of the present application, unless otherwise clearly specified and limited, technical terms such as "installed", "connected", "connected", "fixed" and the like should be understood in a broad sense. For example, it can be a fixed connection, a detachable connection, or an integral connection; it can be a mechanical connection or an electrical connection; it can be a direct connection or an indirect connection through an intermediate medium, and it can be the internal connection of two elements or the interaction relationship between two elements. For those of ordinary skill in the art, the specific meanings of the above terms in the embodiments of the present application can be understood according to the specific circumstances.
[0040] A hash algorithm is a function that maps a transmission message of any length into fixed-length data by padding, grouping, expanding, and compressing the transmission message. It is suitable for digital signatures, integrity detection of transmission messages, and origin authentication detection of messages, and has been widely used in the fields of finance and network transmission. Currently, most hash algorithms are simulated by C language software based on the OpenSSL library, and their performance is difficult to meet the needs of a large number of high-speed application scenarios.
[0041] FPGA emerged as a semi-custom circuit in the field of application-specific integrated circuits (ASICs), which not only solves the shortcomings of custom circuits, but also overcomes the shortcomings of the limited number of gate circuits of the original programmable devices. Implementing hash algorithms on FPGAs using hardware programming languages can effectively improve the bandwidth of hash algorithm operations.
[0042] Figure 1 A flowchart of the SM3 algorithm provided for comparison is shown below: Figure 1 As shown, the input cache module caches 64 512-bit registers to store the string to be hashed. The values of these 64 registers are respectively given to the 64 message extension submodules in the content assignment cache module as their input. Each submodule contains 16 32-bit registers and arithmetic circuits for the expansion of the message word. The W and W' arrays generated by the input data after 64 rounds of calculation are used as the input of the data generation module. The input of the data generation module also includes eight 32-bit registers A, B, C, D, E, F, G, and H. The values of these eight registers are an initial value constant when the message participates in the first calculation. After that, they are provided by the values after participating in a round of hash calculation. Together with the message word, 64 levels of pipeline data iteration are performed to generate a 256-bit hash value and store it in the data cache. The 64-level pipeline here is 64 single-round data generation modules. Each single-round data generation module corresponds to the single-round iterative compression function in SM3. The output of each module data is used as the input of the next module until the final hash value is calculated after 64 levels. After the generated hash value is stored in the data cache, a judgment needs to be made. If the participating message has no remaining content, it is stored in the output cache as the result of the message. Otherwise, the 8 registers of the data generation module are assigned as a new round of calculation until the hash value of the last set of data is calculated.
[0043] Although this multi-stage pipeline approach can greatly improve the throughput of the SM3 hash algorithm, the above algorithm design places great demands on the FPGA's register resource consumption. It may be sufficient for FPGAs with rich register resources, but once applied to FPGAs with fewer resources, there may be insufficient resources. In addition, some application scenarios do not require such high SM3 algorithm performance. This design will also waste FPGA resources, and it is not convenient to transplant, which is not conducive to reuse in different application scenarios.
[0044] In order to solve the above technical problems, the embodiments of the present application provide a data processing method, device, equipment and storage medium based on FPGA, by pre-defining multiple algorithm cores, wherein the number of algorithm cores can be set according to actual conditions, after receiving the data to be processed, an idle target algorithm core is selected to process the data to be processed, thereby obtaining a processing result. The embodiments of the present application can define the number of algorithm cores according to the needs of the actual application scenario, and then adjust the performance required by the processing algorithm.
[0045] It can be understood that the data processing method provided in the embodiments of the present application can be applied to electronic devices in the fields of cloud computing, big data, and artificial intelligence.
[0046] Figure 2 A schematic diagram of a data processing method based on FPGA provided in an embodiment of the present application is shown in FIG. Figure 2 As shown, there are multiple algorithm cores pre-instantiated in the FPGA. It can be understood that the algorithm core includes a processing algorithm, and multiple algorithm cores can work in parallel at the same time. Therefore, the algorithm core can also be understood as an algorithm model. The number of algorithm cores is pre-defined according to different business scenario requirements. For example, if a business scenario requires 10G algorithm performance, and the computing performance of an algorithm core is 2G, then the number of algorithm cores can be pre-defined as 5. Specifically, the number of algorithm cores can be defined by macro definition. The number of algorithm cores can be changed by modifying the parameters of the macro definition according to the actual business scenario at a later stage. The method includes:
[0047] Step 201: receiving data to be processed;
[0048] Step 202: Determine a target algorithm core that is in an idle state;
[0049] Step 203: Process the data to be processed using the processing algorithm in the target algorithm core;
[0050] Step 204: Obtain the processing result output by the target algorithm core and store the processing result.
[0051] Among them, in step 201, the data to be processed can be data that the electronic device needs to send outward, or it can be data received from an external terminal. Therefore, the data to be processed are all types of data that need to be processed using the processing algorithm in the FPGA. The embodiment of the present application does not specifically limit the specific content of the data to be processed.
[0052] In step 202, the idle state refers to a state in which the algorithm core is not currently called, that is, a state in which no data is processed. At the same time, there may be one algorithm core in the idle state, there may be multiple algorithm cores, or there may be no algorithm core in the idle state. If there is no algorithm core in the idle state, the data to be processed needs to wait until an algorithm core changes from the working state to the idle state before processing begins. If there is only one algorithm core in the idle state, the algorithm core is determined as the target algorithm core. If there are multiple algorithm cores in the idle state, one algorithm core can be selected as the target algorithm core at will, or one algorithm core can be selected as the target algorithm core according to certain rules.
[0053] In step 203, the processing algorithm in the target algorithm core is pre-written according to the needs of the business scenario, which can be a hash algorithm. For example: when the business scenario requires SM3 hash calculation on the data to be processed, the processing algorithm is the SM3 hash algorithm, and if the business scenario requires MD5 calculation on the data to be processed, the processing algorithm is the MD5 algorithm. It is understandable that the processing algorithm can also be other hash algorithms, and the embodiments of the present application do not specifically limit the specific type of hash algorithm and the specific process of processing the data to be processed using the hash algorithm.
[0054] In step 204, after the target algorithm core processes the data to be processed, the electronic device can obtain the processing result output by the target algorithm core and store the processing result.
[0055] The embodiment of the present application predefines multiple algorithm cores according to the requirements of different application scenarios, and processes the data to be processed in parallel through the multiple algorithm cores, thereby reducing the consumption of FPGA resources as much as possible while meeting the bandwidth requirements of the processing algorithm.
[0056] Based on the above embodiment, the FPGA includes a FIFO buffer, which stores the algorithm core identifiers in an idle state. It can be understood that each algorithm core has an algorithm core identifier that can represent its uniqueness, and the algorithm core identifier can be pre-generated for each algorithm core.
[0057] The idea of FIFO buffer is first-in, first-out, which is a simple and fair idea. That is, if a data is the first to enter, it can be considered that it is unlikely to be accessed in the future. When the space is full, the first data to enter will be replaced (eliminated) first.
[0058] Description of the FIFO algorithm: Design a cache structure that is sized at construction time, assuming the size is K, and has two functions:
[0059] 1. set(key,value): insert the record (key,value) into the structure. When the cache is full, the first data to enter the cache is replaced.
[0060] 2. get(key): returns the value corresponding to key.
[0061] Implementation: Maintain a FIFO queue, link each data (allocated page) in chronological order to form a queue, and point the replacement pointer to the head of the queue. When performing replacement again, just replace the data (page) pointed by the replacement pointer in sequence and insert the newly added data to the end of the queue.
[0062] Based on the idea of FIFO buffer and FIFO algorithm, it can be known that when the FIFO buffer is initialized, Y data numbers 1, 2, 3...Y (Y means there are Y algorithm cores in total) are written respectively, where each data number represents which algorithm core is in an idle state. In this way, when the FIFO buffer is not empty, every time a data to be processed comes, you only need to read the FIFO buffer to know which algorithm core is idle, and the data to be processed will know which algorithm core to enter. After determining the target algorithm core, the algorithm core identifier corresponding to the target algorithm core is removed from the FIFO cache. In addition, when the algorithm core has processed the data, the number corresponding to the current algorithm core is released and written into the FIFO cache.
[0063] The embodiment of the present application utilizes a FIFO buffer to store algorithm cores in an idle state, and when data that needs to be processed arrives, the algorithm core that first enters the FIFO buffer is selected to process the data, thereby enabling orderly calling of the algorithm cores.
[0064] Based on the above embodiment, multiple algorithm cores are pre-divided into multiple algorithm groups, each algorithm group corresponds to a first-level cache; the processing results are stored, including:
[0065] The processing results are stored in the first-level buffer of the corresponding algorithm group.
[0066] In the specific implementation process, since a first-level cache has an external write interface, only one algorithm core is allowed to write the processing result to the first-level cache at the same time, in order to improve the efficiency of writing the processing result. The embodiment of the present application divides multiple algorithm cores into multiple algorithm groups in advance, each algorithm group includes at least one algorithm core, and each algorithm group corresponds to a first-level cache. After obtaining the processing result, the target algorithm core connects the processing result to the first-level cache corresponding to the algorithm group to which it belongs. For example: if multiple algorithm cores are divided into 5 algorithm groups, 5 algorithm cores can write the processing result to the cache at the same time, thereby improving the efficiency of writing the processing result.
[0067] In addition, when dividing the algorithm groups, the number of algorithm groups can be set in advance, and then the algorithm cores can be evenly divided. The number of algorithm groups and the number of algorithm cores in each algorithm group can also be made as equal as possible.
[0068] The embodiment of the present application improves the efficiency of data writing by predividing multiple algorithm cores into multiple algorithm groups, each algorithm group corresponding to a first-level cache.
[0069] On the basis of the above embodiment, the processing result is stored in the first-level buffer of the corresponding algorithm group, including:
[0070] Obtain the write status of an algorithm core that belongs to the same algorithm group as the target algorithm core and has a higher priority than the target algorithm core;
[0071] If the write status is all idle, the processing result is stored in the first-level buffer of the corresponding algorithm group.
[0072] In the specific implementation process, Y=M*N algorithm cores are defined, and the Y algorithm cores are divided into N algorithm groups, each algorithm group includes M algorithm cores. The output interface of each algorithm core is set to correspond to a single-bit algorithm result status signal (busy_state) and the input interface (M-1) single-bit algorithm result control signals (i.e. busy1, busy2,..., busy(m-1)). Among them, the algorithm result status signal is pulled high when the algorithm writes the result to the cache, indicating that the write enable of the first-level cache is occupied by the current algorithm core at this time, and it is pulled low at other times. The first algorithm core in each group of algorithm cores has the highest priority for writing results. When it writes the algorithm result to the result cache, other algorithm cores must wait for it to finish writing first. The second algorithm core has the second highest priority for writing results. It only has the permission to write to the result cache data when the first algorithm core is idle to write the result, and so on, until the Mth algorithm core has the permission to write to the result cache data when all the previous algorithm cores are idle to write the results. Its connection relationship is as follows Figure 3 It can be understood that the priority of the algorithm core is preset.
[0073] In the embodiment of the present application, since a cache has only one external write interface, only one algorithm core is allowed to call the write interface at the same time. When the processing results are written into the first-level cache, they are written according to the priority order of each algorithm core so that the processing results can be written in order.
[0074] Based on the above embodiment, the FPGA further includes a secondary cache; the method further includes:
[0075] A non-empty first-level cache is obtained, and the processing result in the non-empty first-level cache is stored in the second-level cache.
[0076] In the specific implementation process, since the length of the message sent to the algorithm core is random, the timing of each algorithm calculating the final result and writing it to the result cache is also random. If all processing results are written directly to a result cache, N algorithm cores need to discuss 2 when writing to the result cache. N In this case, when N is relatively large, the FPGA fan-out will be particularly large. In order to solve this technical problem, the embodiment of the present application sets up a two-level cache. Figure 4 A flow chart of a data processing method provided in an embodiment of the present application is as follows: Figure 4As shown, multiple algorithm cores are divided into N groups, each algorithm group includes M algorithm cores. Each algorithm group writes the identifier of the algorithm core in the group that is in an idle state into the FIFO cache. The algorithm core in each algorithm group writes its processing results into the corresponding first-level cache. The electronic device will query whether each first-level cache is empty according to a certain period, and obtain a non-empty first-level cache, and store the processing results in the non-empty first-level cache in the second-level cache.
[0077] In addition, the electronic device can first detect whether cache 1 is empty. If not, the data in cache 1 will be moved to the total cache until it is empty. When cache 1 is empty, it starts to detect whether cache 2 is empty. If not, the data in cache 2 will be moved to the total cache until it is empty. This operation continues until cache N.
[0078] The embodiment of the present application writes the processing result twice, which greatly reduces the judgment of the types of result situations and reduces the fan-out of the FPGA.
[0079] Based on the above embodiment, after determining the target algorithm core in an idle state, the method further includes:
[0080] The data to be processed is stored in the random access memory RAM block corresponding to the target algorithm core, and a start signal is generated;
[0081] The processing algorithm in the target algorithm core is used to process the data to be processed, including:
[0082] According to the start signal, the processing algorithm in the corresponding target algorithm core is called to process the data to be processed.
[0083] In the specific implementation process, the RAM can be pre-divided according to the number of algorithm cores, so that each algorithm core corresponds to a RAM block. After receiving the data to be processed and determining the target algorithm core that processes the data to be processed, the electronic device places the target algorithm core in the RAM block corresponding to the target algorithm core and generates start information. The FPGA starts the corresponding algorithm core to read the data in the RAM block by detecting the start signal and the algorithm core identifier corresponding to the start signal.
[0084] In the embodiment of the present application, a RAM block is allocated in advance for each algorithm core to store the data to be processed, so that the target algorithm core can quickly obtain the data to be processed, thereby improving the processing efficiency of the data to be processed.
[0085] For ease of understanding, the present application embodiment takes the hash algorithm as the SM3 algorithm as an example to describe the FPGA-based data processing method. It should be understood that in addition to being applicable to the SM3 algorithm, the present application embodiment can also be applicable to other hash algorithms such as the MD5 algorithm, as follows:
[0086] The execution process of the SM3 algorithm can be summarized into three steps: message padding, message expansion, and iterative compression. The padding is to fill the message to an integer multiple of 512 bits. The padding rule is to first fill 1 bit "1" at the end of the message, followed by k "0", where k is the smallest positive integer that satisfies (n+1+k)mod512=448. Finally, add a 64-bit message length. The message expansion is based on the content of the message, dividing each 512 bits into 16 message words (each message word is 32 bits long), and using them as the first 16 of the generated 132 message words, and then using these 16 message words to recursively generate the remaining 116 message words, of which the first 68 message words constitute the sequence W, and the last 64 message words constitute the sequence W'. Finally, it is iterative compression, and the expanded message words and the initial vector value are compressed and iterated for 64 rounds through the compression function, and then the generated value is XORed with the currently used vector value, which is the output of the compression function, and this output is used as the initial value when the compression function is called next time. And so on, until the last group of 132 message words are used up.
[0087] According to the method described in the detailed description of the present invention, the specific process is as follows:
[0088] Step 1: Data input cache. The data input cache is used to store the data that will enter the algorithm core. The data is the data after the original data is filled, that is, the data to be processed. The setting of the input cache size is determined by the number of algorithm cores. Assuming that the actual algorithm performance requires 32 algorithm cores, and the length of the processed message data does not exceed 2048 bytes, a RAM cache with a depth of 1024 (2048*32 / 64=1024) and a bit width of 512 bits can be set as the data input cache. The RAM is divided into 32 blocks, corresponding to the 32 algorithm cores. Each RAM block stores a packet of data. The high 5 bits of the address bit width are used to distinguish which algorithm core the current data packet will enter, and the low 5 bits indicate how many 512-bit data there are in the current data packet. For example, if the length of a packet is 258 bytes, then it needs to occupy 258 / 64=5 addresses in RAM to store the packet data. If the idle algorithm core numbered 30 is used, it is represented by 11110 with a 5-bit address width. Therefore, the location of the 258-byte data in RAM is as follows: the first 64-byte data: 1111000000; the second 64-byte data: 1111000001; the third 64-byte data: 1111000010; the fourth 64-byte data: 1111000011; the fifth 64-byte data: 1111000100. Among them, only the upper 2 bytes of the fifth 64-byte data are valid.
[0089] Since the FIFO cache stores the algorithm core identifiers of the algorithm cores that are currently in an idle state, each time a message is stored in the data input cache, it is only necessary to read the algorithm core identifier to know which RAM position to enter.
[0090] Step 2: Implementation of algorithm calculation. The data to be processed enters the target algorithm core, and mainly completes two steps: expansion and iterative compression of the data to be processed. Since each small round of hash calculation only needs one word in the padding word W and W' array, each group of padding words generated by message expansion can be sent to the iterative compression function for calculation. This cycle is repeated 64 times. When 64 message words W' are generated, the last compression iteration is also completed.
[0091] The specific operation of message expansion is: the 512-bit data received from the input buffer of the data to be processed is placed in W0, W1...W 15 These 16 32-bit registers are then input into the arithmetic circuit, where W is generated according to the arithmetic circuit formula To implement, W' is generated according to the operational circuit formula To implement, When each W0' is generated, the above W0, W1...W 15 All the 16 registers are assigned values in a staggered manner, that is, the value of W1 is assigned to W0, the value of W2 is assigned to W1, and so on. 16 The value of W 15 , and output the values of W0 and W0' to the iterative compression module for calculation. This cycle is repeated 64 times to complete the expansion of the message word. The advantage of this is that the expansion of all message words is completed by only relying on the above 16 32-bit registers and two operation circuits for repeated use, which greatly saves FPGA register resources.
[0092] The specific operation of iterative compression is as follows: 8 32-bit registers A, B, C, D, E, F, G, H are used as the input data of the compression function, and their initial values are determined by the 256-bit vector IV, and are processed with the message extension word through the following operation circuit:
[0093] SS1←((A<<12)+E+(T j <<j))<<7;
[0094]
[0095] TT1←FF j (A,B,C)+D+SS2+W j ';
[0096] TT2←GG j(E,F,G)+H+SS1+W j ;
[0097] Implement the re-assignment of ABCDEFGH, and obtain the new values of A`, B`, C`, D`, E`, F`, G`, H` as the input of the next round of calculation, together with the new message expansion word W j and W j ', repeat the above process until the 64th group of message extension words enters the calculation and completes. 64 rounds of calculation are performed exactly. The value generated in the last round is the same as the V used in this hash calculation. (i) After XOR, cache it into a register, and then determine whether there are any remaining data blocks belonging to the same message that need to be hashed. If there are remaining contents, then the cached contents need to be used as V for the next hash calculation. (i+1) , assign values to the above 8 32-bit registers A, B, C, D, E, F, G, H, and enter the compression function again for calculation. If there is no remaining content, the value is output as the 256-bit hash value result of the entire message data packet.
[0098] Step 3: Output of hash results. The 32 algorithm cores can be divided into 8 groups of 4 algorithm cores to write the algorithm results into 8 caches. In this way, each algorithm core input interface is given 4 single-bit result control signals, and the output interface uses an algorithm result status signal. The result control signal at the input port indicates whether other algorithm cores are about to write data to the result cache (i.e., the first-level cache) at this time. As long as there is a high level, it means that the result cache write interface is occupied and the current algorithm core cannot write data into it. Only when all four result control signals are low, it means that the result cache write interface is idle and data can be written into it. When the algorithm core writes data to the result cache, the algorithm result status signal of its output interface is in a high state, otherwise it is pulled low. The connection relationship between the four algorithm cores is as follows Figure 5 As shown in the figure, algorithm core 1 has the highest priority for writing result cache, so all the ports of its 4 result control signals are assigned 0, algorithm core 2 has the second highest priority for writing results, and algorithm core 4 has the lowest priority, and it must judge that the result status signals of the previous algorithm cores are all low before it has the right to use. Whenever the algorithm core writes the result to the cache, the currently used algorithm channel number must also be written into the algorithm idle channel number cache for storage to indicate that the current algorithm core has entered the idle state.
[0099] Step 4: Secondary processing of hash result cache. The data of the first 8 result caches are mainly written into a secondary cache. This processing is relatively simple. Check whether the first result cache is not empty. If it is not empty, move all its data into the main cache. When it is empty, start to check the second result cache, and so on, until the data of the 8th result cache is finally processed.
[0100] The algorithm core in the embodiment of the present application can be instantiated according to the actual application scenario, so it has reusability and can be applied to applications in different scenarios, saving development costs. In addition, by storing the processing results twice, the problem of excessive fan-out generated during the storage of processing results of multiple algorithm cores is solved.
[0101] Figure 6 The following is a schematic diagram of a data processing device based on FPGA provided in an embodiment of the present application. The device may be a module, program segment or code on an electronic device. Figure 2 The method embodiment corresponds to and can be executed Figure 2 The various steps involved in the method embodiment and the specific functions of the device can be found in the description above. To avoid repetition, detailed description is appropriately omitted here. The FPGA includes multiple algorithm cores, wherein the number of algorithm cores is preset, the algorithm core includes a processing algorithm, and the multiple algorithm cores can process data in parallel; the device includes: a data receiving module 601, an algorithm core determination module 602, a data processing module 603 and a result storage module 604, wherein:
[0102] The data receiving module 601 is used to receive data to be processed; the algorithm core determination module 602 is used to determine a target algorithm core that is in an idle state; wherein the target algorithm core includes a processing algorithm; the data processing module 603 is used to process the data to be processed using the processing algorithm in the target algorithm core; the result storage module 604 is used to obtain the processing result output by the target algorithm core and store the processing result.
[0103] Based on the above embodiment, the FPGA also includes a first-in-first-out queue FIFO buffer, and the FIFO buffer includes an algorithm core identifier in an idle state; the algorithm core determination module 602 is specifically used to: use the algorithm core corresponding to the algorithm core identifier in the idle state that is written earliest in the FIFO buffer as the target algorithm core.
[0104] On the basis of the above embodiment, the multiple algorithm cores are pre-divided into multiple algorithm groups, each algorithm group corresponds to a first-level buffer; the result storage module 604 is specifically used for:
[0105] The processing result is stored in the first-level buffer of the corresponding algorithm group.
[0106] Based on the above embodiment, the result storage module 604 is specifically used for:
[0107] Acquire the write status of an algorithm core that belongs to the same algorithm group as the target algorithm core and has a higher priority than the target algorithm core;
[0108] If the write states are all idle, the processing results are stored in the first-level buffer of the corresponding algorithm group.
[0109] On the basis of the above embodiment, the FPGA further includes a secondary cache; the device further includes a secondary storage module for:
[0110] A non-empty first-level cache is obtained, and the processing result in the non-empty first-level cache is stored in the second-level cache.
[0111] Based on the above embodiment, the device further includes:
[0112] The data to be processed is stored in a random access memory RAM block corresponding to the target algorithm core, and a start signal is generated;
[0113] The data processing module 603 is specifically used for:
[0114] The processing algorithm in the corresponding target algorithm core is called according to the start signal to process the data to be processed.
[0115] Figure 7 A schematic diagram of the physical structure of an electronic device provided in an embodiment of the present application, such as Figure 7 As shown, the electronic device includes: a processor (processor) 701, a memory (memory) 702 and a bus 703; wherein,
[0116] The processor 701 and the memory 702 communicate with each other via the bus 703;
[0117] The processor 701 is used to call the program instructions in the memory 702 to execute the methods provided by the above-mentioned method embodiments, for example, including: receiving data to be processed; determining a target algorithm core that is in an idle state; processing the data to be processed using the processing algorithm in the target algorithm core; obtaining the processing result output by the target algorithm core, and storing the processing result.
[0118] The processor 701 may be an integrated circuit chip with signal processing capabilities. The processor 701 may be a general-purpose processor, including a central processing unit (CPU), a network processor (NP), etc.; it may also be a digital signal processor (DSP), an application-specific integrated circuit (ASIC), a field programmable gate array (FPGA) or other programmable logic devices, discrete gates or transistor logic devices, discrete hardware components. It may implement or execute various methods, steps and logic block diagrams disclosed in the embodiments of the present application. A general-purpose processor may be a microprocessor or the processor may also be any conventional processor, etc.
[0119] The memory 702 may include but is not limited to random access memory (RAM), read only memory (ROM), programmable read-only memory (PROM), erasable programmable read-only memory (EPROM), electrically erasable read-only memory (EEPROM), etc.
[0120] The present embodiment discloses a computer program product, which includes a computer program stored on a non-transitory computer-readable storage medium, and the computer program includes program instructions. When the program instructions are executed by a computer, the computer can execute the methods provided by the above-mentioned method embodiments, for example, including: receiving data to be processed; determining a target algorithm core in an idle state; processing the data to be processed using a processing algorithm in the target algorithm core; obtaining a processing result output by the target algorithm core, and storing the processing result.
[0121] The present embodiment provides a non-transitory computer-readable storage medium, which stores computer instructions, and the computer instructions enable the computer to execute the methods provided by the above-mentioned method embodiments, for example, including: receiving data to be processed; determining a target algorithm core that is in an idle state; processing the data to be processed using a processing algorithm in the target algorithm core; obtaining a processing result output by the target algorithm core, and storing the processing result.
[0122] In the embodiments provided in the present application, it should be understood that the disclosed devices and methods can be implemented in other ways. The device embodiments described above are merely schematic. For example, the division of the units is only a logical function division. There may be other division methods in actual implementation. For example, multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be through some communication interfaces, and the indirect coupling or communication connection of the devices or units can be electrical, mechanical or other forms.
[0123] In addition, the units described as separate components may or may not be physically separated, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed on multiple network units. Some or all of the units may be selected according to actual needs to achieve the purpose of the solution of this embodiment.
[0124] Furthermore, the functional modules in the various embodiments of the present application may be integrated together to form an independent part, or each module may exist separately, or two or more modules may be integrated to form an independent part.
[0125] In this document, relational terms such as first and second, etc. are used merely to distinguish one entity or operation from another entity or operation, but do not necessarily require or imply any such actual relationship or order between these entities or operations.
[0126] The above description is only an embodiment of the present application and is not intended to limit the protection scope of the present application. For those skilled in the art, the present application may have various modifications and variations. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present application shall be included in the protection scope of the present application.
Claims
1. A data processing method based on field programmable gate array FPGA, characterized in that: The FPGA includes a plurality of algorithm cores, wherein the number of the algorithm cores is preset, the algorithm cores include processing algorithms, and the plurality of algorithm cores can process data in parallel; the method includes: receiving data to be processed; Determine the target algorithm core that is in an idle state; Processing the data to be processed using the processing algorithm in the target algorithm core; Obtaining a processing result output by the target algorithm core and storing the processing result; The multiple algorithm cores are pre-divided into multiple algorithm groups, each algorithm group corresponds to a first-level cache; the storing of the processing results includes: Storing the processing result in a first-level buffer of the corresponding algorithm group; The step of storing the processing result in a first-level buffer of a corresponding algorithm group includes: Acquire the write status of an algorithm core that belongs to the same algorithm group as the target algorithm core and has a higher priority than the target algorithm core; If the write states are all idle, storing the processing results in the first-level buffer of the corresponding algorithm group; The FPGA also includes a secondary cache; the method also includes: A non-empty first-level cache is obtained, and the processing result in the non-empty first-level cache is stored in the second-level cache.
2. The method according to claim 1, characterized in that The FPGA also includes a first-in first-out queue FIFO buffer, and the FIFO buffer includes an algorithm core identifier in an idle state; The step of determining the algorithm core in an idle state comprises: The algorithm core corresponding to the algorithm core identifier in the idle state written earliest in the FIFO buffer is used as the target algorithm core.
3. The method according to claim 1, characterized in that After determining the target algorithm core in an idle state, the method further includes: The data to be processed is stored in a random access memory RAM block corresponding to the target algorithm core, and a start signal is generated; The processing of the data to be processed by using the processing algorithm in the target algorithm core includes: The processing algorithm in the corresponding target algorithm core is called according to the start signal to process the data to be processed.
4. The method according to any one of claims 1 to 3, characterized in that: The processing algorithm is a hash algorithm.
5. A data processing device based on FPGA, characterized in that: The FPGA includes a plurality of algorithm cores, wherein the number of algorithm cores is preset, the algorithm cores include processing algorithms, and the plurality of algorithm cores can process data in parallel; the device includes: A data receiving module, used for receiving data to be processed; An algorithm core determination module, used to determine a target algorithm core in an idle state; wherein the target algorithm core includes a processing algorithm; A data processing module, used for processing the data to be processed using the processing algorithm in the target algorithm core; A result storage module, used to obtain the processing result output by the target algorithm core and store the processing result; The multiple algorithm cores are pre-divided into multiple algorithm groups, each algorithm group corresponds to a first-level buffer; the result storage module is specifically used for: Storing the processing result in a first-level buffer of the corresponding algorithm group; The step of storing the processing result in a first-level buffer of a corresponding algorithm group includes: Acquire the write status of an algorithm core that belongs to the same algorithm group as the target algorithm core and has a higher priority than the target algorithm core; If the write states are all idle, storing the processing results in the first-level buffer of the corresponding algorithm group; The FPGA also includes a secondary cache; the result storage module is specifically used for: A non-empty first-level cache is obtained, and the processing result in the non-empty first-level cache is stored in the second-level cache.
6. An electronic device, characterized in that: include: processor, memory and bus, wherein, The processor and the memory communicate with each other via the bus; The memory stores program instructions executable by the processor, and the processor can execute the method according to any one of claims 1 to 4 by calling the program instructions.
7. A non-transitory computer-readable storage medium, characterized in that: The non-transitory computer-readable storage medium stores computer instructions, which, when executed by a computer, enable the computer to perform the method according to any one of claims 1 to 4.
Citation Information
Patent Citations
Password service board card and a password service device
CN109800558A
Hardware device for multi-Master encryption and decryption based on multiple symmetric algorithms
CN114696996A
