Method, device and medium for triangular matrix inversion
By storing the triangular matrix in shared memory and dividing it into multiple blocks, and using thread warps to perform iterative inversion calculations, the problem of insufficient parallelism in triangular matrix inversion is solved, and computing performance is significantly improved.
Patent Information
- Application Number
- CN202310155300.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2023-02-22
- Publication Date
- 2025-09-26
- Estimated Expiration
- 2043-02-22
AI Technical Summary
The existing triangular matrix inversion method lacks parallelism in GPU heterogeneous computing, resulting in the failure to fully utilize the computing power of thread bundles and poor computing performance.
The triangular matrix is stored in shared memory, and its non-zero elements are divided into multiple blocks of different orders. The threads included in the thread warp are used to perform n+1 iterative inversion calculations to fully utilize the computing power of the thread warp.
The computational performance of triangular matrix inversion is significantly improved, especially when the order of the matrix to be inverted is equal to the number of threads in the warp, the computational speed can be increased by 2 to 3 times.
Smart Images

Figure CN116089786B_ABST
Abstract
Description
Technical Field
[0001] Embodiments of the present disclosure generally relate to the field of communication technology, and more particularly to a method, device, and medium for triangular matrix inversion. Background Art
[0002] Heterogeneous computing based on graphics processing units (GPUs) has become the forefront of current scientific research. Whether in traditional scientific computing or emerging artificial intelligence, GPUs have become an important computing pillar with their extremely high hardware performance. In traditional scientific computing, solving linear systems is a very important topic. When solving linear systems, it is usually necessary to decompose the relevant matrix (e.g., the graphics matrix) into a lower triangular matrix (i.e., L matrix) and an upper triangular matrix (i.e., U matrix) through LU decomposition, and then perform forward iteration based on the L matrix or reverse iteration based on the U matrix to achieve the corresponding solution. However, for linear systems with multiple right-hand sides, directly using forward iteration or reverse iteration to solve the system suffers from insufficient parallelism and cannot fully utilize the full computing power of the GPU. Therefore, in this case, it is necessary to invert each triangular matrix, and then directly multiply the inverse matrix of the triangular matrix by multiple right-hand sides. This algorithm has better parallelism and is more suitable for heterogeneous computing scenarios of GPUs. Since the scale of such triangular matrices is generally very large (their order is usually greater than or equal to 3), it is very important to find a suitable method to invert the triangular matrix.
[0003] However, in the current method for inverting a triangular matrix, in each iteration, the thread warp only calculates one column of elements, and each thread in the thread warp calculates one element of the current column. Moreover, since each iteration has elements on the diagonal, a large number of threads in the thread warp are often idle, resulting in the inability to fully utilize the computing power of the thread warp. As a result, the computing performance is still less than ideal. Summary of the Invention
[0004] To address the above issues, the present disclosure provides a method, device, and medium for triangular matrix inversion, which can fully utilize the computing power of thread warps when inverting triangular matrices, thereby helping to improve computing performance.
[0005] According to a first aspect of the present disclosure, a method for inverting a triangular matrix is provided, comprising: converting a matrix of order 2 into nThe inverse triangular matrix to be found is stored in a shared memory, wherein the order is less than or equal to the number of threads included in the thread warp that is allowed to access the shared memory, wherein n is an integer greater than or equal to 1; the triangular part of the inverse triangular matrix to be found having non-zero elements is divided into a plurality of blocks of different orders, wherein the plurality of blocks respectively include one or more first to n+1th blocks, wherein each first block forms a first triangular matrix, and each mth block and two adjacent m-1th triangular matrices form an mth triangular matrix, wherein m is an integer greater than or equal to 2 and less than or equal to n+1, wherein the n+1th triangular matrix indicates the triangular part of the inverse triangular matrix to be found; and using the 2 included in the thread warp n A thread performs n+1 iterative inversion calculations in the order of the first triangular matrix, the second triangular matrix, and the n+1th triangular matrix, so as to finally determine the inverse of the triangular matrix to be inverted.
[0006] According to a second aspect of the present disclosure, a computing device is provided, comprising: at least one processor; and a memory communicatively connected to the at least one processor; the memory storing instructions executable by the at least one processor, the instructions being executed by the at least one processor so as to enable the at least one processor to perform the method of the first aspect of the present disclosure.
[0007] In a third aspect of the present disclosure, a non-transitory computer-readable storage medium storing computer instructions is provided, wherein the computer instructions are used to cause a computer to execute the method of the first aspect of the present disclosure.
[0008] It should be understood that the contents described in this section are not intended to identify the key or important features of the embodiments of the present disclosure, nor are they intended to limit the scope of the present disclosure. Other features of the present disclosure will become readily understood through the following description. BRIEF DESCRIPTION OF THE DRAWINGS
[0009] The above and other features, advantages and aspects of the embodiments of the present disclosure will become more apparent with reference to the following detailed description in conjunction with the accompanying drawings. In the accompanying drawings, the same or similar reference numerals represent the same or similar elements.
[0010] Figure 1 An illustrative diagram of a method for inverting a lower triangular matrix in the prior art is shown.
[0011] Figure 2 A flow chart of a method 200 for triangular matrix inversion according to an embodiment of the present disclosure is shown.
[0012] Figure 3 An illustrative diagram showing the partitioning and thread allocation of an exemplary inverse triangular matrix to be determined is shown.
[0013] Figure 4 A flowchart of a method 400 according to an embodiment of the present disclosure is shown for finally determining the inverse of the inverse triangular matrix to be determined by performing n+1 iterations in the order of the inverse of the first triangular matrix, the inverse of the second triangular matrix, and the inverse of the n+1th triangular matrix.
[0014] Figure 5 A flow chart of a method 500 of determining the inverse of each k-th partition is shown.
[0015] Figure 6 A block diagram of an electronic device 600 according to an embodiment of the present disclosure is shown. DETAILED DESCRIPTION
[0016] The following description of exemplary embodiments of the present disclosure is made in conjunction with the accompanying drawings, including various details of the embodiments of the present disclosure to facilitate understanding. These details should be considered as merely exemplary. Therefore, those skilled in the art will recognize that various changes and modifications may be made to the embodiments described herein without departing from the scope and spirit of the present disclosure. Similarly, for the sake of clarity and conciseness, descriptions of well-known functions and structures are omitted in the following description.
[0017] As used herein, the term "including" and its variations represent open inclusion, i.e., "including but not limited to." Unless otherwise stated, the term "or" means "and / or." The term "based on" means "based at least in part on." The terms "an example embodiment" and "an embodiment" mean "at least one example embodiment." The term "another embodiment" means "at least one additional embodiment." The terms "first," "second," etc. may refer to different or the same objects. Other explicit and implicit definitions may also be included below.
[0018] As described above, in the current method of inverting a triangular matrix, in each iteration, the thread warp only calculates one column of elements, and each thread of the thread warp calculates one element of the current column. Moreover, since each iteration has elements on the diagonal, a large number of threads in the thread warp are often idle, resulting in the inability to fully utilize the computing power of the thread warp. As a result, the computing performance is still less than ideal.
[0019] In order to at least partially solve one or more of the above problems and other potential problems, an exemplary embodiment of the present disclosure proposes a method for inverting a triangular matrix, comprising: nThe inverse triangular matrix to be inverted is stored in a shared memory, wherein the order is less than or equal to the number of threads included in the thread warp that is allowed to access the shared memory, wherein n is an integer greater than or equal to 1; the triangular part of the inverse triangular matrix to be inverted having non-zero elements is divided into a plurality of blocks of different orders, wherein the plurality of blocks include a plurality of first to n+1th blocks, wherein each first block forms a first triangular matrix, and each mth block and two adjacent m-1th triangular matrices form an mth triangular matrix, wherein m is an integer greater than or equal to 2 and less than or equal to n+1, wherein the n+1th triangular matrix indicates the triangular part of the inverse triangular matrix to be inverted; and using the 2 included in the thread warp n The threads perform n+1 iterative inversion calculations in the order of the first triangular matrix, the second triangular matrix, and so on to the (n+1)th triangular matrix, to ultimately determine the inverse of the triangular matrix to be inverted. This method can fully utilize the computing power of the thread warp and improve the computational performance of triangular matrix inversion. In particular, when the order of the triangular matrix to be inverted is equal to the number of threads included in the thread warp, the computational performance is the best because all threads in the thread warp can always run at full capacity.
[0020] In order to facilitate understanding of the present invention, the relationship between a triangular matrix and its inverse matrix is described below. It should be understood that the lower triangular matrix The inverse matrix of can be calculated as The upper triangular matrix The inverse matrix of can be calculated as According to the above relationship, the inversion of large-scale triangular matrices can be achieved. In the prior art, the general method is to use Figure 1 The method shown is to realize the inversion of large-scale triangular matrices based on the above relationship.
[0021] Specifically, Figure 1 FIG. 1 is an illustrative diagram of an example method 100 for inverting an example triangular matrix (lower triangular matrix) in the prior art. Figure 1As shown, in the prior art, the inverse of each element on the diagonal of the inverse triangular matrix to be inverted is first calculated, and then the inverse of the inverse triangular matrix to be inverted is finally determined in an iterative manner in the order of gradually increasing or gradually decreasing row numbers. For example, for the example of performing inversion in the order of gradually decreasing row numbers, in each iteration, based on the inverse of the determined first triangular matrix 101 and the inverse of the determined second triangular matrix 102 and the rectangular matrix 103 located between the first triangular matrix 101 and the second triangular matrix 102, the inverse of the rectangular matrix 103 is determined using the aforementioned relationship, wherein the second triangular matrix 102 is a first-order triangular matrix formed by a diagonal element of the inverse triangular matrix to be inverted. After determining the inverse of the rectangular matrix 103, it is equivalent to determining the inverse of the fourth triangular matrix formed by the first triangular matrix 101, the second triangular matrix 102 and the rectangular matrix 103. In the next iteration, the fourth triangular matrix can be used as the first triangular matrix, and the first-order triangular matrix composed of the diagonal elements on the upper left side of the second triangular matrix can be used as the second triangular matrix to repeat the previous process until the inverse of the inverse triangular matrix to be obtained is finally obtained. According to the previous description, it can be determined that in the above example method, in the first iterative calculation, the first triangular matrix based on it is a first-order triangular matrix formed by the diagonal elements with the largest row number of the inverse triangular matrix to be obtained, the second triangular matrix based on it is a first-order triangular matrix formed by the diagonal elements with the second largest row number of the inverse triangular matrix to be obtained, and the rectangular matrix based on it is a first-order rectangular matrix located between such a first triangular matrix and the second triangular matrix.
[0022] In the above method, at each iteration, the thread with thread number ID in the warp is assigned to solve the target element of the rectangular matrix based on the current iteration and the ID-th row of the column where the second triangular matrix is located (that is, the inverse of the rectangular matrix and the inverse of the second triangular matrix in the ID-th row). If the element calculated by the thread is above the diagonal, it returns directly without any calculation. After completing the matrix-vector multiplication, it is multiplied by the negative reciprocal of the element of the second triangular matrix corresponding to the current iteration. In this implementation method, since the elements above the diagonal always exist, a large number of threads in the warp are idle, resulting in poor computing performance.
[0023] Figure 2 FIG. 2 is a flow chart of a method 200 for inverting a triangular matrix according to an embodiment of the present disclosure. The method 200 may be performed as follows: Figure 6 It should be understood that the method 200 may further include additional blocks not shown and / or may omit the blocks shown, and the scope of the present disclosure is not limited in this respect.
[0024] In step 202, the order is 2 nThe inverse triangular matrix to be determined is stored in the shared memory. In the present disclosure, n can be any integer greater than or equal to 1.
[0025] It should be understood that the order is 2 n The inverse triangular matrix to be found refers to the triangular matrix of size 2 n *2 n , that is, with 2 n Row and 2 n Column. In addition, it should be understood that triangular matrices can be divided into upper triangular matrices and lower triangular matrices. The elements below the diagonal of an upper triangular matrix are all zero, while the elements above the diagonal of a lower triangular matrix are all zero. In the present disclosure, the inverse triangular matrix to be determined can be an upper triangular matrix or a lower triangular matrix.
[0026] Shared memory is on-chip and has a much faster storage speed than local and global memory. In addition, shared memory is allocated per thread block, so all threads in a thread block can access the same shared memory. Therefore, by storing the triangular matrix to be inverted in the shared memory for inversion, the triangular matrix can be inverted using the thread warp that can access the shared memory, thereby helping to improve the speed of inversion.
[0027] In the present disclosure, the order of the inverse triangular matrix to be calculated may be less than or equal to the number of threads included in a warp that is allowed to access shared memory. However, when the order of the inverse triangular matrix to be calculated is equal to the number of threads included in the warp, the fullest utilization of all threads included in the warp can be achieved. For example, a warp typically includes 32 threads. In this case, when the order of the inverse triangular matrix to be calculated is 32 (i.e., n is equal to 5), the fullest utilization of the threads in the warp can be achieved.
[0028] In some embodiments of the present disclosure, the order of 2 can be converted into n The inverse triangular matrix to be found is stored in the shared memory. First, based on the order of the inverse triangular matrix to be found, memory space is requested in the shared memory for the inverse triangular matrix to be found. In the present disclosure, in order to avoid bank conflicts, the number of columns of elements that can be stored in the memory space allocated for the inverse triangular matrix to be found can be greater than the number of columns included in the inverse triangular matrix to be found. For example, when the order of the inverse matrix to be found is 2 5In the case of a matrix with a size of 32*34, a memory space capable of storing 32*34 elements can be requested for the inverse matrix to be inverted. This adds two additional elements per row (i.e., two additional columns) compared to the inverse triangular matrix to be inverted. Of course, more columns can be added depending on the actual situation. After requesting the memory space, the inverse triangular matrix to be inverted can be stored in the memory space in a row-first manner, so that the inversion of the inverse triangular matrix to be inverted can be performed in the memory space. Based on the above approach, it can help achieve bank conflict-free reading and writing of shared memory.
[0029] In step 204, the triangular part of the inverse triangular matrix to be inferred, which has non-zero elements, is divided into a plurality of blocks of different orders. Figure 3 The multiple blocks obtained after partitioning the exemplary inverse triangular matrix to be found are shown in FIG. Figure 3 Different gray levels are used to represent each block.
[0030] In the present disclosure, the blocks obtained by segmentation should not overlap with each other, and these blocks may respectively include one or more first to n+1 blocks. In the present disclosure, each first block indicates an element located on the diagonal of the inverse triangular matrix to be determined, so each first block forms a corresponding first triangular matrix. Moreover, in the present disclosure, each m-th block has two m-1-th triangular matrices adjacent to it. Specifically, when the inverse triangular matrix to be determined is a lower triangular matrix, each m-th block has an m-1-th triangular matrix located on its upper side and an m-1-th triangular matrix located on its right side, and when the inverse triangular matrix to be determined is an upper triangular matrix, each m-th block has an m-1-th triangular matrix located on its left side and an m-1-th triangular matrix located on its lower side. In addition, in the present disclosure, each m-th block can form an m-th triangular matrix with its two m-1-th triangular matrices adjacent to it, where m is an integer greater than or equal to 2 and less than or equal to n+1. In the present disclosure, the (n+1)th triangular matrix refers to the triangular portion of the triangular matrix to be inversed, which has nonzero elements. Therefore, according to the aforementioned relationship, the inverse of each (m)th triangular matrix depends on the inverses of the two (m-1)th triangular matrices included in the (m)th triangular matrix and the inverse of the (m)th block included in the (m)th triangular matrix, and the inverse of each (m)th block is determined based on the (m)th block and the inverses of the two (m-1)th triangular matrices.
[0031] For example, in Figure 3 In the example, the 0th row and 0th column element, the 1st row and 1st column element, the 2nd row and 2nd column element, etc. on the diagonal of the inverse triangular matrix to be found are divided into multiple first blocks, which respectively form multiple corresponding first triangular matrices. It is worth mentioning that, if Figure 3As shown, the leftmost column of numbers in the example triangular matrix to be inverted indicates the row number of each element in the matrix, the bottom row of numbers in the triangular matrix indicates the column number of each element in the matrix, and the numbers inside the triangular matrix indicate the thread number of the thread assigned to calculate the target element at the corresponding position (that is, the inverted element at the position).
[0032] exist Figure 3 , the elements in the 1st row and 0th column, the elements in the 3rd row and 2nd column, the elements in the 5th row and 4th column, the elements in the 7th row and 6th column, and so on are respectively divided into corresponding second blocks, and each second block has a corresponding second triangular matrix formed with the two adjacent first blocks. For example, the element in the 1st row and 0th column has the first triangular matrix (formed by the elements in the 0th row and 0th column) located above it and the first triangular matrix (formed by the elements in the 1st row and 1st column) located to its right, and the second block can form a second triangular matrix with the first triangular matrix (formed by the elements in the 0th row and 0th column) located above it and the first triangular matrix (formed by the elements in the 1st row and 1st column) located to its right. For another example, the element in the third row and second column has a first triangular matrix located above it (formed by the elements in the second row and second column) and a first triangular matrix located to its right (formed by the elements in the third row and third column). Furthermore, the second block can form a second triangular matrix with the first triangular matrix located above it (formed by the elements in the second row and second column) and the first triangular matrix located to its right (formed by the elements in the third row and third column). In the present disclosure, by first determining the inverse of each first block, the inverse of each corresponding second block can be determined using the aforementioned relationship, thereby equivalently determining the inverse of each second triangular matrix.
[0033] exist Figure 3 , as an example only, a rectangular matrix consisting of the 2nd row and 0th column elements, the 2nd row and 1st column elements, the 3rd row and 0th column elements, and the 3rd row and 1st column elements is divided into a third block, and it has a second triangular matrix located above it (formed by the 0th row and 0th column elements, the 1st row and 0th column elements, and the 1st row and 1st column elements) and a second triangular matrix located to its right (formed by the 2nd row and 2nd column elements, the 3rd row and 2nd column elements, and the 3rd row and 3rd column elements), and the third block can form a third triangular matrix with the first triangular matrix located above it and the first triangular matrix located to its right. In the present disclosure, by first determining the inverse of each second block, the inverse of each corresponding third block can be determined, which is equivalent to determining the inverse of each third triangular matrix.
[0034] The fourth block, the fifth block, and the corresponding fourth triangular matrix, the fifth triangular matrix, and their inverses can be determined in a similar manner and will not be described in further detail here.
[0035] In this disclosure, the number of the first blocks obtained by segmentation is 2 n and the number of m-th blocks obtained by segmentation is 2 n-m+1 The order of each first block is 1, and the order of each mth block is 2 m-2 For example, in Figure 3 In the example shown, n=5, so the segments include 32 first segments, 16 second segments, 8 third segments, 4 fourth segments, 2 fifth segments, and 1 sixth segment, where the order of the first segment is 1, the order of the second segment is also 1, the order of the third segment is 2, the order of the fourth segment is 4, the order of the fifth segment is 8, and the order of the sixth segment is 16.
[0036] In step 206, the 2 threads included in the warp are used. n A thread performs n+1 iterative inversion calculations in the order of the first triangular matrix, the second triangular matrix, and the n+1th triangular matrix to finally determine the inverse of the triangular matrix to be inverted.
[0037] Specifically, in the present disclosure, the 2 threads included in the warp can be used. n The inverse of each first triangular matrix is determined in an iterative manner, and then the inverse of each second triangular matrix is determined, and then the inverse of each third triangular matrix is determined, and so on, until the inverse of the (n+1)th triangular matrix (i.e., the inverse triangular matrix to be determined) is determined.
[0038] In the present disclosure, especially when the order of the inverse triangular matrix to be found is 2 n When the number of threads in a warp is equal to the number of threads allowed to access shared memory, all threads in the warp can be fully utilized during each iterative calculation, thereby ensuring that the relevant threads in the warp always run at full capacity, thereby improving computing performance. Experiments have found that using the above method, the speed of solving the inverse of a triangular matrix can be increased by at least 2 to 3 times, resulting in extremely excellent computing performance.
[0039] The following will be combined Figure 4 Step 206 is further described in more detail.
[0040] Figure 4 The flowchart of the method 400 for finally determining the inverse of the inverse triangular matrix to be determined is shown in accordance with an embodiment of the present disclosure, by performing n+1 iterations in the order of the inverse of the first triangular matrix, the inverse of the second triangular matrix, and the inverse of the n+1th triangular matrix. The method 400 may be performed as follows: Figure 6 It should be understood that the method 400 may further include additional blocks not shown and / or may omit the blocks shown, and the scope of the present disclosure is not limited in this respect.
[0041] In step 402, during the first iteration of the inverse calculation, 2 n threads (i.e., the 2 mentioned in step 206 n The inverse of all first triangular matrices is determined by a parallel operation of multiple threads, wherein the inverse of each first triangular matrix is the inverse of the corresponding first block.
[0042] In some embodiments, during the first iteration of the inversion calculation, 2 n Each thread in the threads is assigned to solve a target element of the first block (i.e., the inverse of the first block). In this disclosure, for the purpose of clarity and brevity, the element before inversion at any position of the triangular matrix (the position can be represented by rows and columns) is called the original element at that position, and the element after inversion at any position of the triangular matrix is called the target element at that position. In some embodiments, the row number of the target element that each thread is responsible for solving corresponds to the thread number of the thread. For example, Figure 3 As shown, the thread with thread number 0 is assigned to solve the target element of the first block located at row 0, the thread with thread number 1 is assigned to solve the target element of the first block located at row 1, and so on. Since each first block indicates an element located on the diagonal of the triangular matrix to be inverted, solving the inverse of the first block is actually solving the reciprocal of the element, so through the 2 n One parallel operation of two threads can determine all 2 n The inverse of the first triangular matrix.
[0043] In step 404, during the second iteration of the inverse calculation, the 2 n threads (i.e., the 2 mentioned in step 206 n The inverses of all second blocks are determined by one parallel operation of multiple threads (threads) to obtain the inverses of all second triangular matrices.
[0044] In some embodiments, during the second iteration of the inverse calculation, 2 n Each odd-numbered thread in the threads is assigned to solve the target element of the inverse of the second block, wherein the row number of the target element that each odd-numbered thread is responsible for solving corresponds to the thread number of the odd-numbered thread. In addition, during the second iteration of the inverse calculation, 2 n Each even-numbered thread among the threads can return directly.
[0045] For example, Figure 3As shown, threads numbered 1, 3, 5, etc. are respectively assigned to solve the target element of the second block located in the first row (i.e., the inverse of the second block), the target element of the second block located in the third row, the target element of the second block located in the fifth row, etc., and threads numbered 0, 2, 4, etc. return directly. Since each second block is of order 1, i.e., it contains only one element, the 2 n One parallel operation of the odd-numbered threads can determine all 2 n-1 The inverse of the second block is equivalent to obtaining the inverse of all second triangular matrices.
[0046] In step 406, during the kth iteration of the inverse calculation, the 2 n 2 threads k-3 The inverses of all k-th blocks are determined by performing parallel operations to obtain the inverses of all k-th triangular matrices.
[0047] In the present disclosure, the k mentioned in step 406 may indicate any integer greater than or equal to 3 and less than or equal to n+1. Figure 3 In the example shown, since the order of the inverse matrix to be found is 2 5 =32 (i.e., n=5), so it is necessary to perform 6 iterative inversion calculations to invert the matrix to be inverted. Therefore, in this example, the kth iterative inversion calculation in step 406 may refer to any one of the third iterative inversion calculation, the fourth iterative inversion calculation, the fifth iterative inversion calculation, and the sixth iterative inversion calculation.
[0048] In some embodiments, during the kth iteration of the inverse calculation, the 2 n The threads can be grouped into 2 n-k+1 thread sets, each thread set includes 2 k-1 For example, in Figure 3 In the example, when performing the third iteration of the inverse calculation, the 32 threads in the warp are grouped into 2 5-3+1 = 8 thread sets, where each set consists of four threads. In addition, during each parallel operation of the k-th iteration inversion calculation, each thread in the first thread set is assigned to solve the 2 of the first k-th block. k-1 target elements, each thread in the second thread set is assigned to solve the 2nd k-th block k-1 target elements..., and each thread in the last thread set is assigned to solve the 2 of the last k-th block k-1In some embodiments, during each parallel operation of the k-th iterative inversion calculation, each thread in each thread set is assigned to solve the two columns of target elements in the corresponding k-th block, and each thread in the thread set is assigned to solve the two columns of target elements in the corresponding k-th block in ascending order of thread number and from top to bottom and from left to right.
[0049] In some embodiments, when performing the lth parallel operation of the kth iterative inversion calculation, each thread in each thread set is respectively assigned to solve the 2l-1th column and the 2 in the 2lth column of the corresponding kth block. k-1 target elements, where l is an integer greater than or equal to 1. For example, during the first parallel operation of the k-th iteration inversion calculation, each thread in the first thread set is assigned to solve the 2 in the first column and the second column of the first k-th block. k-1 target element, and in the second parallel computation (if there is a second parallel computation), each thread in the first thread set is assigned to solve the 2 in the third column and the fourth column of the first k-th block. k-1 target element, and in the third parallel computation (if there is a third parallel computation), each thread in the first thread set is assigned to solve the 2 in the fifth and sixth columns of the first k-th block. k-1 target elements, and so on, until all target elements in the first k-th block are solved. It should be understood that the same is true for the second k-th block, the third k-th block, and so on.
[0050] For example, Figure 3 7 shows an example allocation method of each thread in the warp during the first parallel operation of the third iterative inversion calculation by the thread numbers marked in each third block; Figure 3 Detailed description is also provided of an exemplary allocation of threads in a warp during the first parallel operation of the fourth iterative inversion calculation by thread numbers marked in each fourth block; Figure 3 , an example allocation method of each thread in the warp during the first parallel operation of the fifth iterative inversion calculation is also shown through the thread numbers marked in each fifth block; Figure 3 The thread numbers in the sixth block also illustrate an example allocation method for each thread in the warp during the first parallel operation of the sixth iterative inversion calculation. The allocation method for each thread in subsequent parallel operations of each iterative inversion calculation can be determined according to the above description.
[0051] The following will be combined Figure 5The method for determining the inverse of each k-th block is further described in more detail. As mentioned above, k can be any integer greater than or equal to 3. In fact, in the present disclosure, when k is 2, the following method is also applicable.
[0052] Figure 5 1 shows a flow chart of a method 500 for determining the inverse of each k-th block. The method 500 may be performed as follows: Figure 6 It should be understood that the method 500 may further include additional blocks not shown and / or may omit the blocks shown, and the scope of the present disclosure is not limited in this respect.
[0053] In step 502 , a first product result between the inverse of the k−1 th triangular matrix located at the first of the k th block and the k th block is determined, so as to store the first product result in a register associated with the shared memory.
[0054] If the inverse triangular matrix to be determined is an upper triangular matrix, the k-1th triangular matrix located on the first side of the k-th block refers to the k-1th triangular matrix located on the left side of the k-th block, and if the inverse triangular matrix to be determined is a lower triangular matrix, the k-1th triangular matrix located on the first side of the k-th block refers to the k-1th triangular matrix located on the right side of the k-th block.
[0055] In the present disclosure, storing the first product result in a register can help speed up the inversion of the k-th block because the register is closer to the shared memory and has a faster storage speed.
[0056] In step 504, a second product result between the first product result and the inverse of the k-1th triangular matrix located on the second side of the kth block is determined to write the second product result back to the shared memory, wherein the negative of the second product result is the inverse of the kth block.
[0057] In the present disclosure, if the inverse triangular matrix to be determined is an upper triangular matrix, the k-1th triangular matrix located on the second side of the k-th block refers to the k-1th triangular matrix located on the lower side of the k-th block, and if the inverse triangular matrix to be determined is a lower triangular matrix, the k-1th triangular matrix located on the second side of the k-th block refers to the k-1th triangular matrix located on the upper side of the k-th block.
[0058] In some embodiments, when determining the product result (e.g., the first product result or the second product result), when each thread needs to exchange data with other threads in the same row, the shfl exclusive-or operation can be used to implement the corresponding data exchange. Figure 3Taking the example shown as an example, when using a thread with thread number 0 to determine the target element in the 4th row and 0th column of the fourth block (i.e., the element after inversion of the position), not only the original element in the 4th row and 0th column of the fourth block (i.e., the element before inversion of the position) is needed, but also the original element in the 4th row and 1st column of the fourth block (i.e., the element before inversion of the position) is needed. Similarly, when using a thread with thread number 4 to determine the target element in the 4th row and 1st column of the fourth block (i.e., the element after inversion of the position), not only the original element in the 4th row and 1st column of the fourth block is needed, but also the original element in the 4th row and 0th column is needed. Therefore, the shfl exclusive-or operation can be used to implement the corresponding data exchange between the two threads, so that the thread with thread number 0 can obtain the original element in the 4th row and 1st column, and the thread with thread number 4 can obtain the original element in the 4th row and 0th column to help determine the corresponding target element. In the present disclosure, by using the shfl exclusive-or operation to implement the corresponding data exchange, the additional data handling of the supply and demand memory can be avoided, thereby helping to further improve the corresponding computing performance.
[0059] Figure 6 A schematic block diagram of an example electronic device 600 that can be used to implement an embodiment of the present disclosure is shown. As shown, the electronic device 600 includes one or more processors 901 (e.g., a graphics processing unit or a central processing unit, etc.), which can perform various appropriate actions and processes according to computer program instructions stored in a read-only memory (ROM) 602 or stored from a storage unit 608 to a random access memory (RAM) 603. In the random access memory 603, various programs and data required for the operation of the electronic device 600 can also be stored. The processor 601, the read-only memory 602, and the random access memory 603 are connected to each other via a bus 604. An input / output (I / O) interface 605 is also connected to the bus 604.
[0060] Multiple components in the electronic device 600 are connected to the input / output interface 605, including: an input unit 606, such as a keyboard, a mouse, a microphone, etc.; an output unit 607, such as various types of displays, speakers, etc.; a storage unit 608, such as a magnetic disk, an optical disk, etc.; and a communication unit 609, such as a network card, a modem, a wireless communication transceiver, etc. The communication unit 609 allows the device 600 to exchange information / data with other devices via a computer network such as the Internet and / or various telecommunication networks.
[0061] The various processes and procedures described above, such as methods 200, 400, and 500, may be executed by processor 601. For example, in some embodiments, methods 200, 400, and 500 may be implemented as a computer software program that is tangibly embodied in a machine-readable medium, such as storage unit 608. In some embodiments, part or all of the computer program may be loaded and / or installed onto device 600 via read-only memory 602 and / or communication unit 609. When the computer program is stored in random access memory 603 and executed by processor 601, one or more actions of methods 200, 400, and 500 described above may be performed.
[0062] The present disclosure relates to methods, apparatuses, systems, electronic devices, computer-readable storage media, and / or computer program products. The computer program products may include computer-readable program instructions for executing various aspects of the present disclosure.
[0063] A computer-readable storage medium can be a tangible device that can hold and store instructions for use by an instruction execution device. A computer-readable storage medium can be, for example, but not limited to, an electrical storage device, a magnetic storage device, an optical storage device, an electromagnetic storage device, a semiconductor storage device, or any suitable combination thereof. More specific examples (a non-exhaustive list) of computer-readable storage media include: a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), a static random access memory (SRAM), a portable compact disc read-only memory (CD-ROM), a digital versatile disk (DVD), a memory stick, a floppy disk, a mechanical encoding device, such as a punch card or a raised structure in a groove on which instructions are stored, and any suitable combination thereof. As used herein, a computer-readable storage medium is not to be construed as a transient signal per se, such as a radio wave or other freely propagating electromagnetic wave, an electromagnetic wave propagating through a waveguide or other transmission medium (e.g., a light pulse through a fiber optic cable), or an electrical signal transmitted through an electrical wire.
[0064] The computer-readable program instructions described herein can be downloaded from a computer-readable storage medium to each computing / processing device, or downloaded to an external computer or external storage device via a network, such as the Internet, a local area network, a wide area network, and / or a wireless network. The network can include copper transmission cables, fiber optic transmission, wireless transmission, routers, firewalls, switches, gateway computers, and / or edge computing devices. The network adapter card or network interface in each computing / processing device receives the computer-readable program instructions from the network and forwards the computer-readable program instructions for storage in the computer-readable storage medium in each computing / processing device.
[0065] The computer program instructions for performing the operations of the present disclosure may be assembly instructions, instruction set architecture (ISA) instructions, machine instructions, machine-dependent instructions, microcode, firmware instructions, state setting data, or source code or object code written in any combination of one or more programming languages, including object-oriented programming languages such as Smalltalk, C++, and conventional procedural programming languages such as "C" language or similar programming languages. Computer-readable program instructions may be executed entirely on a user's computer, partially on a user's computer, as an independent software package, partially on a user's computer, partially on a remote computer, or entirely on a remote computer or server. In the case of a remote computer, the remote computer may be connected to the user's computer via any type of network, including a local area network (LAN) or a wide area network (WAN), or may be connected to an external computer (e.g., utilizing an Internet service provider to connect via the Internet). In some embodiments, an electronic circuit, such as a programmable logic circuit, a field programmable gate array (FPGA), or a programmable logic array (PLA), may be personalized by utilizing the state information of the computer-readable program instructions. The electronic circuit may execute the computer-readable program instructions, thereby realizing various aspects of the present disclosure.
[0066] Various aspects of the present disclosure are described herein with reference to flowcharts and / or block diagrams of methods, apparatus (systems), and computer program products according to embodiments of the present disclosure. It should be understood that each block of the flowcharts and / or block diagrams, and combinations of blocks in the flowcharts and / or block diagrams, can be implemented by computer-readable program instructions.
[0067] These computer-readable program instructions can be provided to a processing unit of a general-purpose computer, a special-purpose computer, or other programmable data processing device, thereby producing a machine such that when these instructions are executed by the processing unit of the computer or other programmable data processing device, a device is generated that implements the functions / actions specified in one or more blocks in the flowchart and / or block diagram. These computer-readable program instructions can also be stored in a computer-readable storage medium, where these instructions cause the computer, programmable data processing device, and / or other device to operate in a specific manner. Thus, the computer-readable medium storing the instructions comprises an article of manufacture that includes instructions for implementing various aspects of the functions / actions specified in one or more blocks in the flowchart and / or block diagram.
[0068] Computer-readable program instructions may also be loaded onto a computer, other programmable data processing apparatus, or other device so that a series of operational steps are performed on the computer, other programmable data processing apparatus, or other device to produce a computer-implemented process, thereby causing the instructions executed on the computer, other programmable data processing apparatus, or other device to implement the functions / actions specified in one or more blocks in the flowchart and / or block diagram.
[0069] The flow charts and block diagrams in the accompanying drawings show the possible architecture, functions and operations of the systems, methods and computer program products according to multiple embodiments of the present disclosure. In this regard, each box in the flow chart or block diagram can represent a part of a module, program segment or instruction, and the part of the module, program segment or instruction contains one or more executable instructions for realizing the prescribed logical function. In some alternative implementations, the functions marked in the box can also occur in a sequence different from that marked in the accompanying drawings. For example, two consecutive boxes can actually be executed substantially in parallel, and they can sometimes be executed in the opposite order, depending on the functions involved. It should also be noted that each box in the block diagram and / or flow chart, and the combination of the boxes in the block diagram and / or flow chart can be implemented by a dedicated hardware-based system that performs the prescribed function or action, or can be implemented by a combination of dedicated hardware and computer instructions.
[0070] While various embodiments of the present disclosure have been described above, the foregoing description is intended to be illustrative, non-exhaustive, and not limited to the disclosed embodiments. Many modifications and variations will be apparent to those skilled in the art without departing from the scope and spirit of the described embodiments. The terminology used herein is selected to best explain the principles of the embodiments, their practical applications, or technological improvements in the marketplace, or to enable others skilled in the art to understand the embodiments disclosed herein.
Claims
1. A method for inverting a triangular matrix, comprising: Set the order to 2 n The inverse triangular matrix to be determined is stored in a shared memory, wherein the order is less than or equal to the number of threads included in the thread warp that is allowed to access the shared memory, where n is an integer greater than or equal to 1; Divide the triangular part of the to-be-inverted triangular matrix having non-zero elements into a plurality of blocks of different orders, wherein the plurality of blocks respectively include one or more first to n+1th blocks, wherein each first block forms a first triangular matrix, and each mth block and two adjacent m-1th triangular matrices form an mth triangular matrix, wherein m is an integer greater than or equal to 2 and less than or equal to n+1, wherein the n+1th triangular matrix indicates the triangular part of the to-be-inverted triangular matrix; as well as Utilize the 2 included in the thread bundle n A thread performs n+1 iterative inversion calculations in the order of the first triangular matrix, the second triangular matrix, and the n+1th triangular matrix, so as to finally determine the inverse of the triangular matrix to be inverted. 2 . The method according to claim 1 , wherein each first block indicates an element located on a diagonal of the inverse triangular matrix to be found.
3. The method according to claim 2, wherein the number of the first blocks obtained by segmentation is 2 n and the number of m-th blocks obtained by segmentation is 2 n-m+1 The order of each first block is 1, and the order of each mth block is 2 m-2 .
4. The method according to claim 1, wherein the inverse of each m-th triangular matrix depends on the inverses of two m-1-th triangular matrices included in the m-th triangular matrix and the inverse of the m-th block included in the m-th triangular matrix, and the inverse of each m-th block is determined based on the m-th block and the inverses of the two m-1-th triangular matrices.
5. The method according to claim 4, wherein the thread warp comprises 2 n A thread performs n+1 iterative inversion calculations in the order of the first triangular matrix, the second triangular matrix, and the n+1th triangular matrix to finally determine the inverse of the triangular matrix to be inverted, including: In the first iteration of the inverse calculation, the 2 n A parallel operation of 10 threads is used to determine the inverses of all first triangular matrices, wherein the inverse of each first triangular matrix is the inverse of the corresponding first block; In the second iteration of the inverse calculation, the 2 n A parallel operation of 10 threads is used to determine the inverses of all second blocks so as to obtain the inverses of all second triangular matrices; as well as In the kth iteration, the 2 n 2 threads k-3 The inverses of all k-th blocks are determined by performing parallel operations to obtain the inverses of all k-th triangular matrices, where k is an integer greater than or equal to 3 and less than or equal to n+1.
6. The method according to claim 5, wherein in the first iteration of the inverse calculation, the 2 n Each thread in the threads is assigned to solve a target element of the first block, wherein the row number of the target element that each thread is responsible for solving corresponds to the thread number of the thread.
7. The method according to claim 5, wherein in the second iteration of the inverse calculation, the 2 n Each odd-numbered thread among the threads is assigned to solve a target element of the second block, wherein the row number of the target element that each odd-numbered thread is responsible for solving corresponds to the thread number of the odd-numbered thread.
8. The method according to claim 5, wherein at the kth iteration inversion, the 2 n The threads are grouped into 2 n-k+1 thread sets, each thread set includes 2 k-1 Threads; When performing each parallel operation of the k-th iterative inversion calculation, each thread in the first thread set is respectively assigned to solve the 2 of the first k-th block k-1 target elements, each thread in the second thread set is assigned to solve the 2nd k-th block k-1 target elements, and each thread in the last thread set is assigned to solve the 2 of the last k-th block. k-1 target element.
9. The method according to claim 8, wherein during each parallel operation of the k-th iterative inversion calculation, each thread in each thread set is assigned to solve the two columns of target elements in the corresponding k-th block, and each thread in the thread set is assigned to solve the two columns of target elements in the corresponding k-th block in ascending order of thread number and from top to bottom and from left to right.
10. The method according to claim 9, wherein during the lth parallel operation of the kth iterative inversion calculation, each thread in each thread set is respectively assigned to solve the 21-1th column and the 21th column of the corresponding kth block. k-1 target elements, where l is an integer greater than or equal to 1.
11. The method according to claim 8, wherein during the k-th iteration of the inverse calculation, the inverse of each k-th block is determined by: determining a first product result between an inverse of a k-1th triangular matrix located on a first side of the kth block and the kth block, so as to store the first product result in a register associated with the shared memory; Determine a second product result between the first product result and the inverse of the k-1th triangular matrix located on the second side of the kth block to write the second product result back to the shared memory, wherein the negative of the second product result is the inverse of the kth block.
12. The method according to claim 11, wherein in the process of determining the first product result or the second product result, when each thread needs to exchange data with other threads in the same row, an shfl exclusive-or operation is used to implement the corresponding data exchange.
13. The method according to claim 1, wherein the order is 2 n The inverse triangular matrix to be found is stored in shared memory including: Based on the order of the inverse triangular matrix to be determined, applying for memory space for the inverse triangular matrix to be determined in a shared memory, where the number of columns of the memory space is greater than the number of columns of the inverse triangular matrix to be determined; as well as The inverse triangular matrix to be found is stored in the memory space in a row-first storage manner, so that the inverse triangular matrix to be found is inverted in the memory space.
14. A computing device comprising: at least one processor; as well as a memory communicatively coupled to the at least one processor; The memory stores instructions that can be executed by the at least one processor, and the instructions are executed by the at least one processor to enable the at least one processor to perform the method according to any one of claims 1 to 13.
15. A non-transitory computer-readable storage medium storing computer instructions, wherein the computer instructions are used to cause a computer to execute the method according to any one of claims 1 to 13.
Citation Information
Patent Citations
Matrix inverse operation method
CN105426345A
Matrix inversion method, device and apparatus and computer readable storage medium
CN110377875A