template class xf::blas::GemmKernel

#include "gemmKernel.hpp"

Overview

Gemm class, implement C = A*B+X t_aColMemWords defines number of memwords in the columns of one row of buffer_A. Due to the reusability, the height of buffer_A is only one memwords. For buffer_B, t_aColMemWords defines number of memwords in the rows of one column in buffer_B, t_bColMemWords defines number of memwords in the cols of one row in buffer_B. t_aRowMemWords and t_bColMemWords define the height and width of buffer_C in terms of memwords.

Parameters:

t_FloatType

matrix A, B entry data type

t_XDataType

matrix X entry data type

t_DdrWidth

number of matrix elements in one memory word

t_XDdrWidth

number of matrix X elements in one memory word

t_aColMemWords

number of memory words in one row of the matrix A buffer

t_aRowMemWords

number of memory words in one column of the matrix A buffer

t_bColMemWords

number of memory words in one row of the matrix B buffer

template <
    typename t_FloatType,
    typename t_XDataType,
    unsigned int t_DdrWidth,
    unsigned int t_XDdrWidth,
    unsigned int t_aColMemWords = 1,
    unsigned int t_aRowMemWords = 1,
    unsigned int t_bColMemWords = 1
    >
class GemmKernel

// typedefs

typedef WideType <t_FloatType, t_DdrWidth> DdrWideType
typedef DdrWideType::t_TypeInt DdrIntType
typedef hls::stream <DdrIntType> DdrStream
typedef TaggedWideType <t_FloatType, t_DdrWidth> TaggedWideFloat
typedef hls::stream <typename TaggedWideType <t_FloatType, t_DdrWidth>::t_TypeInt> EdgeStream
typedef WideType <t_XDataType, t_XDdrWidth> XDdrWideType
typedef hls::stream <typename WideType <t_XDataType, t_XDdrWidth>::t_TypeInt> XDdrStream
typedef WideType <t_XDataType, t_DdrWidth> DdrWideTypeForX
typedef t_FloatType MacBitType
typedef DdrWideType WideMacBitType
typedef DdrStream WideMacBitStream
typedef GemmArgs GemmArgsType

// fields

static const unsigned int t_aMH
static const unsigned int t_bKD
static const unsigned int t_DdrOverXDdr
static const unsigned int t_xColMemWords

Methods

GemmReadMatA

void GemmReadMatA (
    DdrIntType* l_aAddr,
    unsigned int l_aColBlocks,
    unsigned int l_aRowBlocks,
    unsigned int l_bColBlocks,
    unsigned int l_aWordLd,
    DdrStream& p_As
    )

GemmReadMatA load data from Matrix A.

Parameters:

l_aAddr

the base address of matrix A in external memory

l_aColBlocks

the No. blocks along matrix A cols

l_aRowBlocks

the No. blocks along matrix A rows

l_bColBlocks

the No. blocks along matrix B cols

l_aWordLd

the matrix A word leading dimention

p_As

the output stream

GemmReadMatB

void GemmReadMatB (
    DdrIntType* l_bAddr,
    unsigned int l_aColBlocks,
    unsigned int l_aRowBlocks,
    unsigned int l_bColBlocks,
    unsigned int l_bWordLd,
    DdrStream& p_Bs
    )

GemmReadMatB load data from matrix B.

Parameters:

l_bAddr

the base address of matrix B in external memory

l_aColBlocks

the No. blocks along matrix B cols

l_aRowBlocks

the No. blocks along matrix B rows

l_bColBlocks

the No. blocks along matrix B cols

l_bWordLd

the matrix B word leading dimention

p_Bs

the output stream

GemmReadMatX

void GemmReadMatX (
    DdrIntType* l_xAddr,
    unsigned int l_aColBlocks,
    unsigned int l_aRowBlocks,
    unsigned int l_bColBlocks,
    unsigned int l_xWordLd,
    XDdrStream& p_Xs
    )

GemmReadMatX load data from matrix X.

Parameters:

l_xAddr

the base address of matrix X in external memory

l_aColBlocks

the No. blocks along matrix X cols

l_aRowBlocks

the No. blocks along matrix X rows

l_bColBlocks

the No. blocks along matrix X cols

l_xWordLd

the matrix X word leading dimention

p_Xs

the output stream

GemmReadABX

void GemmReadABX (
    DdrIntType* l_aAddr,
    DdrIntType* l_bAddr,
    DdrIntType* l_xAddr,
    unsigned int l_aColBlocks,
    unsigned int l_aRowBlocks,
    unsigned int l_bColBlocks,
    unsigned int l_aWordLd,
    unsigned int l_bWordLd,
    unsigned int l_xWordLd,
    DdrStream& p_As,
    DdrStream& p_Bs,
    XDdrStream& p_Xs
    )

GemmReadABX load data from matrix A, B and X.

Parameters:

l_aAddr

the base address of matrix A in external memory

l_bAddr

the base address of matrix B in external memory

l_xAddr

the base address of matrix X in external memory

l_aColBlocks

the No. blocks along matrix X cols

l_aRowBlocks

the No. blocks along matrix X rows

l_bColBlocks

the No. blocks along matrix X cols

l_aWordLd

the matrix A word leading dimention

l_bWordLd

the matrix B word leading dimention

l_xWordLd

the matrix X word leading dimention

p_As

the output stream for matrix A

p_Bs

the output stream for matrix B

p_Xs

the output stream for matrix X

runGemm

void runGemm (
    DdrIntType* p_DdrRd,
    DdrIntType* p_DdrWr,
    GemmArgsType& p_Args
    )

runGemm launch gemm operation with given arguments

Parameters:

p_DdrRd

the DDR/HBM address for input data

p_DdrWr

the DDR/HBM address for output data

p_Args

the arguments for gemm

GemmWriteDdrStream

void GemmWriteDdrStream (
    DdrIntType* l_cAddr,
    DdrStream& p_Cs,
    unsigned int l_aRowBlocks,
    unsigned int l_bColBlocks,
    unsigned int l_cWordLd
    )

GemmWriteDdrStream write matrix data to Memory.

Parameters:

l_cAddr

the base address of matrix in external memory

p_Cs

the input stream

l_aRowBlocks

the No. blocks along matrix X rows

l_bColBlocks

the No. blocks along matrix X cols

l_cWordLd

the matrix word leading dimention