Skip to content

Commit 0c6ee1c

Browse files
authored
ggml-cpu : re-enable fast gelu_quick_f16 (#22339)
1 parent 2dd8416 commit 0c6ee1c

1 file changed

Lines changed: 6 additions & 13 deletions

File tree

ggml/src/ggml-cpu/vec.h

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1036,12 +1036,12 @@ inline static float ggml_gelu_quick_f32(float x) {
10361036
return x*(1.0f/(1.0f+expf(GELU_QUICK_COEF*x)));
10371037
}
10381038

1039-
//inline static void ggml_vec_gelu_quick_f16(const int n, ggml_fp16_t * y, const ggml_fp16_t * x) {
1040-
// const uint16_t * i16 = (const uint16_t *) x;
1041-
// for (int i = 0; i < n; ++i) {
1042-
// y[i] = ggml_table_gelu_quick_f16[i16[i]];
1043-
// }
1044-
//}
1039+
inline static void ggml_vec_gelu_quick_f16(const int n, ggml_fp16_t * y, const ggml_fp16_t * x) {
1040+
const uint16_t * i16 = (const uint16_t *) x;
1041+
for (int i = 0; i < n; ++i) {
1042+
y[i] = ggml_table_gelu_quick_f16[i16[i]];
1043+
}
1044+
}
10451045

10461046
#ifdef GGML_GELU_QUICK_FP16
10471047
inline static void ggml_vec_gelu_quick_f32(const int n, float * y, const float * x) {
@@ -1060,13 +1060,6 @@ inline static void ggml_vec_gelu_quick_f32(const int n, float * y, const float *
10601060
}
10611061
#endif
10621062

1063-
inline static void ggml_vec_gelu_quick_f16(const int n, ggml_fp16_t * y, const ggml_fp16_t * x) {
1064-
for (int i = 0; i < n; ++i) {
1065-
float v = GGML_CPU_FP16_TO_FP32(x[i]);
1066-
y[i] = GGML_CPU_FP32_TO_FP16(v*(1.0f/(1.0f+expf(GELU_QUICK_COEF*v))));
1067-
}
1068-
}
1069-
10701063
// Sigmoid Linear Unit (SiLU) function
10711064
inline static float ggml_silu_f32(float x) {
10721065
return x/(1.0f + expf(-x));

0 commit comments

Comments
 (0)