Skip to content

Commit

Permalink
[ util ] Implement exp_i function
Browse files Browse the repository at this point in the history
- Add exponential inplace function

**Self evaluation:**
1. Build test:     [X]Passed [ ]Failed [ ]Skipped
2. Run test:     [X]Passed [ ]Failed [ ]Skipped

Signed-off-by: skykongkong8 <[email protected]>
  • Loading branch information
skykongkong8 committed Feb 20, 2024
1 parent cc7da98 commit 8c72f55
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 12 deletions.
11 changes: 11 additions & 0 deletions nntrainer/utils/util_simd_neon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,17 @@ void softmax(const unsigned int N, float *X, float *Y) {
}
}

void exp_i(const unsigned int N, float *X) {
unsigned int i = 0;
for (; N - i >= VL_FP32; i += VL_FP32) {
vst1q_f32(&X[i], exp_ps(vld1q_f32(&X[i])));
}
while (i < N) {
X[i] = std::exp(X[i]);
++i;
}
}

#ifdef ENABLE_FP16
void compute_rotary_embedding_value(unsigned int dim, unsigned int half_,
unsigned int w, __fp16 *in, __fp16 *out,
Expand Down
24 changes: 12 additions & 12 deletions nntrainer/utils/util_simd_neon.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,19 +39,16 @@ void calc_trigonometric_vals_dup(unsigned int N_half, float *angle, float *cos_,
* @param Y float * for Vector Y
* @param Z float * for Vector Z
*/
<<<<<<< HEAD
void swish(const unsigned int N, float *X, float *Y, float *Z);
=======
void swish_neon(const unsigned int N, float *X, float *Y, float *Z);

/**
* @brief returns maximum value of the vector X
*
*
* @param N number of elements in X
* @param X float * for Vector X
* @return float maximum value of vector X
*/
float max(const unsigned int N, float* X);
float max(const unsigned int N, float *X);

/**
* @brief soft max function with neon y_i = exp(x_i) / sum( exp(x_i) )
Expand All @@ -61,7 +58,14 @@ float max(const unsigned int N, float* X);
* @param Y float * for Vector Y
*/
void softmax(const unsigned int N, float *X, float *Y);
>>>>>>> [ util ] Implement softmax function in util_simd

/**
* @brief exponential inplace function
*
* @param N number of elements in X
* @param X float * for Vector X
*/
void exp_i(const unsigned int N, float *X);
#ifdef ENABLE_FP16
/**
* @brief Accelerating function for rotary embedding layer forwarding
Expand All @@ -85,19 +89,16 @@ void compute_rotary_embedding_value(unsigned int dim, unsigned int half_,
* @param Y __fp16 * for Vector Y
* @param Z __fp16 * for Vector Z
*/
<<<<<<< HEAD
void swish(const unsigned int N, __fp16 *X, __fp16 *Y, __fp16 *Z);
=======
void swish_neon(const unsigned int N, __fp16 *X, __fp16 *Y, __fp16 *Z);

/**
* @brief returns maximum value of the vector X
*
*
* @param N number of elements in X
* @param X __fp16 * for Vector X
* @return __fp16 maximum value of vector X
*/
__fp16 max(const unsigned int N, __fp16* X);
__fp16 max(const unsigned int N, __fp16 *X);

/**
* @brief soft max function with neon y_i = exp(x_i) / sum( exp(x_i) )
Expand All @@ -109,7 +110,6 @@ __fp16 max(const unsigned int N, __fp16* X);
* @param Y __fp16 * for Vector Y
*/
void softmax(const unsigned int N, __fp16 *X, __fp16 *Y);
>>>>>>> [ util ] Implement softmax function in util_simd
#endif

} // namespace nntrainer::neon
Expand Down

0 comments on commit 8c72f55

Please sign in to comment.