Method and apparatus for vector based matrix multiplication
A method is provided that includes performing, by a processor in response to a vector matrix multiply instruction, multiplying an m×n matrix (A matrix) and a n×p matrix (B matrix) to generate elements of an m×p matrix (R matrix), and storing the elements of the R matrix in a storage location specified by the vector matrix multiply instruction.
1. A method comprising:
receiving, by a processor, elements of rows of an m×n matrix (A matrix) and elements of columns of a n×p matrix (B matrix) from a streaming engine;
permutating, by the processor, the elements of rows of the A matrix and the elements of columns of the B matrix, wherein the processor includes a permute component;
mapping, by the permute component, the elements of the rows of the A matrix and the elements of the columns of the B matrix to slice multiplication components of vector multiplication units included in a vector data path of the processor, wherein the permute component is coupled between the streaming engine and the vector multiplication units;
performing, by the processor in response to a vector matrix multiply instruction, multiplying the A matrix and the B matrix to generate respective elements of an m×p matrix (R matrix) by using the vector multiplication units, wherein each of the slice multiplication components generates the respective elements of the R matrix; and
storing the elements of the R matrix in a storage location specified by the vector matrix multiply instruction;
wherein the mapping is based on the respective elements of the R matrix to be generated by the slice multiplication components.
2. The method of claim 1 , wherein m=4, n=8, and p=4.
3. A processor comprising:
a permute component configured to:
permute elements of rows of an m×n matrix (A matrix) and elements of columns of a n×p matrix (B matrix); and
map the elements of the rows of the A matrix and the elements of the columns of the B matrix to slice multiplication components of vector multiplication units included in a vector data path of the processor, wherein the permute component is coupled between a streaming engine and the vector multiplication units;
an instruction decoder configured to decode a vector matrix multiply instruction; and
vector matrix multiplication logic configured to multiply, responsive to the vector matrix multiply instruction, the A matrix and the B matrix to generate elements of an m×p matrix (R matrix) by using the vector multiplication units, wherein each of the slice multiplication components generates the respective elements of the R matrix;
wherein the mapping is based on the respective elements of the R matrix to be generated by the slice multiplication components.
4. The processor of claim 3 , wherein m=4, n=8, and p=4.
5. The processor of claim 3 , wherein the processor is a digital signal processor (DSP).