WO2020061762A1 - 数据处理装置和方法 - Google Patents

数据处理装置和方法 Download PDF

Info

Publication number
WO2020061762A1
WO2020061762A1 PCT/CN2018/107393 CN2018107393W WO2020061762A1 WO 2020061762 A1 WO2020061762 A1 WO 2020061762A1 CN 2018107393 W CN2018107393 W CN 2018107393W WO 2020061762 A1 WO2020061762 A1 WO 2020061762A1
Authority
WO
WIPO (PCT)
Prior art keywords
matrix
elements
row
multiply
data processing
Prior art date
Application number
PCT/CN2018/107393
Other languages
English (en)
French (fr)
Inventor
吴穹蔗
仇晓颖
韩彬
Original Assignee
深圳市大疆创新科技有限公司
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by 深圳市大疆创新科技有限公司 filed Critical 深圳市大疆创新科技有限公司
Priority to CN201880037874.0A priority Critical patent/CN110770697A/zh
Priority to PCT/CN2018/107393 priority patent/WO2020061762A1/zh
Publication of WO2020061762A1 publication Critical patent/WO2020061762A1/zh

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F7/00Methods or arrangements for processing data by operating upon the order or content of the data handled
    • G06F7/38Methods or arrangements for performing computations using exclusively denominational number representation, e.g. using binary, ternary, decimal representation
    • G06F7/48Methods or arrangements for performing computations using exclusively denominational number representation, e.g. using binary, ternary, decimal representation using non-contact-making devices, e.g. tube, solid state device; using unspecified devices
    • G06F7/52Multiplying; Dividing
    • G06F7/523Multiplying only
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F17/00Digital computing or data processing equipment or methods, specially adapted for specific functions
    • G06F17/10Complex mathematical operations
    • G06F17/16Matrix or vector computation, e.g. matrix-matrix or matrix-vector multiplication, matrix factorization

Definitions

  • the present application relates to the field of data processing, and more particularly, to a data processing apparatus and method.
  • Matrix multiplication is a common arithmetic operation, which is essentially a multiply-accumulate operation between matrix elements.
  • many data processing devices are internally provided with a special multiply and accumulate (MAC) unit.
  • MAC multiply and accumulate
  • a conventional data processing device usually uses a multiply-accumulate unit to calculate the value of each element in the matrix C one by one. This processing method sometimes results in a low utilization of the multiply-accumulate unit.
  • the present application provides a data processing device and method to improve the utilization rate of the multiply-accumulate unit in the data processing device.
  • a data processing method is provided.
  • the control unit inside the data processing device sequentially performs a multiplication operation corresponding to the ith column element in the s row element in the matrix A and the ith row element in the t column element in the matrix B.
  • the number of multiplication operations corresponding to the i-th column element in the t-th element in the matrix B is exactly equal to k times. Therefore, in the process of calculating the value of the k target elements, k multiply-accumulate units It can be used 100% every time, which improves the utilization of the multiply-accumulate unit.
  • FIG. 1 is a schematic diagram of a conventional calculation method of matrix multiplication.
  • FIG. 2 is a schematic structural diagram of a data processing apparatus according to an embodiment of the present application.
  • FIG. 3 is a schematic diagram of a matrix block manner provided by an embodiment of the present application.
  • FIG. 4 is a schematic diagram of a matrix block manner provided by another embodiment of the present application.
  • FIG. 5 is a schematic diagram of a matrix element multiplication method provided by an embodiment of the present application.
  • FIG. 6 is a schematic diagram of a matrix element multiplication method provided by another embodiment of the present application.
  • FIG. 7 is a schematic diagram of a matrix element multiplication method provided by another embodiment of the present application.
  • FIG. 8 is a schematic diagram of a matrix element multiplication method provided by another embodiment of the present application.
  • FIG. 9 is a schematic diagram of a matrix element multiplication method according to another embodiment of the present application.
  • FIG. 10 is a calculation flowchart of matrix multiplication provided by an embodiment of the present application.
  • FIG. 11 is a flowchart of a data processing method according to an embodiment of the present application.
  • One or more multiply-accumulate units are usually provided inside a data processing device that supports matrix multiplication operations.
  • Multiply-accumulate units are sometimes referred to as multiply-accumulators and can be used exclusively to perform multiply-accumulate operations.
  • the multiply-accumulate unit can usually complete a multiplication and an addition operation in the same clock cycle (or instruction cycle).
  • the data processing device may be, for example, a digital signal processor (DSP), or a neural network processor for performing a convolution operation in a neural network system.
  • DSP digital signal processor
  • a neural network processor for performing a convolution operation in a neural network system.
  • DSP digital signal processor
  • common operations performed by DSP include power calculation, difference operation, and filter operation. These operations are all multiplication and accumulation operations in the final analysis. Therefore, in the DSP, multiple multiply-accumulate units are usually set, such as 8 or 16 multiply-accumulate units.
  • the convolution operation is actually a matrix multiplication. In the final analysis, it is a multiply-accumulate operation. Therefore, similar to the DSP, multiple multiply-accumulate units can be set inside the neural network processor.
  • the conventional calculation method is to use the multiply and accumulate unit to calculate the value of each element in matrix C one by one in rows or columns.
  • the conventional calculation method in order to obtain the value of each element in matrix C, the conventional calculation method usually first uses the 0th row element of matrix A and the 0th column element of matrix B to calculate The value of element C 00 .
  • the traditional data processing device usually uses the 16 multiply-accumulate unit to perform 16 multiply-accumulate operations in the first clock cycle (each multiply-accumulate unit performs a multiply operation), and In the second clock cycle, one multiply-accumulate unit is used to separately perform the remaining one multiply-accumulate operation, and the remaining 15 multiply-accumulate units are idle.
  • FIG. 2 is a schematic structural diagram of a data processing apparatus according to an embodiment of the present application.
  • the embodiment of the present application does not specifically limit the type of the data processing device 20, and may be a DSP or other operation units that need to support matrix multiplication operations, such as a neural network processor for performing a convolution operation.
  • the data processing device 20 may include k multiply-accumulate units 22 and a control unit 24.
  • the value of k is not specifically limited in this application.
  • k can be any positive integer not less than 1.
  • k may be greater than or equal to two.
  • k can be an integer multiple of 2, for example, k can be equal to 8 or 16.
  • control unit 24 may first read from the storage device one of the n-column elements in the s-row element and one of the n-column elements in the t-row element, and then execute k times using the k multiply-accumulate units.
  • the control unit 24 can read from the storage device the remaining n-1 column elements in the s-row element and select one of the elements in column t and the elements in column t Select 1 row of the remaining n-1 rows of elements, and then use k multiply and accumulate units to perform k multiplication operations again (that is, each multiply and accumulate unit performs 1 multiplication operation); perform n times in a similar manner, and The multiplication operation corresponding to the n-th element in the s-row element and the n-th element in the t-row element is completed. It can be understood that during the execution of the multiplication operation, the k multiplication and accumulation units can continuously add the current multiplication result to the previous multiplication result, and finally obtain the values of the k target elements in the matrix C.
  • the matrix A is a 4 ⁇ 2 matrix
  • the matrix C may include a 4 ⁇ 4 block matrix D.
  • the 16 elements C 00 to C 33 in the block matrix D can be used as 16 target elements. The solution process of the 16 target elements is described in detail below.
  • this embodiment does not calculate the values of the 16 target elements one by one based on the four rows of elements in the matrix A and the four columns of the matrix B, but calculates the values of the 16 target elements in parallel. For example, you can calculate the multiplication operation between the 0th column element (that is, A 00 to A 30 ) of the 4 row elements of the matrix A and the 0th row element (that is, B 00 to B 03 ) of the 4 column elements of the matrix B Then, calculate a multiplication operation between the elements of the first column of the matrix A (that is, A 01 to A 31 ) and the elements of the first row of the matrix B (that is, B 10 to B 13 ).
  • the multiplication operation that needs to be performed between the element in column 0 and the element in row 0 of the 4 column element of matrix B is exactly k times: A 00 ⁇ B 00 , A 00 ⁇ B 01 , A 00 ⁇ B 02 , A 00 ⁇ B 03 , A 10 ⁇ B 00 , A 10 ⁇ B 01 , A 10 ⁇ B 02 , A 10 ⁇ B 03 , A 20 ⁇ B 00 , A 20 ⁇ B 01 , A 20 ⁇ B 02 , A 20 ⁇ B 03 , A 30 ⁇ B 00 , A 30 ⁇ B 01 , A 30 ⁇ B 02 , A 30 ⁇ B 03 .
  • the k multiplication and accumulation units can perform k multiplication operations each time, so that k
  • the multiply-accumulate unit can perform all multiplication operations corresponding to k target elements with a utilization rate of 100%, thereby improving the utilization of the multiply-accumulate unit.
  • the matrix A is a matrix of 10 ⁇ 100
  • the matrix C can be divided into blocks as shown in FIG. 4 to form 2 ⁇ 23 block matrices D, where the 16 elements in each block matrix D can be used as 16 Target element.
  • the solution of the upper-left block matrix D in matrix C needs to depend on the first 4 rows of elements of matrix A and the first 4 columns of elements of matrix B.
  • this embodiment does not calculate the 16 target elements in the block matrix D one by one based on the 4 rows of elements in the matrix A and the 4 columns of the elements of the matrix B. Values, but the values of the 16 target elements are calculated in parallel.
  • the specific calculation method of the block matrix D is the same as the calculation method of the 16 target elements in FIG. 3, and will not be described in detail here. With this calculation method, during the calculation of 16 target elements in each block matrix D, k multiply-accumulate units can be used 100%.
  • the embodiment of this application changes the multiplication order of these elements.
  • the conventional way of multiplying a row of elements of matrix A by a column of elements of matrix B is changed to: sequentially execute the i-th element in s-row elements in matrix A and the i-th element in t-elements in matrix B
  • the corresponding multiplication operation Since the number of multiplication operations corresponding to the ith column element in the s row element in matrix A and the ith row element in the t column element in matrix B is exactly equal to k times, the k multiplication and accumulation units can be 100% use.
  • the embodiment of the present application can improve the utilization rate of the multiply-accumulate unit in the data processing device 20, and further improve the efficiency of matrix multiplication.
  • the matrix C may include only k target elements, and the matrix C may be obtained after calculating the values of the target elements in the matrix C.
  • the matrix C may include the remaining elements other than the target element.
  • the remaining elements may be elements outside the dashed box of the matrix C, that is, elements C 04 -C 34 .
  • the calculation method of these remaining elements is not specifically limited in the embodiment of the present application, and calculation can be performed according to a conventional calculation method similar to FIG. 1, that is, calculating the value of each element of the remaining elements one by one.
  • control unit 24 controls the k multiply-accumulate units to sequentially perform k multiplication operations corresponding to the ith column element in the s row element and the ith row element in the t column element.
  • the k-times multiplication operation corresponding to one column element in the s row element and one row element in the t column element may be referred to as a row and column element multiplication operation. Since the matrix A has n columns, in order to obtain the values of the k target elements, the control unit 24 needs to perform n times of column and column element multiplication operations in total.
  • the embodiment of the present application does not specifically limit the execution order of the n-time row and column element multiplication operations, and may be performed sequentially according to the i value from small to large, or may be performed sequentially from the i value from large to small, or It can also be performed in a random manner, as long as it ensures that n times the column and column element multiplication operations are performed.
  • control unit 24 may control the k multiplication and accumulation units to perform the row and column element multiplication operation once every clock cycle (or instruction cycle). In this way, n In the clock cycle, n times of row and column element multiplication operations can be completed, and the results of the multiplication operation are continuously accumulated to obtain the values of k target elements.
  • the control unit 24 may control the multiply-accumulate unit to perform a corresponding operation according to an instruction.
  • the instruction may be an instruction sent by an external processor to the control unit 24, or the control unit 24 may generate an instruction by itself.
  • the positions of the k target elements in the matrix C are not specifically limited, and may be any k elements of s rows and t columns distributed in the matrix C.
  • the k target elements may be adjacent elements in the matrix C, that is, elements in the block matrix D in the matrix C.
  • the control unit 24 may first determine the division mode of the matrix A and the matrix B according to the number of multiplication and accumulation units in the data processing device, so that the division matrix in the matrix A is a matrix of s rows and n columns.
  • Each block matrix in B is a matrix of n rows and t columns.
  • the blocking mode of the matrix A and the matrix B is determined, the product of the matrix A and the matrix B is a blocking matrix D.
  • every 4 rows and 100 columns in matrix A form a block matrix
  • every 100 rows and 4 columns of matrix B form a block matrix.
  • matrix C The form of the block matrix D in is also determined.
  • the positions of the k target elements in the matrix C may not be adjacent.
  • the 16 target elements may be composed of the elements of the first, second, third, and fifth columns of the matrix C; or the first, second, and fourth columns of the matrix C 5th column element composition.
  • this application does not require that the k target elements are necessarily located in the same block matrix of the matrix C, and these target elements may be spaced from each other as long as they are distributed in the s rows and t columns of the matrix C.
  • the k multiply-accumulate units 12 can calculate the value of k target elements in the block matrix D with 100% utilization rate, the more the block matrix D decomposed by the matrix C, the more the multiply-accumulate unit utilization rate The higher.
  • the blocking of the matrix C can make the matrix C satisfy the following conditions: the matrix C includes u ⁇ v block matrices D, and m 1 -s ⁇ u ⁇ s ⁇ m 1 , and / Or m 2 -t ⁇ v ⁇ t ⁇ m 2 , where u and v are both positive integers not less than 1.
  • m 1 -s ⁇ u ⁇ s ⁇ m 1 means that after partitioning, the number of remaining rows of matrix C is less than s. Therefore, matrix C cannot be further divided in the direction of s ⁇ t in the row direction, that is, matrix C has been divided in the row direction. It is fully divided in the form of s ⁇ t.
  • m 2 -t ⁇ v ⁇ t ⁇ m 2 means that after partitioning, the number of remaining columns of matrix C is less than t. Therefore, matrix C cannot be further divided in the column direction according to s ⁇ t, that is, matrix C It has been sufficiently divided in the column direction in the manner of s ⁇ t.
  • k 16
  • s and t are 4
  • the values of u and v can be set to 2 and 23 respectively, so that m 1 -s ⁇ u ⁇ s ⁇ m 1 and m 2 -t ⁇ v ⁇ t ⁇ m 2 .
  • u represents that the matrix C is divided into two block matrices D in the row direction. Since the number of rows of the matrix C is 10, after the matrix C is divided into two block matrices D in the row direction, the remaining number of rows is 2, and a 4 ⁇ 4 block matrix D cannot be further divided in the row direction.
  • v represents that the matrix C is divided into 23 block matrices D in the column direction. Since the number of rows of the matrix C is 94, after the matrix C is divided into 23 block matrices D in the column direction, the remaining number of columns is 2, and a 4 ⁇ 4 block matrix D cannot be further divided in the column direction. .
  • different values of s and t may make the maximum number of divided block matrices D different, thereby making the number of remaining elements of matrix C different.
  • the values of s and t can be determined according to the number of rows m 1 of the matrix A and the number of columns m 2 of the matrix B.
  • the values of s and t can be determined according to the number of rows m 1 of the matrix A and the number of columns m 2 of the matrix B, so that the difference between m 1 ⁇ m 2 and u ⁇ s ⁇ v ⁇ t is minimized.
  • the above description is based on the example of dividing the block matrix D of the same form from the matrix C.
  • the block matrix D of different forms can also be divided from the matrix C (
  • the different forms mentioned here refer to different numbers of rows and columns, but the product of the number of rows and columns is still k).
  • a 2 ⁇ 23 block matrix D can be divided in a 4 ⁇ 4 manner.
  • the remaining elements such as the 2 ⁇ 92 elements located at the bottom of the matrix C, although they cannot be further divided in a 4 ⁇ 4 manner, they can still be further divided in the form of 2 ⁇ 8 or 1 ⁇ 16; similarly, for the matrix located at the matrix
  • the 10 ⁇ 2 elements on the right side of C, although they cannot be further divided in a 4 ⁇ 4 manner, can still be further divided in an 8 ⁇ 2 manner.
  • the elements of matrix A and matrix B that need to be multiplied in each clock cycle can be 16 in a column of matrix A
  • the number of multiplication operations that need to be performed between the element and one element in a row of matrix B is exactly 16 times. Therefore, the 16 multiply-accumulate units can be completed in one clock cycle.
  • Fig. 5 shows an example of 16 elements in a matrix A and 1 element in a matrix B that need to be multiplied.
  • FIG. 6 shows an example of 8 elements in a matrix A and 2 elements in a matrix B that need to be multiplied.
  • FIG. 7 shows an example of four elements in a matrix A and four elements in a matrix B that need to be multiplied.
  • FIG. 8 shows an example of 2 elements in a matrix A and 8 elements in a matrix B that need to be multiplied.
  • the elements of matrix A and matrix B that need to be multiplied in each clock cycle can be 1 in a column of matrix A
  • the number of multiplication operations to be performed between the element and the 16 elements in a row of matrix B is exactly 16 times. Therefore, the 16 multiply-accumulate units can be completed in one clock cycle.
  • FIG. 9 shows an example of 1 element in the matrix A and 16 elements in the matrix B that need to be multiplied.
  • s and t need to be determined according to the actual situation of the matrix C, and some combination of values of s and t may not be suitable for the matrix C with a small size.
  • the control unit 24 may control the k multiply-accumulate units to sequentially calculate the value of each element in the matrix C in a conventional manner.
  • control unit 24 may control k multiply-accumulate units to sequentially calculate the selection of each element in matrix C in a conventional manner. value.
  • control unit 24 may control k multiplication and accumulation units to sequentially calculate matrix C in a conventional manner. The value of each element in.
  • control unit 24 may According to the manner provided in the embodiment of the present application, the k multiply-accumulate units are controlled to perform k multiplication operations corresponding to the i-th element in the s row element and the i-th element in the t column element.
  • the determination of the relationship between m 1 , m 2 , n, and k, and the block manner of the matrix C can be performed by the control unit 24 in the data processing device 20 or by a processor external to the data processing device 20.
  • the implementation of this application Examples are not limited to this.
  • FIG. 10 includes steps 101 to 105.
  • step 101 it is determined whether the number of columns n of the matrix C is a multiple of 16.
  • n is a multiple of 16, go to step 105; if n is not a multiple of 16, go to step 102.
  • step 102 it is determined whether the product of the number of rows m 1 of the matrix A and the number of columns m 2 of the matrix B is 16 or less.
  • step 105 is performed; if m 1 ⁇ m 2 > 16, step 103 is performed.
  • step 103 a block manner of the matrix C is selected according to the values of m 1 and m 2 .
  • partition matrices D can be divided from the matrix C, where each partition matrix D can include k target elements.
  • each partition matrix D can include k target elements.
  • step 104 the values of k target elements in each block matrix D are sequentially calculated.
  • the matrix multiplication method provided in the embodiment of the present application may be used to calculate the values of the k target elements in parallel.
  • step 105 the values of the elements in the matrix C are calculated one by one in a conventional calculation manner.
  • the data processing method provided by the embodiment of the present application is described in detail below with reference to FIG. 11.
  • This method can be executed by the control unit 24 in the data processing device 20.
  • the matrix C includes a block matrix D
  • the block matrix D is a matrix of s ⁇ t
  • k target elements are elements in the block matrix D.
  • the matrix C includes u ⁇ v pieces of the block matrix D, and m 1 -s ⁇ u ⁇ s ⁇ m 1 , m 2 -t ⁇ v ⁇ t ⁇ m 2 , where u and v are both Is a positive integer not less than 1.
  • the method of FIG. 11 may further include: determining the values of s and t according to the number of rows m 1 of the matrix A and the number of columns m 2 of the matrix B, such that m 1 ⁇ m 2 and u ⁇ s ⁇ v ⁇ The difference in t is the smallest.
  • step 1110 may include: if m 1 ⁇ m 2 ⁇ n is greater than k, and n is not an integer multiple of k, controlling k multiply-accumulate units to execute the i-th column element in the s row element and the k multiplication operations corresponding to the i-th row element in the t column element; the method of FIG. 11 may further include: if n is an integer multiple of k or m 1 ⁇ m 2 is less than k, controlling k multiplication and accumulation units to sequentially calculate the The value of each element in matrix C.
  • the computer program product includes one or more computer instructions.
  • the computer may be a general-purpose computer, a special-purpose computer, a computer network, or other programmable devices.
  • the computer instructions may be stored in a computer-readable storage medium or transmitted from one computer-readable storage medium to another computer-readable storage medium, for example, the computer instructions may be from a website site, computer, server, or data center Transmission by wire (such as coaxial cable, optical fiber, digital subscriber line (DSL)) or wireless (such as infrared, wireless, microwave, etc.) to another website site, computer, server, or data center.
  • the computer-readable storage medium may be any available medium that can be accessed by a computer or a data storage device such as a server, a data center, and the like that includes one or more available medium integration.
  • the usable medium may be a magnetic medium (for example, a floppy disk, a hard disk, a magnetic tape), an optical medium (for example, a digital video disc (DVD)), or a semiconductor medium (for example, a solid state disk (SSD)), etc. .
  • a magnetic medium for example, a floppy disk, a hard disk, a magnetic tape
  • an optical medium for example, a digital video disc (DVD)
  • DVD digital video disc
  • SSD solid state disk
  • the disclosed systems, devices, and methods may be implemented in other ways.
  • the device embodiments described above are only schematic.
  • the division of the unit is only a logical function division.
  • multiple units or components may be combined or Can be integrated into another system, or some features can be ignored or not implemented.
  • the displayed or discussed mutual coupling or direct coupling or communication connection may be indirect coupling or communication connection through some interfaces, devices or units, which may be electrical, mechanical or other forms.
  • the units described as separate components may or may not be physically separated, and the components displayed as units may or may not be physical units, may be located in one place, or may be distributed on multiple network units. Some or all of the units may be selected according to actual needs to achieve the objective of the solution of this embodiment.
  • each functional unit in each embodiment of the present application may be integrated into one processing unit, or each of the units may exist separately physically, or two or more units may be integrated into one unit.

Landscapes

  • Engineering & Computer Science (AREA)
  • Physics & Mathematics (AREA)
  • General Physics & Mathematics (AREA)
  • Theoretical Computer Science (AREA)
  • Computational Mathematics (AREA)
  • Mathematical Analysis (AREA)
  • Mathematical Optimization (AREA)
  • Pure & Applied Mathematics (AREA)
  • Mathematical Physics (AREA)
  • General Engineering & Computer Science (AREA)
  • Computing Systems (AREA)
  • Data Mining & Analysis (AREA)
  • Algebra (AREA)
  • Databases & Information Systems (AREA)
  • Software Systems (AREA)
  • Complex Calculations (AREA)

Abstract

提供一种数据处理装置和方法。该数据处理装置能够用于计算矩阵C=矩阵A×矩阵B,其中矩阵A为m 1×n的矩阵,矩阵B为n×m 2的矩阵。该数据处理装置包括k个乘累加单元和控制单元。该控制单元用于执行以下操作:在根据矩阵A中的s行元素和矩阵B中的t列元素计算矩阵C中的k个目标元素的取值的过程中,控制k个乘累加单元依次执行s行元素中的第i列元素与t列元素中的第i行元素对应的k次乘法操作,k=s×t,0≤i<n。由于矩阵A中的s行元素中的第i列元素与矩阵B中的t列元素中的第i行元素对应的乘法操作的数量刚好等于k次,因此,在计算k个目标元素的取值的过程中,k个乘累加单元每次都可以被100%利用。

Description

数据处理装置和方法
版权申明
本专利文件披露的内容包含受版权保护的材料。该版权为版权所有人所有。版权所有人不反对任何人复制专利与商标局的官方记录和档案中所存在的该专利文件或者该专利披露。
技术领域
本申请涉及数据处理领域,并且更为具体地,涉及一种数据处理装置和方法。
背景技术
矩阵乘法是一种常见的运算操作,本质上是矩阵元素之间的乘累加操作。为了加快矩阵乘法的运算速度,许多数据处理装置内部设置有专门的乘累加(multiply and accumulate,MAC)单元。
以矩阵C=矩阵A×矩阵B为例,传统数据处理装置通常利用乘累加单元逐个计算矩阵C中的每个元素的取值,这种处理方式有时会导致乘累加单元的利用率低。
发明内容
本申请提供一种数据处理装置和方法,以提高数据处理装置中的乘累加单元的利用率。
第一方面,提供一种数据处理装置,所述数据处理装置能够用于计算矩阵C=矩阵A×矩阵B,其中所述矩阵A为m 1×n的矩阵,所述矩阵B为n×m 2的矩阵,所述数据处理装置包括:k个乘累加单元;控制单元,用于执行以下操作:在根据所述矩阵A中的s行元素和所述矩阵B中的t列元素计算所述矩阵C中的k个目标元素的取值的过程中,控制k个乘累加单元依次执行所述s行元素中的第i列元素与所述t列元素中的第i行元素对应的k次乘法操作,k=s×t,0≤i<n。
第二方面,提供一种数据处理方法,所述方法能够用于计算矩阵C=矩阵A×矩阵B,其中所述矩阵A为m 1×n的矩阵,所述矩阵B为n×m 2的矩阵, 所述方法包括:在根据所述矩阵A中的s行元素和所述矩阵B中的t列元素计算所述矩阵C中的k个目标元素的取值的过程中,控制k个乘累加单元依次执行所述s行元素中的第i列元素与所述t列元素中的第i行元素对应的k次乘法操作,k=s×t,0≤i<n。
数据处理装置内部的控制单元依次执行矩阵A中的s行元素中的第i列元素与矩阵B中的t列元素中的第i行元素对应的乘法操作,由于矩阵A中的s行元素中的第i列元素与矩阵B中的t列元素中的第i行元素对应的乘法操作的数量刚好等于k次,因此,在计算k个目标元素的取值的过程中,k个乘累加单元每次都可以被100%利用,从而提高了乘累加单元的利用率。
附图说明
图1是矩阵乘法的常规计算方式的示意图。
图2是本申请实施例提供的数据处理装置的示意性结构图。
图3是本申请一个实施例提供的矩阵分块方式的示意图。
图4是本申请另一实施例提供的矩阵分块方式的示意图。
图5是本申请一个实施例提供的矩阵元素相乘方式的示意图。
图6是本申请另一实施例提供的矩阵元素相乘方式的示意图。
图7是本申请另一实施例提供的矩阵元素相乘方式的示意图。
图8是本申请另一实施例提供的矩阵元素相乘方式的示意图。
图9是本申请另一实施例提供的矩阵元素相乘方式的示意图。
图10是本申请实施例提供的矩阵乘法的计算流程图。
图11是本申请实施例提供的数据处理方法的流程图。
具体实施方式
支持矩阵乘法运算的数据处理装置的内部通常设置有一个或多个乘累加单元。乘累加单元有时也可称为乘累加器,可专门用于执行乘累加操作。乘累加单元通常可以在同一个时钟周期(或指令周期)完成一次乘法和一次加法操作。
数据处理装置例如可以是数字信号处理器(digital signal processor,DSP),也可以是神经网络系统中的用于执行卷积操作的神经网络处理器。以DSP为例,DSP执行的常见运算包括功率计算、差分运算、滤波器运算 等,这些运算归根到底都是乘累加运算。因此,在DSP内部,通常会设置多个乘累加单元,如8个或16个乘累加单元。卷积操作实际上也是矩阵乘法,归根到底都是乘累加运算,因此,与DSP类似,神经网络处理器内部也可设置多个乘累加单元。
下面结合图1,对矩阵乘法的常规计算方式进行介绍。
在执行矩阵C=矩阵A×矩阵B的过程中,常规计算方式是利用乘累加单元按行或按列逐个计算矩阵C中的每个元素的取值。
如图1所示,为了得到矩阵C中的各元素的取值,常规计算方式通常会先根据矩阵A的第0行元素和矩阵B的第0列元素,利用乘累加单元计算矩阵C中的元素C 00的取值。
假设矩阵A的列数(或矩阵B的行数)为17,则需要执行17次乘累加运算才可以得到C 00的取值。如果数据处理装置内部仅设置有16个乘累加单元,则无法在一个时钟周期内计算出C 00的取值。在这种情况下,为了简化数据调度,传统的数据处理装置通常会先在第1个时钟周期利用16乘累加单元执行16次乘累加运算(每个乘累加单元执行1次乘法操作),然后在第二个时钟周期利用1个乘累加单元单独执行剩余的1次乘累加运算,其余15个乘累加单元处于空闲状态。
由此可见,传统的数据处理装置有时会使得一些乘累加单元处于空闲状态,导致乘累加单元的利用率低下。为了提高乘累加单元的利用率,下面对本申请实施例提供的数据处理装置和方法进行详细介绍。
图2是本申请实施例提供的数据处理装置的示意性结构图。图2所示的数据处理装置20能够用于计算矩阵C=矩阵A×矩阵B,其中,矩阵A可以为m 1×n的矩阵,矩阵B可以为n×m 2的矩阵,m 1、n、m 2均可以是不小于1的正整数。
本申请实施例对数据处理装置20的类型不做具体限定,可以是DSP,也可以是需要支持矩阵乘法运算的其他运算单元,如用于执行卷积操作的神经网络处理器。
参见图2,数据处理装置20可包括k个乘累加单元22和控制单元24。本申请对k的取值不做具体限定。k可以是不小于1的任意正整数。作为一个示例,k可以大于或等于2。例如,k可以为2的整数倍,如k可以等于8或16。
控制单元24可用于执行以下操作:在根据矩阵A中的s行元素和矩阵B中的t列元素计算矩阵C中的k个目标元素的取值的过程中,控制k个乘累加单元依次执行s行元素中的第i列元素与t列元素中的第i行元素对应的k次乘法操作。k=s×t,0≤i<n。可以理解的是,控制单元24在执行乘法操作的过程中,为了得到k个目标元素的取值,可以控制k个乘累加单元不断将本次乘法结果与前一次乘法结果相加。
例如,控制单元24可以先从存储设备读取s行元素中的n列元素中的1列元素与t列元素中的n行元素中的1行元素,然后利用k个乘累加单元执行k次乘法操作(即每个乘累加单元执行1个乘法操作);接着,控制单元24可以再从存储设备读取s行元素中的剩余n-1列元素中选取1列元素与t列元素中的剩余n-1行元素中选取1行元素,然后利用k个乘累加单元再次执行k次乘法操作(即每个乘累加单元执行1次乘法操作);按照类似的方式执行n次,即可将s行元素中n列元素与t列元素中的n行元素对应的乘法操作执行完毕。可以理解的是,在执行乘法操作的过程中,k个乘累加单元可以不断将本次乘法结果与前一次乘法结果相加,最终得到矩阵C中的k个目标元素的取值。
为了便于理解,先结合图3和图4,以两个具体的矩阵乘法为例,对上述操作方式进行举例说明。
如图3所示,矩阵A为4×2的矩阵,矩阵B为2×5的矩阵,即m 1=4,m 2=5,n=2。以数据处理装置20包括16个乘累加单元(即k=16)为例,矩阵C可以包括一个4×4的分块矩阵D。该分块矩阵D中的16个元素C 00至C 33即可作为16个目标元素。下面详细描述该16个目标元素的求解过程。
首先,根据矩阵乘法的原理可以得知:该16个目标元素的求解需要基于矩阵A中的4行元素(矩阵A中的虚线框中的元素,在该例中,s=4)和矩阵B的4列元素(矩阵B中的虚线框中的元素,在该例中,t=4)进行。
在求解过程中,本实施例并非根据矩阵A中的4行元素和矩阵B的4列元素逐个计算16个目标元素的取值,而是并行地计算该16个目标元素的取值。例如,可以计算矩阵A的4行元素中的第0列元素(即A 00至A 30)与矩阵B的4列元素中的第0行元素(即B 00至B 03)之间的乘法运算,再计算矩阵A的第1列的元素(即A 01至A 31)与矩阵B的第1行元素(即B 10至B 13)之间的乘法运算。或者,可以计算矩阵A的第1列的元素(即A 01 至A 31)与矩阵B的第1行元素(即B 10至B 13)之间的乘法运算,再计算矩阵A的第0列的元素(即A 00至A 30)与矩阵B的第0行元素(即B 00至B 03)之间的乘法运算。
以矩阵A的4行元素中的第0列的元素与矩阵B的4列元素中的第0行元素相乘为例,由矩阵相乘的基本原理可知,矩阵A的4行元素中的第0列的元素与矩阵B的4列元素中的第0行元素之间需要被执行的乘法操作正好为k次:A 00×B 00,A 00×B 01,A 00×B 02,A 00×B 03,A 10×B 00,A 10×B 01,A 10×B 02,A 10×B 03,A 20×B 00,A 20×B 01,A 20×B 02,A 20×B 03,A 30×B 00,A 30×B 01,A 30×B 02,A 30×B 03。同理,矩阵A的4行元素中的第1列的元素与矩阵B的4列元素中的第1行元素之间需要被执行的乘法操作正好也为k次。
由此可见,k个乘累加单元依次执行s行元素中的第i列元素与t列元素中的第i行元素对应的乘法操作的过程中,可以每次执行k次乘法操作,使得k个乘累加单元能够以100%的利用率执行完k个目标元素对应的所有乘法操作,从而可以提高乘累加单元的利用率。
再举一例。如图4所示,矩阵A为10×100的矩阵,矩阵B为100×94的矩阵,即m 1=10,m 2=94,n=100。仍以k=16为例,则矩阵C可以按照如图4所示的方式进行分块,形成2×23个分块矩阵D,其中每个分块矩阵D中的16个元素可作为16个目标元素。
首先,根据矩阵乘法的原理可以得知:每个分块矩阵D中的16个目标元素的取值的求解需要基于矩阵A中的4行元素(矩阵A中的每个虚线框中的元素,在该例中,s=4)和矩阵B的4列元素(即矩阵B中的每个虚线框中的元素,在该例中,t=4)进行。例如,矩阵C中的左上角的分块矩阵D的求解需要依赖于矩阵A的前4行元素和矩阵B的前4列元素。
在求解每个分块矩阵D中的16个目标元素的过程中,本实施例并非根据矩阵A中的4行元素和矩阵B的4列元素逐个计算分块矩阵D中的16个目标元素的取值,而是并行地计算该16个目标元素的取值。分块矩阵D的具体计算方式与图3中的16个目标元素的计算方式同理,此处不再详述。采用这种计算方式,在计算每个分块矩阵D中的16个目标元素的过程中,k个乘累加单元可以被100%利用。
通过以上两个示例可以看出,在利用矩阵A的s行元素和矩阵B的t列 元素计算k个目标元素的取值的过程中,本申请实施例更改了这些元素的相乘顺序,从常规的利用矩阵A的一行元素与矩阵B的一列元素相乘的方式更改为:依次执行矩阵A中的s行元素中的第i列元素与矩阵B中的t列元素中的第i行元素对应的乘法操作的方式。由于矩阵A中的s行元素中的第i列元素与矩阵B中的t列元素中的第i行元素对应的乘法操作的数量刚好等于k次,因此,k个乘累加单元可以被100%利用。综上,本申请实施例可以提高数据处理装置20中的乘累加单元的利用率,进而可以提高矩阵乘法的效率。
矩阵C可以仅包含k个目标元素,则计算完矩阵C中的目标元素的取值之后,即可得到矩阵C。或者,矩阵C可以包括除目标元素之外的剩余元素。以图3为例,该剩余元素可以是矩阵C的虚线框之外的元素,即元素C 04-C 34。本申请实施例对这些剩余元素的计算方式不做具体限定,可以按照与图1类似的常规计算方式进行计算,即逐个计算剩余元素的每个元素的取值。
上文指出,控制单元24控制k个乘累加单元依次执行s行元素中的第i列元素与t列元素中的第i行元素对应的k次乘法操作。为了便于描述,可以将s行元素中的1列元素与t列元素中的1行元素对应的k次乘法操作称为行列元素互乘操作。由于矩阵A具有n列,因此,为了得到k个目标元素的取值,控制单元24共需要执行n次行列元素互乘操作。本申请实施例对该n次行列元素互乘操作的执行顺序不做具体限定,可以按照i取值从小到大的方式依次执行,也可以按照i取值从大到小的方式依次执行,或者也可以按照随机的方式执行,只要保证n次行列元素互乘操作均被执行即可。
此外,在执行n次行列元素互乘操作的过程中,控制单元24可以控制k个乘累加单元在每个时钟周期(或指令周期)执行1次行列元素互乘操作,这样一来,n个时钟周期即可完成n次行列元素互乘操作,将互乘操作的结果不断累加,即可得到k个目标元素的取值。
控制单元24可以按照指令控制乘累加单元执行对应的操作。该指令可以是外部的处理器向控制单元24发送的指令,也可以是控制单元24自己生成指令。
本申请实施例对k个目标元素在矩阵C中的位置不做具体限定,可以是分布在矩阵C中的s行、t列的任意k个元素。作为一个示例,该k个目标 元素可以是矩阵C中的相邻元素,即矩阵C中的分块矩阵D中的元素。具体实现时,控制单元24可以先根据数据处理装置中的乘累加单元的数量,确定矩阵A和矩阵B的分块方式,使得矩阵A中的分块矩阵为s行、n列的矩阵,矩阵B中的每个分块矩阵为n行、t列的矩阵。当矩阵A和矩阵B的分块方式确定之后,矩阵A和矩阵B的乘积为分块矩阵D。以图4为例,矩阵A中的每4行、100列形成一个分块矩阵,矩阵B的每100行4列形成一个分块矩阵,矩阵A和矩阵B的分块方式确定后,矩阵C中的分块矩阵D的形式也就确定下来。
作为另一示例,k个目标元素在矩阵C中的位置也可不相邻。以图3为例,16个目标元素可以由矩阵C的第1列、第2列、第3列、第5列元素组成;也可以由矩阵C的第1列、第2列、第4列、第5列元素组成。换句话说,本申请并不要求k个目标元素一定位于矩阵C的同一分块矩阵中,这些目标元素也可以相互间隔,只要它们分布在矩阵C的s行、t列即可。
由于k个乘累加单元12可以以100%的利用率计算分块矩阵D中的k个目标元素的取值,因此,矩阵C分解出的分块矩阵D越多,则乘累加单元的利用率就越高。
为了充分利用k个乘累加单元12,对矩阵C的分块可以使得矩阵C满足如下条件:矩阵C包括u×v个分块矩阵D,且m 1-s<u×s≤m 1,和/或m 2-t<v×t≤m 2,其中u和v均为不小于1的正整数。
m 1-s<u×s≤m 1表示经过分块,矩阵C的剩余行数小于s,因此,矩阵C在行方向上无法按照s×t的方式被进一步划分,即矩阵C在行方向上已经按照s×t的方式被充分划分。
同理,m 2-t<v×t≤m 2表示经过分块,矩阵C的剩余列数小于t,因此,矩阵C在列方向上无法按照s×t的方式被进一步划分,即矩阵C在列方向上已经按照s×t的方式被充分划分。
以图4为例,矩阵C为10×94的矩阵,即m 1=10,m 2=94。假设k=16,s和t均为4,则u和v的值可以分别设置为2和23,使得m 1-s<u×s≤m 1且m 2-t<v×t≤m 2
u的取值为2,代表矩阵C在行方向上划分出2个分块矩阵D。由于矩阵C的行数为10,因此,矩阵C在行方向上划分出2个分块矩阵D之后,剩余的行数为2,在行方向上无法继续划分出4×4的分块矩阵D。
v的取值为23,代表矩阵C在列方向上划分出23个分块矩阵D。由于矩阵C的行数为94,因此,矩阵C在列方向上划分出23个分块矩阵D之后,剩余的列数为2,在列方向上无法继续划分出4×4的分块矩阵D。
本申请实施例对s和t的取值选取方式不做具体限定,满足k=s×t的任意取值均可用于本申请。但是,针对同一矩阵C,s和t的不同取值可能使得划分出的分块矩阵D的最大数量不同,从而使得矩阵C的剩余元素的数量不同。
可以理解的是,从矩阵C中划分出的分块矩阵D的数量越多,乘累加单元的利用率就可能越高。因此,在某些实施例中,可以根据矩阵A的行数m 1和矩阵B的列数m 2确定s和t的取值。例如,可以根据矩阵A的行数m 1和矩阵B的列数m 2确定s和t的取值,使得m 1×m 2与u×s×v×t的差值最小。m 1×m 2与u×s×v×t的差值最小意味着矩阵C中的除分块矩阵D(s行t列的矩阵)之外的剩余元素最少,则乘累加单元的利用率越高。
上文均是以从矩阵C中划分出相同形式的分块矩阵D为例进行说明的,实际上,在某些实施例中,也可以从矩阵C中划分出不同形式的分块矩阵D(这里提到的不同形式指的是行列数量不同,但行列数量的乘积仍然为k)。
以图4为例,假设k=16,则可以按照4×4的方式划分出2×23个分块矩阵D。对于剩余元素,如位于矩阵C底部的2×92个元素,虽然不能按照4×4的方式被进一步划分,仍然可以按照2×8或1×16的形式被进一步划分;同理,对于位于矩阵C右侧的10×2个元素,虽然不能按照4×4的方式被进一步划分,仍然可以按照8×2的方式被进一步划分。当然,为了简化数据调度或控制逻辑的复杂度,在某些实施例中,可以要求矩阵C中划分出的分块矩阵D均具有相同的形式。
本申请实施例对s和t的取值不做具体限定,只要s与t的乘积等于k即可。以k=16为例,s和t的取值可以是:s=1,t=16;s=2,t=8;s=4,t=4;s=8,t=2;s=16,t=1。
以s=16,t=1为例,则在计算16个目标元素的过程中,矩阵A和矩阵B在每个时钟周期内需要被相乘的元素可以为矩阵A的某列中的16个元素与矩阵B的某行中的1个元素,这些元素之间需要被执行的乘法操作的数量正好为16次,因此,可以由16个乘累加单元在一个时钟周期内完成。图5给出了需要执行乘法操作的矩阵A中的16个元素和矩阵B中的1个元素的 示例。
以s=8,t=2为例,则在计算16个目标元素的过程中,矩阵A和矩阵B在每个时钟周期内需要被相乘的元素可以为矩阵A的某列中的8个元素与矩阵B的某行中的2个元素,这些元素之间需要被执行的乘法操作的数量正好为16次,因此,可以由16个乘累加单元在一个时钟周期内完成。图6给出了需要执行乘法操作的矩阵A中的8个元素和矩阵B中的2个元素的示例。
以s=4,t=4为例,则在计算16个目标元素的过程中,矩阵A和矩阵B在每个时钟周期内需要被相乘的元素可以为矩阵A的某列中的4个元素与矩阵B的某行中的4个元素,这些元素之间需要被执行的乘法操作的数量正好为16次,因此,可以由16个乘累加单元在一个时钟周期内完成。图7给出了需要执行乘法操作的矩阵A中的4个元素和矩阵B中的4个元素的示例。
以s=2,t=8为例,则在计算16个目标元素的过程中,矩阵A和矩阵B在每个时钟周期内需要被相乘的元素可以为矩阵A的某列中的2个元素与矩阵B的某行中的8个元素,这些元素之间需要被执行的乘法操作的数量正好为16次,因此,可以由16个乘累加单元在一个时钟周期内完成。图8给出了需要执行乘法操作的矩阵A中的2个元素和矩阵B中的8个元素的示例。
以s=1,t=16为例,则在计算16个目标元素的过程中,矩阵A和矩阵B在每个时钟周期内需要被相乘的元素可以为矩阵A的某列中的1个元素与矩阵B的某行中的16个元素,这些元素之间需要被执行的乘法操作的数量正好为16次,因此,可以由16个乘累加单元在一个时钟周期内完成。图9给出了需要执行乘法操作的矩阵A中的1个元素和矩阵B中的16个元素的示例。
应注意,s和t的可能的取值需要根据矩阵C的实际情况确定,s和t的某些取值组合可能并不适用于尺寸较小的矩阵C。例如,以k=16为例,s和t共5种取值组合,即s=1,t=16;s=2,t=8;s=4,t=4;s=8,t=2;s=16,t=1。在图4所示的示例中,由于矩阵C为10×94的矩阵,因此,除了s=16,t=1这种取值组合不适用之外,其他的取值组合均适用。在图3所示的示例中,由于矩阵C为4×5的矩阵,因此,只有s=4,t=4这一种取值组合适合该矩阵C。
可选地,在一些实施例中,可以根据矩阵C的尺寸确定是否采用本申请实施例提供的方式计算矩阵C中的元素的取值。
作为一个示例,如果矩阵C的列数n为k个整数倍(即n/k大于等于1),按照常规计算方式也可以使得k个乘累加单元达到100%的利用率。因此,在某些实施例中,如果矩阵C的列数n为k的整数倍,则控制单元24可以控制k个乘累加单元按照常规方式依次计算矩阵C中的每个元素的取值。
作为另一个示例,如果m 1×m 2小于k,即矩阵C包含的元素个数小于k,则控制单元24可以控制k个乘累加单元按照常规方式依次计算矩阵C中的每个元素的取值。
作为另一个示例,如果m 1×m 2×n小于k,即计算矩阵C中的所有元素需要执行的乘法数量小于k,则控制单元24可以控制k个乘累加单元按照常规方式依次计算矩阵C中的每个元素的取值。
作为另一个示例,如果m 1×m 2×n大于k,且n不为k的整数倍,则按照常规方式计算会导致k个乘累加单元的利用率比较低,此时,控制单元24可以按照本申请实施例提供的方式,控制k个乘累加单元执行s行元素中的第i列元素与t列元素中的第i行元素对应的k次乘法操作。
m 1、m 2、n与k的关系的判断,以及矩阵C的分块方式可以由数据处理装置20内的控制单元24执行,也可以由数据处理装置20外部的处理器执行,本申请实施例对此并不限定。
下面结合图10,以k=16为例,给出矩阵乘法的执行过程的一个示例。
图10包括步骤101至步骤105。
在步骤101,判断矩阵C的列数n是否为16的倍数。
如果n为16的倍数,则执行步骤105;如果n不为16的倍数,则执行步骤102。
在步骤102,判断矩阵A的行数m 1和矩阵B的列数m 2的乘积是否小于等于16。
如果m 1×m 2≤16,则执行步骤105;如果m 1×m 2>16,则执行步骤103。
在步骤103,根据m 1和m 2的取值,选取矩阵C的分块方式。
经过分块,可以从矩阵C中划分出一个或多个分块矩阵D,其中每个分块矩阵D可以包括k个目标元素。分块矩阵D的具体分块方式可以参见前文,此处不再详述。
在步骤104,依次计算每个分块矩阵D中的k个目标元素的取值。
在计算每k个目标元素的取值的过程中,可以采用本申请实施例提供的 矩阵乘法方式,并行计算该k个目标元素的取值。
在步骤105,按照常规计算方式逐个计算矩阵C中的元素的取值。
下面结合图11,详细描述本申请实施例提供的数据处理方法。图11的方法能够用于计算矩阵C=矩阵A×矩阵B,其中所述矩阵A为m 1×n的矩阵,所述矩阵B为n×m 2的矩阵。该方法可以由数据处理装置20中的控制单元24执行。
在步骤1110,在根据所述矩阵A中的s行元素和所述矩阵B中的t列元素计算所述矩阵C中的k个目标元素的取值的过程中,控制k个乘累加单元依次执行所述s行元素中的第i列元素与所述t列元素中的第i行元素对应的k次乘法操作,k=s×t,0≤i<n。
可选地,所述矩阵C包括分块矩阵D,所述分块矩阵D为s×t的矩阵,k个所述目标元素为所述分块矩阵D中的元素。
可选地,所述矩阵C包括u×v个所述分块矩阵D,且m 1-s<u×s≤m 1,m 2-t<v×t≤m 2,其中u和v均为不小于1的正整数。
可选地,图11的方法还可包括:根据矩阵A的行数m 1和矩阵B的列数m 2,确定s和t的取值,使得m 1×m 2与u×s×v×t的差值最小。
可选地,步骤1110可包括:如果m 1×m 2×n大于k,且n不为k的整数倍,控制k个乘累加单元执行所述s行元素中的第i列元素与所述t列元素中的第i行元素对应的k次乘法操作;图11的方法还可包括:如果n为k的整数倍或者m 1×m 2小于k,控制k个乘累加单元依次计算所述矩阵C中的每个元素的取值。
在上述实施例中,可以全部或部分地通过软件、硬件、固件或者其他任意组合来实现。当使用软件实现时,可以全部或部分地以计算机程序产品的形式实现。所述计算机程序产品包括一个或多个计算机指令。在计算机上加载和执行所述计算机程序指令时,全部或部分地产生按照本发明实施例所述的流程或功能。所述计算机可以是通用计算机、专用计算机、计算机网络、或者其他可编程装置。所述计算机指令可以存储在计算机可读存储介质中,或者从一个计算机可读存储介质向另一个计算机可读存储介质传输,例如,所述计算机指令可以从一个网站站点、计算机、服务器或数据中心通过有线(例如同轴电缆、光纤、数字用户线(digital subscriber line,DSL))或无线(例如红外、无线、微波等)方式向另一个网站站点、计算机、服务器或数 据中心进行传输。所述计算机可读存储介质可以是计算机能够存取的任何可用介质或者是包含一个或多个可用介质集成的服务器、数据中心等数据存储设备。所述可用介质可以是磁性介质(例如,软盘、硬盘、磁带)、光介质(例如数字视频光盘(digital video disc,DVD))、或者半导体介质(例如固态硬盘(solid state disk,SSD))等。
本领域普通技术人员可以意识到,结合本文中所公开的实施例描述的各示例的单元及算法步骤,能够以电子硬件、或者计算机软件和电子硬件的结合来实现。这些功能究竟以硬件还是软件方式来执行,取决于技术方案的特定应用和设计约束条件。专业技术人员可以对每个特定的应用来使用不同方法来实现所描述的功能,但是这种实现不应认为超出本申请的范围。
在本申请所提供的几个实施例中,应该理解到,所揭露的系统、装置和方法,可以通过其它的方式实现。例如,以上所描述的装置实施例仅仅是示意性的,例如,所述单元的划分,仅仅为一种逻辑功能划分,实际实现时可以有另外的划分方式,例如多个单元或组件可以结合或者可以集成到另一个系统,或一些特征可以忽略,或不执行。另一点,所显示或讨论的相互之间的耦合或直接耦合或通信连接可以是通过一些接口,装置或单元的间接耦合或通信连接,可以是电性,机械或其它的形式。
所述作为分离部件说明的单元可以是或者也可以不是物理上分开的,作为单元显示的部件可以是或者也可以不是物理单元,即可以位于一个地方,或者也可以分布到多个网络单元上。可以根据实际的需要选择其中的部分或者全部单元来实现本实施例方案的目的。
另外,在本申请各个实施例中的各功能单元可以集成在一个处理单元中,也可以是各个单元单独物理存在,也可以两个或两个以上单元集成在一个单元中。
以上所述,仅为本申请的具体实施方式,但本申请的保护范围并不局限于此,任何熟悉本技术领域的技术人员在本申请揭露的技术范围内,可轻易想到变化或替换,都应涵盖在本申请的保护范围之内。因此,本申请的保护范围应以所述权利要求的保护范围为准。

Claims (13)

  1. 一种数据处理装置,其特征在于,所述数据处理装置能够用于计算矩阵C=矩阵A×矩阵B,其中所述矩阵A为m 1×n的矩阵,所述矩阵B为n×m 2的矩阵,
    所述数据处理装置包括:
    k个乘累加单元;
    控制单元,用于执行以下操作:
    在根据所述矩阵A中的s行元素和所述矩阵B中的t列元素计算所述矩阵C中的k个目标元素的取值的过程中,控制k个乘累加单元依次执行所述s行元素中的第i列元素与所述t列元素中的第i行元素对应的k次乘法操作,k=s×t,0≤i<n。
  2. 根据权利要求1所述的数据处理装置,其特征在于,所述矩阵C包括分块矩阵D,所述分块矩阵D为s×t的矩阵,k个所述目标元素为所述分块矩阵D中的元素。
  3. 根据权利要求2所述的数据处理装置,其特征在于,所述控制单元还用于:
    根据所述数据处理装置中的乘累加单元的数量,确定所述矩阵A和所述矩阵B的分块方式,使得所述矩阵A中的分块矩阵为s行、n列的矩阵,所述矩阵B中的每个分块矩阵为n行、t列的矩阵,所述矩阵A和所述矩阵B的乘积为所述矩阵C中的分块矩阵D。
  4. 根据权利要求2或3所述的数据处理装置,其特征在于,所述矩阵C包括u×v个所述分块矩阵D,且m 1-s<u×s≤m 1,m 2-t<v×t≤m 2,其中u和v均为不小于1的正整数。
  5. 根据权利要求4所述的数据处理装置,其特征在于,所述控制单元还用于根据矩阵A的行数m 1和矩阵B的列数m 2,确定s和t的取值,使得m 1×m 2与u×s×v×t的差值最小。
  6. 根据权利要求1-5中任一项所述的数据处理装置,其特征在于,所述控制k个乘累加单元依次执行所述s行元素中的第i列元素与所述t列元素中的第i行元素对应的k次乘法操作,包括:
    如果m 1×m 2×n大于k,且n不为k的整数倍,控制k个乘累加单元执行所述s行元素中的第i列元素与所述t列元素中的第i行元素对应的k次乘 法操作;
    所述控制单元还用于执行以下操作:
    如果n为k的整数倍或者m 1×m 2小于k,控制k个乘累加单元依次计算所述矩阵C中的每个元素的取值。
  7. 根据权利要求1-6中任一项所述的数据处理装置,其特征在于,所述数据处理装置为数字信号处理器。
  8. 一种数据处理方法,其特征在于,所述方法能够用于计算矩阵C=矩阵A×矩阵B,其中所述矩阵A为m 1×n的矩阵,所述矩阵B为n×m 2的矩阵,
    所述方法包括:
    在根据所述矩阵A中的s行元素和所述矩阵B中的t列元素计算所述矩阵C中的k个目标元素的取值的过程中,控制k个乘累加单元依次执行所述s行元素中的第i列元素与所述t列元素中的第i行元素对应的k次乘法操作,k=s×t,0≤i<n。
  9. 根据权利要求8所述的方法,其特征在于,所述矩阵C包括分块矩阵D,所述分块矩阵D为s×t的矩阵,k个所述目标元素为所述分块矩阵D中的元素。
  10. 根据权利要求9所述的方法,其特征在于,所述方法还包括:
    根据所述数据处理装置中的乘累加单元的数量,确定所述矩阵A和所述矩阵B的分块方式,使得所述矩阵A中的分块矩阵为s行、n列的矩阵,所述矩阵B中的每个分块矩阵为n行、t列的矩阵,所述矩阵A和所述矩阵B的乘积为所述矩阵C中的分块矩阵D。
  11. 根据权利要求9或10所述的方法,其特征在于,所述矩阵C包括u×v个所述分块矩阵D,且m 1-s<u×s≤m 1,m 2-t<v×t≤m 2,其中u和v均为不小于1的正整数。
  12. 根据权利要求11所述的方法,其特征在于,所述方法还包括:
    根据矩阵A的行数m 1和矩阵B的列数m 2,确定s和t的取值,使得m 1×m 2与u×s×v×t的差值最小。
  13. 根据权利要求8-12中任一项所述的方法,其特征在于,所述控制k个乘累加单元依次执行所述s行元素中的第i列元素与所述t列元素中的第i行元素对应的k次乘法操作,包括:
    如果m 1×m 2×n大于k,且n不为k的整数倍,控制k个乘累加单元执 行所述s行元素中的第i列元素与所述t列元素中的第i行元素对应的k次乘法操作;
    所述方法还包括:
    如果n为k的整数倍或者m 1×m 2小于k,控制k个乘累加单元依次计算所述矩阵C中的每个元素的取值。
PCT/CN2018/107393 2018-09-25 2018-09-25 数据处理装置和方法 WO2020061762A1 (zh)

Priority Applications (2)

Application Number Priority Date Filing Date Title
CN201880037874.0A CN110770697A (zh) 2018-09-25 2018-09-25 数据处理装置和方法
PCT/CN2018/107393 WO2020061762A1 (zh) 2018-09-25 2018-09-25 数据处理装置和方法

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
PCT/CN2018/107393 WO2020061762A1 (zh) 2018-09-25 2018-09-25 数据处理装置和方法

Publications (1)

Publication Number Publication Date
WO2020061762A1 true WO2020061762A1 (zh) 2020-04-02

Family

ID=69328773

Family Applications (1)

Application Number Title Priority Date Filing Date
PCT/CN2018/107393 WO2020061762A1 (zh) 2018-09-25 2018-09-25 数据处理装置和方法

Country Status (2)

Country Link
CN (1) CN110770697A (zh)
WO (1) WO2020061762A1 (zh)

Families Citing this family (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN113918120A (zh) * 2021-10-19 2022-01-11 Oppo广东移动通信有限公司 计算装置、神经网络处理设备、芯片及处理数据的方法

Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20160140084A1 (en) * 2014-11-14 2016-05-19 Advanced Micro Devices, Inc. Efficient sparse matrix-vector multiplication on parallel processors
CN106445471A (zh) * 2016-10-13 2017-02-22 北京百度网讯科技有限公司 处理器和用于在处理器上执行矩阵乘运算的方法
CN107291666A (zh) * 2017-06-27 2017-10-24 郑州云海信息技术有限公司 一种数据处理方法及处理装置
CN107341133A (zh) * 2017-06-24 2017-11-10 中国人民解放军信息工程大学 基于任意维数矩阵lu分解的可重构计算结构的调度方法

Family Cites Families (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN104346318B (zh) * 2014-10-15 2017-03-15 中国人民解放军国防科学技术大学 面向通用多核dsp的矩阵乘加速方法
CN106325812B (zh) * 2015-06-15 2019-03-08 华为技术有限公司 一种针对乘累加运算的处理方法及装置
US10169296B2 (en) * 2016-12-30 2019-01-01 Intel Corporation Distributed matrix multiplication for neural networks

Patent Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20160140084A1 (en) * 2014-11-14 2016-05-19 Advanced Micro Devices, Inc. Efficient sparse matrix-vector multiplication on parallel processors
CN106445471A (zh) * 2016-10-13 2017-02-22 北京百度网讯科技有限公司 处理器和用于在处理器上执行矩阵乘运算的方法
CN107341133A (zh) * 2017-06-24 2017-11-10 中国人民解放军信息工程大学 基于任意维数矩阵lu分解的可重构计算结构的调度方法
CN107291666A (zh) * 2017-06-27 2017-10-24 郑州云海信息技术有限公司 一种数据处理方法及处理装置

Also Published As

Publication number Publication date
CN110770697A (zh) 2020-02-07

Similar Documents

Publication Publication Date Title
US11720646B2 (en) Operation accelerator
EP3557484A1 (en) Neural network convolution operation device and method
TWI803663B (zh) 一種運算裝置和運算方法
US11656910B2 (en) Data sharing system and data sharing method therefor
JP2020524318A (ja) 代替ループ限界値
US11468145B1 (en) Storage of input values within core of neural network inference circuit
US20200026746A1 (en) Matrix and Vector Multiplication Operation Method and Apparatus
US20220083857A1 (en) Convolutional neural network operation method and device
WO2019084788A1 (zh) 用于神经网络的运算装置、电路及相关方法
CN102334101B (zh) 执行顺序决定装置
CN111583095B (zh) 图像数据存储方法、图像数据处理方法、系统及相关装置
WO2023065983A1 (zh) 计算装置、神经网络处理设备、芯片及处理数据的方法
WO2020061762A1 (zh) 数据处理装置和方法
CN112686379A (zh) 集成电路装置、电子设备、板卡和计算方法
TWI768167B (zh) 集成電路芯片裝置及相關產品
CN111160560A (zh) 预估模拟量子计算所需资源的方法、系统
WO2019206161A1 (zh) 池化运算装置
CN109740115A (zh) 一种实现矩阵乘法运算的方法、装置及设备
US11651202B2 (en) Integrated circuit chip device and related product
CN108108189A (zh) 一种计算方法及相关产品
CN116888591A (zh) 一种矩阵乘法器、矩阵计算方法及相关设备
CN109389213A (zh) 存储装置及方法、数据处理装置及方法、电子装置
CN112765540B (zh) 数据处理方法、装置及相关产品
CN114065121A (zh) 一种求解伊辛模型的计算方法及设备
CN113033813A (zh) 数据处理方法、装置、计算机设备和存储介质

Legal Events

Date Code Title Description
121 Ep: the epo has been informed by wipo that ep was designated in this application

Ref document number: 18934929

Country of ref document: EP

Kind code of ref document: A1

NENP Non-entry into the national phase

Ref country code: DE

122 Ep: pct application non-entry in european phase

Ref document number: 18934929

Country of ref document: EP

Kind code of ref document: A1