Skip to content

Commit 8efdc0b

Browse files
committed
fix ggml time initialization
1 parent bb35ea6 commit 8efdc0b

File tree

3 files changed

+29
-4
lines changed

3 files changed

+29
-4
lines changed

ggml/src/ggml-cpu/ggml-cpu.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3460,6 +3460,13 @@ int ggml_cpu_has_sme(void) {
34603460
}
34613461

34623462
void ggml_cpu_init(void) {
3463+
// needed to initialize ggml_time
3464+
{
3465+
struct ggml_init_params params = { 0, NULL, false };
3466+
struct ggml_context * ctx = ggml_init(params);
3467+
ggml_free(ctx);
3468+
}
3469+
34633470
ggml_critical_section_start();
34643471

34653472
static bool is_first_call = true;

ggml/src/ggml-cpu/simd-mappings.h

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@
1818
#include <immintrin.h>
1919
#endif
2020

21+
#ifdef __cplusplus
22+
extern "C" {
23+
#endif
24+
2125
//
2226
// simd mappings
2327
//
@@ -139,11 +143,7 @@
139143

140144
// precomputed f32 table for f16 (256 KB)
141145
// defined in ggml-cpu.c, initialized in ggml_cpu_init()
142-
#ifdef __cplusplus
143-
extern "C" float ggml_table_f32_f16[1 << 16];
144-
#else
145146
extern float ggml_table_f32_f16[1 << 16];
146-
#endif
147147

148148
// On ARM NEON, it's quicker to directly convert x -> x instead of calling into ggml_lookup_fp16_to_fp32,
149149
// so we define GGML_CPU_FP16_TO_FP32 and GGML_CPU_FP32_TO_FP16 elsewhere for NEON.
@@ -1178,3 +1178,8 @@ static inline void __lzs_f16cx4_store(ggml_fp16_t * x, float32x4_t v_y) {
11781178
#define GGML_F32_ARR (GGML_F32_STEP/GGML_F32_EPR)
11791179
#define GGML_F16_ARR (GGML_F16_STEP/GGML_F16_EPR)
11801180
#endif
1181+
1182+
1183+
#ifdef __cplusplus
1184+
}
1185+
#endif

ggml/src/ggml.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1411,6 +1411,19 @@ static inline bool ggml_can_repeat_rows(const struct ggml_tensor * t0, const str
14111411
////////////////////////////////////////////////////////////////////////////////
14121412

14131413
struct ggml_context * ggml_init(struct ggml_init_params params) {
1414+
static bool is_first_call = true;
1415+
1416+
ggml_critical_section_start();
1417+
1418+
if (is_first_call) {
1419+
// initialize time system (required on Windows)
1420+
ggml_time_init();
1421+
1422+
is_first_call = false;
1423+
}
1424+
1425+
ggml_critical_section_end();
1426+
14141427
struct ggml_context * ctx = GGML_MALLOC(sizeof(struct ggml_context));
14151428

14161429
// allow to call ggml_init with 0 size

0 commit comments

Comments
 (0)