A method and apparatus for reading a symmetric matrix applied to a parallel system

By using symmetric matrix partitioning and mask matrix processing, the problem of repeated reading of symmetric matrix data in parallel computing systems is solved, achieving efficient symmetric matrix computation, especially significantly improving computation speed and load balancing under a multi-level caching structure.

CN117540137BActive Publication Date: 2026-07-14SOUTH CHINA UNIV OF TECH

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
SOUTH CHINA UNIV OF TECH
Filing Date
2023-10-16
Publication Date
2026-07-14

AI Technical Summary

Technical Problem

Existing parallel computing systems, when processing symmetric matrices, directly use general matrix operation interfaces, resulting in half of the data being read repeatedly. This fails to effectively utilize the symmetry of symmetric matrices and affects computational efficiency.

Method used

By dividing the symmetric matrix into three cases—containing valid data, containing half valid data, and containing no valid data—a mask matrix is ​​generated for data preprocessing. After ensuring data alignment, the matrix operation unit is called for calculation. Each core of the parallel computing system reads the blocks in a loop until completion.

Benefits of technology

It efficiently reads symmetric matrices in different parallel computing systems, especially significantly improving computation speed and load balancing in multi-level cache structures, avoiding scalar operations, and increasing the speed of computation task completion.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN117540137B_ABST
    Figure CN117540137B_ABST
Patent Text Reader

Abstract

The application relates to the field of parallel matrix computation, and relates to a symmetric matrix reading and computing method and device applied to a parallel system, which comprises the following steps: dividing a symmetric matrix into multiple subblocks according to the storage and hardware conditions of different parallel systems, and reading one subblock by each computing core of the parallel computing system for computation each time; dividing the subblocks into three cases of containing effective data subblocks, containing half effective data subblocks and not containing effective data subblocks according to a parameter uplo for data preprocessing; calling a matrix operation unit to perform corresponding computation on the data after the preprocessing; and writing back the computation results after processing according to output requirements, completing the computation task of one subblock, and cyclically reading each subblock by each computing core of the parallel computing system until the computation of all the subblocks is completed. The application is suitable for different parallel computing systems, and can efficiently complete the reading and computation of real type symmetric matrices.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of parallel matrix computation, and more specifically to a method and device for reading and computing symmetric matrices in parallel systems. Background Technology

[0002] With the continuous iteration and development of computer hardware and software, while focusing on computational accuracy, people are also placing higher demands on computational speed. To complete calculations more efficiently, parallel computing systems have begun to be widely used to solve parallel computation problems involving large amounts of data. Parallel computing systems typically have multiple computing nodes that can perform calculations simultaneously. In parallel computing, the computational task is divided into multiple subtasks, with each computing node responsible for a portion of the subtasks. Each computing node executes its assigned subtasks simultaneously, thereby improving the speed at which the computational task is completed.

[0003] Current parallel computing systems primarily utilize GPUs or NPUs with a large number of computing cores to perform parallel computations. However, some logically complex computational tasks still require CPUs. Therefore, heterogeneous computing systems combining CPUs and GPUs / NPUs are widely used in the field of parallel computing. Furthermore, the multi-level caching structure within parallel computing systems makes simultaneous computation and data transfer possible, further enhancing the parallelism of computation. Parallel computing systems have highly optimized matrix computation modules tailored to their specific characteristics, whose computational performance can be tens or even hundreds of times that of the same system's vector computation modules. Therefore, parallel systems should generally prioritize the use of matrix computation modules. When matrix computation is not feasible, the computation process should be vectorized and performed using vector computation modules, avoiding the use of the lowest-performing scalar computation modules to accelerate computation speed.

[0004] In practical applications, matrices and vectors are relatively concise and straightforward data types when converting information into computational data. Therefore, accelerating matrix and vector operations is of great significance in high-performance computing. The BLAS library is an interface standard for a series of basic linear algebra operations, including commonly used matrix and vector operations, and is widely used in deep learning, image processing, and computer benchmarking. The BLAS library includes many processing functions for special matrices, with symmetric matrices being a major matrix type. A symmetric matrix is ​​a matrix whose elements are symmetric about the main diagonal. Although its related operations can be performed directly using the general matrix operation interface, there are special cases where the input only contains the upper or lower triangular part of the symmetric matrix. Furthermore, directly using general matrix operations does not utilize the symmetry of symmetric matrices, resulting in half of the data being read repeatedly. Therefore, it is necessary to provide an interface for calculating symmetric matrices. Depending on different performance requirements, operating environments, and hardware devices, BLAS library interfaces that meet corresponding needs can be developed, which also places a demand on the universality of methods for reading and calculating symmetric matrices. Summary of the Invention

[0005] To address the existing technical problems, this invention proposes a method and device for reading and calculating symmetric matrices in parallel systems, which can efficiently complete the reading and calculation of symmetric matrices of various real number types on various parallel platforms.

[0006] The first objective of this invention is to provide a symmetric matrix reading and calculation method applicable to parallel systems.

[0007] A second objective of this invention is to provide a computer device.

[0008] The first objective of this invention can be achieved by adopting the following technical solution:

[0009] A method for reading and calculating a symmetric matrix applied to a parallel system, the method comprising:

[0010] The symmetric matrix is ​​divided into multiple matrix blocks, and each computing core of the parallel computing system reads one matrix block at a time to complete the computing task.

[0011] Based on the parameter uplo, the matrix is ​​divided into three cases: blocks containing valid data, blocks containing half valid data, and blocks containing no valid data. Data preprocessing is performed, the data is rearranged into a form that meets the input requirements of the matrix operation unit, and data is padded for parts that do not meet the byte alignment requirements for data reading, so that the operation unit can directly read and calculate the data.

[0012] The preprocessed data is used to perform matrix calculations in the matrix operation unit to obtain the matrix calculation results.

[0013] The matrix calculation results are organized and written back to the corresponding positions according to the output data arrangement requirements. Each computing core of the parallel computing system reads each block it is responsible for in a loop until all blocks are calculated.

[0014] Specifically, the symmetric matrix is ​​a real number type symmetric matrix, which is an uncompressed symmetric matrix containing half of the valid data. The parameter uplo specifies that the part containing valid data is the upper triangular part or the lower triangular part of the symmetric matrix, and the part without valid data is processed or completed during preprocessing.

[0015] Specifically, the step of dividing the symmetric matrix into multiple matrix blocks during computation includes:

[0016] Based on the number of computing cores, the size of each level of cache, and the shape of matrix blocks in the parallel computing system, the number of matrix blocks allocated to each computing core should be as consistent as possible, and the size of the matrix blocks should fill the memory as much as possible.

[0017] The matrix blocks are square in shape, and the number of rows and columns in each block is the same.

[0018] Specifically, the matrix block size is N×N, and when using a single buffer, the size of N satisfies the following conditions 1 and 2:

[0019] Condition 1: (N 2 (+O+I)×sizeof(T)≤minimum cache size;

[0020] Condition 2: (N 2 +O+I+C)×sizeof(T)≤the size of the cache storing the positions of the mask matrix;

[0021] When using double buffering, the size of N satisfies the following conditions 3 and 4:

[0022] Condition 3: 2×[(N 2 [+O+I)×sizeof(T)]≤minimum cache size;

[0023] Condition 4:

[0024] 2×[(N 2 +O+I)×sizeof(T)]+(C×sizeof(T))

[0025] ≤ The size of the cache storing the mask matrix positions;

[0026] Where, N 2O represents the amount of data in the matrix block, I represents the amount of data in the space required to store the calculation results, C represents the amount of data in the corresponding matrix block or vector segment involved in the calculation, T represents the amount of data in the mask matrix, and sizeof(T) represents the size of a single data item.

[0027] Specifically, the data preprocessing involves dividing the matrix into three cases based on the parameter uplo: blocks containing valid data, blocks containing half valid data, and blocks containing no valid data; this includes:

[0028] When the symmetric matrix is ​​divided into blocks containing valid data, the corresponding block data is directly read and the data arrangement is compared with the data arrangement required by the input matrix and the matrix operation unit for calculation, and the data is rearranged; if the data block does not meet the alignment requirements for data reading, the data is padded to meet the alignment requirements.

[0029] When a symmetric matrix is ​​divided into blocks containing half of the valid data, first generate mask0 and mask1 matrices. The sizes of mask0 and mask1 matrices are consistent with the minimum continuous storage fractal size required by the data arrangement of the matrix operation unit. According to the parameter uplo, set the elements at the specified valid data triangle positions, including the elements on the main diagonal, to 1, and set the rest to 0 to obtain mask0 matrix; then set the elements on the main diagonal of mask0 matrix to 0 to obtain mask1 matrix.

[0030] After reading the block data corresponding to the position of the block containing half of the valid data and rearranging and filling it according to the data arrangement required by the matrix operation unit, each diagonal fractal containing half of the valid data is multiplied by the mask0 matrix and the mask1 matrix respectively to obtain the result of multiplying with the mask0 matrix and the result of multiplying with the mask1 matrix. The result of multiplying with the mask1 matrix is ​​transposed and summed with the result of multiplying with the mask0 matrix to obtain a diagonal fractal containing complete valid data. The remaining fractals without valid data are completed by reading the fractal data of their symmetrical position about the main diagonal and transposing and writing it.

[0031] When the symmetric matrix block that needs to be preprocessed is a block that does not contain valid data, read the block data at the symmetrical position about the main diagonal and transpose it, and then rearrange the data according to the data arrangement required by the matrix operation unit; if the data block does not meet the alignment requirements, fill the data to make it meet the alignment requirements.

[0032] Specifically, when the matrix calculation result is not a symmetric matrix with only half of the valid data, the matrix calculation result is organized and written back to the corresponding position according to the output data arrangement requirements; when the matrix calculation result is still a symmetric matrix with only half of the valid data, a mask2 matrix is ​​generated. The mask2 matrix has the same size as the block, and the elements in the valid data triangle part of the mask2 matrix are 1, and the rest are 0. After organizing the data according to the output matrix data arrangement, the mask2 matrix is ​​multiplied with the matrix calculation result. The invalid data part in the matrix calculation result that does not need to be written back is set to 0, and the original block is read again, added, and written back to obtain the calculation result containing the data of the invalid data part in the original block.

[0033] The second objective of this invention can be achieved by adopting the following technical solution:

[0034] A computer device includes a processor and a memory for storing a processor-executable program, wherein when the processor executes the program stored in the memory, it implements the above-described symmetric matrix reading and calculation method applied to a parallel system.

[0035] The effects achieved by this invention are as follows:

[0036] This invention provides a method and apparatus for reading and calculating symmetric matrices in parallel systems. It can efficiently read and calculate real symmetric matrices with half of the input data being valid in different parallel computing systems. In particular, when the parallel computing system has a multi-level cache structure, the completion speed of the computing task can be significantly improved by further parallel data reading and calculation. Attached Figure Description

[0037] Figure 1 This is a flowchart of a symmetric matrix reading and calculation method applied to a parallel system, as described in an embodiment of the present invention.

[0038] Figure 2 This is an illustration of symmetric matrix block reading in an embodiment of the present invention;

[0039] Figure 3 This is an illustration of symmetric matrix block data recovery containing half of the valid data in an embodiment of the present invention;

[0040] Figure 4 The diagram illustrates the block write-back of a symmetric matrix containing half of the valid data in the embodiments of the present invention. Detailed Implementation

[0041] The following is a specific calculation process using this method, which will be further explained in detail with reference to the accompanying drawings. The specific embodiments described herein are merely illustrative of the invention and are not intended to limit the scope of the invention.

[0042] Example 1

[0043] like Figure 1 The flowchart shown illustrates a symmetric matrix reading and calculation method applied to a parallel system. The specific steps of this symmetric matrix reading and calculation method applied to a parallel system include:

[0044] Step 1: Divide the symmetric matrix into multiple matrix blocks. Each computing core of the parallel computing system reads one matrix block at a time to complete the computing task.

[0045] This method is applicable to symmetric matrices of various real number types (integer and floating-point numbers of various precisions). During computation, the default input symmetric matrix is ​​an uncompressed symmetric matrix containing only half of the valid data. The parameter `uplo` specifies whether the valid data portion is in the upper or lower triangular region. The portion lacking valid data is processed or padded during preprocessing. The value of the `uplo` parameter can be defined as two numerical values ​​or characters, respectively indicating whether the upper or lower triangular region is valid in this computation. In this embodiment, two enumeration constants, `UPPER` and `LOWER`, are predefined using an enumeration type. When `uplo = UPPER`, it indicates that the valid data of the input matrix is ​​in the upper triangular region; when `uplo = LOWER`, it indicates that the valid data of the input matrix is ​​in the lower triangular region. This method can compute half-precision column-major symmetric matrix and vector multiplication on a CPU+NPU heterogeneous parallel computing system.

[0046] Specifically, dividing a symmetric matrix into multiple matrix blocks requires considering the number of computing cores, cache sizes at each level, and the shape of the matrix blocks in the parallel computing system. The goal is to ensure that each computing core calculates as many matrix blocks as possible, and that the block size fills as much memory as possible. This maximizes the utilization of computing resources and efficiently completes the relevant calculations. Furthermore, due to the square nature of symmetric matrices, the shape of the matrix blocks must also be square, meaning that each matrix block must have the same number of rows and columns.

[0047] In this embodiment, taking into account the number of computing cores and the size of each level of cache in the parallel computing system, the symmetric matrix is ​​divided into matrix blocks that fill the cache as much as possible. For the specific process of this computing facility, the size of the square matrix block is set to N×N, and the size of N should satisfy the following conditions:

[0048] When using a single buffer, the size of N satisfies the following conditions 1 and 2:

[0049] Condition 1: (N 2 (+O+I)×sizeof(T)≤minimum cache size;

[0050] Condition 2: (N 2+O+I+C)×sizeof(T)≤the size of the cache storing the positions of the mask matrix;

[0051] Where, N 2 O represents the data size of the matrix block, I represents the data size of other corresponding matrix blocks or vector segments involved in the calculation, C represents the data size of the mask matrix, T represents the data type, and sizeof(T) represents the size of a single data item.

[0052] Condition 1 states that the size of the input matrix blocks and the input and result vector segments cannot exceed the minimum cache size in each level of the computing system; otherwise, the computation will be affected due to incomplete data storage. In addition to satisfying Condition 1, the cache storing the mask matrix should also ensure that, after allocating space for storing the input matrix blocks and the input and result vector segments, the remaining storage space is sufficient to store the mask matrix for convenient subsequent computation, allowing the computation to be completed more efficiently using the mask matrix.

[0053] When using double buffering, the size of N satisfies the following conditions 3 and 4:

[0054] Condition 3: 2×[(N 2 [+O+I)×sizeof(T)]≤minimum cache size;

[0055] Condition 4:

[0056] 2×[(N 2 +O+I)×sizeof(T)]+(C×sizeof(T))

[0057] ≤ The size of the cache storing the mask matrix positions;

[0058] Where, N 2 O represents the data size of the matrix block, I represents the data size of other corresponding matrix blocks or vector segments involved in the calculation, C represents the data size of the mask matrix, T represents the data type, and sizeof(T) represents the size of a single data item.

[0059] When using double buffering, each level of cache needs to be divided into two parts. Both parts need to allocate storage space to store the input matrix blocks and the input and result vector segments. One part serves as a buffer for sending data, and the other serves as a buffer for receiving data. Therefore, the size of the input matrix blocks and the input and result vector segments cannot exceed half the size of the smallest cache in each level of the computing system. Otherwise, the computation will be affected because the data cannot be stored completely.

[0060] Based on condition 3, after allocating two data spaces for storing the input matrix blocks and the input and result vector segments required for double buffering, the remaining storage space for storing the mask matrix is ​​sufficient to store the mask matrix, enabling the computation to be completed more efficiently using the mask matrix.

[0061] Step 2: Consider that the symmetric matrix involved in the calculation is an uncompressed symmetric matrix containing only half of the valid data. According to the parameter uplo, the matrix is ​​divided into three cases: blocks containing valid data, blocks containing half of the valid data (blocks on the diagonal), and blocks containing no valid data. Data preprocessing is performed, the data is rearranged into a form that meets the input requirements of the matrix operation unit, and the parts that do not meet the byte alignment requirements for data reading are padded with data to obtain the data that the operation unit can directly read and calculate.

[0062] Specifically, when the symmetric matrix block to be preprocessed is a block containing valid data, the block data at the corresponding position is directly read and the data arrangement of the input matrix is ​​compared with the data arrangement required by the matrix operation unit for calculation, and the data is rearranged. If the data block does not meet the alignment requirements, the data is filled to meet the alignment requirements by filling with 0.

[0063] Specifically, when the symmetric matrix block to be preprocessed is a block containing half of the valid data, i.e., a block on the diagonal, two reusable mask matrices need to be generated in advance before processing: mask0 matrix and mask1 matrix. The size of mask0 matrix and mask1 matrix is ​​consistent with the minimum continuous storage fractal size of the data arrangement required by the matrix operation unit. According to the parameter uplo, the elements at the specified valid data triangle positions (including the elements on the main diagonal) are set to 1, and the rest are set to 0 to obtain mask0 matrix; based on mask0 matrix, the elements on the main diagonal are set to 0 to obtain mask1 matrix.

[0064] After generating two reusable mask matrices, the corresponding positions of the blocks containing half of the valid data are directly read and rearranged and filled according to the data arrangement required by the matrix operation unit. Then, each fractal on the diagonal containing invalid data is multiplied by the mask0 matrix and the mask1 matrix respectively to obtain the result of multiplying with the mask0 matrix and the result of multiplying with the mask1 matrix. The result of multiplying with the mask1 matrix is ​​transposed and summed with the result of multiplying with the mask0 matrix to obtain a diagonal fractal containing complete valid data. The remaining fractals without valid data are completed by reading the fractal data of their symmetrical positions about the main diagonal and transposing them.

[0065] Specifically, multiplying with the mask1 matrix results in triangular data with a diagonal of 0. Transposing this triangular data yields the correct data for the non-valid data portion of the diagonal fractals. Multiplying with the mask0 matrix results in the result of setting the non-valid data portion to 0. Summing the two results in a diagonal fractal containing complete valid data. The remaining fractals without valid data are completed by reading the fractal data at the symmetrical position about the main diagonal and transposing it. This method avoids scalar operations that assign values ​​one by one and completes the data of the diagonal fractals in a vectorized way.

[0066] Specifically, when the symmetric matrix block that needs to be preprocessed is a block that does not contain valid data, the block data at the symmetrical position about the main diagonal is read and transposed, and then the data is rearranged according to the data arrangement required by the matrix operation unit. If the data block does not meet the alignment requirements, the data is filled to meet the alignment requirements.

[0067] In this implementation, the matrix operation units of the heterogeneous parallel computing system are required to be arranged in 16×16 fractal units. Therefore, before computation, two 16×16 mask matrices are generated according to the effective data positions specified by the parameter uplo: mask0 matrix and mask1 matrix. The mask0 matrix sets the elements at the effective data triangle positions specified by the parameter uplo to 1, and the rest to 0. The elements at the effective data triangle positions include the elements on the main diagonal. The mask1 matrix is ​​based on the mask0 matrix, but sets the elements on the main diagonal to 0.

[0068] like Figure 2 The diagram illustrates the block reading of a symmetric matrix. It explains how the effective symmetric matrix of the lower triangular portion, which is 512×512 in size, is divided into blocks of 256×256.

[0069] When the symmetric matrix is ​​divided into blocks containing valid data, the block data at the corresponding position is directly read from global memory into the first-level cache, and the matrix blocks are arranged in a column-major, continuous storage manner into a data arrangement in 16×16 fractal units and written into the zero-level cache.

[0070] When a symmetric matrix requiring preprocessing is divided into blocks containing half of the valid data, the corresponding block data is directly read from global memory into the L1 cache and rearranged in the L1 cache according to a 16×16 fractal unit. The rearranged data is then restored. The method for restoring the rearranged data includes: reading each 16×16 fractal on the diagonal, multiplying it by two mask matrices, transposing the result of multiplying by mask1, and summing the two results to vectorize and complete the data of the diagonal fractals. The remaining fractals without valid data are completed by reading their fractal data symmetrical about the main diagonal and transposing it. The completed diagonal block is then written to the L0 cache for computation by the matrix operation unit. Figure 3 The diagram illustrates data recovery from a symmetric matrix block (i.e., diagonal block) containing half of the valid data.

[0071] When the symmetric matrix block that needs to be preprocessed is a block that does not contain valid data, the block data symmetrical about the main diagonal is read from global memory into the first-level cache and transposed. Then, the data is rearranged and written to the zero-level cache in a data arrangement method with a fractal size of 16×16.

[0072] Step 3: Call the matrix operation unit to perform matrix calculations on the preprocessed data to obtain the matrix calculation results.

[0073] Specifically, the preprocessed data is called to the matrix operation unit for matrix calculation, including: treating the multiplication of square matrix blocks with vectors as a multiplication operation of square matrix blocks with a matrix block of dimension 1, converting vector operations into matrix operations, and calling the higher-performance matrix calculation unit to complete the operation.

[0074] Specifically, when the matrix operation unit performs matrix calculations, if the parallel computing system has a multi-level cache structure and the computing core still has another block to be calculated, synchronously reading the next block of data into the level one cache can further improve the parallelism of the calculation. In this embodiment, the matrix operation unit of the heterogeneous computing system uses a level zero cache, so if the current computing core still has a block to be completed, it can synchronously read the next block of data into the level one cache without memory conflict, and the two can be performed synchronously.

[0075] Step 4: Organize the matrix calculation results according to the output data arrangement requirements and write them back to the corresponding positions. Each computing core of the parallel computing system reads each block it is responsible for in a loop until all blocks are calculated.

[0076] Specifically, the matrix calculation result is divided into two cases based on whether it is still a symmetric matrix with only half of the valid data. When the matrix calculation result is not a symmetric matrix with only half of the valid data, the matrix calculation result is organized according to the output data arrangement requirements and written back to the corresponding position to complete a block calculation task. When the matrix calculation result is still a symmetric matrix with only half of the valid data, a mask2 matrix needs to be generated in advance. The mask2 matrix has the same size as the block. According to the parameter uplo, the elements of the specified valid data triangle position, including the elements on the main diagonal, are set to 1 (including the elements on the main diagonal), and the rest are set to 0, to obtain the mask2 matrix. After organizing the data according to the output matrix data arrangement, the mask2 matrix is ​​multiplied by the result matrix in blocks. The invalid data part in the calculation result that does not need to be written back is set to 0, and the original block is read again, added, and written back to obtain the calculation result containing the data of the invalid data part in the original block, avoiding direct writing back and data modification of the invalid data triangle part. Figure 4 As shown, the result is still a block write-back illustration of a symmetric matrix containing half of the valid data.

[0077] Specifically, each computing core of the parallel computing system reads each block it is responsible for until all blocks are computed. This includes: each computing core of the parallel computing system is responsible for a part of the computing task. If the computing task is divided according to the result matrix, each time the corresponding vector segment or matrix block to be computed is read, the computing result is accumulated in the level zero cache until the computing of the same column or the same row of matrix block or vector segment is completed. After the computing task of a result block is completed, it is written back to the level one cache and then written to the corresponding position of the result matrix block in the global memory according to the result output requirements. This process is repeated until the computing tasks of each computing core are completed.

[0078] Generally speaking, vector results are stored contiguously and can be written back to the corresponding location without additional processing. However, in certain special cases where intermittent write-back is required, the vector data needs to be reorganized to meet the intermittent write-back conditions before it can be written back to global memory.

[0079] In summary, this invention provides a symmetric matrix reading and calculation method for parallel systems. It can avoid scalar operations through vectorized data completion operations and ensure load balance by cyclically distributing parallel computing tasks in different parallel computing systems. It can efficiently read and calculate real symmetric matrices with half of the input being valid data. Especially when the parallel computing system has a multi-level cache structure, it can significantly improve the completion speed of the computing task by further parallel data reading and calculation.

[0080] Example 2:

[0081] This embodiment provides a computer device, which may be a server, computer, etc., including a processor, memory, input device, display, and network interface connected via a system bus. The processor provides computing and control capabilities. The memory includes a non-volatile storage medium and internal memory. The non-volatile storage medium stores an operating system, computer programs, and a database. The internal memory provides an environment for the operation of the operating system and computer programs in the non-volatile storage medium. When the processor executes the computer programs stored in the memory, it implements the symmetric matrix reading and calculation method applied to a parallel system according to Embodiment 1 above, as follows:

[0082] The symmetric matrix is ​​divided into multiple matrix blocks, and each computing core of the parallel computing system reads one matrix block at a time to complete the computing task.

[0083] Based on the parameter uplo, the matrix is ​​divided into three cases: blocks containing valid data, blocks containing half valid data, and blocks containing no valid data. Data preprocessing is performed, the data is rearranged into a form that meets the input requirements of the matrix operation unit, and data is padded for parts that do not meet the byte alignment requirements for data reading, so that the operation unit can directly read and calculate the data.

[0084] The preprocessed data is used to perform matrix calculations in the matrix operation unit to obtain the matrix calculation results.

[0085] The matrix calculation results are organized and written back to the corresponding positions according to the output data arrangement requirements. Each computing core of the parallel computing system processes each computing block it is responsible for in a loop until all blocks are calculated.

[0086] The symmetric matrix is ​​a real number type symmetric matrix. The symmetric matrix is ​​an uncompressed symmetric matrix containing half of the valid data. The parameter uplo specifies that the part containing valid data is the upper triangular part or the lower triangular part of the symmetric matrix. The part without valid data is processed or padded during preprocessing.

[0087] Based on the number of computing cores, the size of each level of cache, and the shape of matrix blocks in the parallel computing system, the number of matrix blocks allocated to each computing core should be as consistent as possible, and the size of the matrix blocks should fill the memory as much as possible.

[0088] The matrix blocks are square in shape, and the number of rows and columns in each block is the same.

[0089] The matrix block size is N×N. When using a single buffer, the size of the matrix block is N×N, and the size of N satisfies the following conditions 1 and 2:

[0090] Condition 1: (N 2(+O+I)×sizeof(T)≤minimum cache size;

[0091] Condition 2: (N 2 +O+I+C)×sizeof(T)≤the size of the cache storing the positions of the mask matrix;

[0092] When using double buffering, the size of N satisfies the following conditions 3 and 4:

[0093] Condition 3: 2×[(N 2 [+O+I)×sizeof(T)]≤minimum cache size;

[0094] Condition 4:

[0095] 2×[(N 2 +O+I)×sizeof(T)]+(C×sizeof(T))

[0096] ≤ The size of the cache storing the mask matrix positions;

[0097] Where, N 2 O represents the data size of the matrix block, I represents the data size of other corresponding matrix blocks or vector segments involved in the calculation, C represents the data size of the mask matrix, T represents the data type, and sizeof(T) represents the size of a single data item.

[0098] The data preprocessing involves dividing the matrix into three cases based on the parameter uplo: blocks containing valid data, blocks containing half valid data, and blocks containing no valid data; including:

[0099] When the symmetric matrix is ​​partitioned into blocks containing valid data, the corresponding block data is directly read and the data arrangement is compared with the data arrangement required by the input matrix and the matrix operation unit for calculation, and the data is rearranged; if the data block does not meet the alignment requirements, the data is padded to meet the alignment requirements;

[0100] When a symmetric matrix is ​​divided into blocks containing half of the valid data, first generate mask0 and mask1 matrices. The sizes of mask0 and mask1 matrices are consistent with the minimum continuous storage fractal size required by the data arrangement of the matrix operation unit. According to the parameter uplo, set the elements at the specified valid data triangle positions, including the elements on the main diagonal, to 1, and set the rest to 0 to obtain mask0 matrix; then set the elements on the main diagonal of mask0 matrix to 0 to obtain mask1 matrix.

[0101] After reading the block data corresponding to the position of the block containing half of the valid data and rearranging and filling it according to the data arrangement required by the matrix operation unit, each diagonal fractal containing half of the valid data is multiplied by the mask0 matrix and the mask1 matrix respectively to obtain the result of multiplying with the mask0 matrix and the result of multiplying with the mask1 matrix. The result of multiplying with the mask1 matrix is ​​transposed and summed with the result of multiplying with the mask0 matrix to obtain a diagonal fractal containing complete valid data. The remaining fractals without valid data are completed by reading the fractal data of their symmetrical position about the main diagonal and transposing and writing it.

[0102] When the symmetric matrix block that needs to be preprocessed is a block that does not contain valid data, read the block data at the symmetrical position about the main diagonal and transpose it, and then rearrange the data according to the data arrangement required by the matrix operation unit; if the data block does not meet the alignment requirements, fill the data to make it meet the alignment requirements.

[0103] The above embodiments are preferred embodiments of the present invention, but the embodiments of the present invention are not limited to the above embodiments. Any changes, modifications, substitutions, combinations, or simplifications made without departing from the spirit and principle of the present invention shall be considered equivalent substitutions and shall be included within the protection scope of the present invention.

Claims

1. A symmetric matrix reading and calculation method applied to parallel systems, characterized in that, Includes the following steps: The symmetric matrix is ​​divided into multiple matrix blocks, and each computing core of the parallel computing system reads one matrix block at a time to complete the computing task. The symmetric matrix is ​​a real number type symmetric matrix. It is an uncompressed symmetric matrix containing half of the valid data. The parameter uplo specifies whether the part containing valid data is the upper triangular part or the lower triangular part of the symmetric matrix. The part without valid data is processed or padded during preprocessing. The matrix blocks are square in shape, and the number of rows and columns of the matrix blocks are the same. Based on the parameter uplo, the matrix is ​​divided into three cases: blocks containing valid data, blocks containing half valid data, and blocks containing no valid data. Data preprocessing is performed, the data is rearranged into a form that meets the input requirements of the matrix operation unit, and data is padded for parts that do not meet the byte alignment requirements for data reading, so that the operation unit can directly read and calculate the data. The data preprocessing involves dividing the matrix into three cases based on the parameter uplo: blocks containing valid data, blocks containing half valid data, and blocks containing no valid data; including: When the symmetric matrix is ​​partitioned into blocks containing valid data, the corresponding block data is directly read and the data arrangement is compared with the data arrangement required by the input matrix and the matrix operation unit for calculation, and the data is rearranged; if the data block does not meet the alignment requirements, the data is padded to meet the alignment requirements; When a symmetric matrix is ​​divided into blocks containing half of the valid data, first generate mask0 and mask1 matrices. The sizes of mask0 and mask1 matrices are consistent with the minimum continuous storage fractal size required by the data arrangement of the matrix operation unit. According to the parameter uplo, set the elements at the specified valid data triangle positions, including the elements on the main diagonal, to 1, and set the rest to 0 to obtain mask0 matrix; then set the elements on the main diagonal of mask0 matrix to 0 to obtain mask1 matrix. After reading the block data corresponding to the position of the block containing half of the valid data and rearranging and filling it according to the data arrangement required by the matrix operation unit, each diagonal fractal containing half of the valid data is multiplied by the mask0 matrix and the mask1 matrix respectively to obtain the result of multiplying with the mask0 matrix and the result of multiplying with the mask1 matrix. The result of multiplying with the mask1 matrix is ​​transposed and summed with the result of multiplying with the mask0 matrix to obtain a diagonal fractal containing complete valid data. The remaining fractals without valid data are completed by reading the fractal data of their symmetrical position about the main diagonal and transposing and writing it. When the symmetric matrix block that needs to be preprocessed is a block that does not contain valid data, read the block data at the symmetrical position about the main diagonal and transpose it, and then rearrange the data according to the data arrangement required by the matrix operation unit; if the data block does not meet the alignment requirements, fill the data to make it meet the alignment requirements. The preprocessed data is used to perform matrix calculations in the matrix operation unit to obtain the matrix calculation results. The matrix calculation results are organized and written back to the corresponding positions according to the output data arrangement requirements. Each computing core of the parallel computing system reads each block it is responsible for in a loop until all blocks are calculated.

2. The symmetric matrix reading and calculation method applied to a parallel system according to claim 1, characterized in that: The size of the matrix block is N×N. When using a single buffer, the size of N satisfies the following conditions 1 and 2: Condition 1: ; Condition 2: ; When using double buffering, the size of N satisfies the following conditions 3 and 4: Condition 3: ; Condition 4: ; in, O represents the size of the matrix block data, I represents the size of other corresponding matrix blocks or vector segments involved in the calculation, C represents the size of the data space required to store the calculation results, and T represents the data type of the mask matrix. Indicates the size of a single data item.

3. The symmetric matrix reading and calculation method applied to a parallel system according to claim 1, characterized in that: The step of calling the matrix operation unit to perform matrix calculations on the preprocessed data includes: when the data structure involved in the operation contains vectors, the calculation of the square matrix block and the vector is regarded as the operation of the square matrix block and the matrix block with a dimension of 1, the vector operation is converted into a matrix operation, and the matrix calculation unit is called to complete the operation.

4. The symmetric matrix reading and calculation method applied to a parallel system according to claim 3, characterized in that: The step of calling the matrix operation unit to perform matrix calculation on the preprocessed data also includes: when the parallel computing system has a multi-level cache structure and the computing core has another block that needs to be calculated, synchronously reading the next block of data into the first-level cache for processing.

5. The symmetric matrix reading and calculation method applied to a parallel system according to claim 1, characterized in that: When the matrix calculation result is not a symmetric matrix with only half of the valid data, the matrix calculation result is organized and written back to the corresponding position according to the output data arrangement requirements. When the matrix calculation result is still a symmetric matrix with only half of the valid data, a mask2 matrix is ​​generated. The mask2 matrix has the same size as the block. According to the parameter uplo, the elements in the specified valid data triangle position, including the elements on the main diagonal, are set to 1, and the rest are set to 0, thus obtaining the mask2 matrix. After organizing the data according to the output matrix data arrangement, the mask2 matrix is ​​multiplied with the matrix calculation result. The invalid data part in the matrix calculation result that does not need to be written back is set to 0, and the original block is read again, added, and written back to obtain the calculation result containing the data of the invalid data part in the original block.

6. The symmetric matrix reading and calculation method applied to a parallel system according to claim 5, characterized in that: Each computing core of the parallel computing system reads each block it is responsible for until all blocks are computed. This includes: each computing core of the parallel computing system is responsible for a part of the computing task. If the computing task is divided according to the result matrix, each time the corresponding vector segment or matrix block to be computed is read, the computing result is accumulated in the level zero cache until the computing of the same column or row matrix block or the corresponding vector segment is completed. The computing task of a result block is completed, and it is written back to the level one cache and then written to the corresponding position of the result matrix block in the global memory according to the result output requirements. This process is repeated until the computing tasks of each computing core are completed.

7. A computer device comprising a processor and a memory for storing a processor-executable program, characterized in that, When the processor executes the program stored in the memory, it implements the symmetric matrix reading and calculation method for parallel systems as described in any one of claims 1-6.