A data processing method and data processing device based on an AI processor
By dividing the data processing program into a main program and a sub-program, and adopting a heterogeneous parallel approach, with the AI processor and the sub-processor working together, the problem of increased data processing time in existing technologies is solved, and more efficient data processing is achieved.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-09-28
- Publication Date
- 2026-03-06
AI Technical Summary
Existing technologies increase the time required for data processing when using AI processors.
The data processing program is divided into a main program and a sub-program. The main program, which involves matrix multiplication calculations, is executed by the AI processor, while the sub-program is executed by the sub-processor. The processing is carried out in a heterogeneous parallel manner to make full use of the AI processor's computing resources.
It reduces the time required for computers to execute data processing programs and improves the efficiency of computer performance testing.
Smart Images

Figure CN115629872B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of data processing technology, specifically to a data processing method and a data processing device based on an AI processor. Background Technology
[0002] Data processing on a computer, and the results and execution time of the data processing, can be used to test computer performance. Executing matrix factorization programs on a computer to obtain performance data is a common method for testing computer performance. Matrix factorization programs include HPL (High Performance Linpack) and HPL-AI. HPL (High Performance Linpack) is a widely used benchmark program for measuring the actual peak performance of a computer. HPL-AI involves setting up an AI chip in the computer, which, together with the CPU (a coprocessor), executes the matrix factorization program. The AI chip provides more support for single-precision or half-precision matrix multiplication calculations, meaning it has significant performance in handling low-precision matrix multiplication. From the above analysis, existing technologies using AI to perform data processing increase the time required for data processing.
[0003] In summary, existing technologies increase the time required for data processing.
[0004] Therefore, existing technologies still need to be improved and enhanced. Summary of the Invention
[0005] To address the aforementioned technical problems, this invention provides a data processing method and device based on an AI processor, which solves the problem of increased data processing time in existing technologies.
[0006] To achieve the above objectives, the present invention adopts the following technical solution:
[0007] In a first aspect, the present invention provides a data processing method based on an AI processor, comprising:
[0008] Based on whether each program required for data processing involves matrix multiplication, each program is divided into a main program and a sub-program. The main program involves matrix multiplication calculations, while the sub-programs do not.
[0009] The AI processor is controlled to execute the main program, and the sub-processor is controlled to execute the sub-program. The AI processor and the sub-processor are located in the same computer. The execution of the main program by the AI processor and the execution of the sub-program by the sub-processor constitute heterogeneous parallelism. The processing speed of the AI processor is greater than that of the sub-processor.
[0010] Based on the results of the main program executed by the AI processor and the results of the sub-program executed by the sub-processor, the final result of data processing is obtained.
[0011] In one implementation, the process of dividing each program into a main program and sub-programs based on whether the various programs required for data processing involve matrix multiplication, wherein the main program involves matrix multiplication calculations and the sub-programs do not, includes:
[0012] Based on the data processing described above, the matrix decomposition in the data processing is obtained;
[0013] The following programs are identified for matrix decomposition: upper and lower triangular matrix decomposition program, panel decomposition program, triangular matrix solving program, first matrix processing program, general matrix multiplication program, and second matrix processing program. The first matrix processing program is used to process the output results of the panel decomposition program and the triangular matrix solving program, and the second matrix processing program is used to process the output results of the general matrix multiplication program.
[0014] The general matrix multiplication program is divided into the main program, and the upper and lower triangular matrix decomposition program, the panel decomposition program, the triangular matrix solving program, the first matrix processing program, and the second matrix processing program are divided into the sub-programs.
[0015] In one implementation, the AI processor controls the execution of the main program, and the sub-processor controls the execution of the sub-program. The AI processor and the sub-processor reside in the same computer. The execution of the main program by the AI processor and the execution of the sub-program by the sub-processor constitute heterogeneous parallelism. The processing speed of the AI processor is greater than the processing speed of the sub-processor, including:
[0016] The AI processor is controlled to execute the general matrix multiplication program of the current iteration, and the sub-processor is controlled to execute the second matrix processing program of the current iteration. The execution time of the AI processor and the execution time of the sub-processor overlap. The current iteration is one of several iterations in the matrix decomposition.
[0017] When the current iteration is executed until the set conditions are met, the AI processor is controlled to execute the general matrix multiplication program of the current iteration, and the sub-processor is controlled to execute the upper and lower triangular matrix decomposition program, the panel decomposition program, the triangular matrix solving program, and the first matrix processing program of the next iteration. The execution time of the AI processor overlaps with the execution time of the sub-processor.
[0018] In one implementation, the AI processor is controlled to execute the general matrix multiplication program for the current iteration, and the sub-processor is controlled to execute the second matrix processing program for the current iteration. The execution time of the AI processor overlaps with the execution time of the sub-processor. The current iteration is one of several iterations in the matrix decomposition, including:
[0019] Based on the general matrix multiplication procedure of the current iteration, the first-zone matrix multiplication procedure and the second-zone matrix multiplication procedure of the current iteration are obtained. The output of the first-zone matrix multiplication procedure of the current iteration is used first in the next iteration, and the output of the second-zone matrix multiplication procedure is used first in the next iteration.
[0020] The AI processor is controlled to execute the first-zone matrix multiplication program of the current iteration until the first-zone matrix multiplication program of the current iteration is completed. At the same time, the AI processor is controlled to execute the second-zone matrix multiplication program of the current iteration, while the sub-processor is controlled to execute the second matrix processing program of the current iteration.
[0021] In one implementation, when the current iteration reaches the condition of satisfying a set condition, the AI processor is controlled to execute the general matrix multiplication program of the current iteration, and the sub-processor is controlled to execute the upper and lower triangular matrix decomposition program, the panel decomposition program, the triangular matrix solving program, and the first matrix processing program of the next iteration. The execution time of the AI processor overlaps with the execution time of the sub-processor, including:
[0022] When the execution of the first-zone matrix multiplication program of the current iteration ends, the AI processor is controlled to execute the second-zone matrix multiplication program of the current iteration, while the sub-processor is controlled to execute the upper and lower triangular matrix decomposition program, the panel decomposition program, the triangular matrix solving program, and the first matrix processing program of the next iteration in sequence, until the execution of the second-zone matrix multiplication program of the current iteration ends, and the AI processor is controlled to execute the first-zone matrix multiplication program of the next iteration.
[0023] In one implementation, when the current iteration reaches the condition of satisfying a set condition, the AI processor is controlled to execute the general matrix multiplication program of the current iteration, and the sub-processor is controlled to execute the upper and lower triangular matrix decomposition program, the panel decomposition program, the triangular matrix solving program, and the first matrix processing program of the next iteration. The execution time of the AI processor overlaps with the execution time of the sub-processor, including:
[0024] When the first-zone matrix multiplication program of the current iteration ends, the AI processor is controlled to execute the second-zone matrix multiplication program of the current iteration, while the sub-processor is controlled to execute the upper and lower triangular matrix decomposition program, the panel decomposition program, the triangular matrix solving program, the first matrix processing program, and the first-zone matrix multiplication program of the next iteration in sequence.
[0025] In one implementation, controlling the AI processor to execute the first-zone matrix multiplication procedure of the current iteration until the first-zone matrix multiplication procedure of the current iteration is completed, and simultaneously controlling the AI processor to execute the second-zone matrix multiplication procedure of the current iteration, while controlling the sub-processor to execute the second matrix processing procedure of the current iteration, includes:
[0026] After the first-zone matrix multiplication program of the current iteration is completed, the AI processor is controlled to execute the second-zone matrix multiplication program of the current iteration, while the sub-processor is controlled to execute the second matrix processing program of the current iteration to copy the output result of the first-zone matrix multiplication program to the host computer, and the AI processor is controlled to save the output result of the second-zone matrix multiplication program of the current iteration.
[0027] In one implementation, the AI processor controls the execution of the main program, and the sub-processor controls the execution of the sub-program. The AI processor and the sub-processor reside in the same computer. The execution of the main program by the AI processor and the execution of the sub-program by the sub-processor constitute heterogeneous parallelism. The processing speed of the AI processor is greater than the processing speed of the sub-processor, including:
[0028] Control the computer to start a set number of processes;
[0029] The specified number of processes are divided into four categories: Category 1 processes, Category 2 processes, Category 3 processes, and Category 4 processes.
[0030] The AI processor is controlled by the aforementioned process to execute a general matrix multiplication program, and the subprocessor is controlled to execute the upper and lower triangular matrix decomposition program, the panel decomposition program, the triangular matrix solving program, the first matrix processing program, and the second matrix processing program.
[0031] The AI processor is controlled to execute a general matrix multiplication program through the two types of processes, and the sub-processor is controlled to execute the panel decomposition program, the first matrix processing program, and the second matrix processing program.
[0032] The AI processor is controlled to execute the general matrix multiplication program and the sub-processor is controlled to execute the triangular matrix solving program, the first matrix processing program, and the second matrix processing program through the three types of processes.
[0033] The AI processor executes the general matrix multiplication program through the four types of processes.
[0034] In one implementation, obtaining the final result of data processing based on the output of the main program executed by the AI processor and the output of the sub-program executed by the sub-processor includes:
[0035] The final result of data processing is obtained by combining the output of the main program in the current iteration executed by the AI processor with the output of the next generation of the sub-program executed by the sub-processor based on the output of the main program in the current iteration.
[0036] In one implementation, the method further includes calculating the computer runtime corresponding to the final result, wherein the runtime is used to test the actual peak performance of the computer, and testing the actual peak performance of the computer includes:
[0037] The computational complexity of each program is summed to obtain the total computational complexity of the data processing.
[0038] Divide the total computational complexity by the computer runtime to obtain the actual peak performance.
[0039] Secondly, embodiments of the present invention also provide a data processing device based on an AI processor, wherein the device comprises the following components:
[0040] The program classification module is used to divide each program into a main program and a sub-program based on whether each program required for data processing involves matrix multiplication. The main program involves matrix multiplication calculation, while the sub-program does not.
[0041] A processor control module is used to control the AI processor to execute the main program and control the sub-processor to execute the sub-program. The AI processor and the sub-processor are located in the same computer. The execution of the main program by the AI processor and the execution of the sub-program by the sub-processor constitute heterogeneous parallelism. The processing speed of the AI processor is greater than that of the sub-processor.
[0042] The result calculation module is used to obtain the final result of data processing based on the results output by the main program executed by the AI processor and the results output by the sub-processor executed by the sub-processor.
[0043] Thirdly, embodiments of the present invention also provide a terminal device, wherein the terminal device includes a memory, a processor, and an AI processor-based data processing program stored in the memory and executable on the processor, wherein when the processor executes the AI processor-based data processing program, it implements the steps of the AI processor-based data processing method described above.
[0044] Fourthly, embodiments of the present invention also provide a computer-readable storage medium storing an AI processor-based data processing program, wherein when the AI processor-based data processing program is executed by a processor, it implements the steps of the AI processor-based data processing method described above.
[0045] Beneficial Effects: This invention first divides the various programs required for data processing into main programs and sub-programs based on whether they involve matrix multiplication. Since AI processors are suitable for processing matrix multiplication programs, the main programs involving matrix multiplication are executed on the AI processor to fully utilize its computing resources, while the sub-programs that do not involve matrix multiplication are executed on a secondary processor (such as the CPU) to avoid consuming the AI processor's computing resources. The secondary processor and AI processor of this invention work together to reduce the time required for the computer to execute data processing programs. In addition, the AI processor and secondary processor of this invention execute their respective programs in heterogeneous parallel execution. Heterogeneous parallel execution means that both processors execute their respective programs simultaneously, thereby further reducing the time required for the computer to execute data processing programs. Attached Figure Description
[0046] Figure 1 This is an overall flowchart of the present invention;
[0047] Figure 2 This is a schematic diagram of the original matrix A in an embodiment of the present invention;
[0048] Figure 3 This is a schematic diagram of the matrix after performing one iterative decomposition on the original matrix A in an embodiment of the present invention;
[0049] Figure 4 This is a schematic diagram of the matrix after the second iterative decomposition in an embodiment of the present invention;
[0050] Figure 5 This is a schematic diagram of the matrix after the second iterative decomposition in an embodiment of the present invention;
[0051] Figure 6 This is a schematic diagram of the gemm priority update region and gemm remaining region in an embodiment of the present invention;
[0052] Figure 7This is a diagram of the asynchronous parallel pipeline for matrix decomposition in an embodiment of the present invention;
[0053] Figure 8 This is a schematic diagram illustrating all computation and communication steps and their dependencies for the four types of processes in this embodiment of the invention.
[0054] Figure 9 This is a simulation diagram in an embodiment of the present invention;
[0055] Figure 10 This is a block diagram illustrating the internal structure of a terminal device provided in an embodiment of the present invention. Detailed Implementation
[0056] The technical solutions of the present invention will be clearly and completely described below with reference to the embodiments and accompanying drawings. All other embodiments obtained by those skilled in the art based on the embodiments of the present invention without inventive effort are within the scope of protection of the present invention.
[0057] Research has found that data processing on a computer, and the results and execution time of the data processing, can be used to test computer performance. Executing matrix factorization programs on a computer to obtain performance data is a common method for testing computer performance. Matrix factorization programs include HPL (High Performance Linpack) and HPL-AI. HPL (High Performance Linpack) is a widely used benchmark program for measuring the actual peak performance of a computer. HPL-AI involves setting up an AI chip in the computer, which, together with the CPU (a coprocessor), executes the matrix factorization program. The AI chip provides more support for single-precision or half-precision matrix multiplication calculations, meaning it has significant performance in handling low-precision matrix multiplication. Based on the above analysis, existing technologies using AI for data processing increase the time required for data processing.
[0058] To address the aforementioned technical problems, this invention provides a data processing method and apparatus based on an AI processor, solving the problem of increased data processing time in existing technologies. In specific implementation, the data processing is first divided into a main program (involving matrix multiplication) and sub-programs. Then, the AI processor and sub-processor are controlled to execute the main program and sub-programs in parallel, respectively. Finally, the final result of the data processing is obtained based on the output of the main program executed by the AI processor and the output of the sub-program executed by the sub-processor. This embodiment of the data processing program can save the time required for data processing.
[0059] For example, data processing is... Figure 2The original matrix A is decomposed as follows:
[0060] (1) For the matrix A in the upper left corner of A 11 Perform LU decomposition (LU decomposition is the upper and lower triangular matrix decomposition, used to decompose matrix A). 11 Decomposition as Figure 3 The matrix U shown is an upper triangular matrix 11 and lower triangular matrix L 11 ), where A 11 =L 11 *U 11 .
[0061] (2)U 11 and A 21 As input to panel decomposition (panel decomposition procedure), L is obtained. 21 A 21 =L 21 *U 11 +L 22 *0 = L 21 *U 11, Take U 11 and A 31 As the output of panel decomposition, we obtain L 31, L was obtained using the same method. 41 .
[0062] (3) L 11 and A 12 As input to the trsm solver (triangular matrix solver), U is obtained. 12 A 12 =L 11 *U 12 +0*U 22 =L 11 *U 12, With L 11 and A 13 Solving the TRSM yields U. 13, U is obtained using the same method 14 .
[0063] (4) L 21 U 12 and A 22 As input to gemm (a general matrix multiplication procedure), the updated A is obtained from the gemm output. 22 (Right now Figure 3 A in 22 for Figure 2 A in 22 The updated matrix), where A 22 new = A 22 -L21 *U 12 (A 22 new is Figure 3 A in 22, A 22 for Figure 2 A in 22 ); with L 21 U 13 and A 23 As input to gemm (a general matrix multiplication procedure), the updated A is obtained from the gemm output. 23; With L 31 U 12 and A 32 As input to gemm (a general matrix multiplication procedure), the updated A is obtained from the gemm output. 32 Update using the same method. Figure 2 The remaining matrix in the second row, second column, third row, third column, fourth row, and fourth column of the matrix is used to complete the... Figure 2 The update of all matrices is obtained by the following process: Figure 3 The matrix in the diagram. This completes one iteration of matrix decomposition, i.e., in this embodiment, matrix decomposition is performed sequentially by executing LU decomposition, panel decomposition, and trsm solution (these two can be performed simultaneously or sequentially), and then gemm. After completing one iteration of the decomposition program, from the... Figure 3 A in 22 Perform LU decomposition to begin the next iterative decomposition until the following results are obtained sequentially. Figure 4 and Figure 5 The matrix in the matrix.
[0064] When performing the above decomposition on matrix A, the total computational complexity is O(n). in The complexity of gemm (general matrix multiplication) is given by N = 4 * NB, where N is the length of the matrix, NB is the length of the matrix block, and 4 is the number of matrix blocks in one direction. Therefore, the computation speed of gemm has a significant impact on the overall solution speed of matrix decomposition. Thus, in this embodiment, gemm is divided into a main program, while LU decomposition, panel decomposition, and trsm solution are divided into sub-programs. (In another embodiment, matrix decomposition also involves a first matrix processing program gemmPrep and a second matrix processing program gemmPost. gemmPrep converts the single-precision results of panel decomposition and trsm solution into half-precision and copies them to the AI chip's memory. gemmPost copies the gemm calculation results to the host memory. In this embodiment, gemmPrep and gemmPost are also divided into sub-programs.) The gemm main program is then executed on the AI processor, while the other sub-programs are executed on the secondary processor (CPU). Furthermore, in this embodiment, while the AI processor is executing the current iteration of gemm, the CPU is simultaneously controlled to execute the other sub-programs for the next iteration. The former fully utilizes the computing resources of AI processors to accelerate the execution of computationally complex gemm functions, while the latter enables heterogeneous parallelism between AI processors and CPUs. Both can shorten the time required for matrix factorization, and combining the two further reduces the time required to execute matrix factorization programs.
[0065] Exemplary methods
[0066] The data processing method based on an AI processor in this embodiment can be applied to a terminal device, which can be a terminal product with computing capabilities, such as a computer. In this embodiment, as... Figure 1 As shown, the data processing method based on the AI processor specifically includes the following steps:
[0067] S100, based on whether each program required for data processing involves matrix multiplication, each program is divided into a main program and a sub-program, wherein the main program involves matrix multiplication calculation, and the sub-program does not involve matrix multiplication calculation.
[0068] In this embodiment, the quantity processing involves matrix decomposition. Matrix decomposition requires the computer to execute multiple programs, each with varying degrees of compatibility with the AI processor. Programs involving matrix multiplication are more compatible with the AI processor; therefore, these programs are executed on the AI processor to fully utilize its superior computing resources. Step S100 includes the following steps S101, S102, and S103:
[0069] S101, Based on the data processing, the matrix decomposition in the data processing is obtained.
[0070] S102, confirm the upper and lower triangular matrix decomposition program LU, panel decomposition program panel, triangular matrix solver trsm, first matrix processing program gemmPrep, general matrix multiplication program gemm, and second matrix processing program gemmPost among the various programs required for matrix decomposition. The first matrix processing program is used to process the output results of the panel decomposition program and the triangular matrix solver, and the second matrix processing program is used to process the output results of the general matrix multiplication program.
[0071] S103, the general matrix multiplication program is divided into the main program, and the upper and lower triangular matrix decomposition program, the panel decomposition program, the triangular matrix solving program, the first matrix processing program, and the second matrix processing program are divided into the sub-programs.
[0072] S200, control the AI processor to execute the main program and control the sub-processor to execute the sub-program. The AI processor and the sub-processor are located in the same computer. The execution of the main program by the AI processor and the execution of the sub-program by the sub-processor constitute heterogeneous parallelism. The processing speed of the AI processor is greater than the processing speed of the sub-processor.
[0073] In this embodiment, heterogeneous parallelism means that while the AI processor is processing the general matrix multiplication program `gemm` for the current iteration, the secondary processor CPU can begin processing the second matrix processing program `gemmPost` for the current iteration, as well as the upper and lower triangular matrix decomposition program `LU`, the panel decomposition program `panel`, the triangular matrix solving program `trsm`, and the first matrix processing program `gemmPrep` for the next iteration. That is, the AI processor and the secondary processor CPU can process the matrix decomposition programs simultaneously, thereby saving the time required for the computer containing the AI processor and the secondary processor CPU to perform matrix decomposition. In one embodiment, there are many types of AI chips, and different types of AI chips may be suitable for different types of computation. If an AI chip is good at handling panel decomposition or trsm solving, then panel decomposition or trsm solving can be handled by the AI chip.
[0074] For example, in the 0th iteration, the process is completed sequentially. Figure 2 The original matrix is subjected to LU decomposition of the small matrix (the matrix in the top left corner), panel decomposition of the small matrix in the first column excluding the top left corner, and TRSM solution of the small matrix in the first row excluding the top left corner. In the gemmPrep stage, the single-precision results of panel decomposition and TRSM solution are converted to half-precision and copied into the AI chip's memory. gemm is computationally intensive, so it is handled by the AI chip, which is better suited for matrix multiplication. The input data for gemm consists of the half-precision results of panel decomposition and TRSM solution, as well as... Figure 2 The matrix to be updated in gemm is multiplied in half precision and added in single precision. The output data of gemm is... Figure 3 The updated matrix is then processed. gemmPost is the post-processing stage of gemm, where the calculation results of gemm are copied to host memory and the matrix data in host memory is updated.
[0075] Step S200 includes the following steps S201 and S202:
[0076] S201, control the AI processor to execute the general matrix multiplication program of the current iteration, and control the sub-processor to execute the second matrix processing program of the current iteration. The execution time of the AI processor and the execution time of the sub-processor overlap. The current iteration is one of several iterations in the matrix decomposition.
[0077] In this embodiment, the general matrix multiplication procedure is divided into the following subdivisions: Figure 6 The matrix multiplication procedure shown is divided into two parts: a first-zone matrix multiplication procedure (gemm priority update region) and a second-zone matrix multiplication procedure (gemm remaining region). The result of the first-zone matrix multiplication procedure is related to the next iteration and needs to be calculated first. However, when the next iteration is performed, the result of the second-zone matrix multiplication procedure in the current iteration is not used by the first-zone matrix multiplication procedure as early as the next iteration. Therefore, the AI processor is first controlled to execute the first-zone matrix multiplication procedure of the current iteration until the first-zone matrix multiplication procedure of the current iteration is completed. At the same time, the AI processor is controlled to execute the second matrix processing procedure of the current iteration while the sub-processor is controlled to execute the second matrix processing procedure of the current iteration.
[0078] In one embodiment, after the current iteration of the one-zone matrix multiplication procedure has finished executing, as follows: Figure 7 As shown, while controlling the AI processor to execute the current iteration of the two-zone matrix multiplication program, the sub-processor is simultaneously controlled to execute the current iteration of the second matrix processing program, copying the output of the one-zone matrix multiplication program to the computer's host. The AI processor is also controlled to save the output of the current iteration of the two-zone matrix multiplication program. In this embodiment, the reason the sub-processor can execute the current iteration of the second matrix processing program while executing the current iteration of the two-zone matrix multiplication program is that the one-zone matrix multiplication program has already been completed. The result of the one-zone matrix multiplication program can be copied from the AI processor to the computer host for storage via the second matrix processing program (the original matrix and elements in the original matrix that were not calculated in the current iteration are stored on the host), thus saving time.
[0079] S202, when the current iteration is executed until the set conditions are met, the AI processor is controlled to execute the general matrix multiplication program of the current iteration, and the sub-processor is controlled to execute the upper and lower triangular matrix decomposition program, the panel decomposition program, the triangular matrix solving program, and the first matrix processing program of the next iteration. The execution time of the AI processor overlaps with the execution time of the sub-processor.
[0080] In one embodiment, step S202 is as follows: when the execution of the first-zone matrix multiplication program of the current iteration ends, the AI processor is controlled to execute the second-zone matrix multiplication program of the current iteration while the sub-processor is controlled to execute the upper and lower triangular matrix decomposition program, the panel decomposition program, the triangular matrix solving program, and the first matrix processing program of the next iteration in sequence, until the AI processor finishes executing the second-zone matrix multiplication program of the current iteration, and then the AI processor is controlled to execute the first-zone matrix multiplication program of the next iteration.
[0081] like Figure 7 As shown, when the 0-iteration first-zone matrix multiplication program ends (gemm prioritizes updating the region), the AI processor executes the 0-iteration second-zone matrix multiplication program while the sub-processor sequentially executes the 1-generation iteration of the upper and lower triangular matrix decomposition program, the panel decomposition program, the triangular matrix solving program, and the first matrix processing program. In this embodiment, the panel decomposition program and the triangular matrix solving program can also be executed simultaneously.
[0082] In another embodiment, the specific process of step S202 is as follows: When the execution of the first-zone matrix multiplication procedure of the current iteration ends, the AI processor is controlled to execute the second-zone matrix multiplication procedure of the current iteration, while the sub-processor is controlled to sequentially execute the upper and lower triangular matrix decomposition procedure, the panel decomposition procedure, the triangular matrix solving procedure, the first matrix processing procedure of the next iteration, and the first-zone matrix multiplication procedure of the next iteration. In this embodiment, as... Figure 7 As shown, after the 0-iteration first-zone matrix multiplication program ends, the AI processor executes the 0-iteration second-zone matrix multiplication program while the sub-processor executes the 1-iteration upper and lower triangular matrix decomposition program, panel decomposition program, triangular matrix solving program, first matrix processing program, and the first-zone matrix multiplication program for the next iteration.
[0083] The above step S200 uses a heterogeneous parallel approach to control the AI processor and the secondary processor CPU. The heterogeneous parallelism in this embodiment is based on the following principle:
[0084] The `gemm` and `gemmPost` of the current iteration can overlap in time, and also overlap with the small matrix LU decomposition, panel decomposition, and TrSM solution of the next iteration. Originally, `gemmPost` and `gemm` are dependent, but to achieve this overlap, we need to divide the `gemm` region into two parts: the `gemmPriority Update Region` and the `gemmRemaining Region`. After the `gemmPost` of the current iteration is calculated, the small matrix LU decomposition, panel decomposition, TrSM solution, and `gemmPrep` preprocessing of the next iteration can be performed immediately. Therefore, when the `gemm` of the k-th iteration is completed, the `gemmPrep` preprocessing of the (k+1)-th iteration is already completed, and the AI chip does not need to wait any longer and can immediately execute the `gemm` of the (k+1)-th iteration.
[0085] Since the small matrix LU decomposition, panel decomposition, and trsm solution of the next iteration step are only related to the gemm priority update region of the current iteration step, the gemmPost post-processing of the current iteration step only needs to copy the calculation results of the gemm priority update region back to the host, and does not need to copy all the gem calculation results of the current iteration step, thus reducing data transfer.
[0086] The heterogeneous parallelism in this embodiment enables the AI processor and CPU to run independently, reducing their waiting time and thus saving overall running time.
[0087] S300: Based on the results output by the main program executed by the AI processor and the results output by the sub-processor executed by the sub-program, the final result of data processing is obtained.
[0088] In this embodiment, when gemm, which is the main program, is executed by the AI processor for the current iteration, the LU decomposition, panel decomposition, trsm solution, and gemmPrep, which are the sub-programs, are executed by the CPU for the next iteration. The results of these two types of programs are inter-processed until the number of iterations reaches a certain number. Figure 2 All elements of the original matrix are then decomposed, completing the decomposition of the original matrix. Step S300 is detailed as follows: Based on the output of the main program in the current iteration executed by the AI processor and the output of the next generation of the sub-program executed by the sub-processor based on the output of the main program in the current iteration, the final result of data processing is obtained.
[0089] Steps S100 to S300 employ a heterogeneous parallel approach to execute the matrix decomposition program, reducing the time required for decomposition. In one embodiment, the performance of each computer is tested based on the time taken for each computer to execute the same matrix decomposition program. This embodiment sums the computational complexity of each program to obtain the total computational complexity of the data processing, and divides the total computational complexity by the computer's runtime to obtain the actual peak performance.
[0090] In one embodiment, the computer controls the CPU (subprocessor) and AI processor to execute the various programs involved in matrix decomposition through a control process. This embodiment includes the following steps S401 to S406:
[0091] S401, control the computer to start a set number of processes.
[0092] S402, the set number of processes are divided into four categories: Category 1 processes, Category 2 processes, Category 3 processes, and Category 4 processes.
[0093] In this embodiment, eight processes are set up and divided into four types: Class I processes, Class II processes, Class III processes, and Class IV processes.
[0094] S403, through the aforementioned process control, the AI processor executes the general matrix multiplication program and the sub-processor executes the upper and lower triangular matrix decomposition program, the panel decomposition program, the triangular matrix solving program, the first matrix processing program, and the second matrix processing program.
[0095] S404, the AI processor is controlled to execute a general matrix multiplication program and the sub-processor is controlled to execute the panel decomposition program, the first matrix processing program, and the second matrix processing program through the two types of processes.
[0096] S405, the AI processor is controlled to execute the general matrix multiplication program and the sub-processor is controlled to execute the triangular matrix solving program, the first matrix processing program and the second matrix processing program through the three types of processes.
[0097] S406, the AI processor is controlled by the four types of processes to execute the general matrix multiplication program.
[0098] by Figure 8 This embodiment illustrates the detailed process of matrix decomposition performed by the computer through process control of the AI processor and CPU:
[0099] Processes of type one require computation of the small matrix LU decomposition, panel decomposition, and TRSM solution for the (k+1)th iteration step. Processes of type two require computation of the panel decomposition for the (k+1)th iteration step, but do not require computation of the small matrix LU decomposition and TRSM solution for the (k+1)th iteration step. Processes of type three require computation of the TRSM solution for the (k+1)th iteration step, but do not require computation of the small matrix LU decomposition and panel decomposition for the (k+1)th iteration step. Processes of type four do not require computation of the small matrix LU decomposition, panel decomposition, and TRSM solution for the (k+1)th iteration step.
[0100] The above four categories correspond to Figure 8 The four columns. Figure 8 It shows all the computation and communication steps and their dependencies for four types of processes. For example, in one type of process, panel decomposition depends on the result of LU decomposition of small matrix blocks, so the arrow points from Panel to LU. Figure 8 The process starts at the gemm in iteration k and ends at the gemm in iteration (k+1), omitting the preceding and following steps. The process category changes each time the gemm is updated.
[0101] gemm: gemm update. Figure 6 The classification method divides the matrix to be updated into regions that require priority updating and other regions. The LU decomposition, panel decomposition, and TRSM solution of the small matrix in the next iteration depend on the regions that require priority updating in the current iteration step.
[0102] syncNextLU: Wait for the gemm update calculation of the region related to the small matrix LU decomposition of the next iteration to complete;
[0103] CopyNextLU: Copies the gemm update results of the region related to the small matrix LU decomposition of the next iteration from the AI chip memory to the host memory;
[0104] ApplyNextLU: Updates the data in the host memory for the small matrix block that needs to be decomposed into a small matrix LU for the next iteration;
[0105] syncNextPanel: Wait for the gemm update calculation of the region related to the panel decomposition of the next iteration to complete;
[0106] CopyNextPanel: Copies the gemm update results of the region related to the panel decomposition of the next iteration from the AI chip memory to the host memory;
[0107] ApplyNextPanel: Updates the data in the small matrix block in the host memory that needs to be decomposed into a panel for the next iteration;
[0108] syncNextTrsm: Wait for the GeMM update calculation of the region related to the next iteration of Trsm solution to complete;
[0109] CopyNextTrsm: Copies the Gemm update results of the region related to the Trsm solution of the next iteration from the AI chip memory to the host memory;
[0110] ApplyNextTrsm: Updates the data of the small matrix block in the host memory that needs to be solved by Trsm in the next iteration;
[0111] LU: The LU decomposition of the top-left small matrix block of the remaining submatrix in the current iteration step;
[0112] BroadCastLU: The LU decomposition result of the small matrix block broadcast by the host, which is sent by process A.
[0113] ReceiveLU: Processes of classes B and C receive the LU decomposition results of small matrix blocks;
[0114] Panel: Panel decomposition for the current iteration step;
[0115] ConvetPanel: Converts the result of panel decomposition from single precision to half precision;
[0116] CopyPanel: Copies the half-precision results of panel decomposition from host memory to AI chip memory;
[0117] BroadCastPanel: Broadcasts the half-precision results of panel decomposition in the AI chip's memory, which are sent by Class A and Class B processes;
[0118] ReceivePanel: C and D class processes receive the half-precision result of the panel decomposition;
[0119] Trsm: The Trsm solution for the current iteration step;
[0120] ConvetTrsm: Converts the result of trsm from single precision to half precision;
[0121] CopyTrsm: Copies the half-precision result of the trsm solution from the host memory to the AI chip memory;
[0122] BroadCastTrsm: Broadcasts the half-precision result of the trsm solution in the memory of the AI chip, which is sent by both Class A and Class B processes;
[0123] ReceiveTrsm: Receives half-precision results from trsm solutions for C and D classes.
[0124] The following example uses the Ascend AI processor (NPU) to illustrate the superior performance of heterogeneous parallel execution of matrix factorization programs by the AI processor and CPU in this embodiment:
[0125] The present invention has developed a complete set of HPL-AI heterogeneous parallel programs that can run on the Ascend AI processor (NPU). Figure 9 The graph shows the performance of HPL-AI on single-node and dual-node systems. Each node contains 192 CPU cores and 8 Ascend AI processors (NPUs). The half-precision floating-point performance of each Ascend AI processor matrix calculation unit is 256 TFlops. Figure 9 The horizontal axis represents time, and the vertical axis represents the ratio of floating-point performance to the theoretical peak value. Experiments demonstrate that this invention is feasible and effective. The utilization rate in Table 1 represents the utilization rate of AI processor computing resources.
[0126] Table 1
[0127] single node dual nodes Initial utilization rate (%) 40 44 Overall utilization rate (%) 21.6 26.2
[0128] In summary, this invention first divides the various programs required for data processing into main programs and sub-programs based on whether they involve matrix multiplication. Since AI processors are suitable for processing matrix multiplication programs, the main programs involving matrix multiplication are executed on the AI processor to fully utilize its computing resources, while the sub-programs that do not involve matrix multiplication are executed on a secondary processor (such as the CPU) to avoid consuming the AI processor's computing resources. The secondary processor and AI processor of this invention work together to reduce the time required for the computer to execute data processing programs. In addition, the AI processor and secondary processor of this invention execute their respective programs in heterogeneous parallelism. Heterogeneous parallelism means that both processors execute their respective programs simultaneously, thereby further reducing the time required for the computer to execute data processing programs.
[0129] Furthermore, some AI chips are not suitable for performing all the calculations in LU decomposition independently, but currently there is no HPL-AI heterogeneous parallel code available for large-scale systems. This invention proposes a CPU+AI chip heterogeneous parallel scheme to collaboratively complete mixed-precision LU decomposition. Compared to homogeneous schemes using only the CPU or only the AI chip, the heterogeneous scheme has a wider range of applications; as long as the AI chip has half-precision matrix multiplication capability, it can collaborate with the CPU to complete mixed-precision LU decomposition. This invention provides developers who develop, port, or optimize HPL-AI heterogeneous parallel programs for AI chips with a general implementation and optimization method.
[0130] Exemplary device
[0131] This embodiment also provides a data processing device based on an AI processor, the device comprising the following components:
[0132] The program classification module is used to divide each program into a main program and a sub-program based on whether each program required for data processing involves matrix multiplication. The main program involves matrix multiplication calculation, while the sub-program does not.
[0133] A processor control module is used to control the AI processor to execute the main program and control the sub-processor to execute the sub-program. The AI processor and the sub-processor are located in the same computer. The execution of the main program by the AI processor and the execution of the sub-program by the sub-processor constitute heterogeneous parallelism. The processing speed of the AI processor is greater than that of the sub-processor.
[0134] The result calculation module is used to obtain the final result of data processing based on the results output by the main program executed by the AI processor and the results output by the sub-processor executed by the sub-processor.
[0135] Based on the above embodiments, the present invention also provides a terminal device, the principle block diagram of which can be as follows: Figure 10 As shown, the terminal device includes a processor, memory, network interface, display screen, and temperature sensor connected via a system bus. The processor provides computing and control capabilities. The memory includes non-volatile storage media and internal memory. The non-volatile storage media stores the operating system and computer programs. The internal memory provides the environment for the operation of the operating system and computer programs stored in the non-volatile storage media. The network interface is used to communicate with external terminals via a network connection. When the computer program is executed by the processor, it implements a data processing method based on an AI processor. The display screen can be an LCD screen or an e-ink screen. The temperature sensor is pre-installed inside the terminal device to detect the operating temperature of the internal components.
[0136] Those skilled in the art will understand that Figure 10 The block diagram shown is merely a partial structural diagram related to the present invention and does not constitute a limitation on the terminal device to which the present invention is applied. The specific terminal device may include more or fewer components than shown in the figure, or combine certain components, or have different component arrangements.
[0137] In one embodiment, a terminal device is provided, comprising a memory, a processor, and an AI processor-based data processing program stored in the memory and executable on the processor. When the processor executes the AI processor-based data processing program, it implements the following operation instructions:
[0138] Based on whether each program required for data processing involves matrix multiplication, each program is divided into a main program and a sub-program. The main program involves matrix multiplication calculations, while the sub-programs do not.
[0139] The AI processor is controlled to execute the main program, and the sub-processor is controlled to execute the sub-program. The AI processor and the sub-processor are located in the same computer. The execution of the main program by the AI processor and the execution of the sub-program by the sub-processor constitute heterogeneous parallelism. The processing speed of the AI processor is greater than that of the sub-processor.
[0140] Based on the results of the main program executed by the AI processor and the results of the sub-program executed by the sub-processor, the final result of data processing is obtained.
[0141] Those skilled in the art will understand that all or part of the processes in the methods of the above embodiments can be implemented by a computer program instructing related hardware. The computer program can be stored in a non-volatile computer-readable storage medium. When executed, the computer program can include the processes of the embodiments of the above methods. Any references to memory, storage, databases, or other media used in the embodiments provided by this invention can include non-volatile and / or volatile memory. Non-volatile memory can include read-only memory (ROM), programmable ROM (PROM), electrically programmable ROM (EPROM), electrically erasable programmable ROM (EEPROM), or flash memory. Volatile memory can include random access memory (RAM) or external cache memory. By way of illustration and not limitation, RAM is available in various forms, such as static RAM (SRAM), dynamic RAM (DRAM), synchronous DRAM (SDRAM), dual data rate SDRAM (DDRSDRAM), enhanced SDRAM (ESDRAM), synchronous link DRAM (SLDRAM), RAMbus direct RAM (RDRAM), direct memory bus dynamic RAM (DRDRAM), and RAMbus dynamic RAM (RDRAM), etc.
[0142] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention, and not to limit them; although the present invention has been described in detail with reference to the foregoing embodiments, those skilled in the art should understand that modifications can still be made to the technical solutions described in the foregoing embodiments, or equivalent substitutions can be made to some of the technical features; and these modifications or substitutions do not cause the essence of the corresponding technical solutions to deviate from the spirit and scope of the technical solutions of the embodiments of the present invention.
Claims
1. An AI processor-based data processing method, characterized by, The method comprises the following steps: According to whether each program required by data processing involves matrix multiplication, each program is divided into a main program and a subprogram, the main program involves matrix multiplication calculation, and the subprogram does not involve matrix multiplication calculation; Control the AI processor to execute the main program and control the subprocessor to execute the subprogram, the AI processor and the subprocessor are located in the same computer, the AI processor executes the main program and the subprocessor executes the subprogram to constitute heterogeneous parallel, the processing speed of the AI processor is greater than the processing speed of the subprocessor; According to the results output by the AI processor executing the main program and the results output by the subprocessor executing the subprogram, the final result of data processing is obtained; According to whether each program required by data processing involves matrix multiplication, each program is divided into a main program and a subprogram, the main program involves matrix multiplication calculation, and the subprogram does not involve matrix multiplication calculation; According to the data processing, the matrix decomposition in the data processing is obtained; Confirm the upper and lower triangular matrix decomposition program, the panel decomposition program, the triangular matrix solving program, the first matrix processing program, the general matrix multiplication program and the second matrix processing program in each program required by the matrix decomposition, the first matrix processing program is used for processing the output results of the panel decomposition program and the output results of the triangular matrix solving program, and the second matrix processing program is used for processing the output results of the general matrix multiplication program; The general matrix multiplication program is divided into a main program, and the upper and lower triangular matrix decomposition program, the panel decomposition program, the triangular matrix solving program, the first matrix processing program and the second matrix processing program are divided into a subprogram; The control AI processor executes the main program and controls the subprocessor to execute the subprogram, which comprises: According to the current iteration of the general matrix multiplication program, the current iteration of the one-zone matrix multiplication program and the current iteration of the two-zone matrix multiplication program in the current iteration of the general matrix multiplication program are obtained, the output result of the one-zone matrix multiplication program is used by the next iteration in priority to the output result of the two-zone matrix multiplication program; control the AI processor to execute the current iteration of the one-zone matrix multiplication program until the current iteration of the one-zone matrix multiplication program is executed and ended, control the AI processor to execute the current iteration of the two-zone matrix multiplication program and control the subprocessor to execute the current iteration of the second matrix processing program at the same time, the execution time of the AI processor and the execution time of the subprocessor overlap, and the current iteration is one of the several iterations in the matrix decomposition; When the current iteration is executed to satisfy the set condition, control the AI processor to execute the current iteration of the general matrix multiplication program, control the subprocessor to execute the next iteration of the upper and lower triangular matrix decomposition program, the panel decomposition program, the triangular matrix solving program and the first matrix processing program, and the execution time of the AI processor and the execution time of the subprocessor overlap. 2.The AI processor-based data processing method of claim 1, wherein, The control AI processor to execute the general matrix multiplication program of the current iteration, control the sub-processor to execute the upper and lower triangular matrix decomposition program of the next iteration, the panel decomposition program, the triangular matrix solving program, the first matrix processing program when the current iteration is executed to meet the set condition, the execution time of the AI processor and the execution time of the sub-processor overlap, including: When the one-zone matrix multiplication program of the current iteration is executed to the end, the AI processor is controlled to execute the two-zone matrix multiplication program of the current iteration, and the sub-processor is controlled to execute the upper and lower triangular matrix decomposition program, the panel decomposition program, the triangular matrix solving program, and the first matrix processing program of the next iteration in turn until the AI processor executes the two-zone matrix multiplication program of the current iteration to the end, and the AI processor is controlled to execute the one-zone matrix multiplication program of the next iteration. 3.The AI processor-based data processing method of claim 1, wherein, The control AI processor to execute the general matrix multiplication program of the current iteration, control the sub-processor to execute the upper and lower triangular matrix decomposition program of the next iteration, the panel decomposition program, the triangular matrix solving program, the first matrix processing program when the current iteration is executed to meet the set condition, the execution time of the AI processor and the execution time of the sub-processor overlap, including: When the one-zone matrix multiplication program of the current iteration is executed to the end, the AI processor is controlled to execute the two-zone matrix multiplication program of the current iteration, and the sub-processor is controlled to execute the upper and lower triangular matrix decomposition program, the panel decomposition program, the triangular matrix solving program, and the first matrix processing program of the next iteration in turn until the AI processor executes the two-zone matrix multiplication program of the current iteration to the end, and the AI processor is controlled to execute the one-zone matrix multiplication program of the next iteration. 4.The AI processor-based data processing method of claim 1, wherein The control AI processor to execute the one-zone matrix multiplication program of the current iteration until the one-zone matrix multiplication program of the current iteration is executed to the end, and the AI processor is controlled to execute the two-zone matrix multiplication program of the current iteration while the sub-processor executes the second matrix processing program of the current iteration, including: After the one-zone matrix multiplication program of the current iteration is executed to the end, the AI processor is controlled to execute the two-zone matrix multiplication program of the current iteration while the sub-processor executes the second matrix processing program of the current iteration to copy the output result of the one-zone matrix multiplication program to the host of the computer, and the AI processor saves the output result of the two-zone matrix multiplication program of the current iteration. 5.The AI processor-based data processing method of claim 1, wherein The control AI processor to execute the main program and the control sub-processor to execute the sub-program, the AI processor and the sub-processor are located in the same computer, the AI processor executes the main program and the sub-processor executes the sub-program to constitute heterogeneous parallel, and the processing speed of the AI processor is greater than that of the sub-processor, including: Control the computer to start a set number of processes; The set number of processes is equally divided into a class of processes, a class of processes, a class of processes, and a class of processes; The one-class process controls the AI processor to execute the general matrix multiplication program, and controls the sub-processor to execute the upper and lower triangular matrix decomposition program, the panel decomposition program, the triangular matrix solving program, the first matrix processing program, and the second matrix processing program; The second type of process controls the AI processor to execute a general matrix multiplication program and controls the sub-processor to execute the panel decomposition program, the first matrix processing program, and the second matrix processing program; The third type of process controls the AI processor to execute a general matrix multiplication program and controls the sub-processor to execute the triangular matrix solving program, the first matrix processing program, and the second matrix processing program; The fourth type of process controls the AI processor to execute the general matrix multiplication program. 6.The AI processor-based data processing method of claim 1, wherein, The final result of the data processing is obtained according to the result output by the AI processor executing the main program and the result output by the sub-processor executing the sub-program, including: The final result of the data processing is obtained according to the result output by the AI processor executing the current iteration of the main program and the result output by the sub-processor executing the next generation of the sub-program based on the result output by the main program in the current iteration. 7.The AI processor-based data processing method of claim 1, wherein, The method further includes counting the computer running time corresponding to the final result, and the running time is used to test the actual peak performance of the computer, including: The calculation total complexity of the data processing is obtained by accumulating the calculation complexity of each program; The actual peak performance is obtained by dividing the calculation total complexity by the computer running time.
8. An AI processor-based data processing apparatus, comprising: The device includes the following components: The program classification module is used to divide each program into a main program and a sub-program according to whether each program involved in the data processing involves matrix multiplication, the main program involves matrix multiplication calculation, and the sub-program does not involve matrix multiplication calculation; The processor control module is used to control the AI processor to execute the main program and control the sub-processor to execute the sub-program, the AI processor and the sub-processor are located in the same computer, the AI processor executes the main program and the sub-processor executes the sub-program to constitute heterogeneous parallelism, and the processing speed of the AI processor is greater than the processing speed of the sub-processor; The result calculation module is used to obtain the final result of the data processing according to the result output by the AI processor executing the main program and the result output by the sub-processor executing the sub-program; The division of each program into a main program and a sub-program according to whether each program involved in the data processing involves matrix multiplication, including: The matrix decomposition in the data processing is obtained according to the data processing; The upper and lower triangular matrix decomposition program, the panel decomposition program, the triangular matrix solving program, the first matrix processing program, the general matrix multiplication program, and the second matrix processing program in each program required by the matrix decomposition are confirmed, the first matrix processing program is used to process the output result of the panel decomposition program and the output result of the triangular matrix solving program, and the second matrix processing program is used to process the output result of the general matrix multiplication program; The general matrix multiplication program is divided into a main program, and the upper and lower triangular matrix decomposition program, the panel decomposition program, the triangular matrix solving program, the first matrix processing program, and the second matrix processing program are divided into sub-programs; The control of the AI processor to execute the main program and the control of the sub-processor to execute the sub-program, including: According to the general matrix multiplication program of the current iteration, a one-zone matrix multiplication program of the current iteration and a two-zone matrix multiplication program of the current iteration in the general matrix multiplication program of the current iteration are obtained, and the output result of the one-zone matrix multiplication program is preferentially used by the next iteration than the output result of the two-zone matrix multiplication program; the AI processor is controlled to execute the one-zone matrix multiplication program of the current iteration until the one-zone matrix multiplication program of the current iteration is executed to end, the AI processor is controlled to execute the two-zone matrix multiplication program of the current iteration, and the secondary processor is controlled to execute the second matrix processing program of the current iteration at the same time, the execution time of the AI processor overlaps with the execution time of the secondary processor, and the current iteration is one iteration in the plurality of iterations in the matrix decomposition; When the current iteration is executed to meet the set condition, the AI processor is controlled to execute the general matrix multiplication program of the current iteration, the secondary processor is controlled to execute the upper and lower triangular matrix decomposition program, the panel decomposition program, the triangular matrix solving program and the first matrix processing program of the next iteration, and the execution time of the AI processor overlaps with the execution time of the secondary processor.
9. A terminal device, comprising: The terminal device comprises a memory, a processor and an AI processor-based data processing program stored in the memory and executable on the processor, and when the processor executes the AI processor-based data processing program, the steps of the AI processor-based data processing method according to any one of claims 1-7 are implemented.
10. A computer-readable storage medium, characterized in that, The computer readable storage medium stores an AI processor-based data processing program, and when the processor executes the AI processor-based data processing program, the steps of the AI processor-based data processing method according to any one of claims 1-7 are implemented.
Citation Information
Patent Citations
KR20190120509A