Skip to content

Matrix Matrix Multiplication

Module: Matrix Functions

More...

Modules

Name
Matrix Multiplication Kernels

Functions

Name
void plp_mat_mult_f32(const float restrict pSrcA, const float restrict pSrcB, uint32_t M, uint32_t N, uint32_t O, float *restrict pDstC)
Glue code for matrix mutliplication of 32-bit floating-point matrices.
void plp_mat_mult_f32_parallel(const float restrict pSrcA, const float restrict pSrcB, uint32_t M, uint32_t N, uint32_t O, uint32_t nPE, float *restrict pDstC)
Glue code for parallel matrix mutliplication of 32-bit floating-point matrices.
void plp_mat_mult_i16(const int16_t restrict pSrcA, const int16_t restrict pSrcB, uint32_t M, uint32_t N, uint32_t O, int32_t *restrict pDstC)
Glue code for matrix mutliplication of 16-bit integer matrices.
void plp_mat_mult_i16_parallel(const int16_t restrict pSrcA, const int16_t restrict pSrcB, uint32_t M, uint32_t N, uint32_t O, uint32_t nPE, int32_t *restrict pDstC)
Glue code for parallel matrix mutliplication of 16-bit integer matrices.
void plp_mat_mult_i32(const int32_t restrict pSrcA, const int32_t restrict pSrcB, uint32_t M, uint32_t N, uint32_t O, int32_t *restrict pDstC)
Glue code for matrix mutliplication of 32-bit integer matrices.
void plp_mat_mult_i32_parallel(const int32_t restrict pSrcA, const int32_t restrict pSrcB, uint32_t M, uint32_t N, uint32_t O, uint32_t nPE, int32_t *restrict pDstC)
Glue code for parallel matrix mutliplication of 32-bit integer matrices.
void plp_mat_mult_i8(const int8_t restrict pSrcA, const int8_t restrict pSrcB, uint32_t M, uint32_t N, uint32_t O, int32_t *restrict pDstC)
Glue code for matrix mutliplication of 8-bit integer matrices.
void plp_mat_mult_i8_parallel(const int8_t restrict pSrcA, const int8_t restrict pSrcB, uint32_t M, uint32_t N, uint32_t O, uint32_t nPE, int32_t *restrict pDstC)
Glue code for parallel matrix mutliplication of 8-bit integer matrices.
void plp_mat_mult_q16(const int16_t restrict pSrcA, const int16_t restrict pSrcB, uint32_t M, uint32_t N, uint32_t O, uint32_t shift, int16_t *restrict pDstC)
Glue code for matrix mutliplication of 16-bit fix-point matrices.
void plp_mat_mult_q16_parallel(const int16_t restrict pSrcA, const int16_t restrict pSrcB, uint32_t M, uint32_t N, uint32_t O, uint32_t shift, uint32_t nPE, int16_t *restrict pDstC)
Glue code for parallel matrix mutliplication of 16-bit fix-point matrices.
void plp_mat_mult_q32(const int32_t restrict pSrcA, const int32_t restrict pSrcB, uint32_t M, uint32_t N, uint32_t O, uint32_t shift, int32_t *restrict pDstC)
Glue code for matrix mutliplication of 32-bit fix-point matrices.
void plp_mat_mult_q32_parallel(const int32_t restrict pSrcA, const int32_t restrict pSrcB, uint32_t M, uint32_t N, uint32_t O, uint32_t shift, uint32_t nPE, int32_t *restrict pDstC)
Glue code for parallel matrix mutliplication of 32-bit fix-point matrices.
void plp_mat_mult_q8(const int8_t restrict pSrcA, const int8_t restrict pSrcB, uint32_t M, uint32_t N, uint32_t O, uint32_t shift, int8_t *restrict pDstC)
Glue code for matrix mutliplication of 8-bit fix-point matrices.
void plp_mat_mult_q8_parallel(const int8_t restrict pSrcA, const int8_t restrict pSrcB, uint32_t M, uint32_t N, uint32_t O, uint32_t shift, uint32_t nPE, int8_t *restrict pDstC)
Glue code for parallel matrix mutliplication of 8-bit fix-point matrices.

Detailed Description

This module contains the glue code for Matrix Matrix Multiplication. The kernel codes (kernels) are in the Moducle Matrix Matrix Multiplication Kernels.

The Matrix Matrix Multiplication computes the product of two matrices with dimensions MxN and NxO. The first matrix is accessed row wise, the second column wise, all values form the first are multiplied with the values of the second and then sum of the result gives the value for the result matrix.

'pDst[m,o] = pSrcA[m,0]*pSrcB[0,o] + pSrcA[m,1]*pSrcB[1,o] + ... + pSrcA[m,N-1]*pSrcB[N-1,o]`

There are functions for integer 32- 16- and 8-bit data types. For lower precision integers (16- and 8-bit), functions exploiting SIMD instructions are provided.

The naming scheme of the functions follows the following pattern (for example plp_mat_mult_i32):

`plp_<function name>_<data type><precision>[_parallel]`
name description
function_name mat_mult
data type {f, i, q} respectively for floats, integers, fixed points
precision {32, 16, 8} bits

Functions Documentation

function plp_mat_mult_f32

void plp_mat_mult_f32(
    const float *__restrict__ pSrcA,
    const float *__restrict__ pSrcB,
    uint32_t M,
    uint32_t N,
    uint32_t O,
    float *__restrict__ pDstC
)

Glue code for matrix mutliplication of 32-bit floating-point matrices.

Parameters:

  • pSrcA points to the first input matrix
  • pSrcB points to the second input matrix
  • M height of the first input matrix
  • N width of the first input matrix and hight of the second
  • O width of the second input matrix
  • pDstC points to the output matrix

Return: none

Glue code for matrix matrix multiplication of a 32-bit floating-point matrices.

function plp_mat_mult_f32_parallel

void plp_mat_mult_f32_parallel(
    const float *__restrict__ pSrcA,
    const float *__restrict__ pSrcB,
    uint32_t M,
    uint32_t N,
    uint32_t O,
    uint32_t nPE,
    float *__restrict__ pDstC
)

Glue code for parallel matrix mutliplication of 32-bit floating-point matrices.

Parameters:

  • pSrcA points to the first input matrix
  • pSrcB points to the second input matrix
  • M height of the first input matrix
  • N width of the first input matrix and hight of the second
  • O width of the second input matrix
  • nPE Number of cores to use
  • pDstC points to the output matrix

Return: none

Glue code for parallel matrix matrix multiplication of a 32-bit floating-point matrices.

function plp_mat_mult_i16

void plp_mat_mult_i16(
    const int16_t *__restrict__ pSrcA,
    const int16_t *__restrict__ pSrcB,
    uint32_t M,
    uint32_t N,
    uint32_t O,
    int32_t *__restrict__ pDstC
)

Glue code for matrix mutliplication of 16-bit integer matrices.

Parameters:

  • pSrcA points to the first input matrix
  • pSrcB points to the second input matrix
  • M height of the first input matrix
  • N width of the first input matrix and hight of the second
  • O width of the second input matrix
  • pDstC points to the output matrix

Return: none

Glue code for matrix matrix multiplication of a 16-bit integer matrices.

function plp_mat_mult_i16_parallel

void plp_mat_mult_i16_parallel(
    const int16_t *__restrict__ pSrcA,
    const int16_t *__restrict__ pSrcB,
    uint32_t M,
    uint32_t N,
    uint32_t O,
    uint32_t nPE,
    int32_t *__restrict__ pDstC
)

Glue code for parallel matrix mutliplication of 16-bit integer matrices.

Parameters:

  • pSrcA points to the first input matrix
  • pSrcB points to the second input matrix
  • M height of the first input matrix
  • N width of the first input matrix and hight of the second
  • O width of the second input matrix
  • nPE Number of cores to use
  • pDstC points to the output matrix

Return: none

Glue code for parallel matrix matrix multiplication of a 16-bit integer matrices.

function plp_mat_mult_i32

void plp_mat_mult_i32(
    const int32_t *__restrict__ pSrcA,
    const int32_t *__restrict__ pSrcB,
    uint32_t M,
    uint32_t N,
    uint32_t O,
    int32_t *__restrict__ pDstC
)

Glue code for matrix mutliplication of 32-bit integer matrices.

Parameters:

  • pSrcA points to the first input matrix
  • pSrcB points to the second input matrix
  • M height of the first input matrix
  • N width of the first input matrix and hight of the second
  • O width of the second input matrix
  • pDstC points to the output matrix

Return: none

Glue code for matrix matrix multiplication of a 32-bit integer matrices.

function plp_mat_mult_i32_parallel

void plp_mat_mult_i32_parallel(
    const int32_t *__restrict__ pSrcA,
    const int32_t *__restrict__ pSrcB,
    uint32_t M,
    uint32_t N,
    uint32_t O,
    uint32_t nPE,
    int32_t *__restrict__ pDstC
)

Glue code for parallel matrix mutliplication of 32-bit integer matrices.

Parameters:

  • pSrcA points to the first input matrix
  • pSrcB points to the second input matrix
  • M height of the first input matrix
  • N width of the first input matrix and hight of the second
  • O width of the second input matrix
  • nPE Number of cores to use
  • pDstC points to the output matrix

Return: none

Glue code for parallel matrix matrix multiplication of a 32-bit integer matrices.

function plp_mat_mult_i8

void plp_mat_mult_i8(
    const int8_t *__restrict__ pSrcA,
    const int8_t *__restrict__ pSrcB,
    uint32_t M,
    uint32_t N,
    uint32_t O,
    int32_t *__restrict__ pDstC
)

Glue code for matrix mutliplication of 8-bit integer matrices.

Parameters:

  • pSrcA points to the first input matrix
  • pSrcB points to the second input matrix
  • M height of the first input matrix
  • N width of the first input matrix and hight of the second
  • O width of the second input matrix
  • pDstC points to the output matrix

Return: none

Glue code for matrix matrix multiplication of a 8-bit integer matrices.

function plp_mat_mult_i8_parallel

void plp_mat_mult_i8_parallel(
    const int8_t *__restrict__ pSrcA,
    const int8_t *__restrict__ pSrcB,
    uint32_t M,
    uint32_t N,
    uint32_t O,
    uint32_t nPE,
    int32_t *__restrict__ pDstC
)

Glue code for parallel matrix mutliplication of 8-bit integer matrices.

Parameters:

  • pSrcA points to the first input matrix
  • pSrcB points to the second input matrix
  • M height of the first input matrix
  • N width of the first input matrix and hight of the second
  • O width of the second input matrix
  • nPE Number of cores to use
  • pDstC points to the output matrix

Return: none

Glue code for parallel matrix matrix multiplication of a 8-bit integer matrices.

function plp_mat_mult_q16

void plp_mat_mult_q16(
    const int16_t *__restrict__ pSrcA,
    const int16_t *__restrict__ pSrcB,
    uint32_t M,
    uint32_t N,
    uint32_t O,
    uint32_t shift,
    int16_t *__restrict__ pDstC
)

Glue code for matrix mutliplication of 16-bit fix-point matrices.

Parameters:

  • pSrcA points to the first input matrix
  • pSrcB points to the second input matrix
  • M height of the first input matrix
  • N width of the first input matrix and hight of the second
  • O width of the second input matrix
  • shift Amount to shift the result of each multiplication.
  • pDstC points to the output matrix

Return: none

Par: Fix-Point and Shifting

The result will be shifted by the parameter shift to the right (multiplied by 2^-shift). Assume that matrix A is represented as pSrcA * 2^-x, and matrix B as pSrcB * 2^-y (in other words, A has it's x last digits after the binary point). Then, the output is represented as pDstC * 2^-(x + y - shift).

Glue code for matrix matrix multiplication of a 16-bit fix-point matrices.

The output of the matrix multiplication will also be stored as an 16-bit array. Set the shift parameter such that no overflow ocurrs.

function plp_mat_mult_q16_parallel

void plp_mat_mult_q16_parallel(
    const int16_t *__restrict__ pSrcA,
    const int16_t *__restrict__ pSrcB,
    uint32_t M,
    uint32_t N,
    uint32_t O,
    uint32_t shift,
    uint32_t nPE,
    int16_t *__restrict__ pDstC
)

Glue code for parallel matrix mutliplication of 16-bit fix-point matrices.

Parameters:

  • pSrcA points to the first input matrix
  • pSrcB points to the second input matrix
  • M height of the first input matrix
  • N width of the first input matrix and hight of the second
  • O width of the second input matrix
  • shift Amount to shift the result of each multiplication.
  • nPE Number of cores to use
  • pDstC points to the output matrix

Return: none

Par: Fix-Point and Shifting

The result will be shifted by the parameter shift to the right (multiplied by 2^-shift). Assume that matrix A is represented as pSrcA * 2^-x, and matrix B as pSrcB * 2^-y (in other words, A has it's x last digits after the binary point). Then, the output is represented as pDstC * 2^-(x + y - shift).

Glue code for parallel matrix matrix multiplication of a 16-bit fix-point matrices.

The output of the matrix multiplication will also be stored as an 16-bit array. Set the shift parameter such that no overflow ocurrs.

function plp_mat_mult_q32

void plp_mat_mult_q32(
    const int32_t *__restrict__ pSrcA,
    const int32_t *__restrict__ pSrcB,
    uint32_t M,
    uint32_t N,
    uint32_t O,
    uint32_t shift,
    int32_t *__restrict__ pDstC
)

Glue code for matrix mutliplication of 32-bit fix-point matrices.

Parameters:

  • pSrcA points to the first input matrix
  • pSrcB points to the second input matrix
  • M height of the first input matrix
  • N width of the first input matrix and hight of the second
  • O width of the second input matrix
  • shift Amount to shift the result of each multiplication.
  • pDstC points to the output matrix

Return: none

Par: Fix-Point and Shifting

The result will be shifted by the parameter shift to the right (multiplied by 2^-shift). Assume that matrix A is represented as pSrcA * 2^-x, and matrix B as pSrcB * 2^-y (in other words, A has it's x last digits after the binary point). Then, the output is represented as pDstC * 2^-(x + y - shift).

Glue code for matrix matrix multiplication of a 32-bit fix-point matrices.

function plp_mat_mult_q32_parallel

void plp_mat_mult_q32_parallel(
    const int32_t *__restrict__ pSrcA,
    const int32_t *__restrict__ pSrcB,
    uint32_t M,
    uint32_t N,
    uint32_t O,
    uint32_t shift,
    uint32_t nPE,
    int32_t *__restrict__ pDstC
)

Glue code for parallel matrix mutliplication of 32-bit fix-point matrices.

Parameters:

  • pSrcA points to the first input matrix
  • pSrcB points to the second input matrix
  • M height of the first input matrix
  • N width of the first input matrix and hight of the second
  • O width of the second input matrix
  • shift Amount to shift the result of each multiplication.
  • nPE Number of cores to use
  • pDstC points to the output matrix

Return: none

Par: Fix-Point and Shifting

The result will be shifted by the parameter shift to the right (multiplied by 2^-shift). Assume that matrix A is represented as pSrcA * 2^-x, and matrix B as pSrcB * 2^-y (in other words, A has it's x last digits after the binary point). Then, the output is represented as pDstC * 2^-(x + y - shift).

Glue code for parallel matrix matrix multiplication of a 32-bit fix-point matrices.

function plp_mat_mult_q8

void plp_mat_mult_q8(
    const int8_t *__restrict__ pSrcA,
    const int8_t *__restrict__ pSrcB,
    uint32_t M,
    uint32_t N,
    uint32_t O,
    uint32_t shift,
    int8_t *__restrict__ pDstC
)

Glue code for matrix mutliplication of 8-bit fix-point matrices.

Parameters:

  • pSrcA points to the first input matrix
  • pSrcB points to the second input matrix
  • M height of the first input matrix
  • N width of the first input matrix and hight of the second
  • O width of the second input matrix
  • shift Amount to shift the result of each multiplication.
  • pDstC points to the output matrix

Return: none

Par: Fix-Point and Shifting

The result will be shifted by the parameter shift to the right (multiplied by 2^-shift). Assume that matrix A is represented as pSrcA * 2^-x, and matrix B as pSrcB * 2^-y (in other words, A has it's x last digits after the binary point). Then, the output is represented as pDstC * 2^-(x + y - shift).

Glue code for matrix matrix multiplication of a 8-bit fix-point matrices.

The output of the matrix multiplication will also be stored as an 8-bit array. Set the shift parameter such that no overflow ocurrs.

function plp_mat_mult_q8_parallel

void plp_mat_mult_q8_parallel(
    const int8_t *__restrict__ pSrcA,
    const int8_t *__restrict__ pSrcB,
    uint32_t M,
    uint32_t N,
    uint32_t O,
    uint32_t shift,
    uint32_t nPE,
    int8_t *__restrict__ pDstC
)

Glue code for parallel matrix mutliplication of 8-bit fix-point matrices.

Parameters:

  • pSrcA points to the first input matrix
  • pSrcB points to the second input matrix
  • M height of the first input matrix
  • N width of the first input matrix and hight of the second
  • O width of the second input matrix
  • shift Amount to shift the result of each multiplication.
  • nPE Number of cores to use
  • pDstC points to the output matrix

Return: none

Par: Fix-Point and Shifting

The result will be shifted by the parameter shift to the right (multiplied by 2^-shift). Assume that matrix A is represented as pSrcA * 2^-x, and matrix B as pSrcB * 2^-y (in other words, A has it's x last digits after the binary point). Then, the output is represented as pDstC * 2^-(x + y - shift).

Glue code for parallel matrix matrix multiplication of a 8-bit fix-point matrices.

The output of the matrix multiplication will also be stored as an 8-bit array. Set the shift parameter such that no overflow ocurrs.


Updated on 2023-03-01 at 16:16:32 +0000