Skip to content

Commit 011242a

Browse files
slarenarthw
authored andcommitted
ggml : fix gelu tables initialization (ggml-org#10172)
1 parent b25922c commit 011242a

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

ggml/src/ggml-cpu.c

+10-4
Original file line numberDiff line numberDiff line change
@@ -13678,15 +13678,21 @@ int ggml_cpu_get_sve_cnt(void) {
1367813678
}
1367913679

1368013680
void ggml_cpu_init(void) {
13681+
// needed to initialize f16 tables
13682+
{
13683+
struct ggml_init_params params = { 0, NULL, false };
13684+
struct ggml_context * ctx = ggml_init(params);
13685+
ggml_free(ctx);
13686+
}
13687+
1368113688
ggml_critical_section_start();
1368213689

1368313690
static bool is_first_call = true;
1368413691

1368513692
if (is_first_call) {
1368613693
// initialize GELU, Quick GELU, SILU and EXP F32 tables
1368713694
{
13688-
// FIXME: this may be called before ggml_init
13689-
//const uint64_t t_start = ggml_time_us(); UNUSED(t_start);
13695+
const uint64_t t_start = ggml_time_us(); UNUSED(t_start);
1369013696

1369113697
for (int i = 0; i < (1 << 16); ++i) {
1369213698
union {
@@ -13698,9 +13704,9 @@ void ggml_cpu_init(void) {
1369813704
ggml_table_gelu_quick_f16[i] = GGML_FP32_TO_FP16(ggml_gelu_quick_f32(f));
1369913705
}
1370013706

13701-
//const uint64_t t_end = ggml_time_us(); UNUSED(t_end);
13707+
const uint64_t t_end = ggml_time_us(); UNUSED(t_end);
1370213708

13703-
//GGML_PRINT_DEBUG("%s: GELU, Quick GELU, SILU and EXP tables initialized in %f ms\n", __func__, (t_end - t_start)/1000.0);
13709+
GGML_PRINT_DEBUG("%s: GELU, Quick GELU, SILU and EXP tables initialized in %f ms\n", __func__, (t_end - t_start)/1000.0);
1370413710
}
1370513711

1370613712
#if defined(__ARM_ARCH)

0 commit comments

Comments
 (0)