Complex data processing method and related equipment
By packing and storing adjacent complex real and imaginary parts and using SIMD instructions for efficient reading and writing, the problem of low reading and writing efficiency of complex data in fast Fourier transform is solved, and the computing performance is significantly improved.
Patent Information
- Application Number
- CN202310661606.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2023-06-05
- Publication Date
- 2024-12-06
AI Technical Summary
The prior art is difficult to efficiently realize complex data read and store efficiently in fast Fourier transform operations, resulting in low computing efficiency.
A new storage structure format is adopted to package and store the real and imaginary parts of adjacent K complex numbers in a continuous address space, and efficient read and write operations are performed through SIMD instructions to improve data storage and reading efficiency.
It significantly improves the storage and read and write efficiency of complex data, reduces calculation delay, and improves the performance of fast Fourier transform operations.
Smart Images

Figure CN119088283A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of computer technology, and in particular to a complex data processing method and related equipment. Background Art
[0002] Fourier Transform is a tool for converting signals between time domain and frequency domain. People have proposed a fast implementation algorithm for Fourier Transform, namely Fast Fourier Transform (FFT).
[0003] Traditionally, complex numbers are stored in alternating real and imaginary parts. Current FFT libraries also use this method to store complex data during FFT operations, such as the fftw_complex format in FFTW (the Faster Fourier Transform in the West). The difficulty in optimizing fast Fourier transform operations lies in how to efficiently read and store complex data. The current mainstream research direction is to use Single Instruction Multiple Data (SIMD) technology to implement access and calculation operations with fewer instructions to reduce operating delays, but it cannot guarantee efficient reading and storage of complex data. Summary of the invention
[0004] In view of this, it is necessary to provide a complex data processing method and related equipment to improve the reading and writing efficiency of complex data and ensure efficient reading and efficient storage of complex data.
[0005] In a first aspect, the present application provides a complex data processing method, which is applied to an electronic device that performs fast Fourier transform operations, the method comprising: obtaining a first storage instruction; in response to the first storage instruction, storing a first data sequence to a memory according to a first structural format, wherein the first data sequence includes two or more complex numbers related to the fast Fourier operation; the first structural format includes at least one storage structure, the storage structure corresponds to K adjacent complex numbers in the data sequence to be stored, the storage structure includes a first substructure and a second substructure, the first substructure corresponds to K real parts of the adjacent K complex numbers, the second substructure corresponds to K imaginary parts of the adjacent K complex numbers, the K real parts in the first substructure correspond to a continuous address space on the memory, the K imaginary parts in the second substructure correspond to a continuous address space on the memory, and K is an integer greater than or equal to 2.
[0006] Based on the first structural format, the first data sequence (i.e., the complex data sequence to be stored) is stored, that is, for the adjacent K complex numbers in the first data sequence, the K real parts of the K complex numbers are packed together, and the K imaginary parts of the K complex numbers are packed together, and the packed K real parts are continuously present in the memory (memory), and the packed K imaginary parts are continuously present in the memory. Thus, by storing the packed K real parts (imaginary parts) together in the memory, the storage efficiency of the data can be improved, and the reading efficiency of the data can be improved by reading the packed K real parts (imaginary parts) together. The two or more complex numbers included in the first data sequence can be derived from one or more of the following data: the input data required for the FFT operation (calculation), the intermediate data output during the FFT operation, the butterfly factor matrix, and the output data finally output after the FFT operation, which can improve the processing efficiency of the complex data involved in the FFT operation, especially the reading and writing efficiency of the complex numbers involved in the FFT operation.
[0007] In one possible implementation, when the number of storage structures N is greater than or equal to 2, the parts of the data sequence corresponding to each storage structure are different. That is, all complex numbers in the complex data sequence to be stored are stored using the first structural format to improve the read and write efficiency of the complex data sequence. In one possible implementation, when the number of storage structures N is greater than or equal to 2, the first structural format includes N first substructures and N second substructures, and the first substructures and second substructures in the first structural format are arranged alternately. The first substructure and the second substructure are arranged alternately, that is, the first substructure and the second structure belonging to the same storage structure are adjacent, the first substructure is first and the second substructure is later, or the second substructure is first and the first substructure is later. Storing complex numbers in the first structural format can improve the read and write efficiency of data.
[0008] In one possible implementation, storing a first data sequence in a memory according to a first structure format includes: determining K adjacent complex numbers in the first data sequence corresponding to the storage structure; based on the K adjacent complex numbers in the first data sequence, storing K real parts corresponding to a first substructure of the storage structure in a continuous address space on the memory; and based on the K adjacent complex numbers in the first data sequence, storing K imaginary parts corresponding to a second substructure of the storage structure in another continuous address space on the memory.
[0009] By storing K adjacent complex numbers in a memory as a storage structure, the K complex numbers exist continuously in the memory. Specifically, the K real parts of the K complex numbers are used as the first substructure of the storage structure, and the first substructure indicates that the corresponding K real parts exist continuously in the memory. The K imaginary parts of the K complex numbers are used as the second substructure of the storage structure, and the first substructure indicates that the corresponding K imaginary parts exist continuously in the memory. Thus, storing data by the first substructure and the second substructure can improve the efficiency of reading and writing data. The address space of the K real parts in the memory is adjacent or non-adjacent to the address space corresponding to the K imaginary parts in the address space.
[0010] In a possible implementation, when the number of storage structures is greater than or equal to 2, storing the first data sequence to the memory according to the first structure format includes: determining K adjacent complex numbers in the first data sequence corresponding to each storage structure and a continuous first address space on the memory corresponding to each storage structure; for each storage structure, storing K real parts of the K complex numbers corresponding to the storage structure to a continuous sub-address space in the corresponding first address space, and storing K imaginary parts of the K complex numbers corresponding to the storage structure to another continuous sub-address space in the corresponding first address space. By allocating the first address space corresponding to each storage structure, the first address space is used to store the complex numbers corresponding to the storage structure. Each storage structure has its corresponding first address space, and the first address space corresponding to each storage structure is used to store its corresponding K complex numbers. The storage structure indicates that the K complex numbers corresponding to it are continuously present in the first address space corresponding to it, specifically, the K real parts of the K complex numbers are continuously present in a continuous sub-address space in the first address space, and the K imaginary parts of the K complex numbers are continuously present in another continuous sub-address space in the first address space. Storing complex numbers in the first structure format can improve the reading and writing efficiency of data.
[0011] In a possible implementation, the size of K is set according to the length of the register of the electronic device and the bit width of the data to be stored, so as to ensure that the K real parts or K imaginary parts corresponding to a substructure can be stored in the same register, thereby improving the efficiency of data reading and writing. In a possible implementation, the complex numbers related to the fast Fourier operation come from one or more of the following data: input data, intermediate data in the operation process, output data, and butterfly factor matrix. In a possible implementation, when the complex numbers related to the fast Fourier operation come from the butterfly factor matrix, and the butterfly factor matrix is L rows and M columns, the method also includes: dividing the adjacent K butterfly factors in each column of the butterfly factor matrix into a first data sequence, and each data sequence obtained corresponds to a different part of the butterfly factor matrix, and the number of the first data sequence obtained is M*L / K, L is an integer greater than 2, and M is an integer greater than 1. In the subsequent storage of butterfly factors according to the first structure format, the efficiency of data reading and writing is improved.
[0012] In a possible implementation, the method further includes: obtaining a first read instruction; in response to the first read instruction, storing the K real parts in the memory into a register of the electronic device, and loading the K imaginary parts in the memory into another register of the electronic device. Based on the first structural format for storing complex numbers, the K real parts continuously stored in the memory can be subsequently loaded into a register based on the first read instruction (such as the LD1 instruction), and the K imaginary parts continuously stored in the memory can be stored into a register based on another LD1 instruction, thereby improving the data reading efficiency.
[0013] In a second aspect, the present application provides an electronic device, which includes a memory, a register, and at least one processor, wherein the memory is used to store instructions and complex numbers, the register is used to store complex numbers, and the processor is used to execute instructions to implement any of the above methods.
[0014] In a third aspect, the present application provides a computer-readable storage medium, wherein the computer-readable storage medium stores a program, and the program enables an electronic device to execute any of the above methods.
[0015] In a fourth aspect, the present application provides a computer program product, which includes computer-readable instructions, and implements any of the above methods when the computer-readable instructions are executed by one or more processors.
[0016] The technical effects obtained by the above-mentioned second, third and fourth aspects are similar to the technical effects obtained by the corresponding technical means in the first aspect, and will not be repeated here. BRIEF DESCRIPTION OF THE DRAWINGS
[0017] Figure 1A A schematic diagram of a one-dimensional signal provided in an embodiment of the present application.
[0018] Figure 1B The Fourier transform extraction method provided in the embodiment of the present application Figure 1A Illustration of the frequency components of a one-dimensional signal.
[0019] Figure 2A A schematic diagram of an image signal provided in an embodiment of the present application.
[0020] Figure 2B Provided in the embodiments of this application Figure 2A Schematic diagram of the frequency domain result after the image signal is transformed by two-dimensional Fourier transform.
[0021] Figure 3 A schematic diagram of an 8-point radix-2 FFT calculation provided in an embodiment of the present application.
[0022] Figure 4 Schematic diagram of the roof line model provided in an embodiment of the present application.
[0023] Figure 5 A schematic diagram of a vectorized addition operation is provided for an embodiment of the present application.
[0024] Figure 6 A schematic diagram of a reading and writing method when the real part and the imaginary part are stored alternately provided in an embodiment of the present application.
[0025] Figure 7 A schematic diagram of another reading and writing method when the real part and the imaginary part are stored alternately provided in an embodiment of the present application.
[0026] Figure 8 A schematic diagram of the FFT calculation library structure provided in an embodiment of the present application.
[0027] Fig. 9 A schematic diagram of the structure of a complex data processing system provided in an embodiment of the present application.
[0028] Fig.10 A schematic flow chart of a method for processing complex data provided in an embodiment of the present application.
[0029] Fig.11 A schematic diagram of the first structural format storage provided in an embodiment of the present application.
[0030] Fig.12 Another schematic diagram of the first structural format storage provided in an embodiment of the present application.
[0031] Fig.13A A schematic diagram of a butterfly factor matrix provided in an embodiment of the present application.
[0032] Fig. 13B A storage diagram of a butterfly factor matrix provided in an embodiment of the present application.
[0033] Fig. 13C Another storage diagram of the butterfly factor matrix provided in an embodiment of the present application.
[0034] Fig.14 A schematic diagram of an example application scenario of the complex data processing method provided in an embodiment of the present application.
[0035] Fig.15 A schematic diagram of the performance comparison results provided in the embodiments of the present application.
[0036] Fig.16 A schematic diagram of the structure of an electronic device provided in an embodiment of the present application. DETAILED DESCRIPTION
[0037] In order to make the purpose, technical scheme and advantages of the present application clearer, the following will further describe the implementation mode of the present application in detail with reference to the accompanying drawings. In the present application, A and B correspondence can be understood as A and B are associated, or A and B have an associated relationship. It should be understood that the division of the modes, situations, categories and embodiments in the embodiments of the present application is only for the convenience of description and should not constitute a special limitation. The features in various modes, categories, situations and embodiments can be combined without contradiction. It should also be understood that the "first" and "second" in the application embodiments are only for distinction and should not constitute any limitation to the present application.
[0038] Fourier transform is a tool for converting signals between time domain and frequency domain. It is widely used in different fields such as physics, medicine, wireless communication and integrated circuits. Figure 1A The frequency components in the one-dimensional signal shown in the figure, the main frequency components extracted are as follows Figure 1B As shown. For another example, Figure 2A After the image signal is transformed by two-dimensional Fourier transform, the frequency domain result is as follows Figure 2B As shown. Figure 2B The frequency domain results shown show that Fourier transform can achieve filtering and noise reduction functions in the frequency domain. Discrete Fourier Transform (DFT) is a special form of input signal with discrete values. Its mathematical expression is as follows:
[0039]
[0040] Where x[n] is the input signal, X(k) is the output signal, is called the butterfly factor, and N is the signal length. The computational complexity of the above formula is O(N 2In the 1960s, people proposed a fast Fourier transform algorithm (i.e., fast Fourier transform). The most famous of these is the Cooley-Tukey algorithm based on the divide-and-conquer strategy, which successfully reduces the computational complexity to O(N log N). The general form of the Cooley-Tukey algorithm can be expressed as follows:
[0041]
[0042] Wherein N is the signal length, N=N1N2, n=N2n1+n2, 0≤n1≤N1-1, 0≤n2≤N2-1; k=N1k2+k1, 0≤k1≤N1-1, 0≤k2≤N2-1.
[0043] Fast Fourier transform is widely used in various fields (such as signal processing). It is one of the most important algorithms in the field of high performance computing (HPC), but its computational efficiency is low and difficult to optimize. Figure 3 As shown in the figure, an 8-point radix-2 FFT calculation process is introduced as an example, in which the main operations include complex multiplication and addition operations and data transfer. Specifically, the problems involved in the calculation of the fast Fourier transform can be divided into two categories: compute-bound (computational bottleneck area) and memory-bound (bandwidth bottleneck area). Figure 4 The roofline model shown in Figure 1 details the compute-bound and memory-bound regions. When the number of FFT points is small, if the memory footprint is smaller than the size of the CPU's L2 cache, the FFT calculation is prone to compute-bound problems. When the memory footprint of the FFT points exceeds the size of the L2 cache, since the memory access process involves a large number of strided-accesses, cache misses will be difficult to avoid, and the FFT calculation is prone to memory-bound problems.
[0044] The difficulty of FFT optimization lies in how to efficiently transfer data between the computing module and the storage module, that is, how to efficiently read and store (write) data. The current mainstream research direction is to use single instruction multiple data technology to implement access and computing operations with fewer instructions to reduce operation delays. Figure 5As shown in the figure, the vectorized addition operation under the ARM NEON (SIMD instruction set under the ARM platform) extension is introduced as an example. The corresponding elements in two vectors are added by a single instruction vadd (vectorized addition), and the result is stored in the target vector, so that four integer additions can be achieved. An instruction operates on multiple data at the same time in an instruction level (SIMD) manner. The number of data operated at the same time is determined by the length of the vector register and the data type. If the length of the NEON SIMD register is 128 bits, if the operand is a 32-bit floating point number, then the SIMD instruction can operate on 4 numbers at the same time.
[0045] In order to be consistent with the mathematical definition, traditional complex number storage is performed in an alternating manner of real and imaginary parts. Taking complex numbers A and B as examples, the alternating manner of real and imaginary parts is, for example, first storing the real part of complex number A and then the imaginary part of complex number A in a continuous storage block in the memory, then storing the real part of complex number B and finally storing the imaginary part of complex number B. In view of this, when performing FFT calculations, the storage of complex numbers in the FFT calculation library is also in an alternating format of real and imaginary parts. For example, the complex number storage used by the complex FFT transform represented by FFTW (the Faster Fourier Transform in the West) is in an alternating format of real and imaginary parts, and its complex number storage format is defined as follows:
[0046] typedef double fftw_complex[2];
[0047] fftw_plan fftw_plan_dft_1d(int n, fftw_complex*in, fftw_complex*out, intsign, unsigned fags);
[0048] By default, fftw_complex consists of two doubles, where the [0] element stores the real part of the complex number and the [1] element stores the imaginary part of the complex number. typedef double fftw_complex[2] arranges the two double elements in memory in order, with the real part in front and the imaginary part in the back. The input data and output data in the FFT operation are stored in the format of the fftw_complex[2] array. For this alternating storage of the real and imaginary parts, there are two read and write implementation methods under the NEON instruction set.
[0049] The first method uses the gather-load instruction and scatter-store instruction in the NEON instruction set for reading and writing. The gather-load instruction includes the LDx instruction, and the scatter-store instruction includes the STx instruction. The x in the LDx instruction and the STx instruction can be any number from 1 to 4. Among them, LDx / STx can load independent vectors from the memory data of the structure type. For example, the LD1 instruction loads data from the memory to a vector register. The ST1 instruction stores the data in a vector register into the memory. The LD2 instruction loads data from the memory to two vector registers. The ST2 instruction stores the data in two vector registers into the memory. Taking the vector register as 64 bits as an example, for example, the LD2 instruction can load 128 bits of data from the memory at one time and save it to two vector registers, where the data with the memory address relative to address 0 is loaded into vector register 0, and the data with the memory address relative to address 1 is loaded into vector register 1. The LD1 instruction does not have a deinterleaving function, and the LD1 instruction can be used to process non-interleaved data arrays. LD2, LD3 and LD4 all have a deinterleaving function, the difference being that the corresponding numbers of registers are different.
[0050] Take the real part r0 and imaginary part i0 of complex number A, the real part r1 and imaginary part i1 of complex number B, and the real part r2 and imaginary part i2 of complex number C as examples. Figure 6 As shown, complex numbers are stored alternately in memory with their real and imaginary parts, that is, [real part r0, imaginary part i0, real part r1, imaginary part i1, real part r2, imaginary part i2, …]. Specifically, the real part r0 and imaginary part i0 of complex number A exist continuously in the memory (that is, the real part r0 and the imaginary part i0 are located continuously in the memory). In other words, the address space corresponding to the real part r0 and the imaginary part i0 of complex number A is continuous. The same is true for complex numbers B and C. The real part r1 of complex number A and the real part r1 of complex number B do not exist continuously in the memory (that is, the real part r0 and the real part r1 are located non-continuously in the memory). In other words, the address space corresponding to the real part r0 of complex number A and the real part r1 of complex number B is not continuous. As Figure 6As shown, taking a storage block storing a real part or an imaginary part as an example, the storage block storing the real part r0 is continuous with the storage block storing the imaginary part i0, the storage block storing the real part r0 is not continuous with the storage block storing the real part r1, and the storage block storing the real part r0 and the storage block storing the real part r1 are separated by a storage block storing the imaginary part i0. When the complex numbers A and C are read (loaded) from the memory to the register, the real part r0 is stored in the V0 register (register) through the LD2 instruction, the imaginary part i0 is stored in the V1 register, the real part r1 is stored in the V0 register, and the imaginary part i1 is stored in the V1 register. When the complex numbers A and C are stored from the register to the memory, the complex numbers are still stored alternately in the memory with the real and imaginary parts, and the real part r0 and the real part r1 in the V0 register and the imaginary part i0 and the imaginary part i1 in the V1 register are stored in the memory through the ST2 instruction.
[0051] The second method is to read and write based on continuous read and write instructions and data exchange instructions in registers. Among them, taking the continuous read instruction as LD1 instruction and the continuous write instruction as ST1 as an example, the loading method indicated by the LD1 instruction is continuous loading or sequential reading. The data exchange instructions in the register include ZIP1 instruction, ZIP2 instruction, UZIP1 instruction and UZIP2 instruction, among which ZIP1 instruction and ZIP2 instruction indicate interleaving the elements of two vectors (vector compression), and UZIP1 instruction and UZIP2 instruction indicate reverse interleaving the elements of two vectors (vector decompression).
[0052] Figure 7 and Figure 6 The complex numbers in are stored in memory with their real and imaginary parts alternating. Figure 7 and Figure 6 The difference is that Figure 7When complex numbers A and B are read from the memory to the register, the real part r0 and the imaginary part i0 that are continuously in the memory are stored in the V0 register through an LD1 instruction, and the real part r1 and the imaginary part i1 that are continuously in the memory are stored in the V1 register through another LD1 instruction. And the real part r0 in the V0 register and the real part r1 in the V1 register are stored in the V2 register through the ZIP1 instruction and the ZIP2 instruction, that is, the real part r0 and the real part r1 are packed. And the imaginary part i0 in the V0 register and the imaginary part i1 in the V1 register are stored in the V3 register, that is, the imaginary part i0 and the imaginary part i1 are packed. When complex numbers A and B are written from the register to the memory, the real part r0 in the V2 register is stored in the V0 register, the real part r1 is stored in the V1 register, the imaginary part i0 in the V3 register is stored in the V0 register, and the imaginary part i1 is stored in the V1 register through the UZIP2 instruction and the UZIP1 instruction. Then, through another ST1 instruction, the real part r0 and the imaginary part i0 in the V0 register are continuously stored in the memory, and through another ST1 instruction, the real part r1 and the imaginary part i1 in the V1 register are continuously stored in the memory.
[0053] To be consistent with the mathematical definition, as mentioned above, traditional complex numbers are stored in alternating real and imaginary parts. However, from the perspective of underlying instruction implementation, this does not guarantee efficient reading and storage of input and output data. The above two reading and writing methods have low reading and writing efficiency. The first method involves reading and writing data across strides, and the second method involves data exchange operations within registers.
[0054] In another possible implementation, the complex number is split into real and imaginary parts, and the real and imaginary parts are stored separately, that is, the real and imaginary parts of the complex number are stored separately. Taking FFTW as an example, the splitformat is introduced in the guru interface:
[0055] fftw_plan fftw_plan_guru_split_dft(
[0056] int rank,const fftw_iodim*dims,
[0057] int howmany_rank,const fftw_iodim*howmany_dims,
[0058] double*ri, double*ii, double*ro, double*io,
[0059] unsigned flags);
[0060] Among them, ri and ii represent the real and imaginary arrays of the input data, respectively, and ro and io represent the real and imaginary arrays of the output data, respectively. In this data storage format, the LD1 instruction and ST1 instruction can be used to perform continuous read and write operations on each split array (real array and imaginary array).
[0061] For input data and output data, a single complex array is split into two arrays, the real part array and the imaginary part array, which has a high splitting cost. At the same time, it causes a significant increase in the number of function parameters, reducing the robustness of the program. Since a complex array is split into two arrays of real and imaginary parts, two independent pointers are required to access them and there are problems such as memory alignment. The memory overhead of the real and imaginary arrays is greater than that of a complex array, which will aggravate the memory bound problem in large-size FFT operations. In addition, because the two arrays of the real and imaginary parts are located in different locations in the memory, different cache lines may need to be accessed simultaneously during the FFT calculation process, resulting in additional read and write overhead between the cache and the register.
[0062] In view of this, the embodiment of the present application provides a complex data processing method and related equipment, which are applied to complex data processing, especially the storage and reading of complex data. The embodiment of the present application proposes a new structural format (i.e., the first structural format below), the first structural format includes at least one storage structure, the storage structure corresponds to K adjacent complex numbers in a complex data sequence, the storage structure includes a first substructure and a second substructure, the first substructure corresponds to K real parts of the adjacent K complex numbers, the second substructure corresponds to K imaginary parts of the adjacent K complex numbers, the first substructure indicates that the address space of the corresponding K real parts on the memory is continuous, and the second substructure indicates that the address space of the corresponding K imaginary parts on the memory is continuous, and K is an integer greater than or equal to 2. Based on the first structural format, the complex data sequence to be stored is stored, that is, for the adjacent K complex numbers in the complex data sequence to be stored, the K real parts of the K complex numbers are packed together, and the K imaginary parts of the K complex numbers are packed together, and the packed K real parts are continuously present in the memory, and the packed K imaginary parts are continuously present in the memory. Thus, by storing the packed K real parts (imaginary parts) together in the memory, the data storage efficiency can be improved, and by reading the packed K real parts (imaginary parts) together into the register, the data reading efficiency can be improved. The two or more complex numbers included in the complex data sequence to be stored can come from one or more of the following data: input data required for FFT operation (calculation), intermediate data output during FFT operation, butterfly factors, and output data finally output after FFT operation. Storing the complex data involved in FFT operation in the first structural format can improve the processing efficiency of the complex data involved in FFT operation, especially the reading and writing efficiency of the complex numbers involved in FFT operation.
[0063] The FFT operation process is introduced as an example. Figure 8 As shown, the FFT calculation library 800 includes an FFT plan module 801 and an FFT execute module 802. The FFT plan module 801 takes as input the input data length and outputs three types of auxiliary data, including the total decomposition level (such as Figure 8 The three kinds of auxiliary data are used by the FFT execution module 802. The input data of the FFT execution module 802 is a complex array to be processed, intermediate data is generated during the operation, and the output data is a complex array after FFT transformation. The internal execution process of the FFT execution module 802 depends on the auxiliary data generated by the FFT planning module 801. The FFT planning module 801 can be an offline module, and the FFT execution module 802 can be an online execution module.
[0064] Exemplarily, taking the FFT calculation library 800 as an open source FFT library (FFTE-7.0-Spiral) as an example, FFTE-7.0-Spiral is developed based on the Stockham FFT algorithm, and the underlying kernel is designed and optimized for ARM's next-generation SIMD instruction set SVE. For the NEON instruction set, the following code generation rules are designed, and a new acceleration library FFTE_NEON for the NEON instruction set is generated using FFTE-7.0-Spiral as a template. As shown in Table 1 below, most of the primitive descriptions (SVE intrinsics) for SVE instructions in FFTE-7.0-Spiral are replaced by corresponding primitive descriptions (NEONintrinsics) for NEON instructions, and a small number of SVE intrinsics that cannot be matched are implemented using scalar operations.
[0065] Table 1
[0066]
[0067] It can be understood that the complex data processing provided by the present application is not limited to the FFTE library, and the present application does not make specific limitations on this. The complex data processing provided by the present application is of general significance for the construction of the FFT calculation library. Specifically, the first structural format provided in the embodiment of the present application can be used to store complex numbers related to fast Fourier operations, that is, to store complex numbers involved in the FFT operation process, including using the first structural format to store the input data, intermediate data, output data of the FFT execution module 802, and the butterfly factors required in the FFT operation process. In other words, the first structural format can be the data storage format of the complex numbers related to the FFT operation in the FFT execution module 802, including the storage format of the input data, the storage format of the output data, the storage format of the intermediate data in the execution process of the FFT execution module 802, and the storage format of the butterfly factor matrix at all levels. By applying the first structural format, the implementation of the operation of the FFT execution module 802 on the instruction set (such as the NEON instruction set) will be significantly accelerated.
[0068] The complex data processing system provided by the embodiment of the present application is introduced as an example. Fig. 9 As shown, the complex data processing system 100 includes an instruction queue 101, a fetch unit 102, a decode unit 103, an arithmetic logic unit (ALU) 104, a vector unit 105, a load / store unit (LSU) 106, a register 107, a data cache queue 108 and a memory 109.
[0069] The instructions cached in the instruction queue 101 include, but are not limited to, load / store instructions and calculation instructions, wherein the load / store instructions are used to transfer data between the register 107 and the memory 109, such as loading data from the memory 109 (or L1 / L2 cache) into the register 107, or storing data in the register 107 into the memory 109. The calculation instructions are used to perform corresponding arithmetic operations, including but not limited to, scalar addition, scalar subtraction, scalar multiplication, scalar division, vector addition, vector subtraction, vector multiplication, and vector division.
[0070] The processor may perform vector operations on vector operands stored in registers 107. Registers 107 include vector registers, each of which may store a vector operand. Registers 107 may also include other registers, such as scalar registers, which are used to store scalar data values.
[0071] The length of register 107 can be 64 bits or 128 bits, etc. For example, the ARMv7 NEON instruction set architecture has 16 128-bit vector registers, which can be named q0 to q15. In some embodiments, these 16 128-bit registers can be split into 32 64-bit registers, which can be named d0 to d31. This application does not specifically limit the type, length and naming of the registers.
[0072] The memory 109 includes a memory (ie, a memory), including but not limited to: a random access memory (RAM), a read-only memory (ROM), and a cache (CACHE).
[0073] The fetch unit 102 fetches the corresponding instruction from the instruction queue 101 to the decode unit 103. The decode unit 103 decodes the instruction fetched by the fetch unit 102 to generate appropriate control signals for controlling downstream execution resources within the processor to perform the operations required by the instruction. The control signals formed by the decode unit 103 are transmitted to one or more execution units (such as the arithmetic logic unit 104, the vector unit 105, and the load / store unit 106) within the processor.
[0074] The register 107 may store data values that form source operands for performing various operations. The arithmetic logic unit 104 and the vector unit 105 may obtain corresponding source operands from the register 107 according to corresponding control signals to implement each decoded instruction. For example, an arithmetic operation may be sent to the arithmetic logic unit 104 together with the required source operands, thereby enabling the arithmetic logic operation to be performed on these source operands, and the result value is usually output as a destination operand for storage in a specified register in the register 107.
[0075] The vector unit 105 is used to perform vectorized operations in response to decoding SIMD instructions. The vector unit 105 operates in SIMD mode. When the vector unit 105 performs vector operations, its instruction decoding component completes instruction decoding and obtains decoding results such as what instruction operation is performed, the source operand position, and the destination operand position. The vector unit 105 obtains the source operand from the vector register file and performs operations based on the source operand. The operation results are written into the destination vector register file specified by the decoding results. When necessary, the vector data in the vector register file can access the on-chip vector storage through the vector data loading instruction and the vector data loading unit (such as the load / store unit 106). A single vector instruction can simultaneously trigger the vector unit to perform operations on multiple vector data at the same time.
[0076] The load / store unit 106 is used to perform load operations to load data from the memory 109 into one of the specified registers 107 via one or more levels of the data cache queue 108 , and to perform store operations to store data from the specified register 107 back to the memory 109 .
[0077] When the load / store unit 106 performs a storage operation to store data from the register 107 back to the memory 109, the data sequence to be stored in the memory 109 can be stored using the first structural format provided in the embodiment of the present application, and K real parts of K adjacent complex numbers in the data sequence to be stored are packed together and stored in a continuous address space in the memory 109, and K imaginary parts of the K complex numbers are packed together and stored in a continuous address space in the memory 109, where K is an integer greater than or equal to 2.
[0078] The following describes a method for processing complex data in an embodiment of the present application, which can be applied to an electronic device that performs a fast Fourier transform operation, wherein the fast Fourier transform operation includes any one or more of the above operations, or other complex operations, which are not specifically limited in the present application. The method can be executed by the electronic device or by a processor of the electronic device. The following description is given by taking the processor execution as an example.
[0079] See also Fig.10, exemplarily introduces the process of the complex data processing method provided in the embodiment of the present application.
[0080] Step S101: The processor obtains a first storage instruction.
[0081] Among them, the first storage instruction indicates that the first data sequence is stored in the memory in the first structure format. The first data sequence includes two or more complex numbers related to the fast Fourier operation. The complex number related to the fast Fourier operation comes from one or more of the following data: input data, intermediate data in the operation process, output data, and butterfly factor matrix. The relevant content of the memory can refer to the above, and the memory is used as the internal memory for explanation below.
[0082] In an embodiment of the present application, a user may pre-set to store a complex data sequence in a first structural format, and then when performing a fast Fourier transform operation, the complex data sequence may be stored in the first structural format by default upon receiving a storage instruction based on the user's setting operation. In other embodiments, a user may input a storage instruction to a processor when storing a complex data sequence, and the storage instruction indicates to store the complex numbers in the first structural format.
[0083] Exemplarily, the processor receives an FFT operation request sent by an application. The application may be an application involving FFT operation. In the process of the electronic device for performing fast Fourier transform operation running an application, when the application needs to perform FFT operation on the data, an FFT operation request may be sent to the processor in the electronic device. The FFT operation request indicates the input data on which the FFT operation needs to be performed, and indicates that the input data is stored in the memory of the electronic device in a first structural format, that is, the FFT operation request includes a first storage instruction. For example, the application may be the Vienna Ab Initio simulation package (Vienna Ab-initio Simulation Package, VASP). When the wave function needs to be solved in the VASP, a wave function solution request may be sent to the processor, and the wave function solution request is an FFT operation request. When the FFT operation request is a wave function solution request, the first data sequence may be the initial data of the wave function. After receiving the FFT operation request sent by the application, the processor can obtain the first data sequence (i.e., input data) to be subjected to FFT operation from the outside (such as an external memory or an external device) according to the FFT operation request, so as to store the first data sequence to be subjected to FFT operation in the memory of the electronic device in a first structural format.
[0084] For another example, the user pre-sets to store the intermediate data in the FFT operation process in the first structural format. After the processor obtains the input data to be FFT operated according to the FFT operation request, the processor executes each calculation stage of the FFT operation. The result calculated in each calculation stage is the intermediate data. When storing the intermediate data, the storage instruction obtained by the processor is the first storage instruction, and the intermediate data is the first data sequence. The processor stores the intermediate data in the first structural format according to the user's pre-setting.
[0085] For another example, after the processor executes each calculation stage, the processor obtains a storage instruction input by the user, and the storage instruction instructs that the final calculation result (i.e., output data) after performing the FFT operation be stored in the memory in a first structural format. Then the storage instruction input by the user is the first storage instruction, and the output data is the first data sequence to be stored.
[0086] This application does not specifically limit the method for obtaining the first storage instruction.
[0087] In step S102, the processor responds to the first storage instruction and stores the first data sequence to the memory according to the first structural format, wherein the first structural format includes at least one storage structure, the storage structure corresponds to K adjacent complex numbers in the data sequence to be stored, the storage structure includes a first substructure and a second substructure, the first substructure corresponds to K real parts of the K adjacent complex numbers, the second substructure corresponds to K imaginary parts of the K adjacent complex numbers, the K real parts in the first substructure correspond to a continuous address space on the memory, the K imaginary parts in the second substructure correspond to a continuous address space on the memory, and K is an integer greater than or equal to 2.
[0088] Wherein, the size of K is set according to the length of the register of the electronic device. In some embodiments, the size of K is set according to the register of the electronic device and the length of the data type stored by the register (i.e. the bit width of the data to be stored). If the real part and the imaginary part stored in the register are both 32 bits, and the register is 128 bits, K can be set to any number from 2 to 4, that is, the setting of K can ensure that the real part or imaginary part corresponding to a substructure can be stored in the same register. In some embodiments, while ensuring that the setting of K can ensure that the real part or imaginary part corresponding to a substructure can be stored in the same register, the size of K can be configured according to actual conditions (such as user settings). Preferably, the setting of K makes one register correspond to one substructure, that is, one register just stores the real part (or imaginary part) corresponding to a full substructure, such as the above example, preferably setting K to 4, then one register just stores four real parts (or imaginary parts) of a substructure.
[0089] In the embodiment of the present application, each storage structure has its corresponding first substructure and second substructure, and the K real parts corresponding to the first substructure of the storage structure are the real parts of the K complex numbers corresponding to the storage structure. In other words, the K real parts of the K complex numbers corresponding to the storage structure are the real parts corresponding to the first substructure of the storage structure. Correspondingly, the K imaginary parts corresponding to the second substructure of the storage structure are the imaginary parts of the K complex numbers corresponding to the storage structure. In other words, the K imaginary parts of the K complex numbers corresponding to the storage structure are the imaginary parts corresponding to the second substructure of the storage structure.
[0090] In an embodiment of the present application, the storage structure indicates that the K complex numbers corresponding to it exist continuously in the memory. The first substructure indicates that the K real parts corresponding to it exist continuously in the memory, that is, the K real parts in the first substructure correspond to the continuous address space on the memory. The second substructure indicates that the K imaginary parts corresponding to it exist continuously in the memory, that is, the K imaginary parts in the second substructure correspond to the continuous address space on the memory, and the continuous address space includes the continuous physical address space of the memory. In some embodiments, the continuous address space includes the continuous logical address space and the continuous physical address space.
[0091] In some embodiments, the K real parts corresponding to the first substructure of the storage structure and the K imaginary parts corresponding to the second substructure of the storage structure exist continuously in the memory. For example, the K real parts are continuously located in the address space of the memory, and the K imaginary parts are continuously located in another address space of the memory, and the address space where the real part is located is continuous with the address space where the imaginary part is located, such as the address space where the real part is located is located after the address space where the imaginary part is located, or the address space where the imaginary part is located is located in the address space where the real part is located, that is, the K real parts are located after the K imaginary parts, or the K imaginary parts are located after the K real parts.
[0092] In an embodiment of the present application, when the number of storage structures N is greater than or equal to 2, the parts of the data sequence corresponding to each storage structure are different. Taking the case where the data sequence to be stored includes plural numbers A to F, and N is 3, the first structural format corresponding to the data sequence to be stored includes storage structures a, b, and c, where storage structure a corresponds to the first part of the data sequence, which includes plural numbers A and B, another storage structure b corresponds to the second part of the data sequence, which includes plural numbers C and D, and another storage structure c corresponds to the third part of the data sequence, which includes plural numbers E and F. In other words, different storage structures are used to guide the storage of different parts of the data sequence to be stored, so that the data sequence to be stored is guided by the N storage structures.
[0093] In an embodiment of the present application, when the number N of storage structures is greater than or equal to 2, the first structural format includes N first substructures and N second substructures, and the first substructures and the second substructures in the first structural format are arranged alternately. The first substructure and the second substructure may be arranged alternately such that the first substructure is arranged first and the second substructure is arranged later, or the second substructure is arranged first and the first substructure is arranged later. According to the part of the data sequence to be stored corresponding to the N storage structures, the first structural format may indicate the relationship between the N storage structures stored in the memory, or may indicate the order in which the N storage structures are stored.
[0094] As in the above example, the first structure format includes storage structure a, storage structure b and storage structure c, then the first structure format is: [the first substructure of storage structure a, the second substructure of storage structure a, the first substructure of storage structure b, the second substructure of storage structure b, the first substructure of storage structure c, the second substructure of storage structure c], which is specifically expanded to: [the real part of complex number A, the real part of complex number B, the imaginary part of complex number A, the imaginary part of complex number B, the real part of complex number C, the real part of complex number D, the imaginary part of complex number C, the imaginary part of complex number D, the real part of complex number E, the real part of complex number F , the imaginary part of complex number E, the imaginary part of complex number F], or the first structure format is: [the second substructure of storage structure a, the first substructure of storage structure a, the second substructure of storage structure b, the first substructure of storage structure b, the second substructure of storage structure c, the first substructure of storage structure c], specifically expanded to: [the imaginary part of complex number A, the imaginary part of complex number B, the real part of complex number A, the real part of complex number B, the imaginary part of complex number C, the imaginary part of complex number D, the real part of complex number C, the real part of complex number D, the imaginary part of complex number E, the imaginary part of complex number F, the real part of complex number E, the real part of complex number F].
[0095] In an embodiment of the present application, the processor stores the first data sequence to the memory according to the first structure format, including: the processor determines the K adjacent complex numbers in the first data sequence corresponding to the storage structure, the processor stores the K real parts corresponding to the first substructure of the storage structure to a continuous address space on the memory according to the K adjacent complex numbers in the first data sequence, and the processor stores the K imaginary parts corresponding to the second substructure of the storage structure to another continuous address space on the memory according to the K adjacent complex numbers in the first data sequence. In other words, for the same storage structure, the K real parts corresponding to the first substructure of the storage structure are continuously stored in the memory, and the K imaginary parts corresponding to the second substructure of the storage structure are continuously stored in the memory.
[0096] Specifically, when storing according to the first structure format, the K complex numbers corresponding to the storage structure are stored in a continuous address space in the memory, so that the K complex numbers corresponding to the storage structure exist continuously in the memory. Specifically, the K complex numbers are continuously located in the memory according to the first substructure and the second substructure of the storage structure, that is, the K real parts of the K complex numbers are continuously located in a storage address space of the memory according to the first substructure, and the K imaginary parts of the K complex numbers are continuously located in another storage address space of the memory according to the second substructure.
[0097] In an embodiment of the present application, when the number N of storage structures is greater than or equal to 2, the processor stores a first data sequence to a memory according to a first structure format, including: determining K adjacent complex numbers in the first data sequence corresponding to each storage structure and a continuous first address space on the memory corresponding to each storage structure; for each storage structure, storing the K real parts of the K complex numbers corresponding to the storage structure in a continuous sub-address space in the corresponding first address space, and storing the K imaginary parts of the K complex numbers corresponding to the storage structure in another continuous sub-address space in the corresponding first address space.
[0098] For a first data sequence to be stored, the number of storage structures in the corresponding first structure format is determined to be N according to its length and K, and the first data sequence is divided into N parts, and each storage structure corresponds to a part of the sequence. If the first data sequence includes 10 complex numbers and K is 2, it can be determined that N is 5, that is, the first data sequence is divided into 5 partial sequences according to K. A corresponding first address space is allocated to each storage structure, that is, a corresponding first address space is allocated to each of the N partial sequences, and N first address spaces are allocated to the first data sequence. The N first address spaces may be adjacent or non-adjacent in the address space, and the sub-address space storing the real part and the sub-address space storing the imaginary part in the same first address space may be adjacent or non-adjacent in the address space.
[0099] As in the above example, the first data sequence includes complex numbers A to F arranged in sequence, and the first structure format is: [the first substructure of storage structure a, the second substructure of storage structure a, the first substructure of storage structure b, the second substructure of storage structure b, the first substructure of storage structure c, the second substructure of storage structure c], and the processor determines that the portion of the first data sequence corresponding to storage structure a includes complex numbers A and B, and the continuous first address space on the memory allocated to storage structure a is G1. The processor determines that the portion of the first data sequence corresponding to storage structure b includes complex numbers C and D, and the continuous first address space on the memory allocated to storage structure b is G2. The processor determines that the portion of the first data sequence corresponding to storage structure c includes complex numbers E and F, and the continuous first address space on the memory allocated to storage structure c is G3. According to the substructures of each storage structure, K complex numbers are continuously located in the allocated first address space. Specifically, the real part of complex number A and the real part of complex number B are used as the real part corresponding to the first substructure of storage structure a, and the real part of complex number A and the real part of complex number B are continuously located in a continuous subaddress space G11 of the first address space G1. The imaginary part of complex number A and the imaginary part of complex number B are used as the imaginary part corresponding to the second substructure of storage structure a, and the imaginary part of complex number A and the imaginary part of complex number B are continuously located in a continuous subaddress space G12 of the first address space G1. Correspondingly, the real part of complex number C and the real part of complex number D are continuously located in a continuous subaddress space G21 of the first address space G2, and the imaginary part of complex number D and the imaginary part of complex number D are continuously located in a continuous subaddress space G22 of the first address space G2. The rest is analogous and will not be repeated here.
[0100] In an embodiment of the present application, when the complex source butterfly factor matrix related to the fast Fourier operation, that is, the above-mentioned first data sequence belongs to the butterfly factor matrix, and the butterfly factor matrix has L rows and M columns, the complex data processing method of the present application also includes: dividing the adjacent K butterfly factors in each column of the butterfly factor matrix into a first data sequence, and the parts of the butterfly factor matrix corresponding to each obtained data sequence are different from each other, and the number of obtained first data sequences is M*L / K, L is an integer greater than 2, and M is an integer greater than 1.
[0101] In an embodiment of the present application, the processor obtains a first read instruction, and in response to the first read instruction, loads the K real parts in the memory into a register of the electronic device, and records the K imaginary parts in the memory into another register of the electronic device.
[0102] The first storage instruction can be implemented as a SIMD instruction, such as an ST1 instruction, and the first read instruction can be implemented as a SIMD instruction, such as an LD1 instruction. The K real parts of the adjacent K complex numbers in the data sequence to be stored are stored in a continuous address space in the memory through the ST1 instruction, and the K imaginary parts of the adjacent K complex numbers in the data sequence to be stored are stored in another continuous address space in the memory through another ST1 instruction, thereby realizing efficient data storage. Accordingly, when the complex number is stored in the first structural format, the K real parts continuously stored in the memory can be read into a register based on the LD1 instruction, and the K imaginary parts continuously stored in the memory can be read into another register based on another LD1 instruction, thereby improving the data reading efficiency.
[0103] The following description is given by taking the first data sequence as a one-dimensional array.
[0104] The one-dimensional array can be any of the input data, output data and intermediate data in the FFT operation process. Taking K as 2 as an example, the first structural format provided by the embodiment of the present application is exemplified. The first structural format is: [real part, real part, imaginary part, imaginary part, real part, real part, ...]. In other words, the first structural format indicates that the two real parts corresponding to the two adjacent complex numbers in the first data sequence are packed together, followed by the two imaginary parts corresponding to the two adjacent complex numbers being packed together.
[0105] The NEON instruction implementation corresponding to the data storage structure format of [real part, real part, imaginary part, imaginary part, real part, real part, ...] is as follows Fig.11 As shown. Two consecutive real parts are taken out from the memory and stored in the V0 register through an LD1 instruction, and two consecutive imaginary parts are taken out from the memory and stored in the V1 register through another LD1 instruction. Two consecutive real parts in the V0 register are stored in a consecutive address space in the memory through an ST1 instruction, and two consecutive imaginary parts in the V1 register are stored in another consecutive address space in the memory through another ST1 instruction.
[0106] Taking K as 4 as an example, the first structural format provided by the embodiment of the present application is exemplarily introduced. The first structural format is: [real part, real part, real part, real part, imaginary part, imaginary part, imaginary part, imaginary part, ...]. In other words, the first structural format indicates that the four real parts corresponding to the four adjacent complex numbers in the first data sequence are packed together, followed by the four imaginary parts corresponding to the four adjacent complex numbers being packed together.
[0107] The NEON instruction implementation corresponding to the data storage structure format of [real part, real part, real part, real part, imaginary part, imaginary part, imaginary part, imaginary part, ...] is as follows Fig.12As shown. Four consecutive real parts are taken out from the memory and stored in the V0 register through an LD1 instruction, and four consecutive imaginary parts are taken out from the memory and stored in the V1 register through another LD1 instruction. Four consecutive real parts in the V0 register are stored in a consecutive address space in the memory through an ST1 instruction, and four consecutive imaginary parts in the V1 register are stored in another consecutive address space in the memory through another ST1 instruction.
[0108] In the first structural format, data can be efficiently read using SIMD instructions such as the LD1 instruction, and data can be efficiently stored using SIMD instructions such as the ST1 instruction, completely avoiding the cross-stride reading and writing of data in the memory and the exchange of data between registers, and also avoiding the operation of splitting the complex number into two arrays.
[0109] The following description is given by taking the first data sequence as a two-dimensional array.
[0110] The two-dimensional array includes a butterfly factor array (matrix), that is, the complex number to be stored is a butterfly factor. The calculation process of the butterfly factor is introduced as an example. The radix in FFTE_NEON is generated according to the Stockham FFT algorithm. In Stockham FFT, the calculation process of the butterfly factor is as follows:
[0111] Where M = DFT radix, L = N / M, N is the length of the FFT input data. Taking the Stockham FFT of Raidx 4 as an example, the reading mode of the butterfly factor is explained, please refer to the following code:
[0112] Do j=0to L-1
[0113] Do k=0to M-1
[0114] C0=X(k+jm)
[0115] C1=X(k+jm+lm)
[0116] C2=X(k+jm+2lm)
[0117] C3=X(k+jm+3lm)
[0118] D0=C0+C2
[0119] D1=C0-C2
[0120] D2=C1+C3
[0121] D3=i(C1-C3)
[0122] Y(k+4jm)=D0+D2
[0123]
[0124]
[0125]
[0126] End do
[0127] End do
[0128] The butterfly factor in the above code It will be pre-generated in the form of a two-dimensional array. Fig.13A As shown in , the generated butterfly factor matrix has L rows and M columns. The actual arrangement of the butterfly factor matrix in memory is as follows Fig. 13B As shown, the real part and the imaginary part of each butterfly factor are arranged alternately and stored in the same row, and the real part and the imaginary part of the butterfly factor in each row are arranged alternately. Fig. 13B The data along the column direction (L direction) is not continuous in the memory, for example, Fig. 13B The real and imaginary parts in the first row shown are stored in a continuous memory block A in the memory, and Fig. 13B The real and imaginary parts in the second row are shown stored in another continuous memory block B in the memory.
[0129] like Fig. 13B As shown in , when k = 0, vectorization will be performed along the L direction (column direction) of the two-dimensional array. Since the data in the column direction is discontinuous in the memory, Fig. 13B As shown, a very inefficient scalar instruction is used for reading. For example, to read the butterfly factor W 0,0 , W 0,1 , W 1,0 and W 1,1 For example, the butterfly factor W 0,0 and the butterfly factor W 1,0 The real and imaginary parts of are arranged alternately in the first row and stored in memory block A accordingly. The butterfly factor W 0,1 and butterfly factor and W 1,1 The real and imaginary parts of are arranged alternately in the second row and stored in memory block B accordingly. The butterfly factor W is read from memory block A by a scalar instruction. 0,0 The real part Re 0,0 , and then read the butterfly factor W from memory block B through a scalar instruction 0,1 The real part Re 0,1 , and then read the butterfly factor W from memory block A through a scalar instruction 0,0 The imaginary part Im 0,0 , and then read the butterfly factor W from memory block B through a scalar instruction 0,1 The imaginary part Im0,1 , and then read the butterfly factor W from memory block A through a scalar instruction 1,0 The real part Re 1,0 , and then read the butterfly factor W from memory block B through a scalar instruction 1,1 The real part Re 1,1 , and so on, scalar instructions have low efficiency in reading data.
[0130] Based on the first structure format provided by the present application, K adjacent butterfly factors in each column of the butterfly factor matrix are divided into a first data sequence. Fig.13A The butterfly factor matrix shown, K is 2 as an example, for Fig.13A The first column of the butterfly factor matrix shown in FIG. 1 divides two adjacent butterfly factors in the first column into a first data sequence, and the butterfly factor W 0 ,0 , W 0,1 is a first data sequence, W 0,2 , W 0,3 is a first data sequence, and so on, for the first column, L / 2 first data sequences can be obtained. Fig.13A The butterfly factor matrix shown in FIG. 1 can obtain M*L / 2 first data sequences. For each data sequence in the butterfly factor matrix, complex numbers are stored based on the first structure format. For example, for two complex butterfly factors W in the first data sequence, 0,0 , W 0,1 , the butterfly factor W 0,0 The real part and W 0,1 The real part of the butterfly factor W is stored in a continuous address space. 0,0 The imaginary part and W 0,1 The imaginary part of is stored in another continuous address space. For related content, please refer to the above.
[0131] In another specific implementation, based on the first structure format provided by this application, Fig. 13B The butterfly factor matrix shown in the figure is transposed to a size of 2X2. After the transposition, the butterfly factors are arranged in memory as follows Fig. 13C Specifically, taking the first two rows in the butterfly factor matrix as an example, Fig. 13B The imaginary part of the first line is shown as 0,0 and the real part of the second row Re 0,0 Replace the imaginary part of the first row with Im 1,0 and the real part of the second row Re 1,1 Permutation, and so on, we get two adjacent rows, one row stores the real part of the butterfly factor, and the other row stores the imaginary part of the butterfly factor.
[0132] In some embodiments, Fig. 13CIn the figure, two adjacent rows in the transposed butterfly factor matrix are used as a storage structure, and one of the two rows storing the real part is used as the first substructure of the storage structure, and one of the two rows storing the imaginary part is used as the second substructure of the storage structure. Fig. 13C The real part Re 0,0 The row where the imaginary part Im 0,0 As a storage structure, the real part Re 0,0 The row is the first substructure of the storage structure, and the real part Re 0,0 The real parts of the row are stored in a continuous address space in the memory, and the imaginary parts Im 0,0 The row is the second substructure of the storage structure, and the imaginary part Im 0,0 The real parts of the row are stored in another continuous address space in the memory. Fig. 13C The real part Re 0,2 The row where the imaginary part Im 0,2 As another storage structure, and so on.
[0133] Will Fig. 13C As shown in the figure, the data of each row in the transposed butterfly factor matrix is stored in the corresponding continuous address space, and the vectorization after transposition is along the M direction (row direction) of the two-dimensional array. Based on the fact that the data of each row is continuous in the memory, that is, the memory address is continuous, the LD1 instruction can be used to implement the vectorized read operation.
[0134] In other embodiments, Fig. 13C As shown, taking K as 2 as an example, two adjacent real parts Re 0,0 and Re 0,1 Stored to a continuous address space, another LD1 instruction is used to store the two adjacent imaginary parts Im 0,0 and Im 0,1 Stored to another continuous address space. Accordingly, two adjacent real parts Re in a continuous address space can be stored to another continuous address space through an ST1 instruction. 0,0 and Re 0,1 Stored to a register, another ST1 instruction is used to store two adjacent imaginary parts Im in a continuous address space. 0,0 and Im 0,1 Store to another register.
[0135] See also Fig.14 , exemplarily introduces the application scenario of the complex data processing method provided in the embodiment of the present application.
[0136] The novel data storage format proposed in the embodiment of the present application can also be applied to each stage of FFT operation, namely, the input data link of FFT execution module 802, the data storage link during the operation, the butterfly factor storage link during the operation, and the output data storage link after the operation. For example, FFT operation includes three calculation stages, namely, one DFT16 operation stage and two DFT8 operation stages. Fig.14 As shown in (a) in the figure, the input data, the intermediate data involved in the calculation phase, and the output data are all in the format of alternating real and imaginary parts. Fig.14 As shown in (b) of FIG. 1 , the input data, the intermediate data involved in the calculation phase, and the output data are all in the first structure format provided by the present application. In another application scenario, such as Fig.14 As shown in (c) in FIG. 1 , the input data and the output data are both in the format of alternating real and imaginary parts, and the intermediate data involved in the calculation stage are all in the first structure format provided by the present application. In another application scenario, Fig.14 As shown in (d), the input data is in the format of alternating real and imaginary parts, and the intermediate data and output data involved in the calculation stage are all in the first structural format provided by this application. In another possible application scenario, the user can store part of the intermediate data in the calculation stage in the format of alternating real and imaginary parts, and store part of the intermediate data in the first structural format according to actual needs. If the input data is stored in the first structural format, after the DFT16 operation stage, the intermediate data is stored in the memory in the first structural format through the ST1 instruction, and when the DFT8 operation stage is performed, the data stored in the memory is read into the register through the LD1 instruction. After the DFT8 operation stage, the intermediate data is stored in the memory in the form of alternating real and imaginary parts through the ST2 instruction, and when the next DFT8 operation stage is performed, the data stored in the memory is read into the register through the LD2 instruction.
[0137] The embodiment of the present application does not specifically limit which link of the FFT operation the first structure format is used in, nor does it specifically limit the format of alternating storage of the first structure format and the real and imaginary parts. The first structure format can be used flexibly according to actual conditions to achieve a trade-off between performance and data storage format.
[0138] In order to quantify the performance benefits brought by the first structure format, the experimental hardware is Kunpeng 920 processor, 48 cores x2, CPU frequency is 2.6GHz, memory is 504GB DDR4-2933, and 1D complex-to-complex double precision DFT is performed as an example. The comparative experiments shown in Table 2 are set. Experiment 1 is performed in FFTW 3.3.10, and Experiment 2 is performed in FFTE_NEON calculation library. Fig.14 In the application scenario (b) in Experiment 3, the FFTE_NEON computing library is used in Fig.14 In the application scenario (c) in Experiment 4, the FFTE_NEON computing library is used in Fig.14 The experiment was carried out in the application scenario (a) in Experiment 5. The FFTE_NEON computing library was used in Fig.14 The experiment was carried out in the application scenario (d) in Experiment 6, and Experiment 6 was carried out in ARM performance library 21.0.
[0139] Table 2
[0140] Comparative experiment FFT calculation library Experiment 1 FFTW 3.3.10 Experiment 2 FFTE_NEON calculation library is in Fig.14 (b) Application scenario Experiment 3 FFTE_NEON calculation library is in Fig.14 (c) Application scenario Experiment 4 FFTE_NEON calculation library is in Fig.14 (a) Application scenario Experiment 5 FFTE_NEON calculation library is in Fig.14 (d) Application scenario Experiment 6 ARM performance library 21.0
[0141] Performance comparison results are as follows Fig.15 As shown, the performance results of Experiment 1 correspond to curve 1, the performance results of Experiment 2 correspond to curve 2, the performance results of Experiment 3 correspond to curve 3, the performance results of Experiment 4 correspond to curve 4, the performance results of Experiment 5 correspond to curve 5, and the performance results of Experiment 6 correspond to curve 6.
[0142] From Curve 2 corresponding to Experiment 2 and Curve 1 corresponding to Experiment 1, it can be seen that since the input data, intermediate data, and output data in Experiment 2 all use the first structure format, the FFTE_NEON calculation library Fig.14 The performance of the application scenario (b) is 47% higher than that of FFTW3.3.10 (i.e., Giga Floating-point Operations Per Second, GFLOPS) on average. From curve 2 corresponding to experiment 2 and curve 4 corresponding to experiment 4, it can be seen that the FFTE_NEON computing library is Fig.14 The 1 billion floating-point operations per second in the application scenario (b) is 24% higher than the FFTE computing library that does not adopt the first structural format.
[0143] From the curve 5 corresponding to experiment 5 and the curve 1 corresponding to experiment 1, we can see that the FFTE_NEON calculation library is Fig.14The application scenario (d) uses a mixed data format, and its 1 billion floating-point operations per second leads FFTW by an average of 3.3.1041%.
[0144] From Curve 3 corresponding to Experiment 3 and Curve 6 corresponding to Experiment 6, it can be seen that the input and output data formats are real and imaginary alternating formats, and the intermediate data is FFTE_NEON in the first structure format. Its floating-point operations per second are 36% ahead of FFTW 3.3.10 on average, and 27% ahead of ARM_PL 21.0 on average. This proves that even if only the first structure format is used in the intermediate stage, a considerable performance advantage can be obtained.
[0145] See also Fig.16 , which exemplarily introduces the structural diagram of the electronic device provided in the embodiment of the present application.
[0146] The electronic device 10 includes a processor 110 that performs data processing operations on data items in response to a series of instructions executed by the processor 110. The instructions are stored in a memory 120. The instructions retrieved from the memory 120 by a fetch unit 150 are transmitted to a decode unit 140, which generates control signals arranged to control various aspects of the configuration and operation of the processor 110 and a set of registers 130 and a load / store unit 160.
[0147] In some possible implementations, the processor 110 may be arranged in a pipelined manner, as described above. Fig. 9 The arithmetic logic unit 104 , the vector unit 105 , and the load / store unit 106 shown may be units in a processor.
[0148] like Fig.16 As shown, each register 130 includes a memory block for multiple data components, so that the processing circuit can apply a data processing operation to a specified data component within a specified register, or can apply a data processing operation to a specified group of data components ("vectors") within a specified register. In particular, the electronic device 10 shown relates to the execution of vectorized data processing operations, and specifically to the execution of complex processing instructions associated with the data components stored in the register 130. The data values required by the processor 110 when executing instructions and the data values generated as a result of those data processing instructions are stored in the memory 120 or read from the memory 120 via the load / store unit 160, and when stored in the memory 120, they can be stored in the first structure format proposed in the present application.
[0149] In some embodiments, Fig.16The memory 120 shown may be viewed as an example of a computer-readable storage medium on which instructions of the present technology may be stored, typically as part of a predefined series of instructions (a "program") that processing circuitry then executes. However, the processor 110 may access such a program from a variety of different sources, such as in RAM, in ROM, via a network interface, etc. The present disclosure describes various novel instructions that may be executed by the processor 110 and the following figures provide further explanation of the nature of these instructions, changes in the data processing circuitry used to support the execution of those instructions, etc.
[0150] The method disclosed in the above embodiment of the present invention can be applied to the processor 110, or implemented by the processor 110. The processor 110 may be an integrated circuit chip with signal processing capabilities. In the implementation process, each step of the above method can be completed by the hardware integrated logic circuit or software instructions in the processor 110. The above processor 110 can be a general processor, a digital signal processor (Digital Signal Processor, DSP), an application specific integrated circuit (Application Specific Integrated Circuit, ASIC), a field programmable gate array (Field Programmable Gate Array, FPGA) or other programmable logic devices, discrete gates or transistor logic devices, discrete hardware components. The methods, steps and logic block diagrams disclosed in the embodiments of the present application can be implemented or executed. The general processor can be a microprocessor or the processor can also be any conventional processor, etc. The steps of the method disclosed in conjunction with the embodiment of the present invention can be directly embodied as a hardware decoding processor for execution, or a combination of hardware and software modules in the decoding processor for execution. The software module may be located in a storage medium mature in the art, such as a random access memory (RAM), a flash memory, a read-only memory (ROM), a programmable read-only memory, or an electrically erasable programmable memory, a register, etc. The storage medium is located in the memory 120. The program stored in the storage medium includes executing Fig.10 The processor 110 reads the instructions in the memory 120 and completes the steps of the above method in combination with its hardware.
[0151] The embodiment of the present application also provides a computer program product. When the computer program product is run on a computer, the computer is enabled to execute the above-mentioned related steps to implement the complex data processing methods and / or functions in the above-mentioned method embodiments.
[0152] An embodiment of the present application also provides a computer storage medium, including computer instructions. When the computer instructions are executed on an electronic device, the electronic device executes the multiple data processing methods and / or functions as described in the above embodiments.
[0153] Among them, the electronic device, computer storage medium, computer program product or chip system provided in the embodiments of the present application are all used to execute the corresponding methods provided above. Therefore, the beneficial effects that can be achieved can refer to the beneficial effects in the corresponding methods provided above, and will not be repeated here.
[0154] It should be understood that the term "and / or" in this article is only a description of the association relationship of the associated objects, indicating that there can be three relationships. For example, A and / or B can represent: A exists alone, A and B exist at the same time, and B exists alone. In addition, the character " / " in this article generally indicates that the associated objects before and after are in an "or" relationship.
[0155] Those of ordinary skill in the art will appreciate that the units and algorithm steps of each example described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, or a combination of computer software and electronic hardware. Whether these functions are performed in hardware or software depends on the specific application and design constraints of the technical solution. Professional and technical personnel can use different methods to implement the described functions for each specific application, but such implementation should not be considered to be beyond the scope of this application. Those skilled in the art can clearly understand that for the convenience and simplicity of description, the specific working process of the above-described system, device and unit can refer to the corresponding process in the aforementioned method embodiment, and will not be repeated here.
[0156] In the several embodiments provided in the present application, it should be understood that the disclosed systems, devices and methods can be implemented in other ways. For example, the device embodiments described above are only schematic. For example, the division of units is only a logical function division. There may be other division methods in actual implementation. For example, multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be through some interfaces, indirect coupling or communication connection of devices or units, which can be electrical, mechanical or other forms.
[0157] The units described as separate components may or may not be physically separated, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed on multiple network units. Some or all of the units may be selected according to actual needs to achieve the purpose of the solution of this embodiment.
[0158] In addition, each functional unit in each embodiment of the present application may be integrated into one processing unit, or each unit may exist physically separately, or two or more units may be integrated into one unit.
[0159] If the function is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present application, or the part that contributes to the prior art or the part of the technical solution, can be embodied in the form of a software product, which is stored in a storage medium and includes several instructions for a computer device (which can be a personal computer, server, or network device, etc.) to perform all or part of the steps of the various embodiments of the present application. The aforementioned storage medium includes: various media that can store program codes, such as a USB flash drive, a mobile hard disk, a read-only memory, a random access memory, a magnetic disk or an optical disk.
[0160] It is to be understood that the various numerical numbers involved in the embodiments of the present application are only for the convenience of description and are not intended to limit the scope of the embodiments of the present application. The above embodiments provided for the present application are not intended to limit the present application. Any modifications, equivalent substitutions, improvements, etc. made within the spirit and principles of the present application shall be included in the protection scope of the present application.
Claims
1. A complex data processing method, applied to an electronic device performing a fast Fourier transform operation, characterized in that: The method comprises: Obtaining a first storage instruction; In response to the first storage instruction, a first data sequence is stored in a memory according to a first structural format, wherein the first data sequence includes two or more complex numbers related to the fast Fourier operation; the first structural format includes at least one storage structure, the storage structure corresponds to K adjacent complex numbers in the data sequence to be stored, the storage structure includes a first substructure and a second substructure, the first substructure corresponds to K real parts of the K adjacent complex numbers, the second substructure corresponds to K imaginary parts of the K adjacent complex numbers, the K real parts in the first substructure correspond to a continuous address space on the memory, the K imaginary parts in the second substructure correspond to a continuous address space on the memory, and K is an integer greater than or equal to 2.
2. The complex data processing method according to claim 1, characterized in that: When the number N of the storage structures is greater than or equal to 2, the parts of the data sequence corresponding to each of the storage structures are different.
3. The complex data processing method according to claim 1 or 2, characterized in that: When the number N of the storage structures is greater than or equal to 2, the first structural format includes N first substructures and N second substructures, and the first substructures and the second substructures in the first structural format are arranged alternately.
4. The complex data processing method according to any one of claims 1 to 3, characterized in that: The storing of the first data sequence to the memory according to the first structure format comprises: Determine K adjacent complex numbers in the first data sequence corresponding to the storage structure; Storing the K real parts corresponding to the first substructure of the storage structure in a continuous address space on the memory; The K imaginary parts corresponding to the second substructure of the storage structure are stored in another continuous address space on the memory.
5. The complex data processing method according to any one of claims 1 to 3, characterized in that: When the number of the storage structures is greater than or equal to 2, storing the first data sequence to the memory according to the first structure format includes: Determine K adjacent complex numbers in the first data sequence corresponding to each of the storage structures and a continuous first address space on the memory corresponding to each of the storage structures; For each of the storage structures, the K real parts of the K complex numbers corresponding to the storage structure are stored in a continuous sub-address space in the corresponding first address space, and the K imaginary parts of the K complex numbers corresponding to the storage structure are stored in another continuous sub-address space in the corresponding first address space.
6. The complex data processing method according to any one of claims 1 to 5, characterized in that: The size of K is set according to the length of the register of the electronic device and the bit width of the data to be stored.
7. The complex data processing method according to any one of claims 1 to 6, characterized in that: The complex numbers associated with the fast Fourier operation are derived from one or more of the following data: input data, intermediate data in the operation process, output data, and a butterfly factor matrix.
8. The complex data processing method according to claim 7, characterized in that: When the complex number associated with the fast Fourier operation comes from the butterfly factor matrix, and the butterfly factor matrix has L rows and M columns, the method further includes: The adjacent K butterfly factors in each column of the butterfly factor matrix are divided into a first data sequence, so that the number of the first data sequences is M*L / K, where L is an integer greater than 2 and M is an integer greater than 1.
9. The complex data processing method according to any one of claims 1 to 8, characterized in that: The method further comprises: Obtaining a first read instruction; In response to the first read instruction, the K real parts in the memory are loaded into a register of the electronic device, and the K imaginary parts in the memory are loaded into another register of the electronic device.
10. An electronic device, characterized in that: The electronic device comprises a memory, a register and at least one processor, wherein the memory is used to store instructions and complex numbers, the register is used to store complex numbers, and the processor is used to execute the instructions to implement the method according to any one of claims 1 to 9.
11. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores a program that causes an electronic device to execute the method according to any one of claims 1 to 9.
12. A computer program product, characterized in that The computer program product comprises computer readable instructions, which implement the method according to any one of claims 1 to 9 when executed by one or more processors.
