Skip to content

Commit

Permalink
[pre-commit.ci] auto fixes from pre-commit hooks
Browse files Browse the repository at this point in the history
  • Loading branch information
pre-commit-ci[bot] committed Dec 9, 2024
1 parent f3ff077 commit 0f08e7a
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions hls4ml/templates/vivado/nnet_utils/nnet_layernorm.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,15 @@ struct layernorm_config {
template <class x_T, class y_T> using product = nnet::product::mult<x_T, y_T>;
};

template<typename CONFIG_T, int N_TABLE>
void init_invert_sqr_table(typename CONFIG_T::table_t table_out[N_TABLE])
{
template <typename CONFIG_T, int N_TABLE> void init_invert_sqr_table(typename CONFIG_T::table_t table_out[N_TABLE]) {
// Inversion function:
// result = 1/sqrt(x)
float min_val = CONFIG_T::epsilon;
float max_val = CONFIG_T::table_range;
float step = max_val / (float)(N_TABLE);
for (int ii = 0; ii < N_TABLE; ii++) {
float in_val = min_val + step * ii;
table_out[ii] = (typename CONFIG_T::table_t)(1.0/sqrt(in_val));
table_out[ii] = (typename CONFIG_T::table_t)(1.0 / sqrt(in_val));
}
}

Expand Down Expand Up @@ -88,10 +86,13 @@ void layernorm_1d(data_T data[CONFIG_T::n_in / CONFIG_T::seq_len], res_T res[CON
}
var = CONFIG_T::template product<typename CONFIG_T::mean_t, typename CONFIG_T::mean_t>::product(sum_cache2, k_inv);

int index = (var) * (CONFIG_T::table_size) * inv_range_inv;
if (CONFIG_T::table_range > 1) index = (var) * (CONFIG_T::table_size) / (int)CONFIG_T::table_range;
if (index < 0) index = 0;
if (index > CONFIG_T::table_size - 1) index = CONFIG_T::table_size - 1;
int index = (var) * (CONFIG_T::table_size)*inv_range_inv;
if (CONFIG_T::table_range > 1)
index = (var) * (CONFIG_T::table_size) / (int)CONFIG_T::table_range;
if (index < 0)
index = 0;
if (index > CONFIG_T::table_size - 1)
index = CONFIG_T::table_size - 1;
deno_inver = invert_sqr_table[index];

LAYERNORM_1D_RESULT:
Expand Down

0 comments on commit 0f08e7a

Please sign in to comment.