AOCL-DLP provides standalone element-wise operations that apply transformations to a matrix without performing a GEMM. These are different from GEMM post-ops β use eltwise ops when you already have a computed matrix and want to apply activations, type conversions, or other element-wise transforms to it.
Scenario |
Use |
|---|---|
Apply activation after GEMM (same call) |
GEMM with |
Apply activation to a matrix not produced by GEMM |
Standalone eltwise ops |
Convert matrix between data types with fused operations |
Standalone eltwise ops |
Function Signature:
All eltwise functions share the same parameter pattern:
aocl_gemm_eltwise_ops_<input_type>o<output_type>(
const char order, // 'R' = row-major, 'C' = column-major
const char transa, // transpose option for input
const char transb, // transpose option for output
const md_t m, // number of rows
const md_t n, // number of columns
const <in_t>* a, // input matrix
const md_t lda, // leading dimension of input
<out_t>* b, // output matrix
const md_t ldb, // leading dimension of output
dlp_metadata_t* metadata // post-operations to apply
);
The metadata parameter controls which operations are applied and uses the same
dlp_metadata_t struct as GEMM post-ops.
Supported Type Combinations:
Input |
Output |
Function |
|---|---|---|
bfloat16 |
float |
|
bfloat16 |
bfloat16 |
|
float |
float |
|
float |
bfloat16 |
|
float |
int32_t |
|
float |
int8_t |
|
float |
uint8_t |
|
Example: Apply GELU to a Float Matrix:
#include <aocl_dlp.h>
float input[M * N] = { /* ... */ };
float output[M * N] = {0};
dlp_post_op_eltwise gelu_op = {
.sf = NULL,
.algo = { .alpha = NULL, .beta = NULL,
.algo_type = GELU_TANH, .stor_type = DLP_F32 }
};
DLP_POST_OP_TYPE seq[] = { ELTWISE };
dlp_metadata_t meta = {0};
meta.seq_length = 1;
meta.seq_vector = seq;
meta.eltwise = &gelu_op;
meta.num_eltwise = 1;
aocl_gemm_eltwise_ops_f32of32(
'R', 'N', 'N', m, n,
input, n,
output, n,
&meta);
Example: Convert BF16 to F32 with ReLU:
bfloat16 bf16_data[M * N] = { /* ... */ };
float f32_output[M * N] = {0};
dlp_post_op_eltwise relu_op = {
.sf = NULL,
.algo = { .alpha = NULL, .beta = NULL,
.algo_type = RELU, .stor_type = DLP_F32 }
};
DLP_POST_OP_TYPE seq[] = { ELTWISE };
dlp_metadata_t meta = {0};
meta.seq_length = 1;
meta.seq_vector = seq;
meta.eltwise = &relu_op;
meta.num_eltwise = 1;
aocl_gemm_eltwise_ops_bf16of32(
'R', 'N', 'N', m, n,
bf16_data, n,
f32_output, n,
&meta);
For more details, see the Eltwise Guide Wiki and the Eltwise API Reference.