Polaris Project
|
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... | |
Functions that involve computation. This group provides the core computation ability of Polaris library.
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
.
trans_a
equals to POLARIS_NO_TRANS and trans_b
equals to POLARIS_TRANS. (Currently supports calling with this mode only)lda
, ldb
and ldc
is currently not supported in this version of Polaris, this functionality will be released later in December.[in] | ctxt | pointer to PolarisContext object |
[in] | trans_a | if POLARIS_NO_TRANS, a is m * k , otherwise k * m |
[in] | trans_b | if POLARIS_NO_TRANS, b is n * k , otherwise k * n |
[in] | m | dimension m |
[in] | n | dimension n |
[in] | k | dimension k |
[in] | alpha | scalar parameter |
[in] | a | FPGA address of matrix a |
[in] | type_a | data type of matrix a |
[in] | lda | same as LDA in BLAS |
[in] | b | FPGA address of matrix b |
[in] | type_b | data type of matrix b |
[in] | ldb | same as LDB in BLAS |
[in] | beta | scalar parameter |
[in,out] | c | FPGA address of matrix c |
[in] | type_c | data type of matrix c and bias |
[in] | ldc | same as LDC in BLAS |
[in] | bias | FPGA address of bias |
[in] | activation | activaion type |
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
.
[in] | ctxt | pointer to PolarisContext object |
[in] | type | activation type |
[in] | m | number of rows |
[in] | n | number of cols |
[in] | alpha | alpha value |
[in] | x | input matrix |
[in] | type_x | data type of x |
[in] | stride_x | stride of x |
[in] | beta | beta value |
[out] | y | output matrix |
[in] | type_y | data type of y |
[in] | stride_y | stride of y |
m = 1
.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
.
[in] | ctxt | pointer to PolarisContext |
[in] | type | activation type |
[in] | m | number of rows |
[in] | n | number of cols |
[in] | alpha | alpha value |
[in] | y | backward src data (output data of the forward phase) |
[in] | type_y | data type of y |
[in] | stride_y | stride of y |
[in] | dy | gradient of y |
[in] | type_dy | data type of dy |
[in] | stride_dy | stride of dy |
[in] | x | backward destination data (input data of the forward phase) |
[in] | type_x | data type of x |
[in] | stride_x | stride of x |
[in] | beta | beta value |
[out] | dx | gradient of x |
[in] | type_dx | data type of dx |
[in] | stride_dx | stride of dx |
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.
:= v0 + v1
:= v0 * v1
:= min(v0, v1)
:= max(v0, v1)
where v0
is alpha0 * x0
and v1
is alpha1 * x1
.
[in] | ctxt | pointer to PolarisContext |
[in] | type | element wise operation type |
[in] | m | number of rows |
[in] | n | number of cols |
[in] | alpha0 | scalar parameter |
[in] | x0 | input matrix |
[in] | type_x0 | data type of x0 |
[in] | stride_x0 | stride of x0 |
[in] | alpha1 | scalar parameter |
[in] | x1 | input matrix |
[in] | type_x1 | data type of x1 |
[in] | stride_x1 | stride of x1 |
[in] | beta | scalar parameter |
[out] | y | output matrix |
[in] | type_y | data type of y |
[in] | stride_y | stride of y |
m = 1
.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
.
y
and x
should NOT be the same.[in] | ctxt | pointer to PolarisContext object |
[in] | m | dimension m |
[in] | n | dimension n |
[in] | x | FPGA address of input matrix |
[in] | type_x | data type of x |
[in] | stride_x | stride of x |
[out] | y | FPGA address of output matrix |
[in] | type_y | data type of y |
[in] | stride_y | stride of y |