Memory access and parallel efficiency optimization method based on non-synchronous SpTRSV algorithm

By dividing sparse matrix rows and optimizing the thread-level parallel mode, the problem of thread divergence and resource allocation when the SpTRSV algorithm is executed in parallel on the GPU is solved, improving the utilization and computing performance of the GPU, simplifying the preprocessing process, and achieving universal applicability Parallel efficiency optimization.

CN118519787BActive Publication Date: 2024-10-29CALCULATION AERODYNAMICS INST CHINA AERODYNAMICS RES & DEV CENT
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202410985246.2
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2024-07-23
Publication Date
2024-10-29
Estimated Expiration
2044-07-23

AI Technical Summary

Technical Problem

When the SpTRSV algorithm is executed in parallel on the GPU, there are problems with thread divergence and unreasonable resource allocation, resulting in low GPU utilization. The existing optimization methods are complex and not universal.

Method used

By dividing the rows of the sparse matrix into long rows and short rows, and assigning long rows to warp-level processing in thread-level parallel mode, the value of the target vector is preset to the maximum value, and registers are used for data prefetching and dependency situations Judgment, optimize memory access patterns and dependency control.

Benefits of technology

It achieves performance optimization in the thread-level parallel writing phase, ensures reasonable resource allocation for each row of the sparse matrix, improves the parallel computing capability of the GPU, simplifies the preprocessing process, and has universal applicability.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118519787B_ABST
    Figure CN118519787B_ABST
Patent Text Reader

Abstract

The present invention discloses a method for optimizing memory access and parallel efficiency based on a non-synchronous SpTRSV algorithm, which belongs to the field of high-performance parallel computing, and includes: step one, dividing rows into long rows and short rows according to non-zero elements of a sparse matrix; step two, setting the values ​​of target vectors x to maximum values; step three, pre-fetching data required for the write phase into a register; step four, in the read phase, determining the dependency and performing an accumulation operation; step five, in the write phase, reading data from the register and calculating the value of the corresponding row x. The present invention solves the problem of thread divergence in the thread-level parallel write phase in the current non-synchronous SpTRSV algorithm, as well as the coarse-grained selection strategy of the thread level and the thread bundle level, which leads to the problem of low GPU utilization.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of high-performance parallel computing, and more specifically, to a method for optimizing memory access and parallel efficiency based on a synchronization-free SpTRSV algorithm. Background Art

[0002] GPU has a large number of computing cores and is suitable for parallel processing of various large-scale applications, such as video image processing, machine learning, and large-scale sparse matrix operations. Modern GPUs use single instruction multiple threads (SIMT) to enable a large number of threads to execute the same instructions concurrently. CUDA, as a mainstream parallel computing architecture, allows developers to directly access GPU hardware resources and improve computing and storage access efficiency through a combination of software and hardware to solve more complex problems.

[0003] Large-scale sparse matrix operations have always been the focus of research in the field of high-performance computing. The solution of sparse lower triangular equations (SpTRSV) is expressed as Lx=b, where L is the lower triangular sparse matrix, b is a known matrix vector, and x is the target vector to be solved. SpTRSV operations are of great significance in both science and engineering, and occupy a large amount of application time, including least squares, direct methods, and sparse iterative solvers.

[0004] However, compared with common sparse matrix operations, SpTRSV has a large number of dependency order relationships in the solution process, which is a huge challenge for designing parallel algorithms. After the efforts of researchers, a large number of experiments have shown that it is feasible to execute SpTRSV in parallel on GPUs. At present, the research projects that use GPU to accelerate the solution of triangular equations (SpTRSV) mainly include level-set methods and color-set methods that require preprocessing, as well as synchronization-free algorithms that do not require preprocessing.

[0005] Among these methods, the synchronization-free SpTRSV algorithm is the mainstream parallel method on GPU due to its short preprocessing time and outstanding performance. Researchers have also proposed some optimization measures for synchronization-free algorithms to improve their performance on GPU. Currently, synchronization-free algorithms are mainly divided into two modes: thread-level parallelism and warp-level parallelism. However, in some matrix examples, the most advanced synchronization-free algorithms do not perform well. The main problems include: in thread-level parallelism mode, each thread in the warp processes different rows of the sparse matrix, which will lead to a large number of thread divergences; when thread-level and warp-level modes are selected based on the average non-zero elements of the sub-matrix, this may lead to unreasonable allocation of thread resources and tasks, resulting in low GPU utilization; some optimization methods require complex preprocessing, are only applicable to a few matrices, and are not universal. Summary of the invention

[0006] The purpose of the present invention is to overcome the challenge of low parallel efficiency of SpTRSV on GPU, and to provide a memory access and parallel efficiency optimization method based on the asynchronous SpTRSV algorithm, aiming to solve the thread divergence problem in the thread-level parallel write phase in the current asynchronous SpTRSV algorithm, as well as the coarse-grained selection strategy at the thread level and the thread warp level, which leads to the problem of low GPU utilization.

[0007] The object of the present invention is achieved through the following solutions:

[0008] A method for optimizing memory access and parallel efficiency based on a non-synchronized SpTRSV algorithm comprises the following steps:

[0009] Step 1: divide the rows into long rows and short rows according to the non-zero elements of the sparse matrix;

[0010] Step 2, setting the value of the target vector x to the maximum value;

[0011] Step 3, pre-fetch the data required for the write phase into the register;

[0012] Step 4: During the reading phase, determine the dependency and perform accumulation operations;

[0013] Step 5: In the write phase, data is read from the register and the value of the corresponding row x is calculated.

[0014] Furthermore, in step one, the dividing of rows into long rows and short rows according to the non-zero elements of the sparse matrix includes the following sub-steps: by analyzing the structural characteristics of the sparse matrix itself, the rows are divided into long rows and short rows based on the number of non-zero elements in each row as a criterion, wherein continuous short rows form row groups, and finally the long rows are assigned to warp-level processing, and the row groups are assigned to thread-level processing; wherein warp-level represents the thread bundle parallel mode, usually 32 threads form a thread bundle, and thread-level represents the single-thread parallel mode.

[0015] Furthermore, in step 2, setting the values ​​of the target vectors x to the maximum values ​​specifically includes the sub-steps of: before the SpTRSV calculation starts, setting the initial values ​​of the target vectors x to the maximum values ​​through the CUDA function cudaMemset.

[0016] Furthermore, in step three, the data required for the write phase is pre-fetched into the register, specifically including the sub-steps of: pre-fetching "the last value of the row" and "the value corresponding to the b vector" from the global memory into the register; wherein, "the last value of the row" represents the non-zero element L(i,i) on the diagonal of the i-th row in the sparse lower triangular matrix L, and "the value corresponding to the b vector" represents the value b[i] of the i-th row in the known matrix vector b.

[0017] Furthermore, in step 4, the reading phase determines the dependency and performs an accumulation operation, which specifically includes the sub-steps of looping and iterating all non-zero elements before the diagonal to obtain the multiplication and addition sum of all elements.

[0018] Furthermore, the loop iterates all non-zero elements before the diagonal to obtain the sum of multiplication and addition of all elements, specifically including the sub-steps:

[0019] S1, convert the x value into int type through CUDA built-in function __double2hiint(), and determine whether it is still the maximum value;

[0020] S2: If x is not the maximum value, the dependency is considered to be resolved, and the non-zero elements of the sparse matrix are multiplied by the corresponding x values, and the accumulation operation is performed in a loop.

[0021] Furthermore, in step five, in the write phase, data is read from the register to calculate the value of x of the corresponding row, which specifically includes the following sub-steps: in the write phase, the accumulated sum obtained in the read phase and the value pre-fetched into the register are calculated to obtain the x value corresponding to the corresponding row, and the corresponding row is notified that the dependency is resolved.

[0022] The beneficial effects of the present invention include:

[0023] (1) The present invention optimizes the memory access pattern of the synchronization-free SpTRSV algorithm on tread-level parallelism and designs a lightweight dependency control mechanism to minimize the performance impact caused by thread divergence within the same thread bundle.

[0024] (2) The present invention integrates a fine-grained strategy for selecting thread-level and warp-level, ensuring that each row of the sparse matrix is ​​allocated to the appropriate computing resources of the GPU, thereby fully utilizing the parallel computing capabilities of the GPU.

[0025] (3) The present invention does not require complicated preprocessing and adopts the universal CSR matrix storage format, which is universal. BRIEF DESCRIPTION OF THE DRAWINGS

[0026] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative labor.

[0027] Figure 1 It is an example of Lx=b of the present invention, including a sparse lower triangular matrix L, a CSR storage format, and hierarchical set information; wherein, (a) is the lower triangular matrix L; (b) is the CSR matrix storage format; (c) is the level-set hierarchical set;

[0028] Figure 2 This is an example of thread-level parallel execution optimized by the present invention;

[0029] Figure 3 It is a flow chart of the fine-grained thread-level and warp-level fusion strategy of the present invention;

[0030] Figure 4 The effect comparison of the optimization method provided by the present invention with other advanced methods is shown in the figure; among them, (a) is Nvidia's official math library cuSPARSE, (b) is the global synchronization-free method Sync-Free, (c) is the multi-granularity parallel method CapelliniSpTRSV, (d) is the multi-granularity parallel method YuenyeungSpTRSV, and (e) is the method of the present invention. DETAILED DESCRIPTION

[0031] All features disclosed in all embodiments in this specification, or steps in all methods or processes implicitly disclosed, except for mutually exclusive features and / or steps, can be combined and / or expanded or replaced in any manner.

[0032] The embodiment of the present invention provides a method for optimizing memory access and parallel efficiency based on a non-synchronous SpTRSV algorithm, comprising the following steps:

[0033] Step 1: divide the rows into long rows and short rows according to the non-zero elements of the sparse matrix;

[0034] Step 2, setting the value of the target vector x to the maximum value;

[0035] Step 3, pre-fetch the data required for the write phase into the register;

[0036] Step 4: During the reading phase, determine the dependency and perform accumulation operations;

[0037] Step 5: In the write phase, data is read from the register and the value of the corresponding row x is calculated.

[0038] In a specific implementation, in step one, the rows are divided into long rows and short rows according to the non-zero elements of the sparse matrix, including sub-steps: by analyzing the structural characteristics of the sparse matrix itself, the number of non-zero elements in each row is used as a standard to divide the rows into long rows and short rows, wherein continuous short rows form row groups, and finally the long rows are assigned to warp-level processing, and the row groups are assigned to thread-level processing; wherein warp-level represents the thread warp parallel mode, usually 32 threads form a thread warp, and thread-level represents the single-thread parallel mode.

[0039] In a specific implementation, in step 2, the value of the target vector x is set to the maximum value, which specifically includes the sub-steps of: before the SpTRSV calculation starts, the initial value of the target vector x is set to the maximum value through the CUDA function cudaMemset.

[0040] In a specific implementation, in step three, the data required for the write phase is pre-fetched into a register, specifically including the sub-steps of: pre-fetching "the last value of the row" and "the value corresponding to the b vector" from the global memory into the register; wherein, "the last value of the row" represents the non-zero element L(i,i) on the diagonal of the i-th row in the sparse lower triangular matrix L, and "the value corresponding to the b vector represents the value b[i] of the i-th row in the known matrix vector b.

[0041] In a specific implementation, in step 4, the reading phase determines the dependency and performs an accumulation operation, which specifically includes the sub-steps of looping and iterating all non-zero elements before the diagonal to obtain the multiplication and addition sum of all elements.

[0042] In a specific implementation, the loop iterates all non-zero elements before the diagonal to obtain the multiplication and addition of all elements, specifically including the sub-steps:

[0043] S1, convert the x value into int type through CUDA built-in function __double2hiint(), and determine whether it is still the maximum value;

[0044] S2: If x is not the maximum value, the dependency is considered to be resolved, and the non-zero elements of the sparse matrix are multiplied by the corresponding x values, and the accumulation operation is performed in a loop.

[0045] In the specific implementation, in step five, in the write phase, data is read from the register to calculate the value of x of the corresponding row, which specifically includes the following sub-steps: in the write phase, the accumulated sum obtained in the read phase and the value pre-fetched into the register are calculated to obtain the x value corresponding to the corresponding row, and the corresponding row is notified that the dependency is resolved.

[0046] like Figure 1 As shown, the sparse lower triangular matrix L in the present invention is stored in a compressed row storage format (CSR), Row_Ptr represents a row offset array, which contains an index indicating the starting position of each row; Col_Ind represents a column index array, which contains the column index of each non-zero element in the matrix; Val represents a numerical array, which contains an array of non-zero elements in the matrix, and the level-set hierarchical set represents the dependency relationship of the instance matrix. Among them, (a) is the lower triangular matrix L; (b) is the CSR matrix storage format; (c) is the level-set hierarchical set. As shown Figure 2 As shown, the thread-level (thread parallel mode) of the present invention mainly includes a preparation phase, a read phase and a write phase. In the preparation phase, the required data is fetched from the global memory to the register; in the read phase, it is read whether the dependency information is resolved; in the write phase, the corresponding value of x is calculated and the dependency information is changed. Figure 3 As shown in the figure, the rows are divided into short rows and long rows according to the number of non-zero elements in each row of the sparse matrix, and the continuous short rows are grouped into row groups. Finally, the row groups are assigned to thread-level processing, and the long rows are assigned to warp-level processing. Figure 4 As shown, the performance of the method of the invention and four mainstream parallel computing SpTRSV methods on GPU V100 is shown, among which (a) is Nvidia's official math library cuSPARSE, (b) is the global synchronization-free method Sync-Free, (c) is the multi-granularity parallel method CapelliniSpTRSV, (d) is the multi-granularity parallel method YuenyeungSpTRSV, and (e) is the method of the invention. Figure 4 The horizontal axis is parallelism, and the vertical axis is performance, where parallelism is expressed as , performance is measured in floating point operations per second (GFLOPS / s).

[0047] The units involved in the embodiments of the present invention may be implemented by software or hardware, and the units described may also be arranged in a processor. The names of these units do not, in some cases, limit the units themselves.

[0048] According to one aspect of an embodiment of the present invention, a computer program product or a computer program is provided, the computer program product or the computer program includes a computer instruction, and the computer instruction is stored in a computer-readable storage medium. A processor of a computer device reads the computer instruction from the computer-readable storage medium, and the processor executes the computer instruction, so that the computer device executes the method provided in the above various optional implementations.

[0049] As another aspect, an embodiment of the present invention further provides a computer-readable medium, which may be included in the electronic device described in the above embodiment; or may exist independently without being assembled into the electronic device. The above computer-readable medium carries one or more programs, and when the above one or more programs are executed by an electronic device, the electronic device implements the method described in the above embodiment.

Claims

1. A memory access and parallel efficiency optimization method based on the non-synchronized SpTRSV algorithm, It is characterized in that The following steps are involved: Step 1: divide the rows into long rows and short rows according to the non-zero elements of the sparse matrix; By analyzing the structural characteristics of the sparse matrix itself, the number of non-zero elements in each row is used as the standard to divide the rows into long rows and short rows, where continuous short rows form row groups. Finally, long rows are assigned to warp-level processing, and row groups are assigned to thread-level processing. Warp-level indicates the thread warp parallel mode, 32 threads form a thread warp; thread-level indicates the single-thread parallel mode; Step 2: Set the value of the target vector x to the maximum value; before the SpTRSV calculation starts, use the CUDA function cudaMemset to set the initial value of the target vector x to the maximum value; Step 3: pre-fetch the data required for the write phase into the register; pre-fetch the non-zero elements A(i,i) on the diagonal of each row of the sparse matrix A and the value b[i] corresponding to the known vector b from the global memory into the register; pre-fetch the "last value of the row" and "the value corresponding to the b vector" from the global memory into the register; where "the last value of the row" means the non-zero elements L(i,i) on the diagonal of the i-th row of the sparse lower triangular matrix L, and "the value corresponding to the b vector" means the value b[i] of the i-th row of the known matrix vector b; Step 4: in the reading stage, determine the dependency and perform accumulation operation; loop iterate all non-zero elements before the diagonal to obtain the sum of multiplication and addition of all elements; the loop iterate all non-zero elements before the diagonal to obtain the sum of multiplication and addition of all elements, specifically including the sub-steps: S1, convert the x value into int type through CUDA built-in function __double2hiint(), and determine whether it is still the maximum value; S2, if x is not the maximum value, the dependency is considered to be resolved, and the non-zero elements of the sparse matrix are multiplied by the corresponding x values, and the accumulation operation is performed in a loop; Step 5: In the write phase, data is read from the register and the value of x of the corresponding row is calculated. In the write phase, the accumulated sum obtained in the read phase and the value pre-fetched into the register are calculated to obtain the x value corresponding to the corresponding row, and the corresponding row is notified that the dependency has been resolved.

Citation Information

Patent Citations

  • Method for forward of GPU acceleration of massive isomorphic sparse lower trigonometric equation sets

    CN107368454A

  • Lower trigonometric equation parallel solving method for structural grid sparse matrix

    CN111079078A