Calculation sequence sorting method and device and calculation equipment

By using matrix computing units in the processor to transpose and sort the computed sequences, the problem of low sorting efficiency in the prior art is solved, and more efficient computed sequence sorting and FFT calculation are realized.

CN120179969APending Publication Date: 2025-06-20HUAWEI TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202311767624.1
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2023-12-20
Publication Date
2025-06-20

AI Technical Summary

Technical Problem

In the prior art, the sorting method for calculating sequences is inefficient, and the calculation sequence is required to access discontinuously, resulting in low sorting efficiency, which in turn affects the efficiency of FFT calculation.

Method used

By setting up a matrix operation unit in the processor, transpose the multidimensional array using matrix multiplication, thereby sorting the calculation sequence. The specific steps include converting the calculation sequence into a multidimensional array, determining the permutation matrix, and transposing it through matrix multiplication operation to obtain the sorted calculation sequence.

Benefits of technology

Discontinuous access to the calculation sequence is avoided, sorting efficiency is improved, and thus the efficiency of the processor to perform FFT calculations.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120179969A_ABST
    Figure CN120179969A_ABST
Patent Text Reader

Abstract

The embodiment of the invention belongs to the technical field of computing, and particularly relates to a computing sequence sorting method and device and computing equipment. The sorting method of the calculation sequences comprises the steps that the calculation sequences are obtained, the calculation sequences are converted into a first multi-dimensional array, and all levels of dimensions of the first multi-dimensional array are bases of all calculation stages in FFT calculation. And determining a plurality of permutation matrixes for transposing the first multi-dimensional array, transposing the first multi-dimensional array into a second multi-dimensional array based on the plurality of permutation matrixes, the order of each level of dimension of the second multi-dimensional array being opposite to the order of each level of dimension of the first multi-dimensional array. And determining the elements arranged in sequence in the second multi-dimensional array as a sequence after the calculation sequence is sequenced. By adopting the method and the device, the sorting of the calculation sequence can be converted into transposition processing of the multi-dimensional array, so that the sorting of the calculation sequence can be realized through matrix multiplication, the discontinuous reading of the calculation sequence is avoided, and the sorting efficiency of the calculation sequence can be improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of computer technology, and in particular, to a method, apparatus, and computing device for sorting a computing sequence. Background Art

[0002] The Fast Fourier Transform (FFT) is an efficient algorithm for implementing the Discrete Fourier Transform (DFT).

[0003] During the execution of FFT calculations, it is necessary to sort the computing sequence (input sequence or output sequence) of the FFT calculation. For example, when implementing FFT calculations based on time-domain decimation, it is necessary to sort the input sequence of the FFT calculation, while when implementing FFT calculations based on frequency-domain decimation, it is not necessary to sort the input sequence of the FFT calculation.

[0004] Currently, the method for sorting the computing sequence is to determine the order of each element in the computing sequence in the sorted sequence, read the elements in the computing sequence in the determined order in turn, and store the elements read in turn into the memory, thereby obtaining the sorted sequence. Such a sorting method requires non-continuous reading of the elements in the computing sequence, resulting in low sorting efficiency. Summary of the Invention

[0005] Embodiments of this application provide a method, apparatus, and computing device for sorting a computing sequence, which can improve the sorting efficiency of the computing sequence in FFT calculations, and thus improve the efficiency of executing FFT calculations. The corresponding technical solutions are as follows:

[0006] In a first aspect, a method for sorting a computing sequence is provided. The method can be executed by a processor, and a matrix operation unit can be set in the processor for transposing a multi-dimensional array by performing matrix multiplication. The method includes: in response to a sorting request corresponding to the computing sequence of a Fast Fourier Transform (FFT) calculation, obtaining the computing sequence; converting the computing sequence into a first multi-dimensional array, where each level of dimension of the first multi-dimensional array is the base of each calculation stage in the FFT calculation; determining a plurality of permutation matrices for transposing the first multi-dimensional array, and based on the plurality of permutation matrices, transposing the first multi-dimensional array into a second multi-dimensional array, where the order of each level of dimension of the second multi-dimensional array is opposite to the order of each level of dimension of the first multi-dimensional array; and determining the elements arranged in order in the second multi-dimensional array as the sorted sequence of the computing sequence.

[0007] In the solution shown in this application, a matrix multiplication operation can be performed on a multi-dimensional array composed of a calculation sequence and a permutation matrix through a matrix operation unit to achieve the sorting of the calculation sequence in the FFT calculation. In this way, discontinuous access to the calculation sequence can be avoided, the sorting efficiency of the calculation sequence can be improved, and further the efficiency of the processor executing the FFT calculation can be improved.

[0008] In an implementable manner, determining multiple permutation matrices for transposing a first multi-dimensional array, and based on the multiple permutation matrices, transposing the first multi-dimensional array into a second multi-dimensional array includes: determining a first permutation matrix for transposing the current first multi-dimensional array, and based on the first permutation matrix, transposing the current first multi-dimensional array to obtain the first multi-dimensional array after transposition, where the first permutation matrix is used to transpose the (n + 2)-th last level dimension of the current first multi-dimensional array to the last level dimension, where n is the number of times the current first multi-dimensional array has been transposed. When the first multi-dimensional array after transposition does not meet the end condition, go to execute determining the first permutation matrix for transposing the current first multi-dimensional array, and the end condition means that the order of each level dimension of the first multi-dimensional array after transposition is opposite to the order of each level dimension of the first multi-dimensional array that has not been transposed. When the first multi-dimensional array after transposition meets the end condition, determine the first multi-dimensional array after transposition as the second multi-dimensional array.

[0009] In the solution shown in this application, the first permutation matrix is one of the multiple permutation matrices, and the current first multi-dimensional array can be the first multi-dimensional array that has not been transposed, or the first multi-dimensional array that has been transposed one or more times. Among them, before the current first multi-dimensional array is operated with each first permutation matrix, it can be converted into the form of a matrix. After the current first multi-dimensional array is operated with each first permutation matrix, the obtained matrix can be converted back into the form of a multi-dimensional array. The multi-dimensional array after this conversion is the multi-dimensional array obtained by transposing the current first multi-dimensional array through the first permutation matrix. It can be seen that this application can achieve the sorting of the calculation sequence through the operation of multiple first permutation matrices and the first multi-dimensional array, and can improve the sorting efficiency of the calculation sequence.

[0010] In an implementable manner, the above method further includes: converting the current first multi-dimensional array into a third multi-dimensional array, where the first-level dimension of the third multi-dimensional array is equal to the product of the first-level dimension to the penultimate n + 3-level dimensions in the current first multi-dimensional array, the product of the second-level dimension to the s-level dimension of the third multi-dimensional array is equal to the penultimate n + 2-level dimension in the current first multi-dimensional array, the product of the s + 1-level dimension to the s + t-level dimension of the third multi-dimensional array is equal to the product of the penultimate n + 1-level dimension to the last-level dimensions, and the difference between the product of any two dimensions from the second-level dimension to the s + t-level dimension of the third multi-dimensional array and the maximum calculation size supported by the matrix operation unit for performing the transpose processing is less than the difference threshold.

[0011] Wherein, the maximum calculation size supported by the matrix operation unit refers to the maximum size of the matrix that the matrix operation unit can support during one matrix multiplication operation. For example, if the matrix operation unit can perform matrix multiplication operations on two 8*8 matrices at most each time, then the maximum calculation size is 8. In the solution shown in this application, the dimensions of the first multi-dimensional array can be converted and split according to the maximum calculation size supported by the matrix operation unit to obtain the third multi-dimensional array. In this way, before transposing the third multi-dimensional array, the matrix calculation unit can convert the third multi-dimensional array into a matrix suitable for the matrix calculation unit's operation according to the dimensions of the third multi-dimensional array, thereby improving the efficiency of the matrix calculation unit in transposing the third multi-dimensional array and further improving the sorting efficiency of the calculation sequence.

[0012] Correspondingly, determining the first permutation matrix for transposing the current first multi-dimensional array and transposing the current first multi-dimensional array based on the first permutation matrix to obtain the transposed first multi-dimensional array includes: determining multiple second permutation matrices for transposing the third multi-dimensional array, and based on the multiple second permutation matrices, sequentially exchanging the orders of two adjacent levels of dimensions in the third multi-dimensional array until the second-level dimension to the s-level dimension in the third multi-dimensional array are transposed after the s + t-level dimension, thereby obtaining the transposed first multi-dimensional array.

[0013] In an implementable manner, determining multiple second permutation matrices for transposing the third multi-dimensional array and sequentially exchanging the orders of two adjacent levels of dimensions in the third multi-dimensional array based on the multiple second permutation matrices includes: determining two adjacent levels of dimensions in the current third multi-dimensional array that need to have their orders exchanged. Based on the two adjacent levels of dimensions, determining the second permutation matrix for transposing the current third multi-dimensional array. Based on the determined second permutation matrix, transposing the current third multi-dimensional array to obtain the third multi-dimensional array with the orders of the two adjacent levels of dimensions exchanged.

[0014] In an implementable manner, determining a second permutation matrix for transposing a current third multi-dimensional array based on the two adjacent levels of dimensions includes: when the s-th level dimension and the (s + t)-th level dimension in the third multi-dimensional array that has not been transposed are the two adjacent levels of dimensions, determining that the first parameter of the second permutation matrix is the product of the s-th level dimension and the (s + t)-th level dimension, and the second parameter of the second permutation matrix is the s-th level dimension, where the first parameter is used to indicate the size of the second permutation matrix, and the second parameter is used to indicate the number of columns of the matrix transposed by the second permutation matrix; obtaining the second permutation matrix based on the first parameter and the second parameter.

[0015] Correspondingly, based on the determined second permutation matrix, transposing the current third multi-dimensional array to obtain a third multi-dimensional array with the two adjacent levels of dimensions in the current third multi-dimensional array swapped in order includes: converting the current third multi-dimensional array into a first matrix, where the number of rows of the first matrix is equal to the quotient of the length of the calculation sequence and the first parameter, and the number of columns of the first matrix is equal to the first parameter. Transposing the first matrix based on the determined second permutation matrix to obtain a third multi-dimensional array with the two adjacent levels of dimensions swapped in order.

[0016] In an implementable manner, determining a second permutation matrix for transposing a current third multi-dimensional array based on the two adjacent levels of dimensions includes: when the product of the dimensions at each level after the two adjacent levels of dimensions is less than a preset dimension threshold, determining that the first parameter of the second permutation matrix is the product of the two adjacent levels of dimensions, and the second parameter of the second permutation matrix is the dimension that comes first among the two adjacent levels of dimensions, where the first parameter is used to indicate the size of the second permutation matrix, and the second parameter is used to indicate the number of columns of the matrix transposed by the second permutation matrix. Obtaining the second permutation matrix based on the first parameter and the second parameter.

[0017] Correspondingly, based on the determined second permutation matrix, transposing the current third multi-dimensional array to obtain a third multi-dimensional array with the two adjacent levels of dimensions swapped in order includes: converting the current third multi-dimensional array into a second matrix, where the number of rows of the second matrix is equal to the quotient of the length of the calculation sequence and the first value, the first value is equal to the product of the two adjacent levels of dimensions and the corresponding dimensions at each subsequent level, and the number of columns of the second matrix is equal to the first value. Transposing the second matrix based on the determined second permutation matrix and the identity matrix of the first size to obtain a third multi-dimensional array with the two adjacent levels of dimensions swapped in order, where the first size is equal to the product of the dimensions at each level after the two adjacent levels of dimensions.

[0018] In an implementable manner, determining a second permutation matrix for transposing a current third multi-dimensional array based on the adjacent two-level dimensions includes: when the product of the dimensions at all levels after the adjacent two-level dimensions is greater than or equal to a preset dimension threshold, determining that the first parameter of the second permutation matrix is the product of the adjacent two-level dimensions, and the second parameter of the second permutation matrix is the dimension at the back among the adjacent two-level dimensions, where the first parameter is used to indicate the size of the second permutation matrix, and the second parameter is used to indicate the number of columns of the matrix transposed by the second permutation matrix. Based on the first parameter and the second parameter, obtain the second permutation matrix.

[0019] Correspondingly, based on the determined second permutation matrix, transposing the current third multi-dimensional array to obtain a third multi-dimensional array with the adjacent two-level dimensions in the swapped order includes: sequentially reading the elements in the current third multi-dimensional array, and after reading the first number of elements each time, generating a third matrix based on the read first number of elements, where the first number is equal to the product of the adjacent two-level dimensions and the corresponding dimensions at all levels after that, the number of rows of the third matrix is equal to the product of the adjacent two-level dimensions, and the number of columns of the third matrix is equal to the product of the dimensions at all levels after the adjacent two-level dimensions. Based on the determined second permutation matrix, sequentially transpose each generated third matrix to obtain a plurality of transposed third matrices. Based on the plurality of transposed third matrices, determine the third multi-dimensional array with the adjacent two-level dimensions in the swapped order.

[0020] In a second aspect, a sorting device for a calculation sequence is provided, and the device includes:

[0021] An obtaining module, configured to obtain a calculation sequence in response to a sorting request for a calculation sequence corresponding to a fast Fourier transform (FFT) calculation;

[0022] A conversion module, configured to convert the calculation sequence into a first multi-dimensional array, where the dimensions at all levels of the first multi-dimensional array are the bases of each calculation stage in the FFT calculation;

[0023] A determination module, configured to determine a plurality of permutation matrices for transposing the first multi-dimensional array, and based on the plurality of permutation matrices, transpose the first multi-dimensional array into a second multi-dimensional array, where the order of the dimensions at all levels of the second multi-dimensional array is opposite to the order of the dimensions at all levels of the first multi-dimensional array; determine the elements arranged in order in the second multi-dimensional array as the sequence after sorting the calculation sequence.

[0024] In an implementable manner, the determination module is configured to: determine a first permutation matrix for transposing the current first multi-dimensional array; based on the first permutation matrix, transpose the current first multi-dimensional array to obtain the transposed first multi-dimensional array, where the first permutation matrix is used to transpose the (n + 2)-th last-level dimension of the current first multi-dimensional array to the last-level dimension, and n is the number of times the current first multi-dimensional array has been transposed. When the transposed first multi-dimensional array does not meet the end condition, it goes back to determining the first permutation matrix for transposing the current first multi-dimensional array. The end condition means that the order of each level dimension of the transposed first multi-dimensional array is opposite to the order of each level dimension of the first multi-dimensional array before transposition. When the transposed first multi-dimensional array meets the end condition, the transposed first multi-dimensional array is determined as the second multi-dimensional array.

[0025] In an implementable manner, the conversion module is further configured to: convert the current first multi-dimensional array into a third multi-dimensional array, where the first-level dimension of the third multi-dimensional array is equal to the product of the first-level dimension to the (n + 3)-th last-level dimension of the current first multi-dimensional array, the product of the second-level dimension to the s-th level dimension of the third multi-dimensional array is equal to the (n + 2)-th last-level dimension of the current first multi-dimensional array, the product of the (s + 1)-th level dimension to the (s + t)-th level dimension of the third multi-dimensional array is equal to the product of each level dimension from the (n + 1)-th last-level dimension to the last-level dimension of the current first multi-dimensional array, and the difference between the product of any two dimensions from the second-level dimension to the (s + t)-th level dimension of the third multi-dimensional array and the maximum calculation size supported by the matrix operation unit performing the transposition process is less than the difference threshold.

[0026] The determination module is configured to: determine multiple second permutation matrices for transposing the third multi-dimensional array; based on the multiple second permutation matrices, sequentially exchange the order of two adjacent level dimensions in the third multi-dimensional array until the second-level dimension to the s-th level dimension in the third multi-dimensional array are transposed after the (s + t)-th level dimension, obtaining the transposed first multi-dimensional array.

[0027] In an implementable manner, the determination module is configured to: determine two adjacent level dimensions in the current third multi-dimensional array that need to have their order exchanged; based on the two adjacent level dimensions, determine a second permutation matrix for transposing the current third multi-dimensional array; based on the determined second permutation matrix, transpose the current third multi-dimensional array to obtain the third multi-dimensional array with the order of the two adjacent level dimensions exchanged.

[0028] In an implementable manner, the determining module is configured to: when the s-th level dimension and the s + t-th level dimension in the third multi-dimensional array whose adjacent two levels of dimensions are not transposed, determine that the first parameter of the second permutation matrix is the product of the s-th level dimension and the s + t-th level dimension, and the second parameter of the second permutation matrix is the s-th level dimension, where the first parameter is used to indicate the size of the second permutation matrix, and the second parameter is used to indicate the number of columns of the matrix transposed by the second permutation matrix; based on the first parameter and the second parameter, obtain the second permutation matrix.

[0029] In an implementable manner, the determining module is configured to: convert the current third multi-dimensional array into a first matrix, the number of rows of the first matrix is equal to the quotient of the length of the calculation sequence and the first parameter, and the number of columns of the first matrix is equal to the first parameter; transpose the first matrix based on the determined second permutation matrix to obtain the third multi-dimensional array with the adjacent two levels of dimensions in the swapped order.

[0030] In an implementable manner, the determining module is configured to: when the product of the dimensions at all levels after the adjacent two levels of dimensions is less than a preset dimension threshold, determine that the first parameter of the second permutation matrix is the product of the adjacent two levels of dimensions, and the second parameter of the second permutation matrix is the dimension in the front among the adjacent two levels of dimensions, where the first parameter is used to indicate the size of the second permutation matrix, and the second parameter is used to indicate the number of columns of the matrix transposed by the second permutation matrix; based on the first parameter and the second parameter, obtain the second permutation matrix.

[0031] In an implementable manner, the determining module is configured to: convert the current third multi-dimensional array into a second matrix, the number of rows of the second matrix is equal to the quotient of the length of the calculation sequence and the first value, the first value is equal to the product of the adjacent two levels of dimensions and the corresponding dimensions at all levels after that, and the number of columns of the second matrix is equal to the first value; transpose the second matrix based on the determined second permutation matrix and the identity matrix of the first size to obtain the third multi-dimensional array with the adjacent two levels of dimensions in the swapped order, and the first size is equal to the product of the dimensions at all levels after the adjacent two levels of dimensions.

[0032] In an implementable manner, the determining module is configured to: when the product of the dimensions at all levels after the adjacent two levels of dimensions is greater than or equal to a preset dimension threshold, determine that the first parameter of the second permutation matrix is the product of the adjacent two levels of dimensions, and the second parameter of the second permutation matrix is the dimension in the back among the adjacent two levels of dimensions, where the first parameter is used to indicate the size of the second permutation matrix, and the second parameter is used to indicate the number of columns of the matrix transposed by the second permutation matrix; based on the first parameter and the second parameter, obtain the second permutation matrix.

[0033] In an implementable manner, a determination module is configured to: sequentially read elements in a current third multi-dimensional array, and after reading the first number of elements, generate a third matrix based on the read first number of elements, where the first number is equal to the product of two adjacent levels of dimensions and the corresponding subsequent levels of dimensions, the number of rows of the third matrix is equal to the product of the two adjacent levels of dimensions, and the number of columns of the third matrix is equal to the product of the subsequent levels of dimensions after the two adjacent levels of dimensions; based on the determined second permutation matrix, sequentially transpose each generated third matrix to obtain a plurality of transposed third matrices; and based on the plurality of transposed third matrices, determine the third multi-dimensional array with the two adjacent levels of dimensions in the swapped order.

[0034] In a third aspect, a computing device is provided, which includes a memory and a processor. At least one instruction is stored in the memory, and when the processor executes the at least one instruction, the method described in the first aspect above can be implemented.

[0035] In a fourth aspect, a computer-readable storage medium is provided, which stores computer program code. When the computer program code is executed by a computing device, the computing device is caused to execute the method described in the first aspect above.

[0036] In a fifth aspect, a computer program product including instructions is provided. When the computer program product runs on a computing device, the computing device is caused to execute the method described in the first aspect above. Description of the Drawings

[0037] Figure 1 is a flowchart of implementing an 18-point FFT calculation through Cooley-Tukey;

[0038] Figure 2 is a schematic structural diagram of a computing device provided by an embodiment of the present application;

[0039] Figure 3 is a flowchart of a method for sorting a calculation sequence provided by an embodiment of the present application;

[0040] Figure 4 is a schematic diagram of a method for sorting a calculation sequence provided by an embodiment of the present application;

[0041] Figure 5 is a schematic diagram of a method for sorting a calculation sequence provided by an embodiment of the present application;

[0042] Figure 6 is a schematic structural diagram of a device for sorting a calculation sequence provided by an embodiment of the present application. Detailed Embodiments

[0043] To make the objectives, technical solutions, and advantages of this application more clear, the following will further describe in detail the embodiments of this application with reference to the accompanying drawings.

[0044] The Discrete Fourier Transform (DFT) is a form in which the Fourier transform is discrete both in the time-domain data and the frequency-domain data, and is used to transform discrete time-domain sampling data into discrete frequency-domain sampling data. In terms of data form, the input data (discrete time-domain sampling data) and output data (discrete frequency-domain data) of the DFT are finite-length complex sequences, and the lengths of the two complex sequences are equal.

[0045] Fast Fourier Transform (FFT): An algorithm for quickly calculating the Discrete Fourier Transform (DFT) or its inverse transform (IDFT). By recursively decomposing the DFT of a long complex sequence into the DFTs of shorter complex sequences, it can reduce the original computational complexity of the DFT from O(N 2 ) to O(N log N), where N is the length of the long complex sequence.

[0046] The Cooley-Tukey algorithm is a commonly used FFT algorithm. Based on the divide-and-conquer strategy, it can decompose the DFT of a complex sequence with length N into the DFTs of N1 complex sequences with length N2 and complex multiplications with twiddle factors, where N = N1 * N2.

[0047] Figure 1 is a flowchart for implementing 18-point FFT calculation through Cooley-Tukey, and this flowchart can be called a butterfly network. As Figure 1 shown, the calculation process of FFT calculation can be decomposed into multiple calculation stages. The number of calculation stages is equal to the number of times the length of the data sequence for performing FFT calculation is divided by the radix. Among them, the data sequence is a complex sequence. For the FFT calculation with the length of the data sequence being N, it can be called N-point FFT calculation. For example, for the N-point FFT calculation, assuming that N can be decomposed into N1, N2, …, N i (N = N1 * N2 * … * N i ), then the calculation process of the N-point FFT can include i calculation stages. N1, N2, …, N i can be called the radix. N1 is the radix corresponding to the first calculation stage, N2 is the radix corresponding to the second calculation stage, and Ni is the radix corresponding to the i-th calculation stage.

[0048] In the FFT calculation, the input sequence of the first calculation stage can be obtained from the data sequence corresponding to the execution of the FFT calculation. For other calculation stages after the first calculation stage, the input sequence of each calculation stage is obtained from the output sequence of the previous calculation stage, and the lengths of the input sequences of each calculation stage are the same.

[0049] During the execution of the FFT calculation, it is necessary to sort the calculation sequence (input sequence or output sequence) of the FFT calculation. For example, when implementing the FFT calculation based on the time-domain decimation method, it is necessary to sort the input sequence of the FFT calculation, while when implementing the FFT calculation based on the frequency-domain decimation method, it is not necessary to sort the input sequence of the FFT calculation.

[0050] The current sorting method for the calculation sequence is to determine the order of each element in the calculation sequence in the sorted sequence, read the elements in the calculation sequence in the determined order in turn, and store the elements read in turn into the memory, thereby obtaining the sorted sequence. Such a sorting method requires non-continuous reading of the elements in the calculation sequence, and the sorting efficiency is low.

[0051] A multi-dimensional array includes an array with at least two dimensions. In one example, a two-dimensional array is a matrix. The rows in the matrix are the first dimension in the two-dimensional array, also called the first-level dimension, and the value of this first-level dimension is the number of rows in the matrix. The columns in the matrix are the second dimension in the two-dimensional array, also called the second-level dimension, and the value of this second-level dimension is the number of columns in the matrix. Correspondingly, a three-dimensional array includes three levels of dimensions, and an n-dimensional array includes n levels of dimensions. In the embodiments of the present application, the multi-dimensional array A can be expressed as A = N1N2…N m . Wherein, N1 is the value corresponding to the first-level dimension in the multi-dimensional array A, N2 is the value corresponding to the second-level dimension in the multi-dimensional array A, and N m is the value corresponding to the mth-level dimension in the multi-dimensional array A.

[0052] A permutation matrix is a square binary matrix, in which each row and each column includes only one 1, and the remaining elements are 0. A permutation matrix can be determined by two parameters. The first parameter is the size of the permutation matrix, that is, the number of rows or columns of the permutation matrix, and the second parameter is the number of columns included in the matrix transposed by the permutation matrix. Among them, in the embodiments of the present application, the first parameter can be called the first parameter of the permutation matrix, and the second parameter can be called the second parameter of the permutation matrix.

[0053] The embodiment of the present application provides a sorting method for a calculation sequence. According to the characteristics of the sorting of the calculation order in FFT calculation, the calculation sequence to be sorted can be converted into a multi-dimensional array, and then the sorting of the calculation sequence can be realized by transposing the multi-dimensional array. Among them, the transposition of the multi-dimensional array can be realized through matrix multiplication operations. In this way, in the embodiment of the present application, discontinuous access during the sorting of the calculation sequence can be avoided, thereby improving the sorting efficiency of the calculation sequence and the execution efficiency of the FFT calculation.

[0054] Figure 2 It is a schematic structural diagram of a computing device provided by an embodiment of the present application. As Figure 2 shown, the computing device 200 may include: a bus 202, a processor 204, a memory 206. Optionally, the computing device 200 may further include a communication interface 208. The processor 204, the memory 206, and the communication interface 208 communicate with each other through the bus 202. The computing device 200 may be a server or a terminal device. It should be understood that the present application does not limit the number of processors and memories in the computing device 200. The computing device 200 may be a device for running a model, which may be a terminal or a server. When the computing device 200 is a terminal, the computing device 200 includes, but is not limited to, a desktop computer, a mobile phone, a notebook, a tablet computer, etc. When the computing device 200 is a server, the computing device 200 may be a single server or a server cluster composed of multiple servers, and may be a physical machine or a virtual machine or a container virtualized through virtual technology.

[0055] The bus 202 may be a peripheral component interconnect (PCI) bus or an extended industry standard architecture (EISA) bus, etc. The bus may be divided into an address bus, a data bus, a control bus, etc. For the sake of convenience of representation, Figure 2 only one line is shown in the figure, but it does not mean that there is only one bus or one type of bus. The bus 202 may include a path for transmitting information between various components of the computing device 200 (for example, the memory 206, the processor 204, the communication interface 208).

[0056] The processor 204 may include any one or more of processors such as a central processing unit (CPU), a graphics processing unit (GPU), a microprocessor (MP), or a digital signal processor (DSP). Among them, the processor 204 may further include a matrix operation unit, which can be used to perform matrix multiplication operations involved in the FFT calculation process. In addition, the processor 204 may also instruct a system-on-chip (SOC) including components such as the above CPU, GPU, or CPU.

[0057] The memory 206 may include a volatile memory, such as a random access memory (RAM). The memory 206 may also include a non-volatile memory, such as a read-only memory (ROM), a flash memory, a hard disk drive (HDD), or a solid state drive (SSD). The memory 206 may store program code, and the processor 204 may implement the method for performing FFT calculations provided by the embodiments of the present application by executing the program code. For example, obtaining a calculation sequence, converting the calculation sequence into a first multi-dimensional array, where each level of dimension of the first multi-dimensional array is the basis for each calculation stage in the FFT calculation. Determining a plurality of permutation matrices for transposing the first multi-dimensional array, and based on the plurality of permutation matrices, transposing the first multi-dimensional array into a second multi-dimensional array, where the order of each level of dimension of the second multi-dimensional array is opposite to the order of each level of dimension of the first multi-dimensional array. Determining the elements arranged in order in the second multi-dimensional array as the sequence after sorting the calculation sequence, etc.

[0058] The communication interface 208 uses a transceiver module such as, but not limited to, a network interface card or a transceiver to implement communication between the computing device 200 and other devices or communication networks.

[0059] Figure 3 It is a flowchart of a method for sorting a calculation sequence provided by the embodiments of the present application. This method may be executed by the computing device 200 shown above Figure 2 and further may be executed by the processor 204 in the computing device 200. As shown in Figure 3 the method includes:

[0060] Step 301: In response to a sorting request for a calculation sequence corresponding to a fast Fourier transform (FFT) calculation, the processor obtains the calculation sequence.

[0061] In implementation, an application program involving FFT calculation can run in the computing device. For example, the application program can be a high-performance computing (HPC) application, an artificial intelligence (AI) application, etc. During the running of the application program, when FFT calculation is required, an execution request for FFT can be sent to the processor.

[0062] In an example, when the processor implements FFT calculation based on decimation in time, the execution request for FFT is the sorting request for the calculation sequence. After receiving the sorting request, the processor can obtain the calculation sequence and determine it as the input sequence to be subjected to FFT calculation, and implement the sorting of the calculation sequence based on Steps 302 - 304. Then, for the sorted calculation sequence, the first calculation stage in the FFT calculation is executed. When the processor implements FFT calculation based on decimation in frequency, after receiving the execution request for FFT, the processor can obtain the input sequence to be subjected to FFT calculation and perform FFT calculation on the input sequence. After the processor completes the calculation of the last calculation stage in the FFT calculation and receives the sorting request, the output sequence of the last calculation stage can be determined as the calculation sequence, and Steps 302 - 304 are executed to implement the sorting of the calculation sequence, and then the calculation result of the FFT calculation.

[0063] In addition, for the embodiments of the present application, the obtained calculation sequence to be sorted is not limited to the input sequence of the first calculation stage or the output sequence of the last calculation node in the FFT calculation. When the input sequence or output sequence of each calculation stage in the FFT calculation process needs to be sorted, the sorting method of the calculation sequence provided by the embodiments of the present application can be applied.

[0064] Step 302: Convert the calculation sequence into a first multi-dimensional array, and each level dimension of the first multi-dimensional array is the radix of each calculation stage in the FFT calculation.

[0065] After obtaining the calculation sequence, the obtained calculation sequence can be converted into a first multi-dimensional array. In an example, when the processor implements FFT calculation based on decimation in time, the values of each level dimension of the first multi-dimensional array converted from the calculation sequence are successively the radix of the first calculation stage to the radix of the last calculation stage in the FFT calculation. When the processor implements FFT calculation based on decimation in frequency, each level dimension of the first multi-dimensional array converted from the calculation sequence is successively the radix of the last calculation stage to the radix of the first calculation stage in the FFT calculation.

[0066] Since the storage order of the elements in the calculation sequence is the same as that of the elements in the first multi-dimensional array in the memory or the main memory, when the processor converts the calculation sequence into the first multi-dimensional array, it can be completed by adding the description information of the first multi-dimensional array to the calculation sequence, without rearranging the elements in the calculation sequence. Among them, the description information is the value corresponding to each level of dimension of the first multi-dimensional array. For example, in the 8-point FFT calculation implemented based on time-domain decimation, the calculation sequence N = [0, 1, 2, 3, 4, 5, 6, 7]. Among them, 0-7 are the numbers of each element in the calculation sequence N. The calculation sequence N is converted into a first multi-dimensional array S = N1N2N3 (N1-N3 are all 2) with dimensions in turn, and each element in the first multi-dimensional array S is also 0, 1, 2, 3, 4, 5, 6, 7 in turn.

[0067] Step 303, determine multiple permutation matrices for transposing the first multi-dimensional array, and based on the multiple permutation matrices, transpose the first multi-dimensional array into a second multi-dimensional array, where the order of each level of dimension of the second multi-dimensional array is opposite to that of each level of dimension of the first multi-dimensional array.

[0068] After converting the calculation sequence into the first multi-dimensional array, multiple permutation matrices for the first multi-dimensional array can be determined according to each level of dimension of the first multi-dimensional array. Among them, each determined permutation matrix can be used to transpose the first multi-dimensional array, and each transposition can change the order of each level of dimension in the first multi-dimensional array. Finally, the first multi-dimensional array can be transposed into a second multi-dimensional array.

[0069] In one example, each determined permutation matrix can be used to sequentially exchange the order of two adjacent dimensions in the first multi-dimensional array. Furthermore, the first multi-dimensional array can sequentially perform matrix multiplication operations with the multiple permutation matrices to obtain a second multi-dimensional array whose order of each level of dimension is opposite to that of each level of dimension of the first multi-dimensional array. For example, if the order of each level of dimension of the first multi-dimensional array is N1, N2,... N m , then after the first multi-dimensional array is operated with the first permutation matrix, a multi-dimensional array with dimensions N1, N2,... N m , N m-1 can be obtained. After the multi-dimensional array after one transposition is operated with the second permutation matrix, a multi-dimensional array with dimensions N1, N2,... N m , N m-1 , N m-2 can be obtained. After the multi-dimensional array after m-1 transpositions is operated with the m-th permutation matrix, a multi-dimensional array with dimensions N m , N m-1 ,..., N2, N1 can be obtained, that is, the second multi-dimensional array can be obtained.

[0070] Among them, in the process of transposing the first multi-dimensional array into the second multi-dimensional array, for each multi-dimensional array that operates with the permutation matrix, the multi-dimensional array can be converted into a matrix that operates with the permutation matrix, and then the matrix and the corresponding permutation matrix are input into the matrix operation unit to perform matrix multiplication operation, thereby realizing the transposition of the matrix, and obtaining the transposed matrix. The storage order of the elements in the transposed matrix is the same as the storage order of the elements in the transposed multi-dimensional array. Therefore, the transposed matrix can be converted into the transposed multi-dimensional array by modifying the description information corresponding to the transposed matrix.

[0071] In implementation, the permutation matrices for transposing multi-dimensional arrays of various dimensions can be pre-stored in the memory. During the process of transposing the first multi-dimensional array, the corresponding permutation matrix can be obtained according to the levels of dimensions of the current first multi-dimensional array. In one example, when transposing the first multi-dimensional array, the first multi-dimensional array can be converted into a one-dimensional array, and the arrangement order of the elements in the one-dimensional array is the same as the arrangement order of the elements in the corresponding first multi-dimensional array. Then, the left multiplication of the one-dimensional array by the corresponding permutation matrix can be realized through the matrix operation unit in the processor, thereby obtaining the transposed one-dimensional array. Then, the transposed one-dimensional array can be converted into the transposed multi-dimensional array. Among them, each time the first multi-dimensional array is transposed once, the order of two of the dimensions in the first multi-dimensional array can be exchanged, and the number of rows and columns of the permutation matrix is equal to the length of the one-dimensional array.

[0072] Next, an exemplary method for transposing the first multi-dimensional array provided by the embodiments of the present application will be introduced:

[0073] Step S1: The processor determines the first permutation matrix for transposing the current first multi-dimensional array, and based on the first permutation matrix, transposes the current first multi-dimensional array to obtain the transposed first multi-dimensional array.

[0074] Among them, the first permutation matrix is used to transpose the (n + 2)-th last level dimension of the current first multi-dimensional array to the last level dimension, where n is the number of times the current first multi-dimensional array has been transposed. When this step S1 is executed for the first time, the current first multi-dimensional array is the first multi-dimensional array that has not been transposed, and the transposition times n = 0. When this step S1 is executed for the x-th time, the current first multi-dimensional array is the first multi-dimensional array that has been transposed x - 1 times, and the transposition times n = x - 1. The first permutation matrix determined each time step S1 is executed is the multiple permutation matrices determined in step 303.

[0075] Step S2: When the transposed first multi-dimensional array does not meet the end condition, go back to execute step S1.

[0076] Among them, the end condition means that the order of each level of dimensions of the first multi-dimensional array after transposition is opposite to the order of each level of dimensions of the first multi-dimensional array without transposition.

[0077] Step S3: When the first multi-dimensional array after transposition meets the end condition, determine the first multi-dimensional array after transposition as the second multi-dimensional array.

[0078] Step 304: Determine the elements arranged in order in the second multi-dimensional array as the sequence after sorting the calculation sequence.

[0079] After obtaining the second multi-dimensional array, the second multi-dimensional array can be converted into a sequence, that is, the elements arranged in order in the second multi-dimensional array can be used to form a sequence, and the obtained sequence is the sequence after sorting the calculation sequence.

[0080] In one example, when the processor implements FFT calculation based on time-domain decimation, the sorted sequence can be used as the input sequence of the first calculation stage in the FFT calculation, and then each calculation node in the FFT calculation is executed in turn, so as to obtain the calculation result of the FFT calculation. Alternatively, when the processor implements FFT calculation based on frequency-domain decimation, the sorted sequence can be used as the calculation result of the FFT calculation. After the processor obtains the calculation result of the FFT calculation, the calculation result can be returned to the application program that requests the FFT calculation.

[0081] In the embodiments of the present application, the sorting of the calculation sequence in the FFT calculation can be implemented through matrix multiplication operations, thereby avoiding non-continuous reading of the calculation sequence during the sorting of the calculation sequence, and thus improving the sorting efficiency of the calculation sequence and the efficiency of the processor executing the FFT calculation.

[0082] In an implementable manner, in order to improve the efficiency of the matrix operation unit in performing matrix multiplication operations, the first multi-dimensional array can be converted according to the maximum calculation size supported by the matrix operation unit. The processing of the above step S1 may include:

[0083] Step S11: Convert the current first multi-dimensional array into a third multi-dimensional array.

[0084] Among them, the first - level dimension of the third multi - dimensional array is equal to the product of the first - level dimension to the penultimate n + 3 - level dimensions in the current first multi - dimensional array. The product of the second - level dimension to the s - level dimension of the third multi - dimensional array is equal to the penultimate n + 2 - level dimension in the current first multi - dimensional array. The product of the s + 1 - level dimension to the s + t - level dimension of the third multi - dimensional array is equal to the product of the penultimate n + 1 - level dimension to the last - level dimensions. The difference between the product of any two dimensions among the second - level dimension to the s + t - level dimension of the third multi - dimensional array and the maximum calculation size supported by the matrix operation unit performing the transpose process is less than the difference threshold.

[0085] In one example, the un - transposed first multi - dimensional array A 11 = N1N2N3…N m After one transpose of the first multi - dimensional array A 12 = N1N2N3…N m N m-1 After two transposes of the first multi - dimensional array A 13 = N1N2N3…N m N m-1 N m-2 After m - 1 transposes of the first multi - dimensional array A 1m = N m N m-1 N m-2 …N2N1. For the above - mentioned first multi - dimensional arrays A 11 ~A 1m , they can all be expressed as the fourth multi - dimensional array A4 = N a N p N q , where N a is the first - level dimension in the fourth multi - dimensional array, N a is equal to the product of the first - level dimension to the penultimate n + 3 - level dimensions in the current first multi - dimensional array, N p is the second - level dimension in the fourth multi - dimensional array, N p is equal to the penultimate n + 2 - level dimension in the current first multi - dimensional array, N q is the third - level dimension in the fourth multi - dimensional array, N q is equal to the product of the penultimate n + 2 - level dimension, the penultimate n + 1 - level dimension to the last - level dimensions in the current first multi - dimensional array. In this way, for the successive transposes of the first multi - dimensional array, it can be converted into the transposes of the second - level dimension N p and the third - level dimension N q in the fourth multi - dimensional array A4. Where n is the number of transposes of the current first multi - dimensional array.

[0086] Further, according to the maximum calculation size supported by the matrix operation unit, the dimensions to be transposed in the fourth multi-dimensional array can be split into smaller dimensions for transposition. The second-level dimension N in the fourth multi-dimensional array A4 p is split into N p1 , N p2 , … N ps . The third-level dimension N in the fourth multi-dimensional array A4 q is split into N q1 , N q2 , … N qt . Among them, N p is equal to the product of N p1 , N p2 , … N ps . N q is equal to the product of N q1 , N q2 , … N qt . The product of any two terms among N p1 ~N qt is less than or equal to the maximum calculation size supported by the matrix operation unit. In this way, the third multi-dimensional array A3 = N a N p1 N p2 … N ps N q1 N q2 … N qt is obtained.

[0087] In steps S11 to S12, the transposition of the first multi-dimensional array is converted into the transposition of the third multi-dimensional array. To perform the transposition of the third multi-dimensional array, it is necessary to transpose every two dimensions in the second-level dimension to the s + t-level dimension of the third multi-dimensional array in sequence, that is, to exchange the order of the two dimensions in the third multi-dimensional array. When splitting the second-level dimension and the third-level dimension in the fourth multi-dimensional array into the second-level dimension to the s + t-level dimension of the third multi-dimensional array, the product of any two dimensions in the second-level dimension to the s + t-level dimension of the third multi-dimensional array can be close to the maximum calculation size supported by the matrix operation unit for performing the transposition process. For example, the product of the two dimensions is less than or equal to the maximum calculation size supported by the matrix operation unit for performing the transposition process, and the corresponding difference is less than the difference threshold. In this way, when transposing any two dimensions in the third multi-dimensional array, the size of the permutation matrix used is equal to the product of the corresponding two dimensions, so that the size of the permutation matrix can be close to or equal to the maximum calculation size supported by the matrix operation unit, thereby improving the efficiency of transposing the third multi-dimensional array, and further improving the efficiency of sorting the calculation sequence in the FFT calculation and the efficiency of performing the FFT calculation.

[0088] Step S12: Determine multiple second permutation matrices for transposing the third multi-dimensional array. Based on the multiple second permutation matrices, successively exchange the orders of two adjacent levels of dimensions in the third multi-dimensional array until the second-level dimension to the s-level dimension in the third multi-dimensional array are transposed after the s + t-level dimension, obtaining the first multi-dimensional array after transposition.

[0089] Among them, in step S12, the multiple second permutation matrices determined each time are the first permutation matrices determined by executing the above step S1. That is to say, the first permutation matrix in this application can include multiple second permutation matrices.

[0090] After converting the first multi-dimensional array into the third multi-dimensional array, for one transposition of the current first multi-dimensional array, it can be split into s × t transpositions of the third multi-dimensional array, as follows:

[0091] N a N p1 N p2 …N ps N q1 N q2 …N qt

[0092] N a N p1 N p2 …N q1 N ps N q2 …N qt

[0093] N a N p1 N p2 …N q1 N q2 N ps …N qt

[0094] ……

[0095] N a N p1 N p2 …N q1 N q2 …N qt N ps

[0096] ……

[0097] N a N p1 N q1 N q2 …N qt N p2 …N ps

[0098] ……

[0099] N a N q1 N q2 …N qt N p1 N p2 …N ps

[0100] Among them, for each transposition in the above s×t transpositions, the adjacent two-level dimensions that need to be sequentially exchanged in the current third multi-dimensional array can be determined. Based on the adjacent two-level dimensions that need to be sequentially exchanged, the second permutation matrix for transposing the current third multi-dimensional array is determined. Based on the determined second permutation matrix, the current third multi-dimensional array is transposed to obtain the third multi-dimensional array after the adjacent two-level dimensions that need to be sequentially exchanged are exchanged in order.

[0101] In one example, for the third multi-dimensional array, for two adjacent dimensions N pi and N qj that need to be transposed each time, the process of determining the second transposition matrix and the corresponding transposition process include:

[0102] Case 1: When the adjacent two-level dimensions that need to be sequentially exchanged are the s-th level dimension and the (s + t)-th level dimension in the untransposed third multi-dimensional array, the first parameter of the second permutation matrix is determined as the product of the s-th level dimension and the (s + t)-th level dimension, and the second parameter of the second permutation matrix is determined as the s-th level dimension.

[0103] When the adjacent two-level dimensions that need to be sequentially exchanged are the s-th level dimension and the (s + t)-th level dimension in the untransposed third multi-dimensional array, that is, N pi and N qj are respectively N ps and N qt respectively, that is, when transposing the above third multi-dimensional array N a N p1 N p2 …N q1 N q2 …N ps N qt in, the first parameter of the second permutation matrix can be determined as the product of N qt and N ps , and the second parameter of the second permutation matrix is determined as N ps and N qt . That is, the second transposition matrix P1(N ps N ps , N qt , N ps ) is obtained. Among them, N ps Nqt is the first parameter, N ps is the second parameter.

[0104] For case one, the corresponding transpose process includes: converting the current third multi-dimensional array into a first matrix, where the number of rows of the first matrix is equal to the quotient of the length of the calculation sequence and the first parameter of the determined second transpose matrix, and the number of columns of the first matrix is equal to the first parameter. Transpose the first matrix based on the determined second permutation matrix to obtain the third multi-dimensional array in which the adjacent two levels of dimensions to be sequentially exchanged are in the exchanged order.

[0105] The current third multi-dimensional array is N a N p1 N p2 …N q1 N q2 …N ps N qt , and the corresponding first matrix M1 is N R ×N ps N qt matrix, where N R = N / N ps N qt , that is, N R = N a N p1 N p2 …N q1 N q2 …N pt-1 . As Figure 4 shown, for the first matrix M1, the second transpose matrix P1 can be right-multiplied to obtain the transposed first matrix M1. The arrangement order of the elements in the transposed first matrix M1 is the arrangement order of the elements in the third multi-dimensional array N a N p1 N p2 …N q1 N q2 …N qt N ps . Therefore, by modifying the description information corresponding to the transposed first matrix M1, the third multi-dimensional array N a N p1 N p2 …N q1 N q2 …N qt N ps .

[0106] Case 2: When the product of each level of dimensions after two adjacent levels of dimensions that need to be swapped in order is less than a preset dimension threshold, determine the first parameter of the second permutation matrix as the product of the two adjacent levels of dimensions that need to be swapped in order, and the second parameter of the second permutation matrix as the dimension that comes first among the two adjacent levels of dimensions that need to be swapped in order.

[0107] Among them, the preset dimension threshold A is less than the maximum calculation size supported by the matrix operation unit. When the product of each level of dimensions after two adjacent levels of dimensions that need to be swapped in order is less than the preset dimension threshold, that is, when the product Nr of the dimensions after N pi N qj in the current third multi-dimensional array is less than the preset dimension threshold A, the first parameter of the second permutation matrix can be determined as the product of the two adjacent levels of dimensions that need to be swapped in order, that is, N pi N qj , and the second parameter of the second permutation matrix is determined as the dimension that comes first among the two adjacent levels of dimensions that need to be swapped in order, that is, N pi . That is, the second transposed matrix P2(N pi N qj , N pi ) is obtained. Among them, N pi N qj is the first parameter, and N pi is the second parameter.

[0108] For Case 2, the corresponding transpose processing includes: converting the current third multi-dimensional array into a second matrix, the number of rows of the second matrix is equal to the quotient of the length of the calculation sequence and the first value, the first value is equal to the product of two adjacent levels of dimensions that need to be swapped in order and the corresponding subsequent levels of dimensions, the number of columns of the second matrix is equal to the first value, and based on the determined second permutation matrix and the unit matrix of the first size, transpose the second matrix to obtain the third multi-dimensional array after swapping the order of two adjacent levels of dimensions that need to be swapped in order, where the first size is equal to the product of the dimensions after N pi N qj in the current third multi-dimensional array.

[0109] Convert the current third multi-dimensional array into a second matrix M2 of N R ×N pi N qj N r , where N R = N / N pi N qj N r , N is the length of the calculation sequence, N pi N qj N r is the first value, and N ris the product of the dimensions after N in the current third multi-dimensional array pi N qj After obtaining the second matrix M2, the second matrix M2 can be right-multiplied by the outer product result of the second transposed matrix P2 and the identity matrix I Nr to obtain the transposed second matrix M2. The arrangement order of the elements in the transposed second matrix M2 is the arrangement order of the elements in the multi-dimensional array obtained by transposing N in the third multi-dimensional array. Therefore, by modifying the description information corresponding to the transposed second matrix M2, the transposed third multi-dimensional array can be obtained pi N qj

[0110] Case 3: When the product of the dimensions after two adjacent levels of dimensions that need to be swapped is greater than or equal to a preset dimension threshold, determine the first parameter of the second permutation matrix as the product of the two adjacent levels of dimensions that need to be swapped, and the second parameter of the second permutation matrix as the dimension at the back of the two adjacent levels of dimensions that need to be swapped

[0111] When the product of the dimensions after two adjacent levels of dimensions that need to be swapped is greater than or equal to a preset dimension threshold, that is, when the product of the dimensions after N in the third multi-dimensional array pi N qj is greater than or equal to the preset dimension threshold A, the first parameter of the second permutation matrix can be determined as the product of the two adjacent levels of dimensions that need to be swapped, that is, N r N pi N qj and the second parameter of the second permutation matrix can be determined as the dimension at the back of the two adjacent levels of dimensions that need to be swapped, that is, N pj . That is, the second transposed matrix P3(N pi N qj , N pj ) is obtained. Among them, N pi N qj is the first parameter, and N pj is the second parameter

[0112] ​For Case 3, the corresponding transposition process includes: sequentially reading the elements in the current third multi-dimensional array, and after reading the first number of elements each time, generating a third matrix based on the first number of elements read. The first number is equal to the product of two adjacent levels of dimensions that need to be swapped in order and the corresponding subsequent levels of dimensions. The number of rows of the third matrix is equal to the product of two adjacent levels of dimensions that need to be swapped in order, and the number of columns of the third matrix is equal to the product of the subsequent levels of dimensions after the two adjacent levels of dimensions that need to be swapped in order; based on the determined second permutation matrix, sequentially transpose each generated third matrix to obtain multiple transposed third matrices; based on the multiple transposed third matrices, determine the two adjacent levels of dimensions that need to be swapped in order in the third multi-dimensional array after the swap order.

[0113] In Case 3, the processor sequentially reads the elements in the current third multi-dimensional array. Whenever the first number of elements are continuously read, the continuously read first number of elements can be composed into a third matrix M3. Among them, the number of rows of the third matrix M3 is equal to the product of two adjacent levels of dimensions that need to be swapped in order, that is, N pi N qj , and the number of columns of the third matrix M3 is equal to the product of the subsequent levels of dimensions after the two adjacent levels of dimensions that need to be swapped in order, N r .

[0114] As Figure 5 shown, when N pi N qj is N ps N q1 , the third multi-dimensional array can be transformed into N p1 N p2 …N ps-1 third matrices M3. After obtaining multiple third matrices M3, the multiple third matrices M3 can be sequentially left-multiplied by the second permutation matrix P3, and then each transposed third matrix M3 can be obtained. Among them, the elements in each transposed third matrix M3 are stored in order to form a transposed third multi-dimensional array.

[0115] In the embodiments of the present application, decomposing each transposition operation into transpositions of smaller dimensions can reduce the amount of calculation. For example, the amount of calculation for the transposition calculated by matrix multiplication for N p N q is (N p N q ), and when decomposed into N 2 = N p = N p1 N p2 …N ps , N q = N q1 N q2 …N qt, when performing transpositions between small dimensions in sequence, N pi N qj The computational complexity of the transposition is The overall computational complexity is It is reduced compared to the total computational complexity before decomposition. Moreover, the relationship of the computational complexity changes from N 2 to a relationship of N log(N), which has a more obvious advantage for relatively large values of N p and N q .

[0116] Figure 6 is a schematic structural diagram of a sorting device for a calculation sequence provided by an embodiment of the present application. The device may be the calculation device or the processor in the above embodiment, such as Figure 6 shown. The device includes:

[0117] An acquisition module 610, configured to respond to a sorting request for a calculation sequence corresponding to a fast Fourier transform (FFT) calculation, and acquire the calculation sequence, which can specifically be used to implement the acquisition function in step 301 and its implicit steps above.

[0118] A conversion module 620, configured to convert the calculation sequence into a first multi-dimensional array, where each level of dimension of the first multi-dimensional array is the base of each calculation stage in the FFT calculation, and can specifically be used to implement the conversion function in step 302 and its implicit steps above.

[0119] A determination module 630, configured to determine a plurality of permutation matrices for transposing the first multi-dimensional array, and based on the plurality of permutation matrices, transpose the first multi-dimensional array into a second multi-dimensional array, where the order of each level of dimension of the second multi-dimensional array is opposite to the order of each level of dimension of the first multi-dimensional array; and determine the elements arranged in sequence in the second multi-dimensional array as the sequence after sorting the calculation sequence, which can specifically be used to implement the determination function in steps 303 and 304 and their implicit steps above.

[0120] In an implementable manner, the determination module 630 is configured to: determine a first permutation matrix for transposing the current first multi-dimensional array, and based on the first permutation matrix, transpose the current first multi-dimensional array to obtain the transposed first multi-dimensional array, where the first permutation matrix is used to transpose the (n + 2)-th last level of dimension of the current first multi-dimensional array to the last level of dimension, where n is the number of times the current first multi-dimensional array has been transposed. When the transposed first multi-dimensional array does not meet the end condition, go back to execute determining the first permutation matrix for transposing the current first multi-dimensional array. The end condition means that the order of each level of dimension of the transposed first multi-dimensional array is opposite to the order of each level of dimension of the first multi-dimensional array before transposition. When the transposed first multi-dimensional array meets the end condition, determine the transposed first multi-dimensional array as the second multi-dimensional array.

[0121] In an implementable manner, the conversion module 620 is further configured to: convert the current first multi-dimensional array into a third multi-dimensional array, where the first-level dimension of the third multi-dimensional array is equal to the product of the first-level dimension to the penultimate n+3-level dimensions in the current first multi-dimensional array, the product of the second-level dimension to the s-level dimension of the third multi-dimensional array is equal to the penultimate n+2-level dimension in the current first multi-dimensional array, the product of the s+1-level dimension to the s+t-level dimension of the third multi-dimensional array is equal to the product of the penultimate n+1-level dimension to the last-level dimensions, and the difference between the product of any two dimensions from the second-level dimension to the s+t-level dimension of the third multi-dimensional array and the maximum calculation size supported by the matrix operation unit performing the transposition process is less than the difference threshold.

[0122] The determination module 630 is configured to: determine a plurality of second permutation matrices for transposing the third multi-dimensional array, and based on the plurality of second permutation matrices, sequentially exchange the order of two adjacent levels of dimensions in the third multi-dimensional array until the second-level dimension to the s-level dimension in the third multi-dimensional array are transposed after the s+t-level dimension, so as to obtain the first multi-dimensional array after transposition.

[0123] In an implementable manner, the determination module 630 is configured to: determine two adjacent levels of dimensions in the current third multi-dimensional array that need to exchange the order; based on the two adjacent levels of dimensions, determine a second permutation matrix for transposing the current third multi-dimensional array; and based on the determined second permutation matrix, transpose the current third multi-dimensional array to obtain the third multi-dimensional array with the order of the two adjacent levels of dimensions exchanged.

[0124] In an implementable manner, when the two adjacent levels of dimensions are the s-level dimension and the s+t-level dimension in the third multi-dimensional array that has not been transposed, the determination module 630 is configured to: determine that the first parameter of the second permutation matrix is the product of the s-level dimension and the s+t-level dimension, and the second parameter of the second permutation matrix is the s-level dimension, where the first parameter is used to indicate the size of the second permutation matrix, and the second parameter is used to indicate the number of columns of the matrix transposed by the second permutation matrix; and obtain the second permutation matrix based on the first parameter and the second parameter.

[0125] In an implementable manner, the determination module 630 is configured to: convert the current third multi-dimensional array into a first matrix, the number of rows of the first matrix is equal to the quotient of the length of the calculation sequence and the first parameter, and the number of columns of the first matrix is equal to the first parameter; and transpose the first matrix based on the determined second permutation matrix to obtain the third multi-dimensional array with the order of the two adjacent levels of dimensions exchanged.

[0126] In an implementable manner, the determining module 630 is configured to: when the product of the dimensions at each level after the adjacent two levels of dimensions is less than a preset dimension threshold, determine that the first parameter of the second permutation matrix is the product of the adjacent two levels of dimensions, and the second parameter of the second permutation matrix is the dimension in the front among the adjacent two levels of dimensions, where the first parameter is used to indicate the size of the second permutation matrix, and the second parameter is used to indicate the number of columns of the matrix transposed by the second permutation matrix; and obtain the second permutation matrix based on the first parameter and the second parameter.

[0127] In an implementable manner, the determining module 630 is configured to: convert the current third multi-dimensional array into a second matrix, where the number of rows of the second matrix is equal to the quotient of the length of the calculation sequence and the first value, the first value is equal to the product of the adjacent two levels of dimensions and the corresponding dimensions at each subsequent level, and the number of columns of the second matrix is equal to the first value; and transpose the second matrix based on the determined second permutation matrix and the identity matrix of the first size to obtain a third multi-dimensional array with the adjacent two levels of dimensions in the swapped order, where the first size is equal to the product of the dimensions at each level after the adjacent two levels of dimensions.

[0128] In an implementable manner, the determining module 630 is configured to: when the product of the dimensions at each level after the adjacent two levels of dimensions is greater than or equal to a preset dimension threshold, determine that the first parameter of the second permutation matrix is the product of the adjacent two levels of dimensions, and the second parameter of the second permutation matrix is the dimension in the back among the adjacent two levels of dimensions, where the first parameter is used to indicate the size of the second permutation matrix, and the second parameter is used to indicate the number of columns of the matrix transposed by the second permutation matrix; and obtain the second permutation matrix based on the first parameter and the second parameter.

[0129] In an implementable manner, the determining module 630 is configured to: sequentially read the elements in the current third multi-dimensional array, and after reading the first number of elements each time, generate a third matrix based on the read first number of elements, where the first number is equal to the product of the adjacent two levels of dimensions and the corresponding dimensions at each subsequent level, the number of rows of the third matrix is equal to the product of the adjacent two levels of dimensions, and the number of columns of the third matrix is equal to the product of the dimensions at each level after the adjacent two levels of dimensions; sequentially transpose each generated third matrix based on the determined second permutation matrix to obtain a plurality of transposed third matrices; and determine the third multi-dimensional array with the adjacent two levels of dimensions in the swapped order based on the plurality of transposed third matrices.

[0130] In the embodiments of the present application, the division of modules is illustrative. It is only a logical function division. In actual implementation, there may be other division methods. In addition, in each embodiment of the present application, each functional module may be integrated in a processor, may exist independently physically, or two or more modules may be integrated into one module. The above integrated module may be implemented in the form of hardware or in the form of a software functional module. In addition, the sorting device for the calculation sequence provided in the above embodiments and the embodiment of the sorting method for the calculation sequence belong to the same concept. The specific implementation process can be found in the method embodiment and will not be elaborated here.

[0131] If the above integrated module is implemented in the form of a software functional module and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on such an understanding, the technical solution of the present application, in essence, or the part that contributes to the prior art, or all or part of the technical solution, can be embodied in the form of a software product. The computer software product is stored in a storage medium and includes several instructions for causing a terminal device (which may be a personal computer, a mobile phone, or a network device, etc.) or a processor to execute all or part of the steps of the method in each embodiment of the present application. The foregoing storage medium includes: various media such as a USB flash drive, a mobile hard disk, a read-only memory (ROM), a random access memory (RAM), a magnetic disk, or an optical disc that can store program codes.

[0132] The embodiments of the present application also provide a computer program product containing instructions. The computer program product may be a software or program product containing instructions that can run on a computing device or be stored in any available medium. When the computer program product runs on a computing device, it causes at least one computing device to execute the sorting method for the calculation sequence provided in the embodiments of the present application.

[0133] The embodiments of the present application also provide a computer-readable storage medium. The computer-readable storage medium may be any available medium that a computing device can store or a data storage device such as a data center containing one or more available media. The available medium may be a magnetic medium (for example, a floppy disk, a hard disk, a magnetic tape), an optical medium (for example, a DVD), or a semiconductor medium (for example, a solid-state drive), etc. The computer-readable storage medium includes instructions that instruct the computing device to execute the sorting method for the calculation sequence provided in the embodiments of the present application.

[0134] In this application, terms such as "first" and "second" are used to distinguish identical or similar items with basically the same functions and effects. It should be understood that there is no logical or temporal dependency between "first" and "second", nor are the quantity and execution order limited. It should also be understood that although the following description uses terms such as first and second to describe various elements, these elements should not be limited by the terms. These terms are only used to distinguish one element from another. For example, without departing from the scope of various examples, the first multi-dimensional array can be referred to as the second multi-dimensional array, and similarly, the second multi-dimensional array can be referred to as the first multi-dimensional array. The first multi-dimensional array and the multi-dimensional array can both be collectively referred to as the multi-dimensional array, and in some cases, they can be separate and different multi-dimensional arrays.

[0135] In this application, the meaning of the term "at least one" refers to one or more, and the meaning of the term "a plurality of" refers to two or more.

[0136] The above description is only a specific implementation manner of this application, but the protection scope of this application is not limited thereto. Any person skilled in the art in the technical field disclosed by this application can easily think of various equivalent modifications or substitutions within the technical scope disclosed by this application, and these modifications or substitutions should all be covered by the protection scope of this application. Therefore, the protection scope of this application should be subject to the protection scope of the claims.

Claims

1. A sorting method for a calculation sequence, characterized in that, The method includes: In response to a sorting request corresponding to a calculation sequence for fast Fourier transform (FFT) calculation, obtaining the calculation sequence; Converting the calculation sequence into a first multi-dimensional array, where each level of dimension of the first multi-dimensional array is the base of each calculation stage in the FFT calculation; Determining a plurality of permutation matrices for transposing the first multi-dimensional array, and based on the plurality of permutation matrices, transposing the first multi-dimensional array into a second multi-dimensional array, where the order of each level of dimension of the second multi-dimensional array is opposite to the order of each level of dimension of the first multi-dimensional array; Determining the elements arranged in order in the second multi-dimensional array as the sequence after sorting the calculation sequence.

2. The method according to claim 1, characterized in that, The determining a plurality of permutation matrices for transposing the first multi-dimensional array, and based on the plurality of permutation matrices, transposing the first multi-dimensional array into a second multi-dimensional array includes: Determining a first permutation matrix for transposing the current first multi-dimensional array, and based on the first permutation matrix, transposing the current first multi-dimensional array to obtain the transposed first multi-dimensional array, where the first permutation matrix is used to transpose the (n + 2)-th last level of dimension of the current first multi-dimensional array to the last level of dimension, where n is the number of times the current first multi-dimensional array has been transposed; When the transposed first multi-dimensional array does not meet the end condition, turning to execute the determination of the first permutation matrix for transposing the current first multi-dimensional array, where the end condition means that the order of each level of dimension of the transposed first multi-dimensional array is opposite to the order of each level of dimension of the first multi-dimensional array without transposition; When the transposed first multi-dimensional array meets the end condition, determining the transposed first multi-dimensional array as the second multi-dimensional array.

3. The method according to claim 2, characterized in that, The method further includes: Converting the current first multi-dimensional array into a third multi-dimensional array, where the first level of dimension of the third multi-dimensional array is equal to the product of the first level of dimension to the (n + 3)-th last level of dimension in the current first multi-dimensional array, the product of the second level of dimension to the s-th level of dimension of the third multi-dimensional array is equal to the (n + 2)-th last level of dimension in the current first multi-dimensional array, the product of the (s + 1)-th level of dimension to the (s + t)-th level of dimension of the third multi-dimensional array is equal to the product of each level of dimension from the (n + 1)-th last level of dimension to the last level of dimension, and the difference between the product of any two dimensions from the second level of dimension to the (s + t)-th level of dimension of the third multi-dimensional array and the maximum calculation size supported by the matrix operation unit performing the transposition process is less than the difference threshold; The determining a first permutation matrix for transposing the current first multi-dimensional array, and based on the first permutation matrix, transposing the current first multi-dimensional array to obtain the transposed first multi-dimensional array includes: Determine a plurality of second permutation matrices for transposing the third multi-dimensional array. Based on the plurality of second permutation matrices, sequentially exchange the orders of two adjacent levels of dimensions in the third multi-dimensional array until the second-level dimension to the s-level dimension in the third multi-dimensional array are transposed after the (s + t)-level dimension, thereby obtaining the first multi-dimensional array after transposition.

4. The method according to claim 3, characterized in that, The determining a plurality of second permutation matrices for transposing the third multi-dimensional array and, based on the plurality of second permutation matrices, sequentially exchanging the orders of two adjacent levels of dimensions in the third multi-dimensional array includes: Determine two adjacent levels of dimensions in the current third multi-dimensional array that need to have their orders exchanged; Based on the two adjacent levels of dimensions, determine a second permutation matrix for transposing the current third multi-dimensional array; Based on the determined second permutation matrix, transpose the current third multi-dimensional array to obtain the third multi-dimensional array with the orders of the two adjacent levels of dimensions exchanged.

5. The method according to claim 4, characterized in that, The based on the two adjacent levels of dimensions, determining a second permutation matrix for transposing the current third multi-dimensional array includes: When the two adjacent levels of dimensions are sequentially the s-level dimension and the (s + t)-level dimension in the third multi-dimensional array that has not been transposed, determine that the first parameter of the second permutation matrix is the product of the s-level dimension and the (s + t)-level dimension, and the second parameter of the second permutation matrix is the s-level dimension, where the first parameter is used to indicate the size of the second permutation matrix, and the second parameter is used to indicate the number of columns of the matrix transposed by the second permutation matrix; Based on the first parameter and the second parameter, obtain the second permutation matrix.

6. The method according to claim 5, characterized in that, The based on the determined second permutation matrix, transposing the current third multi-dimensional array to obtain the third multi-dimensional array with the orders of the two adjacent levels of dimensions exchanged includes: Convert the current third multi-dimensional array into a first matrix, where the number of rows of the first matrix is equal to the quotient of the length of the calculation sequence and the first parameter, and the number of columns of the first matrix is equal to the first parameter; Based on the determined second permutation matrix, transpose the first matrix to obtain the third multi-dimensional array with the orders of the two adjacent levels of dimensions exchanged.

7. The method according to claim 4, characterized in that, The based on the two adjacent levels of dimensions, determining a second permutation matrix for transposing the current third multi-dimensional array includes: When the product of the levels of dimensions after the two adjacent levels of dimensions is less than a preset dimension threshold, determine that the first parameter of the second permutation matrix is the product of the two adjacent levels of dimensions, and the second parameter of the second permutation matrix is the dimension in front of the two adjacent levels of dimensions, where the first parameter is used to indicate the size of the second permutation matrix, and the second parameter is used to indicate the number of columns of the matrix transposed by the second permutation matrix; Based on the first parameter and the second parameter, obtain the second permutation matrix.

8. The method according to claim 7, characterized in that, The based on the determined second permutation matrix, transposing the current third multi-dimensional array to obtain the third multi-dimensional array with the orders of the two adjacent levels of dimensions exchanged includes: Convert the current third multi-dimensional array into a second matrix, where the number of rows of the second matrix is equal to the quotient of the length of the calculation sequence and a first value, the first value being equal to the product of two adjacent levels of dimensions and the corresponding subsequent levels of dimensions, and the number of columns of the second matrix is equal to the first value; Based on the determined second permutation matrix and the identity matrix of the first size, transpose the second matrix to obtain a third multi-dimensional array in which the two adjacent levels of dimensions are in the swapped order, the first size being equal to the product of the subsequent levels of dimensions after the two adjacent levels of dimensions.

9. The method according to claim 4, characterized in that, The determining the second permutation matrix for transposing the current third multi-dimensional array based on the two adjacent levels of dimensions includes: When the product of the subsequent levels of dimensions after the two adjacent levels of dimensions is greater than or equal to a preset dimension threshold, determine that the first parameter of the second permutation matrix is the product of the two adjacent levels of dimensions and the second parameter of the second permutation matrix is the dimension that comes later among the two adjacent levels of dimensions, where the first parameter is used to indicate the size of the second permutation matrix and the second parameter is used to indicate the number of columns of the matrix to be transposed by the second permutation matrix; Obtain the second permutation matrix based on the first parameter and the second parameter.

10. The method according to claim 9, wherein, The transposing the current third multi-dimensional array based on the determined second permutation matrix to obtain a third multi-dimensional array in which the two adjacent levels of dimensions are in the swapped order includes: Read the elements in the current third multi-dimensional array in sequence. After every first number of elements are read, generate a third matrix based on the read first number of elements, the first number being equal to the product of the two adjacent levels of dimensions and the corresponding subsequent levels of dimensions, the number of rows of the third matrix being equal to the product of the two adjacent levels of dimensions, and the number of columns of the third matrix being equal to the product of the subsequent levels of dimensions after the two adjacent levels of dimensions; Based on the determined second permutation matrix, transpose each generated third matrix in sequence to obtain a plurality of transposed third matrices; Based on the plurality of transposed third matrices, determine a third multi-dimensional array in which the two adjacent levels of dimensions are in the swapped order.

11. A sorting device for a computing sequence, wherein, The apparatus includes: An acquisition module, configured to acquire the calculation sequence in response to a sorting request corresponding to a calculation sequence of a fast Fourier transform (FFT) calculation; A conversion module, configured to convert the calculation sequence into a first multi-dimensional array, where the levels of dimensions of the first multi-dimensional array are the bases of each calculation stage in the FFT calculation; A determination module, configured to determine a plurality of permutation matrices for transposing the first multi-dimensional array, and based on the plurality of permutation matrices, transpose the first multi-dimensional array into a second multi-dimensional array, where the order of the levels of dimensions of the second multi-dimensional array is opposite to the order of the levels of dimensions of the first multi-dimensional array; and determine the elements arranged in sequence in the second multi-dimensional array as the sequence after sorting the calculation sequence.

12. A computing device, wherein, The computing device includes a memory and a processor. At least one instruction is stored in the memory, and the processor executes the at least one instruction to perform the method according to any one of claims 1 to 10.

13. A computer-readable storage medium, wherein, The computer-readable storage medium stores computer program code which, when executed by a computing device, causes the computing device to perform the method according to any one of claims 1 to 10.

14. A computer program product comprising instructions, wherein, When the computer program product runs on a computing device, it causes the computing device to perform the method according to any one of claims 1 to 10.