Files
blis/addon/aocl_gemm/aocl_gemm_post_ops.h
Deepak Negi b5c1b6055a Sigmoid and Tanh post-operation support for bf16 API.
Description:

Implemented sigmoid, tanh as fused post-ops in
aocl_gemm_bf16bf16f32o<f32|bf16) API's

Sigmoid(x) = 1/1+e^(-x)
Tanh(x) = (1-e^(-2x))/(1+e^(2x))

Updated bench_lpgemm to recognize sigmod, tanh
as options for post-ops from bench_input and verified.

AMD-Internal: [SWLCSG-3178]

Change-Id: I78a3ba4a67ab63f9d671fbe315f977b016a0d969
2024-11-15 01:13:31 -04:00

148 lines
3.6 KiB
C

/*
BLIS
An object-based framework for developing high-performance BLAS-like
libraries.
Copyright (C) 2022 - 2024, Advanced Micro Devices, Inc. All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:
- Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
- Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
- Neither the name(s) of the copyright holder(s) nor the names of its
contributors may be used to endorse or promote products derived
from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef AOCL_GEMM_POST_OPS_H
#define AOCL_GEMM_POST_OPS_H
#define AOCL_MAX_POST_OPS 8
#define AOCL_MAX_PRE_OPS 1
typedef enum
{
RELU = 0,
PRELU = 1,
GELU_TANH = 2,
GELU_ERF = 3,
CLIP = 4,
SWISH = 5,
TANH = 6,
SIGMOID = 7,
} AOCL_ELT_ALGO_TYPE;
typedef enum
{
SUM = 1,
ELTWISE = 2,
BIAS = 3,
SCALE = 4,
MATRIX_ADD = 5,
MATRIX_MUL = 6,
} AOCL_POST_OP_TYPE;
typedef struct
{
void* alpha;
void* beta;
AOCL_ELT_ALGO_TYPE algo_type;
} aocl_eltwise_algo;
typedef struct
{
bool is_power_of_2;
void* scale_factor;
void* buff;
void* zero_point;
dim_t scale_factor_len;
dim_t zero_point_len;
} aocl_post_op_sum; // Also use for scale.
typedef struct
{
bool is_power_of_2;
void* scale_factor;
dim_t scale_factor_len;
aocl_eltwise_algo algo;
} aocl_post_op_eltwise;
typedef struct
{
void* bias;
} aocl_post_op_bias;
typedef struct
{
void* matrix;
dim_t ldm;
} aocl_post_op_matrix_add;
typedef struct
{
void* matrix;
dim_t ldm;
} aocl_post_op_matrix_mul;
typedef struct
{
void* zero_point;
//len should be one which is one or n i.e., one zp
//per tensor or one zp per channel respectively
dim_t zero_point_len;
} aocl_pre_op_zp;
typedef struct
{
void* scale_factor;
//len should be one which is one or n i.e., one sf
//per tensor or one sf per channel respectively
dim_t scale_factor_len;
} aocl_pre_op_sf;
typedef struct
{
aocl_pre_op_zp *b_zp;
aocl_pre_op_sf *b_scl;
dim_t seq_length;
} aocl_pre_op;
typedef struct
{
aocl_post_op_sum* sum; // Multiple scale/sum allowed.
aocl_post_op_eltwise* eltwise; // Multiple eltwise allowed.
aocl_post_op_bias* bias;
aocl_post_op_matrix_add* matrix_add;
aocl_post_op_matrix_mul* matrix_mul;
// eg: seq_length = 2
dim_t seq_length;
// eg: seq_vector[0] = BIAS, seq_vector[1] = ELTWISE means bias followed
// by eltwise(relu, if AOCL_ELT_ALGO_TYPE = 1).
AOCL_POST_OP_TYPE* seq_vector;
//Pass pre-op structure also through post-ops
aocl_pre_op *pre_ops;
} aocl_post_op;
#endif //AOCL_GEMM_POST_OPS_H