mirror of
https://github.com/amd/blis.git
synced 2026-05-05 15:01:13 +00:00
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
144 lines
4.0 KiB
C
144 lines
4.0 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 LPGEMM_POST_OPS_H
|
|
#define LPGEMM_POST_OPS_H
|
|
|
|
typedef enum
|
|
{
|
|
POST_OPS_DISABLE = 0,
|
|
POST_OPS_BIAS = 1,
|
|
POST_OPS_RELU = 2,
|
|
POST_OPS_RELU_SCALE = 3,
|
|
POST_OPS_GELU_TANH = 4,
|
|
POST_OPS_GELU_ERF = 5,
|
|
POST_OPS_CLIP = 6,
|
|
POST_OPS_DOWNSCALE = 7,
|
|
POST_OPS_MATRIX_ADD = 8,
|
|
POST_OPS_SWISH = 9,
|
|
POST_OPS_MATRIX_MUL = 10,
|
|
POST_OPS_TANH = 11,
|
|
POST_OPS_SIGMOID = 12,
|
|
POST_OPS_SUM = 13
|
|
|
|
|
|
|
|
} LPGEMM_POST_OP_CODE;
|
|
|
|
// Used as an internal structure.
|
|
typedef struct lpgemm_post_op_t
|
|
{
|
|
uint64_t op_code;
|
|
void* op_args1; // zero_point, bias, sum_buff
|
|
void* op_args2; // alpha, storage order, sum_zero_point
|
|
void* op_args3; // beta, zero_point_len
|
|
void* scale_factor;
|
|
dim_t scale_factor_len;
|
|
bool is_power_of_2;
|
|
struct lpgemm_post_op_t* next;
|
|
} lpgemm_post_op;
|
|
|
|
// Used as an internal structure.
|
|
typedef struct lpgemm_pre_op_t
|
|
{
|
|
uint64_t op_code;
|
|
void *scale_factor;
|
|
dim_t scale_factor_len;
|
|
void *zp;
|
|
dim_t zp_len;
|
|
struct lpgemm_pre_op_t *next;
|
|
} lpgemm_pre_op;
|
|
|
|
// Used as an internal structure.
|
|
typedef struct lpgemm_post_op_attr_t
|
|
{
|
|
uint64_t post_op_c_i;
|
|
uint64_t post_op_c_j;
|
|
uint64_t rs_c_downscale;
|
|
uint64_t cs_c_downscale;
|
|
void* buf_downscale;
|
|
uint64_t is_first_k;
|
|
uint64_t is_last_k;
|
|
uint64_t c_stor_type;
|
|
uint64_t b_sum_offset;
|
|
int32_t* b_col_sum_vec;
|
|
int16_t* b_col_sum_vec_s16;
|
|
void* pre_op_scale_factor;
|
|
dim_t pre_op_scale_factor_len;
|
|
dim_t pre_op_off;
|
|
} lpgemm_post_op_attr;
|
|
|
|
|
|
err_t lpgemm_translate_to_post_ops_list
|
|
(
|
|
aocl_post_op* post_op_unparsed,
|
|
lpgemm_post_op* post_op_list,
|
|
void* scale_buffer,
|
|
void* meta_arg,
|
|
dim_t m,
|
|
dim_t n
|
|
);
|
|
|
|
err_t lpgemm_translate_to_pre_ops_list
|
|
(
|
|
aocl_pre_op *pre_op_unparsed,
|
|
lpgemm_pre_op *pre_op_list,
|
|
dim_t m,
|
|
dim_t n,
|
|
dim_t k
|
|
);
|
|
|
|
#define POST_OP_LABEL_LASTK_SAFE_JUMP \
|
|
if ( ( post_ops_attr.is_last_k == TRUE ) && ( post_ops_list_temp != NULL ) ) \
|
|
{ \
|
|
goto *post_ops_labels[post_ops_list_temp->op_code]; \
|
|
} \
|
|
else \
|
|
{ \
|
|
goto *post_ops_labels[0]; \
|
|
}
|
|
|
|
#define POST_OP_LABEL_LASTK_SAFE_JUMP_WITH_NEXT_PTR \
|
|
post_ops_list_temp = post_ops_list_temp->next; \
|
|
if ( post_ops_list_temp != NULL ) \
|
|
{ \
|
|
goto *post_ops_labels[post_ops_list_temp->op_code]; \
|
|
} \
|
|
else \
|
|
{ \
|
|
goto *post_ops_labels[0]; \
|
|
}
|
|
|
|
#endif //LPGEMM_POST_OPS_H
|