Task data processing method, device, computer equipment and medium in computer
By cached the matrix elements after row scaling in the Sinkhorn-Knopp algorithm and computed the column scaling factor, directly performing column scaling, the problem of low efficiency of SK algorithm in the column scaling process is solved, and the efficiency and spatial locality of task data processing are improved. .
Patent Information
- Application Number
- CN202210620730.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-06-02
- Publication Date
- 2024-11-08
- Estimated Expiration
- 2042-06-02
AI Technical Summary
The Sinkhorn-Knopp (SK) algorithm needs to repeatedly read all row elements during the matrix scaling process after row scaling, resulting in low efficiency in task data processing, and with the increase in matrix size, the scaling time significantly increases, reducing processing efficiency.
By obtaining the SK algorithm matrix corresponding to the calculation task, the row is scaled and cached to a preset array, the column scaling factor is calculated, and the row scaling matrix is scaled based on this factor, avoiding repeated reading of row elements and improving column scaling efficiency .
The efficiency of the column scaling process is improved, thereby improving the overall efficiency of task data processing, reducing cache miss rate and scaling time, and enhancing spatial locality.
Smart Images

Figure CN114996651B_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of computer technology, and in particular to a method, apparatus, computer equipment, storage medium and program product for processing task data in a computer. Background Art
[0002] With the development of computer technology, big data technology has emerged. In the application of big data technology, computers need to process massive amounts of task data. For these task data processing, many scholars have proposed a number of task data processing algorithms, and the Sinkhorn-Knopp (SK) algorithm is one of the most representative algorithms.
[0003] In simple terms, the Sinkhorn-Knopp (SK) algorithm is an iterative algorithm. The SK algorithm has gained increasing attention in the field of artificial intelligence (AI). Generally, the SK algorithm can be applied to computers to handle computing tasks corresponding to optimal transmission problems, computer vision, word movement distance, etc. Usually, the computer first stores the matrix corresponding to the computing task in the cache in row form, and then uses the SK algorithm to sum the elements of each row in the matrix, and then scales the elements of each row in the matrix based on the sum obtained. Then, after summing the elements of each column of the matrix after row scaling, the matrix after row scaling is scaled based on the sum of the elements of each column, so as to obtain a task processing result that meets the iteration requirements.
[0004] However, when the SK algorithm performs column scaling on a row-scaled matrix, it is necessary to repeatedly read all row elements in the row-scaled matrix to obtain the column elements required for column scaling, and then perform column scaling on the column elements in the row-scaled matrix after summing them up, which makes the task data processing efficiency extremely low. Summary of the invention
[0005] Based on this, it is necessary to provide an efficient method, device, computer equipment, storage medium and program product for processing task data in a computer in response to the above technical problems.
[0006] In a first aspect, the present application provides a method for processing task data in a computer, the method comprising:
[0007] Get the SK algorithm matrix corresponding to the calculation task;
[0008] Based on the sum of the elements of each row in the SK algorithm matrix, row scaling is performed on the elements of each row in the SK algorithm matrix, and the scaled row elements are cached in a preset array;
[0009] Obtaining, according to the elements cached in the preset array, a scaling factor for performing column scaling on the SK algorithm matrix after row scaling;
[0010] Based on the scaling factor, column scaling is performed on the SK algorithm matrix after row scaling to obtain the scaled SK algorithm matrix;
[0011] SK algorithm processing is performed according to the scaled SK algorithm matrix to obtain a task data processing result.
[0012] In one embodiment, obtaining a scaling factor for performing column scaling on the SK algorithm matrix after row scaling according to the elements cached in the preset array includes:
[0013] The elements of each column in the preset array are accumulated, and the ratio of the preset elements to the sum of the elements of each column in the preset array is respectively calculated to obtain the scaling factor of the elements of each column in the SK algorithm matrix after the row scaling.
[0014] In one embodiment, the step of performing column scaling on the row-scaled SK algorithm matrix based on the scaling factor to obtain the scaled SK algorithm matrix includes:
[0015] After the row-scaled SK algorithm matrix is divided into blocks according to a preset row dimension and a preset column dimension, a plurality of sub-matrices are obtained;
[0016] Calculate the product of the scaling factor and the elements in each of the submatrices respectively to obtain the scaled elements of the columns corresponding to each of the submatrices;
[0017] The scaled column elements corresponding to the plurality of sub-matrices are combined to obtain the scaled SK algorithm matrix.
[0018] In one embodiment, respectively calculating the product of the scaling factor and the elements in each of the submatrices to obtain the scaled elements of the columns corresponding to each of the submatrices includes:
[0019] Call the instruction set corresponding to column scaling;
[0020] Based on the instruction set, the product of the scaling factor and the elements in each of the sub-matrices is calculated respectively to obtain the scaled elements of the columns corresponding to each of the sub-matrices.
[0021] In one embodiment, the step of respectively calculating the product of the scaling factor and the elements in each of the submatrices based on the instruction set to obtain the scaled column elements corresponding to each of the submatrices includes:
[0022] Reordering the instructions in the instruction set in the microkernel to obtain the reordered instruction set;
[0023] According to the reordered instruction set, the product of the scaling factor and the elements in each submatrix is calculated respectively to obtain the scaled elements of the columns corresponding to each submatrix.
[0024] In one embodiment, the instruction set is the AVX256 instruction set of the x86 architecture.
[0025] In a second aspect, the present application provides a task data processing device in a computer, the device comprising: an acquisition module, a cache module, a calculation module and a processing module.
[0026] The acquisition module is used to obtain the SK algorithm matrix corresponding to the calculation task;
[0027] The cache module is used to perform row scaling on the elements of each row in the SK algorithm matrix based on the sum of the elements of each row in the SK algorithm matrix, and cache the scaled row elements into a preset array;
[0028] The calculation module is used to obtain a scaling factor for performing column scaling on the SK algorithm matrix after row scaling according to the elements cached in the preset array;
[0029] The processing module is used to perform column scaling on the SK algorithm matrix after row scaling based on the scaling factor to obtain the scaled SK algorithm matrix; and perform SK algorithm processing according to the scaled SK algorithm matrix to obtain a task data processing result.
[0030] In a third aspect, the present application further provides a computer device. The computer device includes a memory and a processor, the memory stores a computer program, and the processor implements the following steps when executing the computer program:
[0031] Get the SK algorithm matrix corresponding to the calculation task;
[0032] Based on the sum of the elements of each row in the SK algorithm matrix, row scaling is performed on the elements of each row in the SK algorithm matrix, and the scaled row elements are cached in a preset array;
[0033] Obtaining, according to the elements cached in the preset array, a scaling factor for performing column scaling on the SK algorithm matrix after the row scaling;
[0034] Based on the scaling factor, column scaling is performed on the SK algorithm matrix after row scaling to obtain the scaled SK algorithm matrix;
[0035] SK algorithm processing is performed according to the scaled SK algorithm matrix to obtain a task data processing result.
[0036] In a fourth aspect, the present application further provides a computer-readable storage medium. The computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the following steps are implemented:
[0037] Get the SK algorithm matrix corresponding to the calculation task;
[0038] Based on the sum of the elements of each row in the SK algorithm matrix, row scaling is performed on the elements of each row in the SK algorithm matrix, and the scaled row elements are cached in a preset array;
[0039] Obtaining, according to the elements cached in the preset array, a scaling factor for performing column scaling on the SK algorithm matrix after row scaling;
[0040] Based on the scaling factor, column scaling is performed on the SK algorithm matrix after row scaling to obtain the scaled SK algorithm matrix;
[0041] SK algorithm processing is performed according to the scaled SK algorithm matrix to obtain a task data processing result.
[0042] In a fifth aspect, the present application further provides a computer program product. The computer program product includes a computer program, and when the computer program is executed by a processor, the following steps are implemented:
[0043] Get the SK algorithm matrix corresponding to the calculation task;
[0044] Based on the sum of the elements of each row in the SK algorithm matrix, row scaling is performed on the elements of each row in the SK algorithm matrix, and the scaled row elements are cached in a preset array;
[0045] Obtaining, according to the elements cached in the preset array, a scaling factor for performing column scaling on the SK algorithm matrix after row scaling;
[0046] Based on the scaling factor, column scaling is performed on the SK algorithm matrix after row scaling to obtain the scaled SK algorithm matrix;
[0047] The scaled SK algorithm matrix is processed by the SK algorithm to obtain a task data processing result.
[0048] The task data processing method, device, computer equipment and storage medium in the above-mentioned computer can obtain the scaling factor for column scaling of the column elements of the row-scaled matrix after row scaling by setting a preset array, so that there is no need to repeatedly read each row element in the row-scaled matrix to obtain the column elements required for column scaling in the row-scaled matrix and the sum of the elements of each column in the row-scaled matrix. It is only necessary to calculate the product of the scaling factor and the elements of each column in the row-scaled matrix respectively to obtain the matrix after row scaling and column scaling. Therefore, the entire scheme can improve the efficiency of the column scaling process, thereby improving the efficiency of task data processing. BRIEF DESCRIPTION OF THE DRAWINGS
[0049] Figure 1 A schematic diagram of the principle of scaling matrix based on SK algorithm is provided;
[0050] Figure 2 A flowchart of a method for processing task data in a computer is provided;
[0051] Figure 3 A schematic diagram of a microkernel-based partitioning principle is provided;
[0052] Figure 4 A schematic diagram of an instruction reordering is provided;
[0053] Figure 5 is a structural block diagram of a task data processing device in a computer in one embodiment;
[0054] Figure 6 FIG. 4 is a diagram showing the internal structure of a computer device in one embodiment. DETAILED DESCRIPTION
[0055] In order to make the purpose, technical solution and advantages of the present application more clearly understood, the present application is further described in detail below in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are only used to explain the present application and are not used to limit the present application.
[0056] For example, Figure 1 A schematic diagram of the principle of scaling matrix based on SK algorithm is provided, as shown in Figure 1 As shown, the dimension of the matrix corresponding to the computing task in the computer is M×N. After the elements of each row in the matrix are scaled by row, the elements of each column in the matrix after row scaling are scaled by column, so that the matrix after column scaling can meet the iteration requirements required by the corresponding computing tasks such as optimal transmission problems, computer vision, word movement distance (WMD), etc.
[0057] Among them, the elements of all rows in the matrix can be row-scaled by the first code. In the first code, RMD i The elements of each row in the matrix are summed with RMD i Same, ∑A i Represents the sum of the elements in the i-th row of the matrix. Based on multiple cycles, the final matrix A is the row-scaled matrix. The content of the first code can be described as follows:
[0058]
[0059]
[0060] The second code can be used to perform column scaling on the row-scaled matrix. In the second code, CMD i The elements of the preset setting are the sum of the elements of each column in the row-scaled matrix and CMD j Same, ∑A j Represents the sum of the elements in the jth column of the matrix. Based on multiple cycles, the final A is the column-scaled matrix. The content of the second code can be described as follows:
[0061]
[0062] Although the above first code and second code can be used to scale the matrix by row and column, in the process of column scaling, it is necessary to repeatedly read the matrix after row scaling to obtain the column elements required for column scaling in the matrix after row scaling, and then sum the elements of each column in the matrix after row scaling, which also makes the processing efficiency of task data low; moreover, both row scaling and column scaling of SK algorithm have O(n 2 ), as the matrix size increases, the matrix scaling time will increase significantly, and the processing efficiency of the task data will also be reduced.
[0063] It should be noted that before the computer processes the matrix, it stores the matrix in the form of rows in the cache. When the computer processes the matrix, it reads the matrix from the cache in the form of rows. When the SK algorithm performs column scaling on the matrix after row scaling, only one element required for column scaling is read in each row of elements read, which leads to the problem of high cache but low hit rate. Combining the first code and the second code, it can be understood that the problem of high cache but low hit rate occurs because different cache rows are accessed when sequentially accessing the matrices A[i][j] and A[i+1][j]; moreover, all row elements in the matrix after row scaling need to be repeatedly read from the memory to obtain all column elements required for column scaling, which makes it possible that adjacent column elements required for column scaling are read after multiple row elements, reducing the spatial locality of column scaling.
[0064] Based on the above description, in one embodiment, illustratively, Figure 2 The flowchart of a method for processing task data in a computer is provided, and the method can be executed by a central processing unit (CPU) in the computer, such as Figure 2 As shown, the method may include the following steps:
[0065] S202, obtaining the SK algorithm matrix corresponding to the computing task.
[0066] In the embodiment of the present application, the SK algorithm matrix corresponding to the computing task is related to the actual application scenario. For example, the SK algorithm can be used to process task data corresponding to the optimal transmission problem, computer vision, and word mover's distance (WMD). Therefore, the SK algorithm matrix corresponding to the computing task may refer to the matrix corresponding to the computing tasks of the optimal transmission problem, computer vision, and word mover's distance, which can be specifically set according to the actual application scenario.
[0067] S204, based on the sum of the elements of each row in the SK algorithm matrix, perform row scaling on the elements of each row in the SK algorithm matrix, and cache the scaled row elements into a preset array.
[0068] In an embodiment of the present application, after obtaining the SK algorithm matrix corresponding to the computing task, the elements of each row in the SK algorithm matrix can be read, and then the sum of the elements of each row in the SK algorithm matrix can be obtained. In this way, based on the sum of the elements of each row in the SK algorithm matrix, the elements of each row in the SK algorithm matrix are row-scaled to obtain the SK algorithm matrix after row scaling. A possible implementation method is: calculate the scaling factor for row scaling of the elements in each row of the SK algorithm matrix, and calculate the product of the scaling factor and the elements of each row in the SK algorithm matrix respectively, so as to obtain the SK algorithm matrix after row scaling.
[0069] The scaling factor of the row scaling is the ratio of the preset element corresponding to the row scaling to the element of each row in the SK algorithm matrix. Combined with the content of the first code, the scaling factor of the row scaling can be expressed as α=RMD i / ∑A i , RMD i The corresponding row scales the corresponding preset element.
[0070] In an embodiment of the present application, after obtaining the SK algorithm matrix after row scaling, the scaled row elements can be cached to a preset array, wherein the preset array can be understood as a temporary cache array. When the row scaling process is completed, the CPU does not need to write the preset array back to the main memory. Therefore, using the preset array does not introduce additional overhead.
[0071] S206, obtaining a scaling factor for performing column scaling on the SK algorithm matrix after row scaling according to the elements cached in the preset array.
[0072] Specifically, according to the elements cached in the preset array, a scaling factor for column scaling in the SK algorithm matrix after row scaling is obtained, including: accumulating the elements of each column in the preset array, and calculating the ratio of the preset elements to the sum of the elements of each column in the preset array, to obtain the scaling factor for column scaling of the SK algorithm matrix after row scaling.
[0073] The preset element refers to the preset element corresponding to the column scaling, and the preset element corresponding to the column scaling and the preset element corresponding to the row scaling may be the same or different; combined with the content described in the second code, the scaling factor of the column scaling can be expressed as β=CMD j / ∑A j , CMD j The corresponding column scales the corresponding preset element.
[0074] It can be understood that, since the scaling factor of the column scaling is obtained according to the elements of each column in the preset array, the obtained scaling factor can also be cached in the preset array.
[0075] S208 , based on the scaling factor, performing column scaling on the row-scaled SK algorithm matrix to obtain a scaled SK algorithm matrix.
[0076] Specifically, based on the scaling factor, the row-scaled SK algorithm matrix is column-scaled to obtain the scaled SK algorithm matrix, including: respectively calculating the product of the scaling factor and the elements of each column in the row-scaled SK algorithm matrix to obtain the scaled SK algorithm matrix.
[0077] S210, performing SK algorithm processing according to the scaled SK algorithm matrix to obtain a task data processing result.
[0078] Among them, the SK algorithm can be used to process task data corresponding to optimal transmission problems, computer vision, and word movement distance. Therefore, the task data processing result is the result that meets the iterative requirements of computing tasks such as optimal transmission problems, computer vision, and word movement distance, and can be set specifically according to the actual application scenario.
[0079] To summarize, in an embodiment of the present application, by obtaining the SK algorithm matrix corresponding to the computing task, the elements of each row in the SK algorithm matrix can be row-scaled based on the sum of the elements in each row in the SK algorithm matrix, and the scaled row elements can be cached in a preset array. In this way, according to the elements cached in the preset array, the scaling factor for column scaling of the row-scaled SK algorithm matrix can be obtained, and then, based on the scaling factor, the column scaling of the row-scaled SK algorithm matrix can be performed to obtain the scaled SK algorithm matrix, and SK algorithm processing can be performed according to the scaled SK algorithm matrix to obtain the task data processing result.
[0080] The embodiment of the present application uses a preset array so that after the row scaling is completed, the scaling factor for column scaling of the column elements of the matrix after row scaling can be obtained, so that there is no need to repeatedly read each row element in the matrix after row scaling to obtain the sum of the elements required for column scaling processing in the matrix after row scaling and the elements of each column in the matrix after row scaling. It is only necessary to perform column scaling on the SK algorithm matrix after row scaling based on the scaling factor to obtain the matrix after row scaling and column scaling. Therefore, the efficiency of task data processing can be improved by improving the efficiency of the column scaling process.
[0081] It should be noted that in the embodiment of the present application, the elements of each row in the read SK algorithm matrix are used, and can be used to obtain the sum of the elements of each row in the SK algorithm matrix, and then perform row scaling on the SK algorithm matrix, or can be cached in a preset array to obtain the scaling factor required for column scaling later. Therefore, this can avoid the problem of high cache but low hit rate; moreover, when the row-scaled matrix is column-scaled, even if the elements of each row after row scaling are read in row form, the element is also the element required for column scaling. By calculating the product of the scaling factor and the element of each column after row scaling, the scaled SK algorithm matrix can be obtained. Therefore, this can improve the spatial locality of column scaling.
[0082] exist Figure 2 Based on the content shown, we can design Algorithm 1 to improve the spatial locality of column scaling to obtain the scaled SK algorithm matrix. The input of Algorithm 1 includes: sum initialized to 0 1×N 、temp 1×N , CMD 1×N and A M×N , the output of Algorithm 1 is the column-scaled matrix A M×N , that is, the scaled SK algorithm matrix, M×N is the dimension of A. Specifically, the code content of Algorithm 1 can be described as:
[0083]
[0084] In Algorithm 1, sum represents the sum of the elements of each column after row scaling, temp represents the scaling factor of the column scaling in the preset array, and CMD represents the preset element corresponding to the column scaling.
[0085] It should be noted that, in the first code and the second code described above, the inner loop index i of the code has a long stride, which may cause the matrix elements read from the buffer each time to be unused, i.e., a high cache miss problem. In Algorithm 1 of the present application, the access stride is changed to 1, allowing sequential access to the elements in the matrix, thereby improving spatial locality and reducing cache miss rate by exchanging the order of loop execution.
[0086] For high-performance computing tasks optimized from the perspective of computer architecture, especially for computationally intensive tasks such as general matrix multiplication (GEMM), an important idea is to use cache more efficiently. Blocking technology plays an important role in GEMM optimization. Modern mainstream linear algebra libraries such as GotoBLAS, OpenBLAS, and BLASFEO all use blocking technology to optimize matrix multiplication.
[0087] Based on this, the row-scaled SK algorithm matrix can be divided into blocks to obtain multiple sub-matrices. According to the scaling factor, each sub-matrix can obtain the scaled column elements corresponding to each sub-matrix. In this way, the scaled SK algorithm matrix can be obtained by combining the scaled column elements corresponding to multiple sub-matrices.
[0088] exist Figure 2 Based on the content shown, in one embodiment, based on the scaling factor, the row-scaled SK algorithm matrix is column-scaled to obtain the scaled SK algorithm matrix, including: dividing the row-scaled SK algorithm matrix into blocks according to a preset row dimension and a preset column dimension to obtain multiple sub-matrices; respectively calculating the product of the scaling factor and the elements in each sub-matrix to obtain the column-scaled elements corresponding to each sub-matrix; combining the column-scaled elements corresponding to multiple sub-matrices to obtain the scaled SK algorithm matrix.
[0089] It should be noted that cache content may be missing for large matrices because all elements of the matrix may not be stored in the cache. Therefore, the row-scaled SK algorithm matrix can be divided into several sub-matrices that can be appropriately placed in the cache by dividing the row-scaled SK algorithm matrix into blocks according to preset row dimensions and preset column dimensions, so that all elements of the matrix can be stored in the cache. In this way, when the scaled SK algorithm matrix is processed based on the SK algorithm, the accuracy of the task data processing results can be improved.
[0090] exist Figure 2 Based on the content shown, in one embodiment, the product of the scaling factor and the elements in each submatrix is calculated respectively to obtain the scaled column elements corresponding to each submatrix, including: calling the instruction set corresponding to the column scaling; based on the instruction set, the product of the scaling factor and the elements in each submatrix is calculated respectively to obtain the scaled column elements corresponding to each submatrix.
[0091] Furthermore, in one embodiment, based on the instruction set, the product of the scaling factor and the elements in each submatrix is calculated respectively to obtain the scaled elements of the columns corresponding to each submatrix, including: reordering the instructions in the instruction set in the microkernel to obtain a reordered instruction set; and according to the reordered instruction set, calculating the product of the scaling factor and the elements in each submatrix respectively to obtain the scaled elements of the columns corresponding to each submatrix.
[0092] Among them, the instruction set may refer to the instruction set corresponding to the vectorized instruction, which is an instruction set that supports single instruction multiple data (SIMD) stream, and the vectorized instruction is a data-level parallel processing instruction; the instruction set may be the AVX256 instruction set of the x86 architecture, and when a matrix is processed based on the AVX256 instruction set in the microkernel, the dimension of the matrix is a 4×4 matrix, or it can be understood that when a row-scaled matrix is column-scaled based on the AVX256 instruction set in the microkernel, the elements in 16 sub-matrices can be read sequentially in parallel, and the elements in the 16 matrices can be multiplied by the scaling factor at the same time, so that the column-scaled elements corresponding to the elements in the 16 sub-matrices can be obtained, and so on, until the column-scaled elements corresponding to multiple sub-matrices are obtained.
[0093] It should be noted that reordering the instructions in the instruction set in the microkernel can be understood as enhancing the implementation of the microkernel at the assembly level through instruction reordering, that is, enhancing the way in which multiple matrices can be processed in parallel in the microkernel.
[0094] For example, Figure 3 A schematic diagram of the microkernel-based partitioning principle is provided, such as Figure 3 As shown, the dimension of the SK algorithm matrix after row scaling is M×N, nc is the preset row dimension, nc is the preset column dimension, mr and nr are the corresponding matrix dimensions in the microkernel, temp is a one-dimensional preset array, and the scaling factor is stored in temp.
[0095] It should be noted that the preset row dimension can be the same as M, and the preset column dimension can be the same as N. In this way, after the row-scaled SK algorithm matrix is divided into blocks according to the preset row dimension and the preset column dimension, the element in each sub-matrix obtained is one, which can be multiplied by the scaling factor to obtain the column-scaled element corresponding to each sub-matrix.
[0096] It should be noted that the column dimension of the preset array is the same as the column dimension of the SK algorithm matrix after row scaling, that is, the column dimension of the preset array is nc. Since the column dimension of the preset array is nc, rather than N, when the preset array stores the scaling factor of the column scaling, it is easier to be used by the L1 cache, which can reduce the number of data exchanges between the CPU and the memory, improve the efficiency of the CPU column scaling process, and thus improve the processing efficiency of the task data.
[0097] The specific values of mr and nr are related to the type of instruction set. Therefore, when using different instruction sets, the values of mr and nr can be set to values corresponding to the instruction set used. For example, when the instruction set is the AVX256 instruction set, mr and nr are both 4.
[0098] Combined with the above description, it can be understood that after the row-scaled SK algorithm matrix is divided into blocks to obtain multiple sub-matrices, the instructions in the instruction set can be reordered in the microkernel so that the reordered instruction set can calculate the product of the scaling factor and the elements in each sub-matrix in parallel to obtain the scaled column elements corresponding to each sub-matrix, and the scaled column elements corresponding to multiple sub-matrices are combined to obtain the scaled SK algorithm matrix; moreover, since the instruction set used is a data-level parallel processing instruction, the efficiency of task data processing can be improved.
[0099] For example, Figure 4 A schematic diagram of an instruction reordering is provided, such as Figure 4 As shown, Figure 4 The content on the left is the assembly code of the C / C++ statement before the instruction reordering. Figure 4 The content on the right side is the assembly code after the instructions are reordered.
[0100] It should be noted that processing matrices in the microkernel requires repeating three operations, each operation is for four double-precision floating-point data, and the three operations are loading (i.e., _mm256_loadu_pd), multiplication (i.e., _mm256_mul_pd) and storage (i.e., _mm256_storeu_pd). There is a data dependency between loading, multiplication and storage, that is, there is data dependency between loading and multiplication, and there is data dependency between multiplication and storage. The present application reduces the loop overhead by utilizing the CPU microkernel to expand the innermost loop of the column-scaled matrix, and reduces the data dependency by reordering instructions.
[0101] Among them, the loading process can be understood as reading the scaling factor from the preset array and reading the elements from the multiple sub-matrices after blocking; the multiplication process can be understood as calculating the product of the scaling factor and the elements in each sub-matrix to obtain the scaled column elements corresponding to each sub-matrix; the storage process can be understood as storing the scaled column elements corresponding to each sub-matrix at the corresponding positions in the row-scaled SK algorithm matrix. In this way, the scaled SK algorithm matrix can be obtained by storing the scaled column elements corresponding to multiple sub-matrices in the row-scaled SK algorithm matrix.
[0102] Combination Figure 4 The load instructions include a movq instruction and a vmovupd instruction. The movq instruction and the vmovupd instruction have data dependency on registers. Therefore, by inserting calculation instructions between the movq instruction and the vmovupd instruction, the data dependency can be further resolved.
[0103] In combination with the above description, it should be noted that S202 to S208 is actually a processing process of the SK algorithm. The SK algorithm is processed according to the scaled SK algorithm matrix to obtain the task data processing result. It can be understood that the processes corresponding to S202 to S208 are repeatedly executed, and in this process, the process of dividing the row-scaled matrix into blocks and the process of calculating the scaled column elements corresponding to each sub-matrix in the microkernel can still be executed until the iterative requirements of computing tasks such as optimal transmission problems, computer vision, and word movement distance are met. The result obtained is the task data processing result.
[0104] It should be understood that, although the various steps in the flowcharts involved in the above-mentioned embodiments are displayed in sequence according to the indication of the arrows, these steps are not necessarily executed in sequence according to the order indicated by the arrows. Unless there is a clear explanation in this article, the execution of these steps does not have a strict order restriction, and these steps can be executed in other orders. Moreover, at least a part of the steps in the flowcharts involved in the above-mentioned embodiments can include multiple steps or multiple stages, and these steps or stages are not necessarily executed at the same time, but can be executed at different times, and the execution order of these steps or stages is not necessarily to be carried out in sequence, but can be executed in turn or alternately with other steps or at least a part of the steps or stages in other steps.
[0105] Based on the same inventive concept, the embodiment of the present application also provides a computer task data processing device for implementing the above-mentioned computer task data processing method. The implementation scheme for solving the problem provided by the device is similar to the implementation scheme recorded in the above-mentioned method, so the specific limitations in one or more computer task data processing device embodiments provided below can refer to the above-mentioned limitations on the computer task data processing method, and will not be repeated here.
[0106] In one embodiment, Figure 5 As shown, a task data processing device in a computer is provided, comprising: an acquisition module 502, a cache module 504, a calculation module 506 and a processing module 508, wherein:
[0107] The acquisition module is used to obtain the SK algorithm matrix corresponding to the computing task.
[0108] The cache module is used to scale the elements of each row in the SK algorithm matrix based on the sum of the elements of each row in the SK algorithm matrix, and cache the scaled row elements to a preset array.
[0109] A calculation module, used for obtaining a scaling factor for performing column scaling on the SK algorithm matrix after row scaling according to the elements cached in the preset array;
[0110] The processing module is used to perform column scaling on the row-scaled SK algorithm matrix based on the scaling factor to obtain the scaled SK algorithm matrix; and to perform SK algorithm processing according to the scaled SK algorithm matrix to obtain the task data processing result.
[0111] In one embodiment, the computing module is further configured to:
[0112] The elements of each column in the preset array are accumulated, and the ratio of the preset element to the sum of the elements of each column in the preset array is calculated respectively to obtain the scaling factor of the elements of each column in the SK algorithm matrix after row scaling.
[0113] The processing module is also used to:
[0114] After the row-scaled SK algorithm matrix is divided into blocks according to the preset row dimension and the preset column dimension, a plurality of sub-matrices are obtained;
[0115] Calculate the product of the scaling factor and the elements in each submatrix respectively to obtain the scaled elements of the columns corresponding to each submatrix;
[0116] The scaled column elements corresponding to the multiple sub-matrices are combined to obtain the scaled SK algorithm matrix.
[0117] In one embodiment, the processing module is further configured to:
[0118] Call the instruction set corresponding to column scaling;
[0119] Based on the instruction set, the product of the scaling factor and the elements in each sub-matrix is calculated respectively to obtain the scaled elements of the columns corresponding to each sub-matrix.
[0120] In one embodiment, the processing module is further configured to:
[0121] Reorder the instructions in the instruction set in the microkernel to obtain a reordered instruction set;
[0122] According to the reordered instruction set, the product of the scaling factor and the elements in each submatrix is calculated respectively to obtain the scaled elements of the columns corresponding to each submatrix.
[0123] In one embodiment, the instruction set is the AVX256 instruction set of the x86 architecture.
[0124] Each module in the task data processing device in the above-mentioned computer can be implemented in whole or in part by software, hardware and a combination thereof. Each of the above-mentioned modules can be embedded in or independent of the processor in the computer device in the form of hardware, or can be stored in the memory in the computer device in the form of software, so that the processor can call and execute the operations corresponding to each of the above modules.
[0125] In one embodiment, a computer device is provided. The computer device may be a server, and its internal structure diagram may be as follows: Figure 6As shown. The computer device includes a processor, a memory and a network interface connected through a system bus. Among them, the processor of the computer device is used to provide computing and control capabilities. The memory of the computer device includes a non-volatile storage medium and an internal memory. The non-volatile storage medium stores an operating system and a computer program. The internal memory provides an environment for the operation of the operating system and the computer program in the non-volatile storage medium. The network interface of the computer device is used to communicate with an external terminal through a network connection. When the computer program is executed by the processor, a task data processing method in a computer is implemented.
[0126] Those skilled in the art will understand that Figure 6 The structure shown in the figure is only a block diagram of a part of the structure related to the solution of the present application, and does not constitute a limitation on the computer device to which the solution of the present application is applied. The specific computer device may include more or fewer components than those shown in the figure, or combine certain components, or have a different arrangement of components.
[0127] In one embodiment, a computer device is provided, including a memory and a processor, wherein a computer program is stored in the memory, and when the processor executes the computer program, the following steps are implemented:
[0128] Get the SK algorithm matrix corresponding to the calculation task;
[0129] Based on the sum of the elements of each row in the SK algorithm matrix, the elements of each row in the SK algorithm matrix are row-scaled, and the scaled row elements are cached in a preset array;
[0130] According to the elements cached in the preset array, a scaling factor for column scaling of the SK algorithm matrix after row scaling is obtained;
[0131] Based on the scaling factor, the SK algorithm matrix after row scaling is scaled to obtain a scaled SK algorithm matrix;
[0132] The SK algorithm is processed according to the scaled SK algorithm matrix to obtain the task data processing result.
[0133] In one embodiment, when the processor executes the computer program, the processor further implements the following steps:
[0134] The elements of each column in the preset array are accumulated, and the ratio of the preset element to the sum of the elements of each column in the preset array is calculated respectively to obtain the scaling factor of the elements of each column in the SK algorithm matrix after row scaling.
[0135] In one embodiment, when the processor executes the computer program, the processor further implements the following steps:
[0136] After the row-scaled SK algorithm matrix is divided into blocks according to the preset row dimension and the preset column dimension, a plurality of sub-matrices are obtained;
[0137] Calculate the product of the scaling factor and the elements in each submatrix respectively to obtain the scaled elements of the columns corresponding to each submatrix;
[0138] The scaled column elements corresponding to the multiple sub-matrices are combined to obtain the scaled SK algorithm matrix.
[0139] In one embodiment, when the processor executes the computer program, the processor further implements the following steps:
[0140] Call the instruction set corresponding to column scaling;
[0141] Based on the instruction set, the product of the scaling factor and the elements in each sub-matrix is calculated respectively to obtain the scaled elements of the columns corresponding to each sub-matrix.
[0142] In one embodiment, when the processor executes the computer program, the processor further implements the following steps:
[0143] Reorder the instructions in the instruction set in the microkernel to obtain a reordered instruction set;
[0144] According to the reordered instruction set, the product of the scaling factor and the elements in each submatrix is calculated respectively to obtain the scaled elements of the columns corresponding to each submatrix.
[0145] In one embodiment, the instruction set is the AVX256 instruction set of the x86 architecture.
[0146] In one embodiment, a computer readable storage medium is provided, on which a computer program is stored, and when the computer program is executed by a processor, the following steps are implemented:
[0147] Get the SK algorithm matrix corresponding to the calculation task;
[0148] Based on the sum of the elements of each row in the SK algorithm matrix, the elements of each row in the SK algorithm matrix are row-scaled, and the scaled row elements are cached in a preset array;
[0149] According to the elements cached in the preset array, a scaling factor for column scaling of the SK algorithm matrix after row scaling is obtained;
[0150] Based on the scaling factor, the SK algorithm matrix after row scaling is scaled to obtain a scaled SK algorithm matrix;
[0151] The SK algorithm is processed according to the scaled SK algorithm matrix to obtain the task data processing result.
[0152] In one embodiment, when the computer program is executed by a processor, the following steps are also implemented:
[0153] The elements of each column in the preset array are accumulated, and the ratio of the preset element to the sum of the elements of each column in the preset array is calculated respectively to obtain the scaling factor of the elements of each column in the SK algorithm matrix after row scaling.
[0154] In one embodiment, when the computer program is executed by a processor, the following steps are also implemented:
[0155] After the row-scaled SK algorithm matrix is divided into blocks according to the preset row dimension and the preset column dimension, a plurality of sub-matrices are obtained;
[0156] Calculate the product of the scaling factor and the elements in each submatrix respectively to obtain the scaled elements of the columns corresponding to each submatrix;
[0157] The scaled column elements corresponding to the multiple sub-matrices are combined to obtain the scaled SK algorithm matrix.
[0158] In one embodiment, when the computer program is executed by a processor, the following steps are also implemented:
[0159] Call the instruction set corresponding to column scaling;
[0160] Based on the instruction set, the product of the scaling factor and the elements in each sub-matrix is calculated respectively to obtain the scaled elements of the columns corresponding to each sub-matrix.
[0161] In one embodiment, when the computer program is executed by a processor, the following steps are also implemented:
[0162] Reorder the instructions in the instruction set in the microkernel to obtain a reordered instruction set;
[0163] According to the reordered instruction set, the product of the scaling factor and the elements in each submatrix is calculated respectively to obtain the scaled elements of the columns corresponding to each submatrix.
[0164] In one embodiment, the instruction set is the AVX256 instruction set of the x86 architecture.
[0165] In one embodiment, a computer program product is provided, comprising a computer program, which, when executed by a processor, implements the following steps:
[0166] Get the SK algorithm matrix corresponding to the calculation task;
[0167] Based on the sum of the elements of each row in the SK algorithm matrix, the elements of each row in the SK algorithm matrix are row-scaled, and the scaled row elements are cached in a preset array;
[0168] According to the elements cached in the preset array, a scaling factor for column scaling of the SK algorithm matrix after row scaling is obtained;
[0169] Based on the scaling factor, the SK algorithm matrix after row scaling is scaled to obtain a scaled SK algorithm matrix;
[0170] The SK algorithm is processed according to the scaled SK algorithm matrix to obtain the task data processing result.
[0171] In one embodiment, when the computer program is executed by a processor, the following steps are also implemented:
[0172] The elements of each column in the preset array are accumulated, and the ratio of the preset element to the sum of the elements of each column in the preset array is calculated respectively to obtain the scaling factor of the elements of each column in the SK algorithm matrix after row scaling.
[0173] In one embodiment, when the computer program is executed by a processor, the following steps are also implemented:
[0174] After the row-scaled SK algorithm matrix is divided into blocks according to a preset row dimension and a preset column dimension, a plurality of sub-matrices are obtained;
[0175] Calculate the product of the scaling factor and the elements in each submatrix respectively to obtain the scaled elements of the columns corresponding to each submatrix;
[0176] The scaled column elements corresponding to the multiple sub-matrices are combined to obtain the scaled SK algorithm matrix.
[0177] In one embodiment, when the computer program is executed by a processor, the following steps are also implemented:
[0178] Call the instruction set corresponding to column scaling;
[0179] Based on the instruction set, the product of the scaling factor and the elements in each sub-matrix is calculated respectively to obtain the scaled elements of the columns corresponding to each sub-matrix.
[0180] In one embodiment, when the computer program is executed by a processor, the following steps are also implemented:
[0181] Reorder the instructions in the instruction set in the microkernel to obtain a reordered instruction set;
[0182] According to the reordered instruction set, the product of the scaling factor and the elements in each submatrix is calculated respectively to obtain the scaled elements of the columns corresponding to each submatrix.
[0183] In one embodiment, the instruction set is the AVX256 instruction set of the x86 architecture.
[0184] Those skilled in the art can understand that all or part of the processes in the above-mentioned embodiment methods can be completed by instructing the relevant hardware through a computer program, and the computer program can be stored in a non-volatile computer-readable storage medium. When the computer program is executed, it can include the processes of the embodiments of the above-mentioned methods. Among them, any reference to the memory, database or other medium used in the embodiments provided in the present application can include at least one of non-volatile and volatile memory. Non-volatile memory can include read-only memory (ROM), magnetic tape, floppy disk, flash memory, optical memory, high-density embedded non-volatile memory, resistive random access memory (ReRAM), magnetoresistive random access memory (MRAM), ferroelectric random access memory (FRAM), phase change memory (PCM), graphene memory, etc. Volatile memory can include random access memory (RAM) or external cache memory, etc. As an illustration and not limitation, RAM can be in various forms, such as static random access memory (SRAM) or dynamic random access memory (DRAM). The database involved in each embodiment provided in this application may include at least one of a relational database and a non-relational database. Non-relational databases may include distributed databases based on blockchains, etc., but are not limited to this. The processor involved in each embodiment provided in this application may be a general-purpose processor, a central processing unit, a graphics processor, a digital signal processor, a programmable logic device, a data processing logic device based on quantum computing, etc., but are not limited to this.
[0185] The technical features of the above embodiments may be combined arbitrarily. To make the description concise, not all possible combinations of the technical features in the above embodiments are described. However, as long as there is no contradiction in the combination of these technical features, they should be considered to be within the scope of this specification.
[0186] The above-described embodiments only express several implementation methods of the present application, and the descriptions thereof are relatively specific and detailed, but they cannot be understood as limiting the scope of the present application. It should be pointed out that, for a person of ordinary skill in the art, several variations and improvements can be made without departing from the concept of the present application, and these all belong to the protection scope of the present application. Therefore, the protection scope of the present application shall be subject to the attached claims.
Claims
1. A method for processing task data in a computer, characterized in that: The method comprises: Get the SK algorithm matrix corresponding to the calculation task; Based on the sum of the elements of each row in the SK algorithm matrix, row scaling is performed on the elements of each row in the SK algorithm matrix, and the scaled row elements are cached in a preset array; Obtaining, according to the elements cached in the preset array, a scaling factor for performing column scaling on the SK algorithm matrix after row scaling; After the row-scaled SK algorithm matrix is divided into blocks according to a preset row dimension and a preset column dimension, a plurality of sub-matrices are obtained; Call the instruction set corresponding to column scaling; Reordering the instructions in the instruction set in the microkernel to obtain the reordered instruction set; According to the reordered instruction set, respectively calculating the product of the scaling factor and the elements in each of the sub-matrices to obtain the scaled elements of the columns corresponding to each of the sub-matrices; Combining the scaled column elements corresponding to the plurality of sub-matrices to obtain the scaled SK algorithm matrix; SK algorithm processing is performed according to the scaled SK algorithm matrix to obtain a task data processing result.
2. The method according to claim 1, characterized in that: The step of obtaining, according to the elements cached in the preset array, a scaling factor for performing column scaling on the SK algorithm matrix after row scaling, comprises: The elements of each column in the preset array are accumulated, and the ratio of the preset elements to the sum of the elements of each column in the preset array is calculated respectively to obtain the scaling factor of the elements of each column in the SK algorithm matrix after the row scaling.
3. The method according to claim 1, characterized in that The step of scaling the elements of each row in the SK algorithm matrix based on the sum of the elements of each row in the SK algorithm matrix, and caching the scaled row elements in a preset array includes: Obtaining a scaling factor for row scaling of elements in each row of the SK algorithm matrix, where the scaling factor for row scaling is a ratio of a preset element corresponding to the row scaling to a sum of elements in each row of the SK algorithm matrix; Calculate the product of the row scaling factor and the element of each row in the SK algorithm matrix to obtain the row-scaled SK algorithm matrix; Based on the row-scaled SK algorithm matrix, the scaled row elements are cached into a preset array.
4. The method according to claim 1, characterized in that: The instruction set is the AVX256 instruction set of the x86 architecture.
5. A task data processing device in a computer, characterized in that: The device comprises: an acquisition module, a cache module, a calculation module and a processing module. The acquisition module is used to obtain the SK algorithm matrix corresponding to the calculation task; The cache module is used to perform row scaling on the elements of each row in the SK algorithm matrix based on the sum of the elements of each row in the SK algorithm matrix, and cache the scaled row elements into a preset array; The calculation module is used to obtain a scaling factor for performing column scaling on the SK algorithm matrix after row scaling according to the elements cached in the preset array; The processing module is used to perform block processing on the SK algorithm matrix after row scaling according to preset row dimensions and preset column dimensions to obtain multiple sub-matrices; call the instruction set corresponding to column scaling; reorder the instructions in the instruction set in the microkernel to obtain the reordered instruction set; according to the reordered instruction set, respectively calculate the product of the scaling factor and the elements in each sub-matrix to obtain the column-scaled elements corresponding to each sub-matrix; combine the column-scaled elements corresponding to multiple sub-matrices to obtain a scaled SK algorithm matrix; perform SK algorithm processing according to the scaled SK algorithm matrix to obtain a task data processing result.
6. The device according to claim 5, characterized in that The calculation module is also used to accumulate the elements of each column in the preset array, and calculate the ratio of the preset elements to the sum of the elements of each column in the preset array, so as to obtain the scaling factor of the elements in each column of the SK algorithm matrix after the row scaling.
7. The device according to claim 5, characterized in that The cache module is further used to obtain a scaling factor for row scaling of elements in each row of the SK algorithm matrix, where the scaling factor for row scaling is a ratio of a preset element corresponding to the row scaling to a sum of elements in each row of the SK algorithm matrix; The product of the row scaling factor and the elements of each row in the SK algorithm matrix is calculated to obtain the row-scaled SK algorithm matrix; based on the row-scaled SK algorithm matrix, the scaled row elements are cached into a preset array.
8. A computer device comprising a memory and a processor, wherein the memory stores a computer program, wherein: When the processor executes the computer program, the steps of the method according to any one of claims 1 to 4 are implemented.
9. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the steps of the method according to any one of claims 1 to 4 are implemented.
10. A computer program product, comprising a computer program, characterized in that When the computer program is executed by a processor, the steps of the method according to any one of claims 1 to 4 are implemented.
