Polaris Project
Functions
Computation Interface

Functions

PolarisStatus polaris_gemm (PolarisContext *ctxt, PolarisTransType trans_a, PolarisTransType trans_b, int m, int n, int k, float alpha, const void *a, PolarisDataType type_a, int lda, const void *b, PolarisDataType type_b, int ldb, float beta, void *c, PolarisDataType type_c, int ldc, const void *bias, PolarisActivationType activation)
 Perform matrix multiplication with bias and activation support. More...
 
PolarisStatus polaris_activation_2d (PolarisContext *ctxt, PolarisActivationType type, int m, int n, float alpha, const void *x, PolarisDataType type_x, int stride_x, float beta, void *y, PolarisDataType type_y, int stride_y)
 Compute activation functions. More...
 
PolarisStatus polaris_deactivation_2d (PolarisContext *ctxt, PolarisActivationType type, int m, int n, float alpha, const void *y, PolarisDataType type_y, int stride_y, const void *dy, PolarisDataType type_dy, int stride_dy, const void *x, PolarisDataType type_x, int stride_x, float beta, void *dx, PolarisDataType type_dx, int stride_dx)
 Compute derived activation functions. More...
 
PolarisStatus polaris_elementwise_2d (PolarisContext *ctxt, PolarisElementWiseType type, int m, int n, float alpha0, const void *x0, PolarisDataType type_x0, int stride_x0, float alpha1, const void *x1, PolarisDataType type_x1, int stride_x1, float beta, void *y, PolarisDataType type_y, int stride_y)
 Element wise functions. More...
 
PolarisStatus polaris_transpose (PolarisContext *ctxt, int m, int n, const void *x, PolarisDataType type_x, int stride_x, void *y, PolarisDataType type_y, int stride_y)
 Perform matrix transpose on FPGA. More...
 

Detailed Description

Functions that involve computation. This group provides the core computation ability of Polaris library.

Function Documentation

◆ polaris_gemm()

PolarisStatus polaris_gemm ( PolarisContext ctxt,
PolarisTransType  trans_a,
PolarisTransType  trans_b,
int  m,
int  n,
int  k,
float  alpha,
const void *  a,
PolarisDataType  type_a,
int  lda,
const void *  b,
PolarisDataType  type_b,
int  ldb,
float  beta,
void *  c,
PolarisDataType  type_c,
int  ldc,
const void *  bias,
PolarisActivationType  activation 
)

Perform matrix multiplication with bias and activation support.

This function perform the calculation as the formula:

c = activation( alpha * op(a) * op(b) + beta * c + bias )

This function behaves similar with SGEMM function in CBLAS, with the extended ability of adding bias vector and performing activation functions, which match better for the need of deep neural network. In another word, this function provides the ability of the forward process of a full-connected layer.

Parameters like trans_a, trans_b, m, n, k, alpha, a, lda b, ldb, beta, c, ldc all have the same meaning with that in CBLAS SGEMM.

bias is a vector with dimension 1 * n, which will be added to each row of output matrix c.

activation indicates the activation function type to be performed after the bias procession.

Caller could specify the data type of input matrix a, b, c with type_a, type_b, type_c , data type of bias is the same with c.

Note
this function best performed with trans_a equals to POLARIS_NO_TRANS and trans_b equals to POLARIS_TRANS. (Currently supports calling with this mode only)
Warning
lda, ldb and ldc is currently not supported in this version of Polaris, this functionality will be released later in December.
For data type, only POLARIS_FP32 is available for now, support for other data type will be released later.
Parameters
[in]ctxtpointer to PolarisContext object
[in]trans_aif POLARIS_NO_TRANS, a is m * k, otherwise k * m
[in]trans_bif POLARIS_NO_TRANS, b is n * k, otherwise k * n
[in]mdimension m
[in]ndimension n
[in]kdimension k
[in]alphascalar parameter
[in]aFPGA address of matrix a
[in]type_adata type of matrix a
[in]ldasame as LDA in BLAS
[in]bFPGA address of matrix b
[in]type_bdata type of matrix b
[in]ldbsame as LDB in BLAS
[in]betascalar parameter
[in,out]cFPGA address of matrix c
[in]type_cdata type of matrix c and bias
[in]ldcsame as LDC in BLAS
[in]biasFPGA address of bias
[in]activationactivaion type
Returns
Execution status, POLARIS_OK on success.

◆ polaris_activation_2d()

PolarisStatus polaris_activation_2d ( PolarisContext ctxt,
PolarisActivationType  type,
int  m,
int  n,
float  alpha,
const void *  x,
PolarisDataType  type_x,
int  stride_x,
float  beta,
void *  y,
PolarisDataType  type_y,
int  stride_y 
)

Compute activation functions.

This function calculate the following formula:

y = alpha * ActivationType(x) + beta * y

where both x and y have length elements. Activation type is indicated by type.

Parameters
[in]ctxtpointer to PolarisContext object
[in]typeactivation type
[in]mnumber of rows
[in]nnumber of cols
[in]alphaalpha value
[in]xinput matrix
[in]type_xdata type of x
[in]stride_xstride of x
[in]betabeta value
[out]youtput matrix
[in]type_ydata type of y
[in]stride_ystride of y
Note
Not fully supported by FPGA hardware yet.
Currently supports using with m = 1.
Returns
Execution status, POLARIS_OK on success.

◆ polaris_deactivation_2d()

PolarisStatus polaris_deactivation_2d ( PolarisContext ctxt,
PolarisActivationType  type,
int  m,
int  n,
float  alpha,
const void *  y,
PolarisDataType  type_y,
int  stride_y,
const void *  dy,
PolarisDataType  type_dy,
int  stride_dy,
const void *  x,
PolarisDataType  type_x,
int  stride_x,
float  beta,
void *  dx,
PolarisDataType  type_dx,
int  stride_dx 
)

Compute derived activation functions.

This function computes the following formula:

dx = DerivedActivation(y, dy, x)

It is used in the backward phase, and computes dx according to y, dy and x, where x and y is actually the input and output data separately of the forward phase of the same operation, while dy is the gradient of y.

Parameters
[in]ctxtpointer to PolarisContext
[in]typeactivation type
[in]mnumber of rows
[in]nnumber of cols
[in]alphaalpha value
[in]ybackward src data (output data of the forward phase)
[in]type_ydata type of y
[in]stride_ystride of y
[in]dygradient of y
[in]type_dydata type of dy
[in]stride_dystride of dy
[in]xbackward destination data (input data of the forward phase)
[in]type_xdata type of x
[in]stride_xstride of x
[in]betabeta value
[out]dxgradient of x
[in]type_dxdata type of dx
[in]stride_dxstride of dx
Note
Not supported by FPGA hardware yet.
Returns
Execution status, POLARIS_OK on success.

◆ polaris_elementwise_2d()

PolarisStatus polaris_elementwise_2d ( PolarisContext ctxt,
PolarisElementWiseType  type,
int  m,
int  n,
float  alpha0,
const void *  x0,
PolarisDataType  type_x0,
int  stride_x0,
float  alpha1,
const void *  x1,
PolarisDataType  type_x1,
int  stride_x1,
float  beta,
void *  y,
PolarisDataType  type_y,
int  stride_y 
)

Element wise functions.

Perform element-wise operations indicated by the following fomula:

y = ElementWiseOperation(alpha0 * x0, alpha1 * x1) + beta * y

where type indicates the exact operation to be performed.

where v0 is alpha0 * x0 and v1 is alpha1 * x1.

Parameters
[in]ctxtpointer to PolarisContext
[in]typeelement wise operation type
[in]mnumber of rows
[in]nnumber of cols
[in]alpha0scalar parameter
[in]x0input matrix
[in]type_x0data type of x0
[in]stride_x0stride of x0
[in]alpha1scalar parameter
[in]x1input matrix
[in]type_x1data type of x1
[in]stride_x1stride of x1
[in]betascalar parameter
[out]youtput matrix
[in]type_ydata type of y
[in]stride_ystride of y
Note
Not fully supported by FPGA hardware yet.
Currently supports using with m = 1.
Returns
Execution status, POLARIS_OK on success.

◆ polaris_transpose()

PolarisStatus polaris_transpose ( PolarisContext ctxt,
int  m,
int  n,
const void *  x,
PolarisDataType  type_x,
int  stride_x,
void *  y,
PolarisDataType  type_y,
int  stride_y 
)

Perform matrix transpose on FPGA.

Dimension of matrix x is m * n, and y is n * m.

Warning
address of y and x should NOT be the same.
Parameters
[in]ctxtpointer to PolarisContext object
[in]mdimension m
[in]ndimension n
[in]xFPGA address of input matrix
[in]type_xdata type of x
[in]stride_xstride of x
[out]yFPGA address of output matrix
[in]type_ydata type of y
[in]stride_ystride of y
Note
Not supported by FPGA hardware yet.
Returns
Execution status, POLARIS_OK on success.