|
| 1 | +/* |
| 2 | +* Copyright 2021, Synopsys, Inc. |
| 3 | +* All rights reserved. |
| 4 | +* |
| 5 | +* This source code is licensed under the BSD-3-Clause license found in |
| 6 | +* the LICENSE file in the root directory of this source tree. |
| 7 | +* |
| 8 | +*/ |
| 9 | + |
| 10 | +#include "mli_krn_gru_cell.h" |
| 11 | + |
| 12 | +#include "mli_check.h" |
| 13 | +#include "mli_config.h" |
| 14 | +#include "mli_debug.h" |
| 15 | +#include "mli_helpers_api.h" |
| 16 | +#include "mli_prv_activation_lut.h" |
| 17 | +#include "mli_types.h" |
| 18 | + |
| 19 | +#ifdef __cplusplus |
| 20 | +extern "C" { |
| 21 | +#endif |
| 22 | + |
| 23 | +typedef mli_acc32_t mli_sa8_sa8_sa32_accu_t; |
| 24 | +typedef mli_acc40_t mli_fx16_accu_t; |
| 25 | +typedef mli_acc32_t mli_fx16_fx8_fx8_accu_t; |
| 26 | + |
| 27 | +#pragma MLI_CODE_SECTION_START(".mli_lib") |
| 28 | + |
| 29 | +mli_status mli_krn_gru_cell_fx16 ( |
| 30 | + const mli_tensor * in, |
| 31 | + const mli_tensor * prev_out, |
| 32 | + const mli_tensor * weights_in, |
| 33 | + const mli_tensor * weights_out, |
| 34 | + const mli_tensor * bias, |
| 35 | + const mli_lut * tanh_lut, |
| 36 | + const mli_lut * sigm_lut, |
| 37 | + const mli_rnn_cell_cfg * cfg, |
| 38 | + mli_tensor * out) { |
| 39 | + mli_status ret = MLI_CHECK_STATUS(mli_chk_gru_cell_fx16 |
| 40 | + (in, prev_out, weights_in, weights_out, bias, tanh_lut, sigm_lut, cfg, out), __func__); |
| 41 | + if (ret != MLI_STATUS_OK) return ret; |
| 42 | + |
| 43 | + mli::krn::gru_cell_prepare_and_run<int16_t, int16_t, int16_t, mli_fx16_accu_t, |
| 44 | + mli::krn::fx_quant_specific_params> |
| 45 | + (in, prev_out, weights_in, weights_out, bias, tanh_lut, sigm_lut, cfg, out); |
| 46 | + |
| 47 | + return ret; |
| 48 | +} |
| 49 | + |
| 50 | +mli_status mli_krn_gru_cell_fx16_fx8_fx8 ( |
| 51 | + const mli_tensor * in, |
| 52 | + const mli_tensor * prev_out, |
| 53 | + const mli_tensor * weights_in, |
| 54 | + const mli_tensor * weights_out, |
| 55 | + const mli_tensor * bias, |
| 56 | + const mli_lut * tanh_lut, |
| 57 | + const mli_lut * sigm_lut, |
| 58 | + const mli_rnn_cell_cfg * cfg, |
| 59 | + mli_tensor * out) { |
| 60 | + mli_status ret = MLI_CHECK_STATUS(mli_chk_gru_cell_fx16_fx8_fx8 |
| 61 | + (in, prev_out, weights_in, weights_out, bias, tanh_lut, sigm_lut, cfg, out), __func__); |
| 62 | + if (ret != MLI_STATUS_OK) return ret; |
| 63 | + |
| 64 | + mli::krn::gru_cell_prepare_and_run<int16_t, int8_t, int8_t, mli_fx16_fx8_fx8_accu_t, |
| 65 | + mli::krn::fx_quant_specific_params> |
| 66 | + (in, prev_out, weights_in, weights_out, bias, tanh_lut, sigm_lut, cfg, out); |
| 67 | + |
| 68 | + return ret; |
| 69 | +} |
| 70 | + |
| 71 | +mli_status mli_krn_gru_cell_sa8_sa8_sa32 ( |
| 72 | + const mli_tensor * in, |
| 73 | + const mli_tensor * prev_out, |
| 74 | + const mli_tensor * weights_in, |
| 75 | + const mli_tensor * weights_out, |
| 76 | + const mli_tensor * bias, |
| 77 | + const mli_lut * tanh_lut, |
| 78 | + const mli_lut * sigm_lut, |
| 79 | + const mli_rnn_cell_cfg * cfg, |
| 80 | + mli_tensor * out) { |
| 81 | + mli_status ret = MLI_CHECK_STATUS(mli_chk_gru_cell_sa8_sa8_sa32 |
| 82 | + (in, prev_out, weights_in, weights_out, bias, tanh_lut, sigm_lut, cfg, out), __func__); |
| 83 | + if (ret != MLI_STATUS_OK) return ret; |
| 84 | + |
| 85 | + mli::krn::gru_cell_prepare_and_run<int8_t, int8_t, int32_t, mli_sa8_sa8_sa32_accu_t, |
| 86 | + mli::krn::s8asym_quant_specific_params> |
| 87 | + (in, prev_out, weights_in, weights_out, bias, tanh_lut, sigm_lut, cfg, out); |
| 88 | + |
| 89 | + return ret; |
| 90 | +} |
| 91 | + |
| 92 | +#pragma MLI_CODE_SECTION_END() |
| 93 | + |
| 94 | +#ifdef __cplusplus |
| 95 | +} |
| 96 | +#endif |
0 commit comments