# US 11,120,101 B2 · Matrix multiplication system and method

> Agents: this data is available as JSON from the patentgrep API and MCP server — see https://patentgrep.com/llms.txt

- Number: US 11,120,101 B2
- Document ID: US11120101B2
- Status: Granted
- Kind: B2
- Application number: 16/585,265
- Filed: 2019-09-27
- Published: 2021-04-01
- Granted: 2021-09-14
- Earliest claimed: 2019-09-27
- Assignees: Arm Limited
- Applicants: Arm Limited
- Inventors: Zhi-Gang Liu; Matthew Mattina; Paul Nicholas Whatmough
- Web page: https://patentgrep.com/patent/US11120101B2

## CPC

- G06F 17/16: Matrix or vector computation {, e.g. matrix-matrix or matrix-vector multiplication, matrix factorization (matrix transposition G06F7/78)}
- G06N 3/045: Combinations of networks
- G06N 3/0464: Convolutional networks [CNN, ConvNet]
- G06N 3/0495: Quantised networks; Sparse networks; Compressed networks
- G06N 3/063: using electronic means
- H03M 7/30: Compression (speech analysis-synthesis for redundancy reduction G10L19/00; for image communication H04N); Expansion; Suppression of unnecessary data, e.g. redundancy reduction
- H03M 7/3066: {by means of a mask or a bit-map}
- H03M 7/70: {Type of the data to be coded, other than image and sound}
- G06F: ELECTRIC DIGITAL DATA PROCESSING (computer systems based on specific computational models G06N)
- G06N: COMPUTING ARRANGEMENTS BASED ON SPECIFIC COMPUTATIONAL MODELS
- H03M: CODING; DECODING; CODE CONVERSION IN GENERAL (using fluidic means F15C4/00; optical analogue/digital converters G02F7/00; coding, decoding or code conversion, specially adapted for particular applications, see the relevant subclasses, e.g. G01D, G01R, G06F, G06T, G09G, G10L, G11B, G11C, H04B, H04L, H04M, H04N; ciphering or deciphering for cryptography or other purposes involving the need for secrecy G09C)

## Abstract

The present disclosure advantageously provides a system method for efficiently multiplying matrices with elements that have a value of 0. A bitmap is generated for each matrix. Each bitmap includes a bit position for each matrix element. The value of each bit is set to 0 when the value of the corresponding matrix element is 0, and to 1 when the value of the corresponding matrix element is not 0. Each matrix is compressed into a compressed matrix, which will have fewer elements with a value of 0 than the original matrix. Each bitmap is then adjusted based on the corresponding compressed matrix. The compressed matrices are then multiplied to generate an output matrix. For each element i,j in the output matrix, a dot product of the ith row of the first compressed matrix and the jth column of the second compressed matrix is calculated based on the bitmaps.

## Claims

### Claim 1

A system, comprising:
a memory;
a processor, coupled to the memory, configured to:
generate a first bitmap based on a first matrix, the first bitmap having a plurality of bit positions, each bit position corresponding to a different element of the first matrix, each bit position having a value of 1 when a value of the corresponding element of the first matrix is not 0, and a value of 0 when the value of the corresponding element of the first matrix is 0,
compress the first matrix into a first compressed matrix, the first compressed matrix including fewer elements having the value of 0 than the first matrix,
adjust the first bitmap based on the first compressed matrix,
generate a second bitmap based on a second matrix, the second bitmap having a plurality of bit positions, each bit position corresponding to a different element of the second matrix, each bit position having the value of 1 when a value of the corresponding element of the second matrix is not 0, and the value of 0 when the value of the corresponding element of the second matrix is 0,
compress the second matrix into a second compressed matrix, the second compressed matrix including fewer elements having the value of 0 than the second matrix, and
adjust the second bitmap based on the second compressed matrix; and
a matrix multiply accelerator (MMA), coupled to the processor and the memory, configured to multiply the first compressed matrix and the second compressed matrix to generate an output matrix, including:
for each element i,j of the output matrix, calculate a dot product of the ith row of the first compressed matrix and the jth column of the second compressed matrix based on the first bitmap and the second bitmap.

### Claim 2 (depends on 1)

The system according to claim 1, where the MMA includes:
a first scalar register to store the first bitmap;
a first vector register to store the first compressed matrix;
a second scalar register to store the second bitmap;
a second vector register to store the second compressed matrix;
an output register to store the output matrix; and
an array of compute elements (CEs), coupled to the first scalar register, the second scalar register, the first vector register, the second vector register and the output register, each CE calculating the dot product for a different element i,j of the output matrix.

### Claim 3 (depends on 2)

The system according to claim 2, where each CE includes:
a first multiplexer to receive a row of the first compressed matrix, the row including a plurality of first elements, and to selectively output each of the first elements of the row based on a first data selection signal;
a second multiplexer to receive a column of the second compressed matrix, the column including a plurality of second elements, and to selectively output each of the second elements of the column based on a second data selection signal;
a data selection circuit, coupled to the first multiplexer and the second multiplexer, to receive the first bitmap and the second bitmap, to generate the first data selection signal based on the first bitmap, and to generate the second data selection signal based on the second bitmap;
a multiplier circuit, coupled to the first multiplexer and the second multiplexer, to receive the first elements selectively output by the first multiplexer and the second elements selectively output by the second multiplexer, to multiply respective first elements and second elements to generate respective intermediate products, and to output the respective intermediate products; and
an accumulator circuit, coupled to the multiplier circuit, to receive the respective intermediate products, and to accumulate the respective intermediate products into a value for one element of the output matrix.

### Claim 4 (depends on 1)

The system according to claim 1, where:
the first matrix has m rows and n columns, the first compressed matrix has m rows and c columns, and n is a multiple of c;
the second matrix has n rows and p columns, and the second compressed matrix has c rows and p columns;
the output matrix has m rows and p columns; and
i goes from 1 to m, and j goes from 1 to p.

### Claim 5 (depends on 4)

The system according to claim 4, where said calculate the dot product of the ith row of the first compressed matrix and the jth column of the second compressed matrix based on the first bitmap and the second bitmap includes:
when the bit position in the first bitmap corresponding to an element i,k of the ith row of the first compressed matrix has a value of 1 and when the bit position in the second bitmap corresponding to an element k,j of the jth column of the second compressed matrix has a value of 1, multiplying the element i,k and the element k,j to generate an intermediate product;
when the bit position in the first bitmap corresponding to an element i,k of the ith row of the first compressed matrix has a value of 0 or when the bit position in the second bitmap corresponding to an element k,j of the jth column of the second compressed matrix has a value of 0, not multiplying the element i,k and the element k,j; and
summing the intermediate products to generate the element i,j;
where k goes from 1 to c.

### Claim 6 (depends on 5)

The system according to claim 5, where:
said compress the first matrix into the first compressed matrix includes:
beginning with an element located at a first row and a first column of the first matrix, move each element of the first matrix that has a non-zero value into the first compressed matrix in row major order, and
when a row of the first matrix has less than c elements that have a non-zero value, move one or more elements that have a zero value into the first compressed matrix so that the corresponding row of the first compressed matrix has c elements;
said adjust the first bitmap based on the first compressed matrix includes change the corresponding bit values in the first bit map from 0 to 1 for said one or more elements of the first matrix that have a zero value that are moved into the first compressed matrix;
said compress the second matrix into the second compressed matrix includes:
beginning with an element located at a first row and a first column of the second matrix, move each element of the second matrix that has a non-zero value into the second compressed matrix in column major order, and
when a column of the second matrix has less than c elements that have a non-zero value, move one or more elements that have a zero value into the second compressed matrix so that the corresponding column of the second compressed matrix has c elements; and
said adjust the second bitmap based on the second compressed matrix includes change the corresponding bit values in the second bit map from 0 to 1 for said one or more elements of the second matrix that have a zero value that are moved into the second compressed matrix.

### Claim 7 (depends on 6)

The system according to claim 6, where a first number of non-zero elements in the first matrix is equal to or less than c times m, and a second number of non-zero elements in the second matrix is equal to or less than c times p.

### Claim 8 (depends on 1)

The system according to claim 1, where said compress the first matrix into the first compressed matrix is performed in place, and said compress the second matrix into the second compressed matrix is performed in place.

### Claim 9

A matrix multiply accelerator (MMA), comprising:
a first scalar register to store a first bitmap associated with a first matrix, the first bitmap having a plurality of bit positions, each bit position corresponding to a different element of the first matrix, each bit position having a value of 0 when the corresponding element of the first matrix is 0, and a value of 1 when the corresponding element of the first matrix is not 0;
a first vector register to store a first compressed matrix, the first compressed matrix including fewer elements having the value of 0 than the first matrix;
a second scalar register to store a second bitmap associated with a second matrix, the second bitmap having a plurality of bit positions, each bit position corresponding to a different element of the second matrix, each bit position having a value of 0 when the corresponding element of the second matrix is 0, and a value of 1 when the corresponding element of the second matrix is not 0;
a second vector register to store a second compressed matrix, the second compressed matrix including fewer elements having the value of 0 than the second matrix;
an output vector register to store an output matrix; and
an array of compute elements (CEs), coupled to the first scalar register, the first vector register, the second scalar register, the second vector register and the output register, each CE calculating a dot product of the ith row of the first compressed matrix and the jth column of the second compressed matrix, based on the first bitmap and the second bitmap, to generate an element i,j of the output matrix.

### Claim 10 (depends on 9)

The matrix multiply accelerator according to claim 9, where each CE includes:
a first multiplexer to receive a row of the first compressed matrix, the row including a plurality of first elements, and to selectively output each of the first elements of the row based on a first data selection signal;
a second multiplexer to receive a column of the second compressed matrix, the column including a plurality of second elements, and to selectively output each of the second elements of the column based on a second data selection signal;
a data selection circuit, coupled to the first multiplexer and the second multiplexer, to receive the first bitmap and the second bitmap, to generate the first data selection signal based on the first bitmap, and to generate the second data selection signal based on the second bitmap;
a multiplier circuit, coupled to the first multiplexer and the second multiplexer, to receive the first elements selectively output by the first multiplexer and the second elements selectively output by the second multiplexer, to multiply respective first elements and second elements to generate respective intermediate products, and to output the respective intermediate products; and
an accumulator circuit, coupled to the multiplier circuit, to receive the respective intermediate products, and to accumulate the respective intermediate products into a value for one element of the output matrix.

### Claim 11 (depends on 9)

The matrix multiply accelerator according to claim 9, where:
the first matrix has m rows and n columns, the first compressed matrix has m rows and c columns, and n is a multiple of c;
the second matrix has n rows and p columns, and the second compressed matrix has c rows and p columns;
the output matrix has m rows and p columns; and
i goes from 1 to m, and j goes from 1 to p.

### Claim 12 (depends on 11)

The matrix multiply accelerator according to claim 11, where said calculate the dot product of the ith row of the first compressed matrix and the jth column of the second compressed matrix based on the first bitmap and the second bitmap includes:
when the bit position in the first bitmap corresponding to an element i,k of the ith row of the first compressed matrix has the value of 1 and when the bit position in the second bitmap corresponding to an element k,j of the jth column of the second compressed matrix has the value of 1, multiplying the element i,k and the element k,j to generate an intermediate product;
when the bit position in the first bitmap corresponding to an element i,k of the ith row of the first compressed matrix has the value of 0 or when the bit position in the second bitmap corresponding to an element k,j of the jth column of the second compressed matrix has the value of 0, not multiplying the element i,k and the element k,j; and
accumulating the intermediate products to generate the element i,j,
where k goes from 1 to c.

### Claim 13 (depends on 12)

The matrix multiply accelerator according to claim 12, where a first number of non-zero elements in the first matrix is equal to or less than c times m, and a second number of non-zero elements in the second matrix is equal to or less than c times p.

### Claim 14

A computer-based method for multiplying matrices, comprising:
at a processor coupled to a memory:
generating a first bitmap based on a first matrix, the first bitmap having a plurality of bit positions, each bit position corresponding to a different element of the first matrix, each bit position having a value of 1 when a value of the corresponding element of the first matrix is not 0, and a value of 0 when the value of the corresponding element of the first matrix is 0;
compressing the first matrix into a first compressed matrix, the first compressed matrix including fewer elements having a value of 0 than the first matrix;
adjusting the first bitmap based on the first compressed matrix;
generating a second bitmap based on a second matrix, the second bitmap having a plurality of bit positions, each bit position corresponding to a different element of the second matrix, each bit position having the value of 1 when a value of the corresponding element of the second matrix is not 0, and the value of 0 when the value of the corresponding element of the second matrix is 0;
compressing the second matrix into a second compressed matrix, the second compressed matrix including fewer elements having a value of 0 than the second matrix;
adjusting the second bitmap based on the second compressed matrix; and
at a matrix multiply accelerator (MMA) coupled to the processor and the memory:
multiplying the first compressed matrix and the second compressed matrix, based on the first bitmap and the second bitmap, to generate an output matrix, including:
for each element i,j in the output matrix, calculating a dot product of the ith row of the first compressed matrix and the jth column of the second compressed matrix based on the first bitmap and the second bitmap.

### Claim 15 (depends on 14)

The computer-based method according to claim 14, where:
the first matrix has m rows and n columns, the first compressed matrix has m rows and c columns, and n is a multiple of c;
the second matrix has n rows and p columns, and the second compressed matrix has c rows and p columns;
the output matrix has m rows and p columns; and
i goes from 1 to m, and j goes from 1 to p.

### Claim 16 (depends on 15)

The computer-based method according to claim 15, where said calculating the dot product of the ith row of the first compressed matrix and the jth column of the second compressed matrix based on the first bitmap and the second bitmap includes:
when the bit position in the first bitmap corresponding to an element i,k of the ith row of the first compressed matrix has the value of 1 and when the bit position in the second bitmap corresponding to an element k,j of the jth column of the second compressed matrix has the value of 1, multiplying the element i,k and the element k,j to generate an intermediate product;
when the bit position in the first bitmap corresponding to an element i,k of the ith row of the first compressed matrix has the a value of 0 or when the bit position in the second bitmap corresponding to an element k,j of the jth column of the second compressed matrix has the value of 0, not multiplying the element i,k and the element k,j; and
accumulating the intermediate products to generate the element i,j,
where k goes from 1 to c.

### Claim 17 (depends on 16)

The computer-based method according to claim 16, where:
said compressing the first matrix into the first compressed matrix includes:
beginning with an element located at a first row and a first column of the first matrix, moving each element of the first matrix that has a non-zero value into the first compressed matrix in row major order, and
when a row of the first matrix has less than c elements that have a non-zero value, moving one or more elements of the first matrix that have a zero value into the first compressed matrix so that the corresponding row of the first compressed matrix has c elements;
said adjusting the first bitmap based on the first compressed matrix includes changing the corresponding bit values in the first bit map, for said one or more elements of the first matrix that have a zero value, from 0 to 1;
said compressing the second matrix into the second compressed matrix includes:
beginning with an element located at a first row and a first column of the second matrix, moving each element of the second matrix that has a non-zero value into the second compressed matrix in column major order, and
when a column of the second matrix has less than c elements that have a non-zero value, moving one or more elements that have a zero value into the second compressed matrix so that the corresponding column of the second compressed matrix has c elements; and
said adjusting the second bitmap based on the second compressed matrix includes changing the corresponding bit values in the second bit map, for said one or more elements of the second matrix that have a zero value, from 0 to 1.

### Claim 18 (depends on 17)

The computer-based method according to claim 17, where a first number of non-zero elements in the first matrix is equal to or less than c times m, and a second number of non-zero elements in the second matrix is equal to or less than c times p.

### Claim 19 (depends on 14)

The computer-based method according to claim 14, where said compressing the first matrix into the first compressed matrix is performed in place, and said compressing the second matrix into the second compressed matrix is performed in place.
