IP Library › Granted Patent US 11,334,648
Granted Patent B2
US 11,334,648 · App. 16/915,915 · Granted May 17, 2022

Matrix multiplier

Inventors: Hu Liu (Shenzhen, CN); Heng Liao (Shanghai, CN); Jiajin Tu (Shenzhen, CN); Honghui Yuan (Hangzhou, CN); Hou Fun Lam (Hong Kong, CN); Fan Zhu (Shenzhen, CN)
Assignee: HUAWEI TECHNOLOGIES CO., LTD.
G06F17/16
View Patent ↗
Loading inventors, assignments & file history…
Monitor This Case
Get email alerts when status or documents change.
Order Certified Copies
Most orders are placed with the USPTO same day — all within 24 business hours.
Order via The Patent Place →
Pre-filled with this patent's details
Quick Facts
Patent No.
US 11,334,648
App. No.
16/915,915
Granted
May 17, 2022
Kind
B2
Abstract

Embodiments of the present invention disclose a matrix multiplier, and relate to the field of data computing technologies, so as to divide two matrices into blocks for computation. The matrix multiplier includes: a first memory, a second memory, an operation circuit, and a controller, where the operation circuit, the first memory, and the second memory may perform data communication by using a bus; and the controller is configured to control, according to a preset program or instruction, a first matrix and a second matrix to be divided into blocks, and control the operation circuit to perform a multiplication operation on corresponding blocks in the first memory and the second memory based on block division results of the controller. The matrix multiplier may be configured to perform a multiplication operation on two matrices.

Claims (149)

1. A matrix multiplier, comprising:

a first memory, configured to store a first matrix, wherein the first matrix is an M*K matrix;

a second memory, configured to store a second matrix, wherein the second matrix is a K*N matrix;

an operation circuit connected to the first memory and the second memory, wherein the operation circuit comprises operation units of X rows and Y columns, and each operation unit comprises a vector multiplication circuit and an addition circuit, wherein the vector multiplication circuit is configured to receive row vector data sent by the first memory and column vector data sent by the second memory, and multiply the two vectors; and the addition circuit is configured to add results obtained by multiplying the two vectors, and accumulate computation results of a same operation unit, to obtain an operation result of each operation unit; and

a controller connected to the operation circuit, wherein the controller is configured to perform the following actions:

dividing the first matrix into blocks in a unit of a sub-block whose size is X*L, to obtain S×R sub-blocks of a same size, wherein a sub-block in a row s and a column r of the S×R sub-blocks is denoted as A sr , s=(1, 2, 3, . . . , and S), and r=(1, 2, 3, . . . , and R); and

dividing the second matrix into blocks in a unit of a sub-block whose size is L*Y, to obtain R×T sub-blocks of a same size, wherein a sub-block in a row r and a column t in the R×T sub-blocks is denoted as B rt , r=(1, 2, 3, . . . , and R), and t=(1, 2, 3, . . . , and T); wherein

the controller is further configured to perform the following action:

inputting a row x in X row vectors of any sub-block A sr and a column y in Y column vectors of a corresponding sub-block B rt into an operation unit in a row x and a column y in the operation units of X rows and Y columns, so as to perform an operation, wherein x=(1, 2, 3, . . . , and X), y=(1, 2, 3, . . . , and Y), and r in the any sub-block A sr and r in the corresponding sub-block B rt have an equal value.

2. The matrix multiplier according to claim 1 , wherein the controller is specifically configured to perform the following action:

inputting the row x in the X row vectors of the any sub-block A sr and the column y in the Y column vectors of the corresponding sub-block B rt into the operation unit in a row x and a column y in the operation units of X rows and Y columns in parallel in a same clock cycle, so as to perform the operation.

3. The matrix multiplier according to claim 1 , wherein

the controller is further configured to control row vectors of the any sub-block A sr to successively enter, in ascending order of x row numbers, a row x corresponding to the operation units of X rows and Y columns, wherein a difference between moments at which adjacent row vectors enter operation units in a same column and different rows is one clock cycle; and the controller is further configured to simultaneously control column vectors of the corresponding sub-block B rt to successively enter, in ascending order of y column numbers, a column y corresponding to the operation units of X rows and Y columns, wherein a difference between moments at which adjacent column vectors enter operation units in a same row and different columns is one clock cycle.

4. The matrix multiplier according to claim 1 , wherein the controller is further configured to control:

values of s and r to remain unchanged and a value of t to be changed in at least two consecutive sub-block multiplication computation cycles, so that the first memory reuses a same sub-block A sr within the at least two consecutive sub-block multiplication computation cycles, wherein the sub-block multiplication computation cycle is a time used by the operation units of X rows and Y columns to complete a matrix multiplication operation on one sub-block A sr and a corresponding sub-block B rt .

5. The matrix multiplier according to claim 1 , wherein the matrix multiplier further comprises a third memory connected to the operation circuit; and

the controller is configured to control the operation units of X rows and Y columns to store operation results of the vector multiplication circuit and the addition circuit into the third memory.

6. The matrix multiplier according to claim 5 , wherein the matrix multiplier further comprises: a fourth memory connected to the first memory and the second memory, and a fifth memory connected to the third memory; and

the controller is further configured to control: before performing a multiplication operation on the first matrix and the second matrix,

data sources of the first matrix and the second matrix to be moved from the fourth memory to the first memory and the second memory respectively, and the computation results to be moved from the third memory to the fifth memory.

7. The matrix multiplier according to claim 1 , wherein the vector multiplication circuit comprises L multipliers, and the addition circuit comprises an adder tree with an input quantity being L+1.

8. The matrix multiplier according to claim 1 , wherein

the first memory, the second memory, the operation circuit, and the controller are connected by using a bus interface unit.

9. The matrix multiplier according to claim 1 , wherein

S

=

{

M

/

X

,

M

⁢

%

⁢

X

=

0

[

M

X

]

+

1

,

M

⁢

%

⁢

X

≠

0

,

and

⁢

⁢

R

=

{

K

/

L

,

K

⁢

%

⁢

L

=

0

[

K

L

]

+

1

,

K

⁢

%

⁢

L

≠

0

;

when M % X≠0, computation is not performed on a row (M+1) to a row (S*X−M) of the first matrix, and a value of a result is assigned 0; and when K % Y≠0, computation is not performed on a column (K+1) to a column (R*Y−K) of the first matrix, and a value of a result is assigned 0.

10. The matrix multiplier according to claim 1 , wherein

R

=

{

K

/

L

,

K

⁢

%

⁢

L

=

0

[

K

L

]

+

1

,

K

⁢

%

⁢

L

≠

0

,

and

⁢

⁢

T

=

{

N

/

Y

,

N

⁢

%

⁢

Y

=

0

[

N

Y

]

+

1

,

N

⁢

%

⁢

Y

≠

0

;

when K % Y≠0, computation is not performed on a column (K+1) to a column (R*Y−K) of the first matrix, and a value of a result is assigned 0; and when N % X≠0, computation is not performed on a row (N+1) to a row (T*X−N) of the first matrix, and a value of a result is assigned 0.

Priority Claims (1)
CN 201711499179.X · Dec 29, 2017 · national
Continuity (2)
Continuation PCTCN2018111077 · Oct 19, 2018
Related Publication 20200334322A1 · Oct 22, 2020