A calculation method and device for completing continuous matrix multiplication in a register

By adjusting the order of warp thread registers in the AI ​​accelerator, the continuous multiplication of matrices A, B and the permuted matrix C is realized, which solves the problem of slow matrix multiplication and misalignment in the existing technology, improves computing efficiency, and is suitable for acceleration lattice passwords and other information security algorithms.

CN118227939BActive Publication Date: 2024-10-11UNIV OF CHINESE ACAD OF SCI
View PDF 8 Cites 0 Cited by

Patent Information

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

AI Technical Summary

Technical Problem

When existing AI accelerators perform on-ring polynomial multiplication calculations, matrix multiplication operations are slow, and due to inconsistent wmma.load and wmma.store transformations, misalignment occurs during continuous matrix operations and high performance consumption.

Method used

By obtaining the 16×16 matrices A, B and the permuted matrix C′, adjusting the register order of each thread in the warp, achieving the continuous multiplication results of matrices A, B and C, reducing the number of reads and writes, and optimizing the matrix Multiplication process.

Benefits of technology

It greatly improves the calculation speed, reduces performance consumption, and realizes efficient matrix continuous multiplication operations on the AI ​​accelerator, which is suitable for accelerating lattice cryptography and other information security algorithms.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118227939B_ABST
    Figure CN118227939B_ABST
Patent Text Reader

Abstract

The present invention discloses a calculation method and device for completing continuous matrix multiplication in a register, belonging to the field of computer science. The method comprises: obtaining matrix A, matrix B and matrix C′; wherein the matrix C′ is obtained by permuting matrix C; after respectively reading matrix A, matrix B and matrix C′ into warp based on wmma.load transformation, the continuous multiplication results of matrix A, matrix B and matrix C are obtained by adjusting the register order of each thread in warp. The present invention can make full use of the computing power resources of AI accelerator and greatly improve the computing speed.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The invention belongs to the field of computing technology and relates to a computing method and a device for completing continuous matrix multiplication in a register. Background Art

[0002] Thanks to the development of artificial intelligence, related applications are becoming more and more popular. To this end, some manufacturers have developed their own AI processors or accelerators, such as Google's TPU, Intel's neural network stick, Tesla's driverless car chip, and the neural network acceleration engine that many smartphones now have, to provide strong performance processing capabilities for specialized businesses. These AI accelerators usually adopt low-precision, novel data flow, and in-memory computing architectures, and are optimized for specific algorithm operations (such as convolution operations). The performance is much higher than that of general-purpose processors. For example, the Tensor Core of NVIDIA Tesla V100 can provide 125Tensor TFLOPS of computing power. With the development of technology, such powerful computing resources will inevitably become more common and easier to access. If the computing power of AI accelerators can be used in other fields besides artificial intelligence applications, such as cryptographic computing, it will definitely greatly improve the computing efficiency in this field.

[0003] On the other hand, quantum computers have brought huge challenges to information security, especially the security of existing cryptographic systems. Lattice cryptography, as a quantum-resistant cryptography, is widely considered to be the most promising cryptographic system for the next generation of public key cryptography standards. In standard lattices, polynomial multiplication calculations on rings are particularly time-consuming operations. Therefore, solving the problem of the speed of polynomial multiplication on rings has important research significance and value for promoting lattice cryptography and even the entire information security.

[0004] Among them, a computing unit in Tensor Core is called a warp, which consists of 32 threads. When reading a 16×16 matrix, the 256 matrix elements are stored in 8 of the 32 threads. Figure 1 As shown in Figure 1, the warp reads continuous data from the memory and arranges it in the 32 threads as follows. This transformation is recorded as wmma.load. After the warp performs the multiplication operation between the two matrices, it writes them to the memory from the 32 threads, as shown in Figure 1. Figure 2 As shown in the figure, this transformation is recorded as wmma.store. Since the two transformations are not consistent, it is impossible to directly perform two consecutive matrix operations, because the transformation result of wmma.store will be misaligned when executing wmma.store, and further matrix operations will cause errors. Manual memory data exchange must be performed, resulting in high performance consumption. Summary of the invention

[0005] In response to the above problems, the present invention provides a calculation method and device for completing continuous matrix multiplication in a register based on NVIDIA's Tensor Core (hereinafter referred to as Tensor Core). This method can make full use of the computing power resources of the AI ​​accelerator and greatly improve the calculation speed.

[0006] To achieve the above object, the technical solution of the present invention includes the following contents.

[0007] A calculation method for completing continuous matrix multiplication in a register, the method comprising:

[0008] Obtain a 16×16 matrix A, a 16×16 matrix B, and a 16×16 matrix C′; wherein the matrix C′ is obtained by performing a permutation process on the 16×16 matrix C;

[0009] After reading matrix A, matrix B and matrix C′ into warp respectively based on wmma.load transformation, the continuous multiplication results of matrix A, matrix B and 16×16 matrix C are obtained by adjusting the register order of each thread in warp.

[0010] Further, the permutation processing of the matrix C includes:

[0011] A 16×16 permutation matrix P is obtained; wherein the rows of the permutation matrix P are numbered from 0 to 15 from top to bottom, the columns of the permutation matrix P are numbered from 0 to 15 from left to right, and 16 elements of row 0 and column 0, row 1 and column 1, row 2 and column 4, row 3 and column 5, row 4 and column 8, row 5 and column 9, row 6 and column 12, row 7 and column 13, row 8 and column 2, row 9 and column 3, row 10 and column 6, row 11 and column 7, row 12 and column 10, row 13 and column 11, row 14 and column 14, and row 15 of the permutation matrix P are 1, and the other elements are 0.

[0012] Calculate the matrix C′=P -1 C.

[0013] Furthermore, the method of obtaining the continuous multiplication results of matrix A, matrix B and matrix C by adjusting the register order of each thread in the warp includes:

[0014] Calculate the product of matrix A and matrix B to obtain a 16×16 matrix G;

[0015] Adjust the register order of each thread in the warp to obtain the 16×16 matrix G′ corresponding to the matrix G;

[0016] Calculate the product of matrix C′ and matrix G′ to obtain a 16×16 matrix D;

[0017] Create matrix D as the result of the successive multiplications of matrix A, matrix B, and matrix C.

[0018] Furthermore, the step of adjusting the register order of each thread in the warp to obtain a matrix G′ corresponding to the matrix G includes:

[0019] Mark the 8 registers in a thread in order to get the register order (r0, r1, r2, r3, r4, r5, r6, r7);

[0020] Swap register r2 and register r3 with register r4 and register r5 to obtain the new order of registers in this thread (r0, r1, r4, r5, r2, r3, r6, r7);

[0021] According to the values ​​of each register in the new register order (r0, r1, r4, r5, r2, r3, r6, r7), the matrix G′ corresponding to the matrix G is obtained.

[0022] Further, after respectively reading the matrix A, the matrix B and the matrix C′ into the warp based on the wmma.load transformation, the continuous multiplication results of the matrix A, the matrix B and the matrix C are obtained by adjusting the register order of each thread in the warp, and further comprising:

[0023] Writes the matrix D from the warp to memory based on the wmma.store transformation.

[0024] A computing device for performing continuous matrix multiplication in a register, the device comprising:

[0025] A matrix acquisition module, used to acquire matrix A, matrix B and matrix C′; wherein the matrix C′ is obtained by performing a permutation process on matrix C;

[0026] The online computing module is used to read the matrix A, the matrix B and the matrix C′ into the warp respectively based on the wmma.load transformation, and then obtain the continuous multiplication results of the matrix A, the matrix B and the matrix C by adjusting the register order of each thread in the warp.

[0027] An electronic device comprises: a processor and a memory storing computer program instructions; when the processor executes the computer program instructions, the calculation method of completing continuous matrix multiplication in a register as described in any one of the above items is implemented.

[0028] A computer-readable storage medium, characterized in that computer program instructions are stored on the computer-readable storage medium, and when the computer program instructions are executed by a processor, the calculation method for completing continuous matrix multiplication in a register described in any one of the above items is implemented.

[0029] The prior art requires a complete process to perform a multiplication: 1) read the data into the warp before calculation; 2) perform matrix multiplication in the warp; 3) write the data in the warp to the memory after calculation. These three steps need to be repeated when performing matrix multiplication continuously. Compared with the prior art, the technology proposed in the present invention only requires one read-in and one write-out in the whole process when performing multiple multiplications continuously. The continuous matrix multiplication implemented by the present invention can save unnecessary instructions and memory consumption, and greatly improve the calculation speed. BRIEF DESCRIPTION OF THE DRAWINGS

[0030] Figure 1 This is a diagram showing the relationship between the data in memory and registers before and after wmma.load transformation.

[0031] Figure 2 This is a diagram showing the relationship between registers and data in memory before and after wmma.store transformation.

[0032] Figure 3 A block diagram of a calculation method for completing continuous matrix multiplication in a register of the present invention.

[0033] Figure 4 This is a calculation flow chart of the offline calculation module of the present invention.

[0034] Figure 5 It is a calculation flow chart of the online calculation module of the present invention.

[0035] Figure 6 It is a structural diagram of the permutation matrix P of the present invention. DETAILED DESCRIPTION

[0036] The present invention is further described in detail below with reference to the accompanying drawings.

[0037] The calculation method of completing continuous matrix multiplication in a register of the present invention is as follows: Figure 3 As shown, it can be based on Figure 4 The permutation matrix C′ of the matrix C obtained by the offline calculation module is combined with the order adjustment of the registers to achieve the following Figure 5 The shown are successive matrix multiplications of Matrix A, Matrix V, and Matrix C.

[0038] The calculation method of completing continuous matrix multiplication in the register of the present invention is to use AI accelerator (TensorCore) to realize the acceleration of polynomial multiplication calculation on the ring. In one embodiment, when D=A×B×C is the calculation target, where A, B, and C are all 16×16 matrices, the steps are:

[0039] 1) Read matrix A from memory into warp and transform it using wmma.load.

[0040] 2) Read matrix B from memory into warp and transform it using wmma.load.

[0041] 3) Calculate C′=P -1 ×C.

[0042] 4) Read the matrix C′ from memory into the warp and transform it using wmma.load.

[0043] 5) Calculate G = A × B in the warp.

[0044] 6) Let the registers of each thread in the warp be (r0, r1, r2, r3, r4, r5, r6, r7), and swap r2 and r3 with r4 and r5, so that we get (r0, r1, r4, r5, r2, r3, r6, r7). The matrix is ​​denoted as G′.

[0045] Specifically, for the 8 registers in a thread, they are recorded in order as (r0, r1, r2, r3, r4, r5, r6, r7). After the first matrix multiplication calculation, r2 and r3 are replaced by r4 and r5 respectively, so that (r0, r1, r4, r5, r2, r3, r6, r7) is obtained. The matrix G′ after register replacement is the product of the first matrix multiplication result G and the matrix P, that is, G′=G×P, where the matrix P is a 16×16 matrix, as shown in Figure 6 As shown, from top to bottom, the row numbers of P are 0 to 15; from left to right, the column numbers of P are 0 to 15. The 16 elements of P, row 0 and column 0, row 1 and column 1, row 2 and column 4, row 3 and column 5, row 4 and column 8, row 5 and column 9, row 6 and column 12, row 7 and column 13, row 8 and column 2, row 9 and column 3, row 10 and column 6, row 11 and column 7, row 12 and column 10, row 13 and column 11, row 14 and column 14, and row 15 and column 15 are all 1, and the other elements are all 0.

[0046] 7) Calculate D = G' × C' in the warp.

[0047] 8) Write the matrix D from the warp to memory, after the wmma.store transformation

[0048] In summary, polynomial multiplication on lattice is the basic calculation of lattice-based cryptographic algorithms and is also the performance bottleneck of algorithm implementation. NTT is the mainstream acceleration algorithm for accelerating polynomial multiplication.

[0049] By using the technology proposed in this invention, based on high-performance computing devices, only two consecutive matrix operations can be completed in registers, greatly reducing consumption. Matrix continuous operation is one of the important components of NTT and its inverse transformation, which can be used to implement high-performance NTT implementation technology, effectively accelerate polynomial multiplication calculations on lattices, and directly reduce the calculation time of post-quantum key encapsulation mechanism algorithm Kyber and post-quantum digital signature algorithm Dilithium.

[0050] Those skilled in the art will readily appreciate other embodiments of the present disclosure after considering the specification and practicing the present disclosure. The present disclosure is intended to cover any variations, uses or adaptations of the present disclosure, which follow the general principles of the present disclosure and include common knowledge or customary technical means in the art that are not disclosed in the present disclosure. The specification and examples are intended to be exemplary only, and the present disclosure is not limited to the precise structures described above and shown in the accompanying drawings, and various modifications and changes may be made without departing from the scope thereof.

Claims

1. A method for performing continuous matrix multiplication in a register, characterized in that: The method comprises: Get 16×16 matrix A, 16×16 matrix B, and 16×16 matrix C ′ ; Wherein, the matrix C ′ It is obtained by permuting the 16×16 matrix C; Based on wmma.load transformation, matrix A, matrix B and matrix C are respectively ′ After the warp is read in, the register order of each thread in the warp is adjusted to obtain the continuous multiplication results of the matrix A, the matrix B and the 16×16 matrix C; wherein the continuous multiplication results of the matrix A, the matrix B and the matrix C are obtained by adjusting the register order of each thread in the warp, including: Calculate the product of matrix A and matrix B to obtain a 16×16 matrix G; Adjust the register order of each thread in the warp to obtain the 16×16 matrix G corresponding to the matrix G ′ ; wherein the register order of each thread in the warp is adjusted to obtain a 16×16 matrix G corresponding to the matrix G ′ ,include: Mark the 8 registers in a thread in order to get the register order r0, r1, r2, r3, r4, r5, r6, r7; Swap register r2 and register r3 with register r4 and register r5 to obtain the new register order r0, r1, r4, r5, r2, r3, r6, r7 in this thread; According to the values ​​of each register in the new register order r0, r1, r4, r5, r2, r3, r6, r7, we get the matrix G corresponding to the matrix G. ′ ; Calculate the matrix C ′ and the matrix G ′ The product of , we get a 16×16 matrix D; Create matrix D as the result of the successive multiplications of matrix A, matrix B, and matrix C.

2. The method according to claim 1, characterized in that The permutation process of the 16×16 matrix C includes: Obtain a 16×16 permutation matrix P; wherein the row numbers of the permutation matrix P are 0 to 15 from top to bottom, the column numbers of the permutation matrix P are 0 to 15 from left to right, and 16 elements of row 0 and column 0, row 1 and column 1, row 2 and column 4, row 3 and column 5, row 4 and column 8, row 5 and column 9, row 6 and column 12, row 7 and column 13, row 8 and column 2, row 9 and column 3, row 10 and column 6, row 11 and column 7, row 12 and column 10, row 13 and column 11, row 14 and column 14, and row 15 and column 15 of the permutation matrix P are 1, and the other elements are 0; Calculate the matrix C ′ =P -1 C.

3. The method according to any one of claims 1 to 2, characterized in that: The wmma.load transformation is based on the matrix A, matrix B and matrix C. ′ After reading the warp, by adjusting the register order of each thread in the warp, the continuous multiplication results of matrix A, matrix B and matrix C are obtained, and it also includes: Writes the matrix D from the warp to memory based on the wmma.store transformation.

4. A computing device for performing continuous matrix multiplication in a register, characterized in that: The device comprises: Matrix acquisition module, used to obtain matrix A, matrix B and matrix C ′ ; Wherein, the matrix C ′ It is obtained by permuting the matrix C; Online calculation module, used to transform matrix A, matrix B and matrix C respectively based on wmma.load transformation ′ After the warp is read in, the register order of each thread in the warp is adjusted to obtain the continuous multiplication results of the matrix A, the matrix B and the matrix C; wherein the adjusting the register order of each thread in the warp to obtain the continuous multiplication results of the matrix A, the matrix B and the matrix C includes: Calculate the product of matrix A and matrix B to obtain a 16×16 matrix G; Adjust the register order of each thread in the warp to obtain the 16×16 matrix G corresponding to the matrix G ′ ; wherein the register order of each thread in the warp is adjusted to obtain a 16×16 matrix G corresponding to the matrix G ′ ,include: Mark the 8 registers in a thread in order to get the register order r0, r1, r2, r3, r4, r5, r6, r7; Swap register r2 and register r3 with register r4 and register r5 to obtain the new register order r0, r1, r4, r5, r2, r3, r6, r7 in this thread; According to the values ​​of each register in the new register order r0, r1, r4, r5, r2, r3, r6, r7, we get the matrix G corresponding to the matrix G. ′ ; Calculate the matrix C ′ and the matrix G ′ The product of , we get a 16×16 matrix D; Create matrix D as the result of the successive multiplications of matrix A, matrix B, and matrix C.

5. An electronic device, characterized in that: The electronic device comprises: a processor and a memory storing computer program instructions; when the processor executes the computer program instructions, the processor implements the calculation method for completing continuous matrix multiplication in a register as described in any one of claims 1-3.

6. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores computer program instructions, which, when executed by a processor, implement a calculation method for completing continuous matrix multiplication in a register as described in any one of claims 1 to 3.

Citation Information

Patent Citations

  • Data processing method and device

    CN106877882A

  • Method and device for realizing on-loop polynomial multiplication calculation acceleration by using AI accelerator

    CN111796797A

  • Matrix multiplication operation method and device

    CN116090513A

  • Data processing method and device based on matrix mode processor

    CN117216464A

  • Systems and methods for providing vector-wise sparsity in a neural network

    US20210065005A1