Method, apparatus, and device for performing FFT
Patent Information
- Application Number
- CN202111617811.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Priority Date
- 2021-09-27
- Filing Date
- 2021-12-27
- Publication Date
- 2026-10-27
- Estimated Expiration
- 2041-12-27
AI Technical Summary
但通过标量运算和/或矢量运算实现FFT的效率仍然不高
Smart Images

Figure CN115859003B_ABST
Abstract
Description
[0001] This application claims priority to Chinese Patent Application No. 202111132603.3, filed on September 27, 2021, entitled "A Method and Apparatus for Implementing Fast Fourier Transform", the entire contents of which are incorporated herein by reference. Technical Field
[0002] This application relates to the field of computer technology, and in particular to a method, apparatus, and device for performing FFT. Background Technology
[0003] The Discrete Fourier Transform (DFT) is a commonly used technique in computer science to transform discrete time-domain data into discrete frequency-domain data. Generally, the Fast Fourier Transform (FFT) is used when performing the DFT to improve processing efficiency.
[0004] In related technologies, the FFT can be implemented through a System-on-Chip (SOC) with scalar computation units and / or vector computation units, meaning that the FFT can be implemented through scalar operations and / or vector operations. However, the efficiency of implementing the FFT through scalar operations and / or vector operations is still not high. Summary of the Invention
[0005] This application provides a method, apparatus, and device for performing FFT, which can improve the efficiency of FFT execution. The technical solution is as follows:
[0006] In a first aspect, a method for performing an Fast Fourier Transform (FFT) is provided. This method includes: receiving an execution request for a Fast Fourier Transform (FFT) sent by an application; obtaining first input data indicating that an FFT computation needs to be performed, as indicated by the FFT execution request; decomposing the FFT computation into multiple computation stages based on the cardinality of the FFT computation, wherein the input data of the first computation stage is the first input data, the input data of the second computation stage following the first computation stage is the output data of the preceding computation stage, and a third computation stage includes a Derivative Fourier Transform (DFT) computation, wherein the third computation stage is any one of the multiple computation stages; determining the DFT computation matrix corresponding to the DFT computation in the third computation stage; determining a first data matrix for matrix operations with the DFT computation matrix based on the input data of the third computation stage during the execution of the third computation stage; performing matrix multiplication on the DFT computation matrix and the first data matrix to perform the DFT computation; and returning the computation result to the application after the multiple computation stages are completed.
[0007] The solution shown in this application embodiment allows the processor, upon receiving an FFT execution request from the application, to decompose the FFT calculation into multiple computation stages based on the cardinality of the FFT calculation, and to determine the DFT calculation matrix for each computation stage. During DFT calculation, matrix multiplication can be performed on the first data matrix and the DFT calculation matrix using a matrix operation unit, thereby achieving the DFT calculation. This transforms the DFT calculations in each computation stage into matrix operations, which can then be implemented by the matrix operation unit. Thus, a single matrix operation can complete the DFT calculation for multiple data elements in the first data matrix, improving the efficiency of executing DFT calculations in each computation stage and consequently improving the efficiency of FFT calculation.
[0008] In one possible implementation, determining the DFT calculation matrix corresponding to the DFT calculation in the third calculation stage includes: converting the DFT coefficients corresponding to the DFT calculation in the third calculation stage into a DFT calculation matrix.
[0009] The third computation stage is any stage in the FFT computation. The DFT computation in each stage consists of a set of formulas that perform complex addition and multiplication on the input data. The DFT coefficients are the coefficients of each input data item in this set of formulas. The real and imaginary parts of the complex numbers in this set of formulas can be separated, and the formulas can be represented by matrix-vector multiplication. The resulting matrix is the DFT computation matrix. Thus, by transforming the DFT coefficients into the DFT computation matrix, and thereby performing DFT computation through a matrix, the efficiency of DFT computation in each stage can be improved.
[0010] In one possible implementation, determining the DFT calculation matrix corresponding to the DFT calculation in the third calculation stage includes: determining the DFT calculation matrix corresponding to the DFT calculation in the third calculation stage based on the cardinality corresponding to the third calculation stage and the preset correspondence between the cardinality and the DFT calculation matrix.
[0011] The third calculation stage can be any one of the calculation stages in the FFT calculation. Technicians can pre-set the correspondence between each cardinality and the DFT calculation matrix. This way, after determining the cardinality corresponding to each calculation stage in the FFT calculation, the DFT calculation matrix corresponding to each calculation stage can be directly determined based on this correspondence. This improves the efficiency of determining the DFT calculation matrix for each calculation stage, thereby improving the efficiency of executing the DFT calculation.
[0012] In one possible implementation, the third calculation stage further includes rotation factor calculation; determining the first data matrix to be used for matrix operations with the DFT calculation matrix based on the input data of the third calculation stage includes: performing rotation factor calculation based on the rotation factor calculation corresponding to the rotation factor calculation in the third calculation stage and the input data of the third calculation stage to obtain the input data for DFT calculation; and converting the input data for DFT calculation into the first data matrix to be used for matrix operations with the DFT calculation matrix.
[0013] Each third computation stage includes DFT computation and twiddle factor computation. When the FFT computation is implemented based on a temporal decimation method, the twiddle factor computation in each computation stage precedes the DFT computation. The input data for the twiddle factor computation is the input data for the corresponding computation stage, and the output data for the twiddle factor computation is the input data for the DFT computation. Thus, the DFT input data can be obtained by performing twiddle factor computation on the input data of the third computation stage. After obtaining the output data of the twiddle factor computation (which is also the DFT input data), the DFT input data can be assembled into a first data matrix. Then, matrix operations can be performed between the first data matrix and the DFT computation matrix to perform the DFT computation in each computation stage, thereby improving the execution efficiency of each computation stage.
[0014] In one possible implementation, the rotation factor calculation is performed based on the rotation factor corresponding to the rotation factor calculation in the third calculation stage and the input data of the third calculation stage. This includes: if the number of times the same rotation factor is involved in the calculation is greater than or equal to the first number threshold, then determining the rotation factor matrix corresponding to each rotation factor in the rotation factor calculation; converting the input data of the third calculation stage into a second data matrix; and performing matrix multiplication on the rotation factor matrix and the second data matrix to obtain a first data matrix.
[0015] Each third computation stage includes DFT computation and twiddle factor computation. When the FFT computation is implemented based on the temporal decimation method, the twiddle factor computation in each computation stage precedes the DFT computation. The input data for the twiddle factor computation is the input data for the corresponding computation stage, and the output data is the input data for the corresponding DFT computation. If it is determined that the twiddle factor computation satisfies the matrix operation conditions, the input data of the third computation stage can be transformed into a second data matrix, and the twiddle factor in the twiddle factor computation can be transformed into a twiddle factor matrix. Then, by performing matrix operations on the second data matrix and the twiddle factor matrix, the twiddle factor is calculated, thus obtaining the input data for the DFT computation. The input data for the DFT computation can then be transformed into a first data matrix. In this way, both the DFT computation and the twiddle factor computation in the computation stage can be implemented through matrix operations, which can improve the execution efficiency of the computation stage in the FFT computation.
[0016] In one possible implementation, the third calculation stage further includes rotation factor calculation, where the first data matrix is a matrix transformed from the input data of the third calculation stage; after performing matrix multiplication on the DFT calculation matrix and the first data matrix to perform DFT calculation, the third calculation stage further includes: if the number of times the same rotation factor is involved in the calculation is greater than or equal to the first number threshold, then determining the rotation factor matrix corresponding to each rotation factor in the rotation factor calculation; and performing matrix multiplication on the third data matrix and the rotation factor matrix obtained by performing the DFT calculation to perform the rotation factor calculation.
[0017] Each third computation stage includes DFT computation and twiddle factor computation. When the FFT computation is implemented based on the frequency domain decimation method, the twiddle factor computation in each computation stage follows the DFT computation. The input data for the twiddle factor computation is the output data of the DFT computation, and the output data of the twiddle factor computation is the output data of its respective computation stage. Thus, after obtaining the DFT output data, if it is determined that the twiddle factor computation satisfies the matrix operation conditions, the DFT output data can be converted into a third data matrix, and the twiddle factor in the twiddle factor computation can be converted into a twiddle factor matrix. Then, by performing matrix operations on the third data matrix and the twiddle factor matrix, the twiddle factor computation is achieved. In this way, both the DFT computation and the twiddle factor computation in the computation stage can be implemented through matrix operations, which can improve the execution efficiency of the computation stage in the FFT computation.
[0018] Herein, regarding the above matrix operation condition, it may be that the number of times a same twiddle factor participates in the calculation in twiddle factor calculation is greater than or equal to a preset first number threshold. For twiddle factor calculation, if it is determined that each twiddle factor participates in the calculation a relatively large number of times, it indicates that there are multiple data elements multiplied by each twiddle factor in the input data of the twiddle factor calculation. Therefore, multiple data elements corresponding to one twiddle factor can form an input data vector, input data vectors corresponding to multiple twiddle factors can form a data matrix, and the multiple twiddle factors are converted into a twiddle factor matrix. In this way, a matrix operation unit can perform matrix multiplication calculation on the data matrix and the twiddle factor matrix to implement the twiddle factor calculation. The first number threshold may be preset by a technician.
[0019] In a possible implementation, the third calculation stage further includes twiddle factor calculation; implementing DFT calculation by performing matrix multiplication calculation on a DFT calculation matrix and a first data matrix includes: determining a twiddle factor matrix corresponding to each twiddle factor in the twiddle factor calculation; if it is determined that the twiddle factor matrix and the DFT calculation matrix satisfy a matrix merging condition, multiplying the twiddle factor matrix and the DFT calculation matrix to obtain a merged calculation matrix; and performing matrix multiplication calculation on the merged calculation matrix and the first data matrix.
[0020] Herein, the matrix merging condition includes that the number of times the same twiddle factor matrix participates in the matrix operation in the twiddle factor calculation is greater than a preset second number threshold. In the calculation stage, both DFT calculation and twiddle factor calculation can be converted into matrix operations. If the DFT calculation and the twiddle factor calculation satisfy the matrix merging condition, the matrix operations corresponding to the DFT calculation and the twiddle factor calculation can be merged for operation, that is, the twiddle factor matrix and the DFT calculation matrix can be multiplied to obtain a merged calculation matrix, and matrix multiplication calculation is performed on the merged calculation matrix and the first data matrix to implement the twiddle factor calculation and the DFT calculation in the calculation stage. In this way, by merging the matrix operations, the number of matrix operations can be reduced, and the efficiency of performing DFT calculation and twiddle factor calculation can be improved.
[0021] In a possible implementation, the third calculation stage corresponds to a radix M, the number of input data of the third calculation stage is N, the third calculation stage is divided into N / M butterfly units according to the radix M, each butterfly unit includes at least one twiddle factor, where M<N, and M and N are natural numbers; the determining the twiddle factor matrix corresponding to each twiddle factor in the twiddle factor calculation includes: converting the twiddle factors of the N / M butterfly units into a twiddle factor matrix.
[0022] Each computational stage has a unique cardinality, which is equal to the number of data elements in the input data corresponding to each butterfly junction within that stage. Therefore, if the input data for a computational stage contains N data elements and the corresponding cardinality is M, then that computational stage includes N / M butterfly junctions. Each butterfly junction corresponds to at least one twist factor. When assembling the twist factors into a matrix, the twist factors of the N / M butterfly junctions can be converted into at least one twist factor matrix. Furthermore, twist factor calculation can be achieved by performing matrix operations on this at least one twist factor matrix, thus improving the efficiency of twist factor calculation.
[0023] In one possible implementation, converting the rotation factors of N / M butterfly junctions into a rotation factor matrix includes: determining at least one set of rotation factors based on the rotation factors of the N / M butterfly junctions, wherein the at least one set of rotation factors includes the same number of rotation factors; and constructing a rotation factor matrix based on the rotation factors in each set of rotation factors.
[0024] By dividing the twiddle factors into at least one set of twiddle factors, each set containing the same number of twiddle factors, the resulting twiddle factor matrices, after being transformed from each set, have the same size. Furthermore, twiddle factor calculations in each computational stage can be performed using matrix operations, thereby improving the efficiency of twiddle factor calculations.
[0025] In one possible implementation, constructing a rotation factor matrix based on rotation factors in the rotation factor set includes: determining the cell matrix corresponding to each rotation factor in the rotation factor set; and arranging the cell matrices corresponding to each rotation factor diagonally to construct the rotation factor matrix.
[0026] Twister calculation involves multiplying different twisters by at least one data element in the corresponding input data. If we separate the real and imaginary parts of the twisters and data elements, and represent the calculation of the twisters with data elements as a matrix-vector multiplication, the resulting matrix is the twister matrix corresponding to that twister. A twister matrix corresponding to a single twister can be called a unit matrix. When constructing a twister matrix from multiple twisters, the unit matrices corresponding to the multiple twisters can be arranged diagonally and padded with zeros to construct the twister matrix. This results in a twister matrix containing multiple twisters. Thus, by performing a single matrix operation on the twister matrix and its corresponding data matrix, the calculation of multiplying multiple twisters by data elements can be completed, improving the efficiency of twister calculation.
[0027] In one possible implementation, determining a first data matrix for matrix operations with the DFT calculation matrix based on the input data of the third calculation stage includes: determining a first data matrix of at least one first size composed of the data elements in the input data of the third calculation stage, based on the arrangement order of the data elements in the input data of the third calculation stage.
[0028] To perform matrix operations, the first size of the first data matrix is equal to the size of the DFT calculation matrix used in the matrix operation with the first data matrix. The input data for the DFT calculation in each butterfly knot can form an input data vector. At least one first data matrix can be formed by arranging the input data vectors corresponding to the DFT calculations in each butterfly knot according to the order of the data elements in the input data. Thus, a first data matrix includes the input data vectors corresponding to the DFT calculations of multiple butterfly knots. Therefore, by performing a single matrix operation between the first data matrix and the DFT calculation matrix, the DFT calculations in multiple butterfly knots can be completed, improving the efficiency of DFT calculations.
[0029] In one possible implementation, determining a first data matrix of at least one first size composed of data elements in the input data of the third calculation stage according to the arrangement order of data elements in the input data of the third calculation stage includes: determining a first data matrix of at least one first size composed of data elements in the input data of the third calculation stage according to the arrangement order of data elements in the input data of the third calculation stage and a matrix compression algorithm.
[0030] In the process of assembling the first data matrix, the first data matrix can be compressed using a matrix compression algorithm, which can reduce the number of first data matrices obtained, reduce the number of matrix operations in the DFT calculation, and thus improve the efficiency of performing the DFT calculation.
[0031] In one possible implementation, transforming the input data of the third calculation stage into a second data matrix includes: for each rotation factor matrix, determining a second data matrix of at least a second size composed of data elements corresponding to the rotation factors included in the rotation factor matrix, based on the arrangement order of the data elements in the input data of the third calculation stage that correspond to the rotation factors included in the rotation factor matrix.
[0032] To enable matrix operations, the second size of the second data matrix is equal to the size of the rotation factor matrix used in the operation. When constructing the second data matrix, the data elements in the input data that are multiplied by the rotation factors included in the rotation factor matrix are arranged sequentially according to their order in the input data. This allows a single second data matrix to contain multiple rotation factors. Therefore, by performing matrix operations sequentially between the second data matrix and the rotation factor matrix, multiple rotation factors can be calculated, improving the efficiency of rotation factor calculations.
[0033] In one possible implementation, determining a second data matrix of at least a second size composed of data elements corresponding to the rotation factors included in the rotation factor matrix, based on the arrangement order of data elements corresponding to the rotation factors included in the rotation factor matrix in the input data of the third calculation stage, includes: determining a second data matrix of at least a second size composed of data elements corresponding to the rotation factors included in the rotation factor matrix, based on the arrangement order of data elements corresponding to the rotation factors included in the rotation factor matrix in the input data of the third calculation stage and a matrix compression algorithm.
[0034] In the process of assembling the second data matrix, the second data matrix can be compressed using a matrix compression algorithm, which can reduce the number of second data matrices obtained and the number of matrix operations in the calculation of the rotation factor, thereby improving the efficiency of performing the rotation factor calculation.
[0035] Among them, the matrix operations mentioned above are performed by a matrix operation unit. The matrix operation unit is more efficient than the matrix operation unit, which is more efficient than the processor, vector operation unit, etc., thereby improving the efficiency of FFT calculation.
[0036] In a second aspect, an apparatus for performing an FFT is provided, the apparatus comprising at least one module for implementing the method for performing an FFT provided in the first aspect and possible implementations thereof.
[0037] Thirdly, a computer device for performing FFT is provided, the computer device including a processor and a matrix operation unit, wherein the processor is configured to perform the methods provided in the first aspect and possible implementations thereof; and the matrix operation unit is configured to perform matrix multiplication calculations in the first aspect.
[0038] Fourthly, a computer-readable storage medium is provided that stores computer program code, which, when executed by a computer device, causes the computer device to perform the method for performing FFT provided in the first aspect and its possible implementations.
[0039] Fifthly, a computer program product containing instructions is provided, which, when run on a computer device, causes the computer device to execute the method for performing FFT provided in the first aspect and possible implementations of the first aspect. Attached Figure Description
[0040] Figure 1 This is a schematic diagram of the structure of a computer device provided in an embodiment of this application;
[0041] Figure 2 This is a schematic diagram of the structure of a computer device provided in an embodiment of this application;
[0042] Figure 3 This is a schematic diagram of a matrix operation unit performing matrix operations according to an embodiment of this application;
[0043] Figure 4 This is an 8-point FFT butterfly diagram provided in an embodiment of this application;
[0044] Figure 5 This is an 8-point FFT butterfly diagram provided in an embodiment of this application;
[0045] Figure 6 This is a flowchart illustrating a method for performing an FFT according to an embodiment of this application;
[0046] Figure 7 This is a flowchart illustrating a method for performing an FFT according to an embodiment of this application;
[0047] Figure 8 This is a flowchart illustrating a method for performing an FFT according to an embodiment of this application;
[0048] Figure 9 This is a flowchart illustrating a method for performing an FFT according to an embodiment of this application;
[0049] Figure 10 This is a flowchart illustrating a method for performing an FFT according to an embodiment of this application;
[0050] Figure 11 This is a schematic diagram of a device structure for performing FFT provided in an embodiment of this application. Detailed Implementation
[0051] This application provides a method for performing FFT, which can be implemented by a computer device, such as an embedded device, a general-purpose computer, or a server.
[0052] like Figure 1As shown, in one possible scenario, the system-on-chip (SOC) 100 of this computer device includes a processor 110, a matrix operation unit 120, and a memory 130. This computer device can run applications involving FFT calculations. For example, the application could be a large-scale atomic / molecular massively parallel simulation tool (LAMMPS) or a computer package for atomic-scale material simulation (Vienna Ab-initio Simulation Package, VASP) used in quantum mechanics, or it could be open-source field operation and manipulation (OpenFOAM) software used in fluid mechanics.
[0053] when Figure 1 During the execution of an application involving FFT calculations on the computer device shown, if the application requires FFT calculations, it can send an FFT execution request to the processor 110. The processor 110 can receive the FFT execution request sent by the application, and then retrieve the input data to be performed on the FFT from the memory 130. It performs FFT calculations on the input data. If matrix operations are required during processing, the processor 110 can send matrix operation instructions to the matrix operation unit 120, where the processor 110 can be a central processing unit (CPU). After receiving the matrix operation instructions from the processor 110, the matrix operation unit 120 can retrieve the matrix to be operated on from the memory 130, perform matrix operations on the retrieved matrix, and then store the matrix operation results in the memory 130. The memory 130 can be used to store the input data to be performed on the FFT, as well as data generated by the processor 110 and the matrix operation unit 120 during the execution of the FFT calculations, such as the matrix to be operated on and the matrix operation results. The memory 130 can be a register or cache on the SOC.
[0054] like Figure 2 As shown, in another possible scenario, the computer device includes at least SOC 200 and SOC 300. SOC 200 includes a processor 210 and a memory 220, while SOC 300 includes a processor 310, a memory 320, and a matrix operation unit 320.
[0055] when Figure 2During the execution of an application involving FFT calculations in the computer device shown, the processor 210 in the SOC 200 can be used to perform calculations other than FFT calculations involved in the application, and the memory 220 can store data for various calculations to be performed in the application. If the application needs to perform FFT calculations, it can send an FFT execution request to the processor 210. After receiving the FFT execution request from the application, the processor 210 in the SOC 200 can forward the FFT execution request to the processor 310 in the SOC 300 and store the input data to be performed for FFT in the memory 330. After receiving the FFT execution instruction, the processor 310 in the SOC 300 can retrieve the input data to be performed for FFT from the memory 330, perform FFT calculation processing on the input data to be performed for FFT, and send matrix operation instructions to the matrix operation unit 320 when matrix operations are required during processing. After receiving a matrix operation instruction from the processor 310, the matrix operation unit 320 can retrieve the matrix to be operated on from the memory 330, perform the matrix operation on the retrieved matrix, and then store the matrix operation result in the memory 330. The memory 330 can be used to store the matrix to be operated on, the matrix operation result, etc.
[0056] Specifically, the matrix operation unit 120 or 320 can be implemented based on an outer product architecture or an inner product architecture. Matrix operation unit 120 or 320 can support at least two matrix inputs and perform matrix operations on the two input matrices. In one possible implementation, the matrix operation unit 120 or 320 can support three matrix inputs and perform multiplication and addition operations on the three input matrices. Figure 3 As shown, the input matrices are matrix A, matrix B, and matrix C, and the output matrix is matrix D. The matrix operation unit 120 can perform the operation "matrix D = matrix A * matrix B + matrix C", where matrix A has a size of N*K, matrix B has a size of K*M, and matrix C has a size of N*M. If only the multiplication of matrix A and matrix B needs to be calculated, matrix C can be set to a zero matrix. If only the addition of matrix A (or matrix B) and matrix C needs to be calculated, matrix A (or matrix B) can be set to an identity matrix. The SOC 100, SOC 200, and SOC 300 can also integrate scalar operation units and vector operation units to perform scalar and vector operations.
[0057] The relevant concepts of the embodiments of this application are introduced below:
[0058] The Discrete Fourier Transform (DFT) is a Fourier transform that presents discrete data in both the time and frequency domains. It is used to transform discrete time-domain sampled data into discrete frequency-domain sampled data. In terms of data format, the DFT's input data (discrete time-domain sampled data) and output data (discrete frequency-domain data) are finite-length complex sequences, and both complex sequences are of equal length.
[0059] The Fast Fourier Transform (FFT) is a method for quickly computing the DFT or inverse DFT. Compared to the DFT, the FFT has lower computational complexity.
[0060] The Cooley-Tukey algorithm is a commonly used FFT algorithm. Based on the divide-and-conquer strategy, it can decompose a complex sequence DFT of length N into DFTs of lengths N1 and N2 and complex multiplication with the twist factor, where N = N1 * N2.
[0061] Radix-2 FFT is a classic Kuley-graphical algorithm. This algorithm can be applied to lengths of N=2. L The complex sequence (L is a positive integer). For example, to compute the DFT of a complex sequence of length 8 (8-point DFT), it can be decomposed into two 4-point DFTs, and then the two 4-point DFTs can be further decomposed into two 2-point DFTs.
[0062] The Cooley-Tugis algorithm will be further introduced below using radix-2 FFT as an example:
[0063] According to the definition of Discrete Fourier Transform, for a complex sequence x of length N, performing DFT will yield a complex sequence X of length N. The corresponding DFT calculation formula (1) is as follows:
[0064]
[0065] Where k∈[0, N-1], n∈[0, N-1]. x(n) is any data element in the complex sequence x, and X(k) is any data element in the complex sequence X of length N obtained after performing a DFT on the complex sequence x. For rotation factor, To improve the computational efficiency of the DFT, the FFT can be used to simplify the DFT calculation process. When the size of the complex sequence x (i.e., the number of data elements in the complex sequence x) N = 2... L When x(n) is divided into two groups according to the parity of n, we get the following formula (2):
[0066]
[0067] By utilizing the periodicity and symmetry of the rotation factor, a series of transformations can be performed on formula (2) to obtain the following formulas (3) and (4):
[0068]
[0069]
[0070] Where k∈[0, N / 2), X1(k) is the result of performing an N / 2-point DFT on the N / 2 data elements corresponding to x(n) when n is even, and X2(k) is the result of performing an N / 2-point DFT on the N / 2 data elements corresponding to x(n) when n is odd. From formulas (3) and (4), it can be seen that only two N / 2-point DFTs, namely X1(k) and X2(k), need to be obtained. Then, complex multiplication and addition operations are performed on the results of the two N / 2-point DFTs to obtain the result of the N-point DFT. Furthermore, for X1(k) and X2(k), they can also be further divided based on the ideas of the above formulas (1)-(4). By calculating two N / 4-point DFTs, the result of the N / 2-point DFT can be obtained. By analogy, the N-point DFT can be divided L times, where N=2 L .
[0071] The radix-2 FFT algorithm is explained below using an 8-point FFT as an example. The calculation formulas for X(0)-X(7) are as follows:
[0072]
[0073]
[0074]
[0075]
[0076]
[0077]
[0078]
[0079]
[0080] X(0)-X(7) are the results obtained after performing an FFT on the input data x(0)-x(7). X1(0)-X1(3) are the results of performing an N / 2-point DFT on the N / 2 data elements corresponding to even n in x(n), that is, performing a 4-point DFT on x(0), x(2), x(4), and x(6). X2(0)-X2(3) are the results of performing an N / 2-point DFT on the N / 2 data elements corresponding to odd n in x(n), that is, performing a 4-point DFT on x(1), x(3), x(5), and x(7). Based on the above calculation formula for X(0)-X(7), the flowchart for calculating an 8-point FFT based on the calculation results of the two 4-point DFTs can be obtained, as follows: Figure 4 As shown.
[0081] Furthermore, the calculation results of the N / 2 point DFT can also be obtained from the calculation results of the two N / 4 point DFTs. That is, X1(0)-X1(3) can be obtained from the calculation of the two 2-point DFTs, and X2(0)-X2(3) can also be obtained from the calculation structure of the two 2-point DFTs. The corresponding calculation formulas are as follows:
[0082]
[0083]
[0084]
[0085]
[0086]
[0087]
[0088]
[0089]
[0090] Among them, X3(0)-X3(1) is the result of 2-point DFT calculation of the even-numbered data elements in the sequence corresponding to x(0), x(2), x(4), and x(6), which is the result of DFT calculation of x(0) and x(4).
[0091] X4(0)-X4(1) is the result of performing a 2-point DFT on the odd-numbered data elements in the sequence corresponding to x(0), x(2), x(4), and x(6), which is the result of performing a DFT on x(2) and x(6).
[0092] X5(0)-X5(1) is the result of 2-point DFT calculation of the even-numbered data elements in the sequence corresponding to x(1), x(3), x(5), and x(7), which is the result of DFT calculation of x(1) and x(5).
[0093] X6(0)-X6(1) is the result of 2-point DFT calculation of the odd-numbered data elements in the sequence corresponding to x(1), x(3), x(5), and x(7), which is the result of DFT calculation of x(3) and x(7).
[0094] Since the two-point DFT cannot be simplified further, X3(0), X3(1), X4(0), X4(1), X5(0), X5(1), X6(0), and X6(1) can be calculated using x(0)-x(7) respectively. The corresponding calculation formulas are as follows:
[0095]
[0096]
[0097]
[0098]
[0099]
[0100]
[0101]
[0102]
[0103] Thus, the actual calculation of an 8-point FFT can include three calculation stages, among which:
[0104] The first calculation stage: Calculate X3(0), X3(1), X4(0), X4(1), X5(0), X5(1), X6(0), and X6(1) respectively based on x(0)-x(7);
[0105] The second calculation stage: Calculate X1(0)-X1(3) and X2(0)-X2(3) based on X3(0), X3(1), X4(0), X4(1), X5(0), X5(1), X6(0), X6(1);
[0106] The third calculation stage: Calculate X(0)-X(7) based on X1(0)-X1(3) and X2(0)-X2(3).
[0107] For the calculation process of the 8-point FFT, please refer to [link / reference]. Figure 5 The butterfly diagram shown includes three computation stages in an 8-point FFT. Each stage contains four butterfly nodes, and each node includes twiddle factor calculation and DFT calculation. Twiddle factor calculation involves multiplying the input data of the computation stage or the output data of the DFT calculation with the corresponding twiddle factor. DFT calculation refers to the calculation performed on the DFT cells within the butterfly nodes, i.e., performing DFT calculations on the input data of the DFT cells. Each butterfly node includes one DFT cell. For details on butterfly nodes and DFT cells, please refer to... Figure 5 The first calculation stage in the process.
[0108] Additionally, it's important to note that there are two decimation methods for FFT: Decimation-in-time (DIT) and Decimation-in-frequency (DFT). DIT involves partitioning the input data for the DFT to perform the FFT calculation. DFT involves partitioning the output data (i.e., the result data) for the DFT to perform the FFT calculation. In DIT-based FFT calculations, the twiddle factor in the butterfly junction is calculated before the DFT calculation; in DFT-based FFT calculations, the twiddle factor is calculated after the DFT calculation. The above description of radix-2 FFT is based on DIT; the details of the 8-point DFT corresponding to DFT will not be discussed further here.
[0109] Regardless of whether the FFT calculation is based on time-domain decimation or frequency-domain decimation, for an N-point FFT calculation, assuming N can be decomposed into N1, N2, ..., Ni, the N-point FFT calculation process can include i calculation stages. Each calculation stage includes the multiplication of twitch factors and the DFT calculation. Here, N = N1 * N2 * ... * Ni, where N1, N2, ..., Ni can be called the cardinality. N1 is the cardinality corresponding to the first calculation stage, N2 is the cardinality corresponding to the second calculation stage, and Ni is the cardinality of the i-th calculation stage. For the j-th calculation stage out of the i calculation stages, the number of butterfly junctions included in the j-th calculation stage is N / M, where M is the cardinality corresponding to the i-th calculation stage. The value of each twitch factor in each calculation stage can be calculated based on the number of data elements N in the input data and the order of the current calculation stage, where M < N, and M and N are natural numbers.
[0110] As can be seen, any FFT calculation can be divided into several calculation stages, each of which may include twiddle factor calculation and DFT calculation. Specifically, in FFT calculations based on time-domain decimation, twiddle factor calculation can be performed first, followed by DFT calculation, within the same calculation stage; the result of the twiddle factor calculation serves as the input data for the DFT calculation. Similarly, in FFT calculations based on frequency-domain decimation, DFT calculation can be performed first, followed by twiddle factor calculation, within the same calculation stage; the result of the DFT calculation serves as the input data for the twiddle factor calculation.
[0111] The execution principle of the embodiments of this application is described below:
[0112] The method for performing FFT provided in this application can convert the calculations of each calculation stage in FFT into matrix calculations. It provides a method for performing FFT calculations through matrix operations in software and can perform FFT calculations through a SOC including a matrix operation unit in hardware.
[0113] As discussed in the above introduction to radix-2 FFT, the calculation of an 8-point DFT can be divided into two 4-point DFT calculations, and then each 4-point DFT can be further divided into two 2-point DFTs. For the detailed calculation process, please refer to [link to relevant documentation]. Figure 5 Thus, the calculation of the 8-point DFT can be divided into three stages, each of which includes the calculation of the rotation factor and the DFT calculation.
[0114] (1) Convert DFT calculation into matrix operations
[0115] like Figure 5 As shown, the calculation of the 8-point DFT can be divided into 3 calculation stages, each of which includes 4 butterfly knots, and each butterfly knot includes a DFT unit. Assuming that the input of any DFT unit is x[0] and x[1], and the output is X[0] and X[1], the corresponding calculation formulas are as follows: formula (5) and formula (6).
[0116] X[0]=x[0]+x[1] Formula (5)
[0117] X[1]=x[0]-x[1] Formula (6)
[0118] The above formulas (5) and (6) can be converted into the format of matrix multiplication of vector as shown in formula (7):
[0119]
[0120] Since the input and output data in DFT are both complex numbers, that is, X[0], X[1], x[0], and x[1] are all complex numbers, and real and complex numbers are stored separately in computer devices, if the real and imaginary parts of X[0], X[1], x[0], and x[1] are calculated separately, the above formula for multiplying a matrix by a vector can be written as the following formula (8):
[0121]
[0122] Where X[0].r represents the real part of X[0], X[0].i represents the imaginary part of X[0]; X[1].r represents the real part of X[1], X[1].i represents the imaginary part of X[1]; x[0].r represents the real part of x[0], x[0].i represents the imaginary part of x[0], x[1].r represents the real part of x[1], and x[1].i represents the imaginary part of x[1].
[0123] In the above formula (8), the matrix multiplied by the input data vector does not contain any variables related to the input data; that is, the matrix does not change with different input data. In other words, for any 2-point DFT calculation in any computation stage, the real and imaginary parts of the input data can be separated to form an input data vector, and the product of this matrix and the input data vector is determined as the output of the 2-point DFT calculation. This matrix can be called the DFT calculation matrix.
[0124] Similarly, there is a unique DFT calculation matrix for each of the 3-point DFT calculation, 4-point DFT calculation, and 5-point DFT calculation in the calculation stage. The reasoning process will not be listed here.
[0125] Furthermore, since the DFT calculation matrices corresponding to each DFT calculation within the same computation stage of the FFT are the same (e.g., in an 8-point FFT, each computation stage includes four 2-point DFT calculations), the matrix-vector multiplication calculations corresponding to each DFT calculation within the same computation stage can be merged into a matrix-matrix multiplication calculation.
[0126] Continuing with the example of the computation stage in an 8-point FFT, let's assume the input vectors for the four 2-point DFT computations are as follows: The calculation of the four 2-point DFT matrix-vector multiplications can be combined into a single matrix-matrix multiplication, as shown in formula (9):
[0127]
[0128] Similarly, for any computation stage in any FFT process, the DFT computation can be transformed into matrix operations.
[0129] (2) Convert the rotation factor calculation into matrix operations
[0130] Each computation stage in FFT also includes the multiplication of twiddle factors. A single twiddle factor multiplication can be expressed as y = W * x, where W is the twiddle factor, x is the data element multiplied by the twiddle factor, and y is the result. If the real and imaginary parts of x, y, and W are separated, then y = W * x can be expressed as the following formula (10):
[0131] y.r+j*yi=(W.r+j*Wi)*(x.r+j*xi) Formula (10)
[0132] If we convert the above formula into the form of matrix multiplication of vectors, it can be expressed as formula (11):
[0133]
[0134] According to formula (11), any rotation factor can be represented by a 2×2 matrix, which can be called the rotation factor matrix. A matrix transformed from a rotation factor can also be called a unit matrix. Here, Wr represents the real part of the rotation factor W, and Wi represents the imaginary part of the rotation factor W. xr represents the real part of the data element multiplied by the rotation factor W, and xi represents the imaginary part of that data element. yr represents the real part of the result data obtained after the rotation factor calculation, and yi represents the imaginary part of the result data. Thus, the calculation of any rotation factor can be converted into a matrix-vector multiplication operation.
[0135] Suppose that in a rotation factor calculation, there are two data elements that are multiplied by the same rotation factor W, corresponding to x1 and x2 respectively. Then, according to formula (11), the multiplication of rotation factor W with y1 and y2 respectively can be expressed as formula (12) and formula (13) as follows.
[0136]
[0137]
[0138] Formulas (12) and (13) above can be combined into a single matrix multiplication calculation, as shown in formula (14).
[0139]
[0140] Assuming that four rotation factor calculations are required in the same computational phase, and that each calculation corresponds to a different rotation factor, then they can be expressed as follows:
[0141]
[0142]
[0143]
[0144]
[0145] The above four matrix-vector multiplication operations are combined into one matrix-vector multiplication operation, as shown in formula (15):
[0146]
[0147] Among them, the matrix composed of the unit matrices corresponding to at least one rotation factor can be called the rotation factor matrix.
[0148] If 32 rotation factor calculations are required in the same calculation stage, and there are a total of 4 rotation factors in this calculation stage, with each rotation factor participating in 8 rotation factor calculations, then there will be 8 matrix-vector multiplication operations similar to formula (15), and the rotation factor matrix corresponding to each calculation is the same. Therefore, these 8 matrix-vector multiplication calculations can be combined into a single matrix-matrix multiplication calculation, as shown in formula (16):
[0149]
[0150] Among them, x1.rx 31 .r represents the real part of the data element multiplied by the four rotation factors, x1.ix 31 .i represents the imaginary part of the data element that is multiplied by the four rotation factors.
[0151] As can be deduced from the above reasoning, for any computation stage in any FFT process, if the same twitch factor is involved in multiple twitch factor multiplication operations in that computation stage, then the twitch factor multiplication in that computation stage can be converted into matrix multiplication computation.
[0152] The method for performing FFT provided in the embodiments of this application will now be described:
[0153] Figure 6 This is a flowchart of a method for performing an FFT according to an embodiment of this application. This method embodiment can be used in... Figure 1 or Figure 2 Execute on the provided computer device, see [link / reference] Figure 6 The method includes:
[0154] Step 601: The processor receives the FFT execution request sent by the application.
[0155] The application program can be one of the aforementioned applications involving FFT calculations. Figure 1 or Figure 2 When a computer device is running an application, and the application needs to perform FFT calculations on the data, it can send an FFT execution request to the processor in the computer device. For example, the application could be a VASP (Virtual Application Service). When the VASP needs to solve for the wave function, it can send a wave function solution request to the processor; this wave function solution request is the FFT execution request. The wave function is a common function in quantum mechanics, and the wave function can be solved by performing FFT calculations on the input data of the wave function to obtain the solution result.
[0156] Regarding the FFT execution method provided in this application, a skilled craftsman can write the corresponding processing program as an FFT processing function and add it to the application's mathematical library. This mathematical library, which can be stored on the computer device executing the corresponding application, includes a large number of processing functions that can be used to perform various mathematical calculations involved in the application. When the application needs to perform FFT calculations, it can send an FFT execution request to the processor. The processor can then execute the FFT processing function by calling it to perform the following steps.
[0157] Step 602: The processor acquires the first input data to be performed on the FFT.
[0158] The first input data is the input data for which an FFT calculation needs to be performed, as indicated by the FFT execution request. For example, when the FFT execution request is a wavefunction solution request, the first input data can be the initial data of the wavefunction.
[0159] After receiving the FFT execution request sent by the application, the processor can load the first input data to be FFT from the memory of the computer device to the memory of the SOC, such as the cache of the SOC, according to the FFT execution request, so as to further process the first input data.
[0160] Step 603: The processor determines the computational stages for performing the FFT computation.
[0161] When the number of data elements in the input data to be calculated for FFT is different, the number of calculation stages involved in the FFT calculation may also be different, and the cardinality corresponding to each calculation stage may also be different. Therefore, before performing FFT calculation on the input data, the FFT calculation can be decomposed into multiple calculation stages based on the number of data elements in the input data, and the cardinality corresponding to each calculation stage can be determined.
[0162] In one possible scenario, the user can specify the number of data elements in the input data for FFT computation, and configure the number of computation stages and the radix for each stage within the application settings. The FFT execution request can then carry the user-defined radix for each computation stage, allowing the processor to further divide the FFT computation into stages based on these radixes. Specifically, the product of the radixes for each computation stage equals the number of data elements in the input data.
[0163] In another possible scenario, the FFT execution request sent by the application may include the number of data elements in the input data, or the processor may calculate the number of data elements in the input data. After determining the number of data elements in the input data, the processor can determine the computational stages for performing the FFT on the input data and the corresponding radix for each stage, based on the Cooley-Tukey algorithm. For example, if the number of data elements in the input data is 8, it can be decomposed into 2*2*2, resulting in three computational stages for the FFT, with each stage having a radix of 2. Similarly, if the number of data elements in the input data is 27, it can be decomposed into 3*3*3, resulting in three computational stages for the FFT, with each stage having a radix of 3. Furthermore, if the size of the input data is 30, it can be decomposed into 2*3*5, resulting in three computational stages for the FFT, with radixes of 2, 3, and 5 for each stage.
[0164] Step 604: The processor determines the DFT calculation matrix corresponding to the DFT calculation in each calculation stage based on the cardinality corresponding to each calculation stage.
[0165] In one possible scenario, since the DFT calculation matrix corresponding to the DFT calculation in any calculation stage is related to the cardinality of that calculation stage, technicians can pre-define the correspondence between cardinality and DFT calculation matrices. For example, a DFT calculation matrix corresponding to cardinality 2, a DFT calculation matrix corresponding to cardinality 3, a DFT calculation matrix corresponding to cardinality 4, and so on. After determining the cardinality corresponding to each calculation stage, for the DFT calculation matrix corresponding to the DFT calculation, the cardinality corresponding to the calculation stage to which the DFT calculation belongs, and the correspondence between cardinality and DFT calculation matrices, can be determined, thus determining the DFT calculation matrix corresponding to the DFT calculation.
[0166] In another possible scenario, the processor can determine the DFT coefficients based on the cardinality corresponding to the computation stage to which the DFT calculation belongs, and then convert the DFT coefficients into a DFT calculation matrix. The DFT calculation for each computation stage in the FFT calculation consists of a set of calculation formulas that perform complex addition and complex multiplication on the input data. Once the cardinality corresponding to the computation stage to which the DFT calculation belongs is determined, this set of calculation formulas can be determined; see the execution principle description above for details. The DFT coefficients refer to the coefficients of each input data item in this set of calculation formulas. The real and imaginary parts of the complex numbers in this set of calculation formulas can be separated, and the set of calculation formulas can be represented by matrix-vector multiplication; the resulting matrix is the DFT calculation matrix.
[0167] Step 605: The processor determines the first data matrix corresponding to the DFT calculation in the calculation phase.
[0168] The input data for the first computational stage in the FFT computation is the data to be FFTed. For each computational stage other than the first, the input data for each stage is the output data of the previous stage. The output data of the last computational stage is the result data after performing FFT on the input data to be FFTed. After determining the DFT computation matrix corresponding to the DFT computation in each computational stage, the DFT computation and twiddle factor calculation in each computational stage can be performed sequentially according to the order of the computational stages and the corresponding input data.
[0169] If the FFT calculation in this method is based on the temporal decimation method, then the twist factor calculation in this calculation stage is performed before the DFT calculation. That is, for any calculation stage, the twist factor can be calculated on the input data of this calculation stage first, and then the calculation result of the twist factor can be used as the input data of the DFT calculation. Then, the DFT calculation is performed on the input data of the DFT calculation, and the calculation result of the DFT calculation is the output data of this calculation stage.
[0170] If the FFT in this method is based on frequency domain decimation, then the twiddle factor calculation in this computation stage follows the DFT calculation. That is, for any computation stage, the input data can be DFT calculated first, and then the DFT result can be used as the input data for the twiddle factor calculation. The twiddle factor calculation result is then the output data for that computation stage. In one possible case, the twiddle factor value might be all 1s. When the twiddle factor value is all 1s, this twiddle factor calculation can be skipped, and the corresponding input data can be directly used as the corresponding output data.
[0171] In this step, during DFT calculation, the processor can transform the input data corresponding to the DFT calculation into at least one first data matrix; the specific processing will not be described here. Additionally, this method can also perform rotation factor calculation. This can be achieved by multiplying the data elements in the input data corresponding to the rotation factor using vector or scalar operation units to obtain the rotation factor calculation result. The calculation of the rotation factor using vector or scalar operation units is existing technology and will not be described in detail here. During rotation factor calculation in this method, the calculation can also be transformed into matrix calculation, implemented through matrix operation units. The processing for rotation factor calculation through matrix operation units will not be described here.
[0172] Step 606: The processor sends matrix operation instructions to the matrix operation unit.
[0173] After the processor converts the input data corresponding to the DFT calculation into at least one first data matrix, it can send a matrix operation instruction to the matrix operation unit and store the first data matrix and the DFT calculation matrix into the corresponding register of the matrix operation unit in sequence, so that the matrix operation unit can perform matrix multiplication calculation on the first data matrix and the DFT calculation matrix.
[0174] Step 607: The matrix operation unit performs matrix operations according to the matrix operation instructions.
[0175] After receiving a matrix operation instruction, the matrix operation unit can sequentially retrieve the first data matrix and the DFT calculation matrix from the register, and perform matrix multiplication on the first data matrix and the DFT calculation matrix to obtain the calculation result of the DFT.
[0176] Step 608: The matrix operation sends a matrix operation completion notification to the processor.
[0177] After performing a matrix operation, the matrix operation unit can store the calculation result in the corresponding register of the matrix operation unit and send a matrix operation completion notification to the processor.
[0178] Step 609: After the processor determines the execution of each computation stage, it returns the computation result of the FFT to the application.
[0179] After receiving the matrix operation completion instruction from the matrix operation unit, the processor can retrieve the result matrix corresponding to the DFT calculation from the register of the matrix operation unit. The data elements included in this result matrix then constitute the output data for the DFT calculation. If it is determined that all stages of the FFT calculation have been completed, the FFT calculation result can be returned to the application program. For example, the application program could be a VASP, and the corresponding calculation result would be the result of the FFT calculation on the initial data of the wavefunction.
[0180] If it is determined that all computational stages of the FFT calculation have not yet been completed, the calculation can continue based on the obtained DFT calculation results, performing the twiddle factor calculation for the current stage, or the calculation for the next stage. For example... Figure 7 As shown, Figure 7 This is a flowchart illustrating the process of the processor and matrix operation unit performing matrix operations according to this application. During matrix operations, the processor can retrieve the input data to be performed on the matrix operation from memory, such as the first input data for FFT calculation. It converts the input data into a data matrix, and then sends a matrix LOAD instruction to the register corresponding to the matrix operation unit to store the data matrix and the calculation matrix (such as the DFT calculation matrix) from memory in the register. For example... Figure 7 Matrix A and Matrix B are the two matrices to be calculated. Since the matrix operation unit performs the matrix calculation as matrix D = matrix A * matrix B + matrix C, matrix C can be set to zero if matrix A * matrix B is required. Then, a matrix operation instruction can be sent to the matrix operation unit to load matrices A, B, and C from the registers, thus performing the operation D = matrix A * matrix B + matrix C. The matrix operation unit can store the calculated result (matrix D) in a register and send a matrix operation completion notification to the processor. The processor can then send a matrix STORE instruction to the register, storing the resulting matrix D in memory. The CPU can load the data elements from matrix D from memory to form the data matrix for the next matrix operation, and then control the matrix operation unit to execute the matrix operation again until the processor determines that it has completed the processing of each stage of the FFT calculation. After the processor determines that it has completed the processing of each stage of the FFT calculation, it can return the FFT calculation result to the application program.
[0181] In this embodiment of the application, during the processor's execution of FFT calculations, DFT calculations in each calculation stage can be converted into matrix operations, and matrix operations can be implemented through a matrix operation unit. In this way, a single matrix operation can complete the DFT calculation for multiple data elements in the first data matrix, improving the efficiency of DFT calculations in each calculation stage, and thus improving the efficiency of FFT calculations.
[0182] In one possible implementation, in step 605 above, the processor converts the input data of the DFT calculation into a first data matrix as follows: based on the arrangement order of the data elements in the input data corresponding to the DFT calculation, a first data matrix of at least one first size is determined from the input data corresponding to the DFT calculation.
[0183] The first data matrix refers to the data matrix used in matrix operations with the DFT calculation matrix. To achieve matrix operations, the first size of the first data matrix can be the same as the size of the DFT calculation matrix. The input data for the DFT calculation can be obtained by sorting the output data from the previous calculation stage or the output data from the rotation factor calculation in the same calculation stage. In the sorted input data for the DFT calculation, the data elements can be arranged according to the order of the DFT units in the DFT calculation. For example, if one DFT unit corresponds to N data elements, then the first N data elements in the input data for the DFT calculation are the data elements corresponding to the first DFT unit, the (N+1)th to (m+1)th elements are the data elements corresponding to the second DFT unit, and the (mN+1)th to (m+1)th data elements are the data elements corresponding to the (m+1)th DFT unit. Sorting the output data from the previous calculation stage or the output data from the rotation factor calculation in the same calculation stage is existing technology and can be implemented using the FFT algorithm; it will not be described in detail here.
[0184] The size of the DFT computation matrix is related to the cardinality of the computation stage. When the cardinality is N, the input data of each DFT unit has N data elements, and the size of the DFT computation matrix is 2N×2N. Separating the real and imaginary parts of the data elements in the input data of a DFT unit yields an input data vector with 2N data elements. Therefore, the input data corresponding to every 2N DFT units in the DFT computation can be sequentially assembled into a 2N×2N first data matrix. If there is a case where the number of DFT units p is less than 2N, the input data vectors of p DFT units can be assembled into a 2N×p matrix, and then zero-padding is used to obtain the 2N×2N first data matrix.
[0185] Taking a 256-point FFT as an example, a 256-point FFT may include four computation stages, each with a base of 4, i.e., 256 = 4 * 4 * 4 * 4. For any DFT computation in any of the four stages, there are 64 4-point DFT units. The DFT computation matrix corresponding to a 4-point DFT unit is an 8×8 matrix. The input of a 4-point DFT unit consists of 4 data elements. After separating the real and imaginary parts of these 4 data elements, a vector with 8 data elements can be formed. In other words, the computation of each 4-point DFT unit can be converted into multiplying an 8×8 DFT computation matrix by an input data vector containing 8 data elements. Since the DFT computation matrices corresponding to the 64 4-point DFT units are identical, the input data vectors corresponding to the 64 DFT units can be sequentially merged into 8 first data matrices.
[0186] This process converts the input data corresponding to the DFT calculation into a first data matrix, and then uses a matrix operation unit to perform matrix multiplication on each first data matrix and the corresponding DFT calculation matrix, thereby improving the efficiency of DFT calculation in each calculation stage.
[0187] In another possible scenario, the processor's determination of the DFT calculation matrix corresponding to the DFT calculation in each calculation stage in step 604 above can also be as follows: The processor can simplify the DFT calculation based on the maximum matrix size supported by the matrix operation unit in a single matrix operation. For example, when the maximum matrix size supported by the matrix operation unit in a single matrix operation is 2N×2N, and the DFT calculation in the calculation stage is an N+1 point DFT calculation, the N+1 point DFT calculation can be simplified to an N point DFT calculation. For example, when the DFT unit is a 5-point DFT, and the maximum matrix size supported by the matrix operation unit in a single matrix operation is 8×8, the 5-point DFT can be transformed into a 4-point DFT for calculation using the Winograd Fast Fourier Transform algorithm. If the 5-point DFT is calculated directly, the matrix operation unit can only split the 10×10 DFT calculation matrix and data matrix corresponding to the 5-point DFT into multiple smaller matrices for calculation. However, if the 5-point DFT is simplified to a 4-point DFT for calculation, the matrix operation unit only needs to perform one matrix operation on the 8×8 matrix to obtain the result data corresponding to the 5-point DFT. The DFT calculation matrix corresponding to the simplified 5-point DFT can be pre-stored by technicians. The data matrix corresponding to this DFT calculation matrix can be obtained using the Nograad Fast Fourier Transform algorithm.
[0188] In this embodiment of the application, during the process of the processor performing FFT calculation, the DFT calculation in each calculation stage of FFT calculation can be converted into matrix operation, and the corresponding matrix operation can be performed through the matrix operation unit, which can improve the calculation efficiency of FFT calculation.
[0189] Figure 8 This is a flowchart illustrating a method for transforming input data for DFT calculations into a first data matrix. This method incorporates a matrix compression algorithm, which uses a processor to compress the matrix composed of the input data, reducing the number of components in the first data matrix and consequently reducing the number of matrix operations. The corresponding processing is as follows:
[0190] Step 801: Obtain the input data for DFT calculation.
[0191] Step 802: Based on the arrangement order of data elements in the input data for DFT calculation, select a first number of data elements from the input data for DFT calculation to form a first matrix of a first size, and determine the sparsity of the first matrix.
[0192] The first number is half the number of data elements included in the first data matrix of the first size.
[0193] After obtaining the first number of data elements, the real and imaginary parts of these data elements can be combined to form a first matrix. After forming the first matrix, its sparsity can be detected. Sparsity can be determined by identifying the proportion of data elements with a value of 0 in each row of the first matrix, and the lowest proportion corresponding to each row is defined as the sparsity of the first matrix.
[0194] Step 803: If the sparsity of the first matrix is less than the preset sparsity threshold, then the first matrix is determined as the first data matrix.
[0195] The sparsity threshold can be preset by technicians; for example, the sparsity threshold could be 50% or 75%. If it is determined that the sparsity of the first matrix is less than the preset sparsity threshold, then matrix compression processing can be omitted, and the first matrix can be directly determined as the first data matrix.
[0196] Step 804: If the sparsity of the first matrix is greater than or equal to the sparsity threshold, then the first matrix is determined as the intermediate matrix.
[0197] Step 805: Compress the intermediate matrix to obtain the second matrix.
[0198] If the sparsity of the first matrix is greater than or equal to a preset sparsity threshold, then the first matrix can be identified as the intermediate matrix, and compression processing is performed on the intermediate matrix. Compression processing refers to removing data elements with values of 0 from the intermediate matrix. For example, if the sparsity index is 50%, then 50% of the 0 values in the first matrix can be removed. If the size of the first matrix is 8×8, then after row-by-row compression, the resulting compressed second matrix will have a size of 4×8.
[0199] Step 806: Based on the arrangement order of the data elements in the input data of the DFT calculation, select a second number of data elements from the unselected data elements in the input data of the DFT calculation and add them to the second matrix to obtain the third matrix of the target size.
[0200] The second number is equal to half the difference between the number of data elements in the first data matrix and the number of data elements in the second matrix. After obtaining the compressed second matrix, data elements can be added to it again. For example, if the compressed second matrix has a size of 5×8 and contains 40 data elements, and the first data matrix has a size of 8×8 and contains 64 data elements, then the second number can be determined to be 12.
[0201] After supplementing the real and imaginary parts of the second number of data elements into the second matrix, a third matrix of the target size can be obtained.
[0202] It should be noted that if the number of unselected data elements in the input data for DFT calculation is less than the second number, all unselected data elements can be added to the second matrix, and the second matrix can be padded with zeros to obtain a fourth matrix with the same size as the first data matrix. The fourth matrix is then used as the first data matrix.
[0203] Step 807: If the sparsity of the third matrix is greater than or equal to the sparsity threshold, then the third matrix is determined as the intermediate matrix and the process proceeds to step 805.
[0204] After forming the third matrix, the sparsity of the third matrix can be detected. If the sparsity of the third matrix is still greater than or equal to the sparsity threshold, it means that the third matrix can be further compressed. Therefore, the third matrix can be used as an intermediate matrix again and the process can be transferred to step 805 to compress the intermediate matrix again.
[0205] Step 808: If the sparsity of the third matrix is less than the sparsity threshold, then the third matrix is determined as the first data matrix.
[0206] If the sparsity of the third matrix is less than the sparsity threshold, then the third matrix can be determined as the first data matrix.
[0207] It should be noted that during the execution of steps 801-808, whenever a first data matrix is determined, if there are still data elements in the DFT calculation that are not included in the first data matrix, then a first number of data elements can be selected again in sequence from the unselected data elements to form a first matrix of a first size, and the process proceeds to step 803. If the number of unselected data elements in the input data for the DFT calculation is less than the first number, then zero-padding can be used to form a fifth matrix identical to the first data matrix, and then the fifth matrix is determined as the first data matrix.
[0208] Furthermore, for the first data matrix obtained after compression, a corresponding position matrix can be generated. This position matrix includes the position information of each data element in the first data matrix within the uncompressed matrix. When performing matrix operations on the compressed first data matrix and the corresponding DFT calculation matrix, the output data matrix obtained after matrix multiplication can be determined based on the position matrix. The DFT calculation result data can then be obtained from the output data matrix.
[0209] When the input data for DFT calculation contains a large number of data elements with a value of 0, matrix compression can be used to reduce the sparsity of the first data matrix, thereby reducing the number of first data matrices and consequently reducing the number of matrix operations performed during DFT calculation, thus improving the efficiency of DFT calculation.
[0210] Figure 9 This is a flowchart of a method for calculating rotation factors through matrix operations provided in an embodiment of this application. See also... Figure 9 The method includes:
[0211] Step 901: The processor determines the rotation factor calculation that satisfies the conditions for matrix operations.
[0212] As can be seen from the above execution principle, when the rotation factor is involved in the rotation factor calculation many times, the rotation factor calculation can be transformed into a matrix operation. Therefore, before executing each calculation stage, the number of times the rotation factor is involved in the rotation factor calculation in each calculation stage can be determined. If the number of times the same rotation factor is involved in the calculation is greater than or equal to the threshold of the first number, it means that the rotation factor calculation satisfies the conditions of matrix operation.
[0213] For example, in the second computation stage of a 256-point FFT implemented based on frequency domain decimation, there are four 64-point DFTs. In each 64-point DFT, 64 different twiddle factors participate in the twiddle factor multiplication operation. However, since there are four 64-point DFTs, a single twiddle factor can participate in four twiddle factor multiplication operations. If the first threshold is set to 4, it can be determined that the twiddle factor calculation in this second computation stage satisfies the matrix operation conditions.
[0214] Step 902: The processor determines the rotation factors that satisfy the conditions for matrix operations and calculates the corresponding rotation factor matrix.
[0215] In one feasible approach, once the number of data elements in the input data is determined, the number of computation stages in the corresponding FFT calculation, the cardinality of each computation stage, and the twist factor are also determined accordingly. Therefore, in practical processing, the correspondence between the number of data elements and the twist factor matrix of each computation stage can be pre-stored. In implementation, after determining the number of data elements in the input data, the twist factor matrix corresponding to the twist factor calculation of each computation stage in the FFT calculation can be determined based on the above correspondence.
[0216] In another feasible approach, after determining the rotation factor calculations that satisfy the conditions for matrix operations, the rotation factors in these calculations can be transformed into rotation factor matrices. Before transforming the rotation factors into rotation factor matrices, the number of rotation factors included in each rotation factor matrix can be determined based on the size of the rotation factor matrices.
[0217] The size of the rotation factor matrix can be preset by the technicians. For example, the size of the rotation factor matrix can be set to the size of the DFT calculation matrix corresponding to the same calculation stage. Alternatively, to improve the efficiency of performing matrix operations on the rotation factor matrix and the corresponding data matrix, the size of the rotation factor matrix can be set to the maximum matrix size supported by the matrix operation unit in a single matrix operation.
[0218] As described in the execution principle above, a twiddle factor can be converted into a 2×2 twiddle factor matrix, which can also be called a unit matrix. When converting multiple twiddle factors into a twiddle factor matrix, the unit matrices corresponding to the multiple twiddle factors can be arranged diagonally and padded with zeros to form a twiddle factor matrix. In this way, N twiddle factors can be converted into a 2N×2N twiddle factor matrix.
[0219] Thus, the target number of rotation factors comprising each rotation factor matrix can be determined based on the set size of the rotation factor matrix. This divides the multiple rotation factors involved in the rotation factor calculation into at least one rotation factor set, with each set containing the target number of rotation factors. Then, the rotation factors in each set can be converted into corresponding unit matrices, and these unit matrices are arranged diagonally and padded with zeros to form the rotation factor matrix.
[0220] Step 903: When performing rotation factor calculation through matrix operations, convert the input data for rotation factor calculation into a data matrix.
[0221] In this context, when the FFT algorithm is implemented based on time-domain decimation, the input data for the twiddle factor calculation is the input data of the computation stage to which the twiddle factor calculation belongs. In this case, the data matrix transformed from the input data for the twiddle factor calculation can be called the second data matrix. When the FFT algorithm is implemented based on frequency-domain decimation, the input data for the twiddle factor calculation is the output data of the DFT calculation in the same computation stage. In this case, the data matrix transformed from the input data for the twiddle factor calculation can be called the third data matrix. To perform matrix operations between the second or third data matrix and the twiddle factor matrix, the second dimension of the second or third data matrix is equal to the dimension of the twiddle factor matrix; that is, the dimension of the second or third data matrix is the same as the dimension of the corresponding twiddle factor matrix.
[0222] For the process of transforming the input data for twitch factor calculation into a second or third data matrix, the data elements that are multiplied by the twitch factors that make up the twitch factor matrix can be obtained from the input data for twitch factor calculation. The second or third data matrix can be constructed sequentially according to the order of the obtained data elements in the input data.
[0223] The following explanation uses the conversion of the input data corresponding to the rotation factor calculation into the second data matrix as an example. The process of converting the input data corresponding to the rotation factor calculation into the third data matrix is the same and will not be repeated here.
[0224] A twiddle factor matrix is composed of one or more unit matrices representing twiddle factors. If each twiddle factor matrix in the twiddle factor calculation is composed of a unit matrix corresponding to a twiddle factor, then the second data matrix corresponding to the twiddle factor matrix can be composed of data elements multiplied with that twiddle factor. Since the size of the twiddle factor matrix is 2×2, a second data matrix of the same size as the twiddle factor matrix can be formed by the real and imaginary parts of two data elements. Therefore, for each twiddle factor matrix, data elements multiplied with the twiddle factors constituting that twiddle factor matrix can be obtained, and the second data matrix can be formed pairwise according to the order of the obtained data elements in the input data.
[0225] If each rotatable matrix in the calculation of the rotatable matrix is composed of multiple element matrices corresponding to rotatable factors, then the second data matrix corresponding to the rotatable matrix can be constructed by multiplying the data elements of the rotatable factors that constitute the rotatable matrix. Assuming the rotatable matrix consists of N rotatable factors, the size of the resulting rotatable matrix is 2N×2N. For any rotatable factor in the rotatable matrix, 2N data elements multiplied by that rotatable factor can be obtained, and then a second data matrix of size 2N×2N can be constructed using the real and imaginary parts of the 2N data elements corresponding to the N rotatable factors.
[0226] Therefore, for each rotation factor matrix, the data elements multiplied by the rotation factors constituting that rotation factor matrix can be obtained. Based on the position of the cell matrix corresponding to each rotation factor within the rotation factor matrix, the positions of the real and imaginary parts of the 2N data elements multiplied by the rotation factor in the resulting second data matrix are determined. For example, if the cell matrix of the rotation factor is in the first two rows of the rotation factor matrix, then the real and imaginary parts of the data elements corresponding to that rotation factor are in the first and second rows of the second data matrix, respectively. The real and imaginary parts of each input data are located in the same column, and the real or imaginary parts of data elements in the same row can be arranged according to the order of the data elements in the input data. If the number of data elements corresponding to the rotation factors is less than 2N, zero-padding can be used to form a second data matrix of size 2N×2N from the data elements corresponding to the rotation factors in the rotation factor matrix.
[0227] For example, the element matrices corresponding to rotation factors W0, W1, W2, and W3 respectively form the following rotation factor matrix:
[0228]
[0229] Where W0.r is the real part of W0, W0.i is the imaginary part of W0, W1.r is the real part of W1, W1.i is the imaginary part of W1, W2.r is the real part of W2, W2.i is the imaginary part of W2, W3.r is the real part of W3, and W3.i is the imaginary part of W3.
[0230] Assuming that the data elements multiplied by each of the rotation factors W0, W1, W2, and W3 comprise eight elements, we can separate the real and imaginary parts of each rotation factor and determine the position of the corresponding data element in the second data matrix based on its position in the rotation factor matrix. For example, if the cell matrix corresponding to rotation factor W0 is in the first and second rows of the rotation factor matrix, then the real and imaginary parts of the data element corresponding to rotation factor W0 can be in the first and second rows of the data matrix, respectively. Therefore, when multiplying the rotation factor matrix and the second data matrix, the real and imaginary parts of the data element corresponding to rotation factor W0 can be multiplied by the cell matrix corresponding to rotation factor W0, respectively. Thus, the second data matrix formed by the above rotation factor matrices is as follows:
[0231]
[0232] Where x0.r-x7.r- is the real part of each data element corresponding to W0, x0.i-x7.i- is the imaginary part of each data element corresponding to W0, and x8.rx 15 .r- represents the real part of each data element corresponding to W1, x8.ix 15 .i- represents the imaginary part of each data element corresponding to W1, x 16 .rx 23 .r- represents the real part of each data element corresponding to W2, x 16 .ix 23 .i- represents the imaginary part of each data element corresponding to W3, x 24 .rx 31 .r- represents the real part of each data element corresponding to W3, x 24 .ix 31 .i- represents the imaginary part of each data element corresponding to W0.
[0233] In one possible scenario, a second or third data matrix can be generated using a matrix compression algorithm, followed by further processing and reference to the above. Figure 8 The processing described herein will not be elaborated upon here. Thus, by compressing the second or third data matrix using a matrix compression algorithm during the formation of the second or third data matrix, the number of resulting second or third data matrices can be reduced, the number of matrix operations can be decreased, and consequently, the efficiency of DFT calculations can be improved.
[0234] Step 904: The processor sends matrix operation instructions to the matrix operation unit.
[0235] After obtaining the data matrix and the rotation factor matrix, the processor can store the data matrix and the rotation factor matrix in the register corresponding to the matrix operation unit, and send matrix operation instructions to the matrix operation unit.
[0236] Step 905: The matrix operation unit performs matrix multiplication calculations between the data matrix and the rotation factor matrix.
[0237] After receiving a matrix operation instruction from the processor, the matrix operation unit can retrieve the second data matrix and the rotation factor matrix from the register, perform matrix multiplication on the data matrix and the rotation factor matrix, and store the result in the register. The processor can then retrieve the stored result from the register to obtain the result of the rotation factor calculation. Further processing can then be performed, such as converting the rotation factor calculation result into the data matrix for the next DFT calculation.
[0238] In this embodiment of the application, during the FFT calculation process performed by the processor, the calculation of the rotation factor in each calculation stage of the FFT calculation can be transformed into matrix operations, and the corresponding matrix operations can be performed through the matrix operation unit, which can improve the computational efficiency of the FFT calculation.
[0239] Figure 10 This application provides a method for combining DFT calculation and twiddle factor calculation, as illustrated in the embodiments of this application. See [link to relevant documentation]. Figure 10 The method includes:
[0240] Step 1001: The processor determines whether there is a target computation stage in each computation stage that meets the conditions for merging computations.
[0241] If, in a computational phase, the twitch factor calculation involves only one matrix multiplication with a third data matrix, and the DFT calculation involves only one DFT calculation matrix multiplied with a first data matrix, then this computational phase can be calculated using the following formula:
[0242] Output data matrix = Twist factor matrix * DFT calculation matrix * First data matrix
[0243] For the above formula, we can first calculate "rotation factor matrix * DFT calculation matrix". The corresponding calculation result can be called the merged calculation matrix or the butterfly calculation matrix. Therefore, for the calculation stage to which this rotation factor calculation belongs, it can be calculated using the following two-step formula:
[0244] Butterfly knot calculation matrix = twitch factor matrix * DFT calculation matrix
[0245] Output data matrix = Butterfly knot calculation matrix * First data matrix
[0246] If multiple twitch factor matrices are involved in the matrix operations during twitch factor calculation, then multiple butterfly calculation matrices need to be calculated in the corresponding calculation stage, and multiple output data matrices need to be calculated based on these butterfly calculation matrices. Assuming there are N twitch factor matrices involved in the matrix operations, then N butterfly calculation matrices and N output data matrices need to be calculated. This requires 2N matrix multiplications. However, if the N twitch factor matrices involved in the matrix operations are identical, and since there is only one DFT matrix in each calculation stage, then the calculation of the butterfly calculation matrix only needs to be performed once. Then, based on the obtained butterfly calculation matrix and the N first data matrices, N output data matrices are calculated. This requires only N+1 matrix operations. If m twitch factor matrices among the N twitch factor matrices involved in the matrix operations each participate in q matrix operations, where N = m * q, then only q butterfly calculation matrices need to be calculated, and then N output data matrices are calculated based on the q butterfly calculation matrices. This requires only N+q matrix operations.
[0247] Clearly, the more times the same twitch factor matrix participates in matrix operations, the more efficient the FFT execution becomes. By first calculating the butterfly calculation matrix and then merging the DFT and twitch factor calculations in the corresponding calculation stages, the number of matrix operations required in the same calculation stage can be reduced, thus improving the efficiency of FFT execution. Therefore, before starting each calculation stage, the number of times the same twitch factor matrix corresponding to the twitch factor calculation participates in matrix operations in each calculation stage can be determined. If the number of times the same twitch factor matrix needs to participate in matrix operations exceeds a preset second threshold, then the calculation stage can be determined to meet the merging calculation condition.
[0248] The number of times a twiddle factor matrix participates in matrix operations can be determined based on the number of times the same twiddle factor participates in multiplication operations during the corresponding twiddle factor calculation and the size of the twiddle factor matrix. If the number of times a twiddle factor participates in multiplication operations is X, and the size of the twiddle factor matrix is Y×Y, then the number of times the twiddle factor matrix participates in matrix operations can be Y / X. It should be noted that the prerequisite for merging twiddle factor calculation and DFT calculation is that the twiddle factor matrix and the DFT calculation matrix have the same matrix size in the same calculation stage.
[0249] Step 1002: The processor sends matrix operation instructions to the matrix operation unit.
[0250] After determining the target computation stage that meets the conditions for merging computation, the processor can store the DFT computation matrix and rotation factor matrix corresponding to the target computation matrix into the registers of the matrix operation unit, and send matrix operation instructions to the matrix operation unit.
[0251] Step 1003: The matrix operation unit performs matrix multiplication on the DFT calculation matrix and the rotation factor matrix to obtain the merged calculation matrix corresponding to the target calculation stage.
[0252] After receiving a matrix operation instruction, the matrix operation unit can obtain the DFT calculation matrix and the rotation factor matrix from the register, and perform matrix multiplication on the DFT calculation matrix and the rotation factor matrix to obtain the merged calculation matrix corresponding to the target calculation stage.
[0253] Step 1004: The matrix operation unit sends a matrix operation completion notification to the processor.
[0254] After calculating the merged matrix, the matrix operation unit can store the merged matrix in a register and send a matrix operation completion notification to the processor.
[0255] Steps 1003 and 1004 can be performed multiple times to obtain at least one merged computation matrix in the target computation stage.
[0256] Step 1005: The processor determines the first data matrix corresponding to the target calculation stage.
[0257] When the processor executes the target calculation stage, it can directly convert the input data of the target calculation stage into a first data matrix. Then, it can perform matrix multiplication between the first data matrix and the merged calculation matrix to merge the DFT calculation and the twiddle factor calculation, thereby obtaining the output data of the target calculation stage.
[0258] Specifically, the method described above for generating the second or third data matrix corresponding to the rotation factor matrix can be used to generate the first data matrix corresponding to the merged calculation matrix in the target calculation stage.
[0259] Step 1006: The processor sends matrix operation instructions to the matrix operation unit.
[0260] After obtaining the first data matrix and the rotation factor matrix, the processor can store the first data matrix and the merge calculation matrix into the memory, and send matrix operation instructions to the matrix operation unit.
[0261] Step 1007: The matrix operation unit performs matrix multiplication calculations between the first data matrix and the merged calculation matrix.
[0262] After receiving a matrix operation instruction from the processor, the matrix operation unit can retrieve a first data matrix and a merge calculation matrix from the register, perform matrix multiplication on the first data matrix and the merge calculation matrix, and store the calculation result in the register. The processor can then retrieve the calculation result stored in the register to obtain the result of the merge calculation. Further processing can then be performed, such as converting the result of the merge calculation into input data for the next calculation stage.
[0263] In this embodiment, during the FFT calculation performed by the processor, the DFT calculation and twiddle factor calculation in each stage of the FFT calculation are combined using matrices, which reduces the number of matrix operations and thus improves the computational efficiency of the FFT calculation. It should be understood that the methods for performing FFT provided in this embodiment are also applicable to the Inverse Fast Fourier Transform (IFFT). The implementation principle and calculation process of IFFT calculation are consistent with those of FFT calculation and will not be repeated in this application.
[0264] Based on the same technical concept, this application also provides an apparatus for performing FFT, which can be the computer device in the above embodiments, see [link to previous document]. Figure 11 The device includes:
[0265] The receiving module 1110 is used to receive the Fast Fourier Transform (FFT) execution request sent by the application; specifically, it can implement the receiving function mentioned above, as well as other implicit steps.
[0266] The acquisition module 1120 is used to acquire the first input data for which FFT calculation needs to be performed as indicated by the FFT execution request; specifically, it can implement the acquisition function mentioned above, as well as other implicit steps.
[0267] The decomposition module 1130 is used to decompose the FFT calculation into multiple calculation stages according to the cardinality of the FFT calculation. The input data of the first calculation stage in the multiple calculation stages is the first input data, the input data of the second calculation stage after the first calculation stage is the output data of the previous calculation stage of the second calculation stage, and the third calculation stage in the multiple calculation stages includes DFT calculation, wherein the third calculation stage is any one of the multiple calculation stages; specifically, it can implement the decomposition function mentioned above, as well as other implicit steps.
[0268] The determination module 1140 is used to determine the DFT calculation matrix corresponding to the DFT calculation in the third calculation stage; specifically, it can implement the determination function mentioned above, as well as other implicit steps.
[0269] The execution module 1150 is used to determine the first data matrix for matrix operation with the DFT calculation matrix based on the input data of the third calculation stage when performing the calculation in the third calculation stage; specifically, it can implement the execution function mentioned above, as well as other implicit steps.
[0270] The calculation module 1160 is used to perform DFT calculation by performing matrix multiplication on the DFT calculation matrix and the first data matrix, and return the calculation result to the application after multiple calculation stages are completed; specifically, it can implement the calculation functions mentioned above, as well as other implicit steps.
[0271] In one possible implementation, the determining module 1140 is used to: determine the DFT calculation matrix corresponding to the DFT calculation in the third calculation stage based on the cardinality corresponding to the third calculation stage and the preset correspondence between the cardinality and the DFT calculation matrix.
[0272] In one possible implementation, the determining module 1140 is used to: convert the DFT coefficients corresponding to the DFT calculation in the third calculation stage into a DFT calculation matrix.
[0273] In one possible implementation, the calculation module 1160 is used to: calculate the corresponding rotation factor based on the rotation factor in the third calculation stage of the data matrix and the input data of the third calculation stage of the data matrix, perform data matrix rotation factor calculation, and obtain the input data for data matrix DFT calculation;
[0274] The execution module 1150 is used to: convert the input data of the data matrix DFT calculation into a first data matrix that performs matrix operations with the data matrix DFT calculation matrix.
[0275] In one possible implementation, the execution module 1150 is configured to: determine the rotation factor matrix corresponding to each rotation factor in the data matrix rotation factor calculation if the number of times the same rotation factor is involved in the calculation is greater than or equal to the first number threshold; and convert the input data of the third calculation stage of the data matrix into a second data matrix.
[0276] The calculation module 1160 is used to: calculate the rotation factor of the data matrix by performing matrix multiplication on the rotation factor matrix and the second data matrix to obtain the first data matrix.
[0277] In one possible implementation, the third calculation stage also includes rotation factor calculation, and the first data matrix is a matrix transformed from the input data of the third calculation stage of the data matrix.
[0278] The execution module 1150 is further configured to: if the number of times a same rotation factor participates in the calculation in the data matrix rotation factor calculation is greater than or equal to a first number threshold, determine a rotation factor matrix corresponding to each rotation factor in the data matrix rotation factor calculation;
[0279] The calculation module 1160 is configured to: perform matrix multiplication calculation on a third data matrix obtained by performing DFT calculation on the data matrix and the data matrix rotation factor matrix to implement the data matrix rotation factor calculation.
[0280] In a possible implementation, the third calculation stage of the data matrix further includes rotation factor calculation;
[0281] The execution module 1150 is configured to: determine a rotation factor matrix corresponding to each rotation factor in the data matrix rotation factor calculation; and if it is determined that the data matrix rotation factor matrix and the data matrix DFT calculation matrix satisfy a matrix combination condition, multiply the data matrix rotation factor matrix and the data matrix DFT calculation matrix to obtain a combined calculation matrix;
[0282] The calculation module 1160 is configured to: perform matrix multiplication calculation on the data matrix combined calculation matrix and the first data matrix of the data matrix.
[0283] In a possible implementation, the third calculation stage of the data matrix corresponds to a radix M, the number of input data of the third calculation stage of the data matrix is N, the third calculation stage of the data matrix is divided into N / M butterfly units according to the radix M of the data matrix, each butterfly unit includes at least one rotation factor, where M<N, and M and N are natural numbers;
[0284] The execution module 1150 is configured to: convert the rotation factors of the N / M butterfly units of the data matrix into a rotation factor matrix.
[0285] In a possible implementation, the execution module 1150 is configured to:
[0286] determine at least one rotation factor set according to the rotation factors of the N / M butterfly units of the data matrix, where the number of rotation factors included in the at least one rotation factor set of the data matrix is the same; and for each rotation factor set of the data matrix, construct a rotation factor matrix based on the rotation factors in the rotation factor set of the data matrix.
[0287] In a possible implementation, the above matrix multiplication calculation is performed by a matrix operation unit.
[0288] It should be noted that the above-mentioned receiving module 1110, acquiring module 1120, decomposition module 1130, determining module 1140, and execution module 1150 can be implemented by a processor, or by a processor in conjunction with a memory. The calculation module 1160 can be implemented by a matrix operation unit, or by a matrix operation unit in conjunction with a memory.
[0289] In this embodiment, after receiving an FFT execution request from the application, the processor can decompose the FFT calculation into multiple calculation stages based on the cardinality of the FFT calculation, and determine the DFT calculation matrix for each calculation stage. During DFT calculation, matrix multiplication can be performed on the first data matrix and the DFT calculation matrix by the matrix operation unit, thereby realizing the DFT calculation. In this way, the DFT calculation in each calculation stage is transformed into matrix operations, which can be implemented by the matrix operation unit. A single matrix operation can complete the DFT calculation for multiple data elements in the first data matrix, improving the efficiency of executing DFT calculations in each calculation stage, and thus improving the efficiency of FFT calculation.
[0290] It should be noted that the FFT execution apparatus provided in the above embodiments is only illustrated by the division of the above functional modules. In practical applications, the above functions can be assigned to different functional modules as needed. That is, the internal structure of the FFT execution apparatus can be divided into different functional modules to complete all or part of the functions described above. Furthermore, the FFT execution apparatus and the FFT execution method embodiments provided in the above embodiments belong to the same concept, and their specific implementation process can be found in the method embodiments, which will not be repeated here.
[0291] In the above embodiments, implementation can be achieved entirely or partially through software, hardware, firmware, or any combination thereof. When implemented using software, it can be implemented entirely or partially in the form of a computer program product. The computer program product includes one or more computer instructions. When these computer program instructions are loaded and executed on a device, they generate, in whole or in part, the processes or functions described in the embodiments of this application. The computer instructions can be stored in a computer-readable storage medium or transmitted from one computer-readable storage medium to another. For example, the computer instructions can be transmitted from one website, computer, server, or data center to another website, computer, server, or data center via wired (e.g., coaxial cable, fiber optic cable, digital subscriber line) or wireless (e.g., infrared, wireless, microwave, etc.) means. The computer-readable storage medium can be any available medium accessible to the device or a data storage device such as a server or data center that integrates one or more available media. The available medium can be a magnetic medium (e.g., floppy disk, hard disk, and magnetic tape), an optical medium (e.g., Digital Video Disk (DVD), etc.), or a semiconductor medium (e.g., solid-state drive, etc.).
[0292] Those skilled in the art will understand that all or part of the steps of the above embodiments can be implemented by hardware or by a program instructing related hardware. The program can be stored in a computer-readable storage medium, such as a read-only memory, a disk, or an optical disk.
[0293] In this embodiment of the application, a computer program product is also provided, which includes a computer program stored in a computer-readable storage medium. The computer program is loaded by a processor to implement the above-described method for performing FFT, or to implement the functions of the above-described apparatus for performing FFT.
[0294] The above description is merely one embodiment of this application and is not intended to limit this application. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of this application should be included within the protection scope of this application.
Claims
1. A method for performing an FFT, characterized in that, The method includes: The processor receives the Fast Fourier Transform (FFT) execution request sent by the application. The processor acquires the first input data indicating that an FFT calculation needs to be performed, as indicated by the FFT execution request; The processor decomposes the FFT calculation into multiple calculation stages based on the radix of the FFT calculation. The input data of the first calculation stage in the multiple calculation stages is the first input data. The input data of the second calculation stage after the first calculation stage is the output data of the previous calculation stage of the second calculation stage. The third calculation stage in the multiple calculation stages includes DFT calculation. The third calculation stage is any one of the multiple calculation stages. The DFT calculation is the complex addition corresponding to the butterfly knot in the third calculation stage. The processor determines the DFT calculation matrix corresponding to the DFT calculation in the third calculation stage, wherein the determined DFT calculation matrix is stored in memory; When the processor performs the calculation in the third calculation stage, it determines a first data matrix for matrix operation with the DFT calculation matrix based on the input data corresponding to the multiple butterfly junctions in the third calculation stage, wherein the determined first data matrix is stored in the memory; The processor, according to the matrix LOAD instruction, stores the DFT calculation matrix and the first data matrix stored in the memory into the register corresponding to the matrix operation unit, and sends a matrix operation instruction to the matrix operation unit to control the matrix operation unit to perform matrix multiplication calculation on the DFT calculation matrix and the first data matrix stored in the register to realize the DFT calculation; After the processor has completed the execution of the multiple calculation stages, it returns the calculation result of the last calculation stage to the application.
2. The method according to claim 1, characterized in that, Determining the DFT calculation matrix corresponding to the DFT calculation in the third calculation stage includes: Based on the cardinality corresponding to the third calculation stage and the preset correspondence between the cardinality and the DFT calculation matrix, the DFT calculation matrix corresponding to the DFT calculation in the third calculation stage is determined.
3. The method according to claim 1, characterized in that, Determining the DFT calculation matrix corresponding to the DFT calculation in the third calculation stage includes: The DFT coefficients corresponding to the DFT calculation in the third calculation stage are converted into a DFT calculation matrix.
4. The method according to claim 1, characterized in that, The third calculation stage also includes rotation factor calculation; The step of determining the first data matrix for matrix operations with the DFT calculation matrix based on the input data corresponding to the multiple butterfly knots in the third calculation stage includes: Based on the rotation factor calculated in the third calculation stage and the input data corresponding to the multiple butterfly knots in the third calculation stage, the rotation factor calculation is performed to obtain the input data for the DFT calculation. The input data for the DFT calculation is converted into a first data matrix that performs matrix operations with the DFT calculation matrix.
5. The method according to claim 4, characterized in that, The performing the twiddle factor calculation according to the twiddle factor corresponding to the twiddle factor calculation in the third calculation stage and the input data respectively corresponding to the plurality of butterfly units in the third calculation stage comprises: If the number of times a same twiddle factor participates in the calculation in the twiddle factor calculation is greater than or equal to a first number threshold, determining a twiddle factor matrix corresponding to each twiddle factor in the twiddle factor calculation; converting the input data respectively corresponding to the plurality of butterfly units in the third calculation stage into a second data matrix; performing matrix multiplication calculation on the twiddle factor matrix and the second data matrix to implement the twiddle factor calculation, so as to obtain the first data matrix.
6. The method according to claim 1, characterized in that, The third calculation stage further comprises twiddle factor calculation, wherein the first data matrix is a matrix converted from the input data of the third calculation stage; After implementing the DFT calculation by performing matrix multiplication calculation on the DFT calculation matrix stored in the register and the first data matrix, the method further comprises: If the number of times a same twiddle factor participates in the calculation in the twiddle factor calculation is greater than or equal to a first number threshold, determining a twiddle factor matrix corresponding to each twiddle factor in the twiddle factor calculation; performing matrix multiplication calculation on a third data matrix obtained by performing the DFT calculation and the twiddle factor matrix to implement the twiddle factor calculation.
7. The method according to claim 1, characterized in that, The third calculation stage further comprises twiddle factor calculation; The implementing the DFT calculation by performing matrix multiplication calculation on the DFT calculation matrix stored in the register and the first data matrix comprises: determining a twiddle factor matrix corresponding to each twiddle factor in the twiddle factor calculation; If it is determined that the twiddle factor matrix and the DFT calculation matrix satisfy a matrix merging condition, multiplying the twiddle factor matrix and the DFT calculation matrix to obtain a merged calculation matrix; performing matrix multiplication calculation on the merged calculation matrix and the first data matrix.
8. The method according to any one of claims 5-7, characterized in that, The third calculation stage corresponds to a radix M, the number of input data of the third calculation stage is N, the third calculation stage is divided into N / M butterfly units according to the radix M, each butterfly unit comprises at least one twiddle factor, wherein M<N, and M and N are natural numbers; The determining a twiddle factor matrix corresponding to each twiddle factor in the twiddle factor calculation comprises: converting the twiddle factors of the N / M butterfly units into a twiddle factor matrix.
9. The method according to claim 8, characterized in that, The converting the twiddle factors of the N / M butterfly units into a twiddle factor matrix comprises: determining at least one twiddle factor set according to the twiddle factors of the N / M butterfly units, wherein the number of twiddle factors comprised in the at least one twiddle factor set is the same; for each twiddle factor set, constructing a twiddle factor matrix based on the twiddle factors in the twiddle factor set.
10. An apparatus for performing an FFT, characterized in that, The apparatus is configured in a processor, and the apparatus comprises: a receiving module, configured to receive an execution request for Fast Fourier Transform (FFT) sent by an application program; an obtaining module, configured to obtain first input data that is indicated by the FFT execution request and needs to be subjected to FFT calculation. The decomposition module is used to decompose the FFT calculation into multiple calculation stages according to the cardinality of the FFT calculation. The input data of the first calculation stage in the multiple calculation stages is the first input data. The input data of the second calculation stage after the first calculation stage is the output data of the previous calculation stage of the second calculation stage. The third calculation stage in the multiple calculation stages includes DFT calculation. The third calculation stage is any one of the multiple calculation stages. The DFT calculation is the complex addition corresponding to the butterfly knot in the third calculation stage. The determination module is used to determine the DFT calculation matrix corresponding to the DFT calculation in the third calculation stage; The execution module is used to determine a first data matrix for matrix operation with the DFT calculation matrix based on the input data corresponding to the multiple butterfly knots in the third calculation stage when performing the calculation in the third calculation stage. The calculation module is used to store the DFT calculation matrix and the first data matrix stored in memory into the register corresponding to the matrix operation unit according to the matrix LOAD instruction, and send matrix operation instructions to the matrix operation unit to control the matrix operation unit to perform matrix multiplication calculation on the DFT calculation matrix and the first data matrix stored in the register to realize the DFT calculation. After all the multiple calculation stages are completed, the calculation result of the last calculation stage among the multiple calculation stages is returned to the application.
11. The apparatus according to claim 10, characterized in that, The determining module is used for: Based on the cardinality corresponding to the third calculation stage and the preset correspondence between the cardinality and the DFT calculation matrix, the DFT calculation matrix corresponding to the DFT calculation in the third calculation stage is determined.
12. The apparatus according to claim 10, characterized in that, The determining module is used for: The DFT coefficients corresponding to the DFT calculation in the third calculation stage are converted into a DFT calculation matrix.
13. The apparatus according to claim 10, characterized in that, The computing module is used for: Based on the rotation factor calculated in the third calculation stage and the input data corresponding to the multiple butterfly knots in the third calculation stage, the rotation factor calculation is performed to obtain the input data for the DFT calculation. The execution module is configured to: convert the input data of the DFT calculation into a first data matrix that performs matrix operations with the DFT calculation matrix.
14. The apparatus according to claim 13, characterized in that, The execution module is used for: If the number of times the same rotation factor is involved in the calculation of the rotation factor is greater than or equal to the first number threshold, then the rotation factor matrix corresponding to each rotation factor in the calculation of the rotation factor is determined; the input data corresponding to the multiple butterfly knots in the third calculation stage are converted into a second data matrix. The calculation module is used to: perform matrix multiplication on the rotation factor matrix and the second data matrix to calculate the rotation factor, so as to obtain the first data matrix.
15. The apparatus according to claim 10, characterized in that, The third calculation stage also includes rotation factor calculation, and the first data matrix is a matrix transformed based on the input data of the third calculation stage; the execution module is further configured to: if the number of times that the same twiddle factor participates in the calculation in the twiddle factor calculation is greater than or equal to a first number threshold, determine a twiddle factor matrix corresponding to each twiddle factor in the twiddle factor calculation; the calculation module is configured to: perform matrix multiplication calculation on a third data matrix obtained by performing the DFT calculation and the twiddle factor matrix to implement the twiddle factor calculation.
16. The apparatus according to claim 10, characterized in that, the third calculation phase further comprises twiddle factor calculation; the execution module is configured to: determine a twiddle factor matrix corresponding to each twiddle factor in the twiddle factor calculation; if it is determined that the twiddle factor matrix and the DFT calculation matrix satisfy a matrix merging condition, multiply the twiddle factor matrix and the DFT calculation matrix to obtain a merged calculation matrix; the calculation module is configured to: perform matrix multiplication calculation on the merged calculation matrix and the first data matrix.
17. The apparatus according to any one of claims 14-16, characterized in that, the third calculation phase corresponds to a radix M, the number of input data of the third calculation phase is N, the third calculation phase is divided into N / M butterfly units according to the radix M, each butterfly unit comprises at least one twiddle factor, wherein M<N, and M and N are natural numbers; the execution module is configured to: convert the twiddle factors of the N / M butterfly units into a twiddle factor matrix.
18. The apparatus according to claim 17, characterized in that, the execution module is configured to: determine at least one twiddle factor set according to the twiddle factors of the N / M butterfly units, wherein the number of twiddle factors comprised in the at least one twiddle factor set is the same; for each twiddle factor set, construct a twiddle factor matrix based on the twiddle factors in the twiddle factor set.
19. A computer device for performing FFT, characterized in that, the computer device comprises a processor and a matrix operation unit, wherein: the processor is configured to perform the method according to any one of claims 1 to 9; the matrix operation unit is configured to perform the matrix multiplication calculation.
20. A computer-readable storage medium, characterized in that, the computer-readable storage medium stores computer program code, which, when executed by a computer device, causes the computer device to perform the method according to any one of claims 1 to 9.
21. A computer program product containing instructions, characterized in that, when the computer program product runs on a computer device, the computer program product causes the computer device to perform the method according to any one of claims 1 to 9.
Citation Information
Patent Citations
System and method for performing a fast fourier transform using a matrix-vector multiply instruction
US6366937B1