MCPcopy Create free account
hub / github.com/Tiiny-AI/PowerInfer / ggml_init

Function ggml_init

ggml.c:2165–2277  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2163////////////////////////////////////////////////////////////////////////////////
2164
2165struct ggml_context * ggml_init(struct ggml_init_params params) {
2166 // make this function thread safe
2167 ggml_critical_section_start();
2168
2169 static bool is_first_call = true;
2170
2171 if (is_first_call) {
2172 // initialize time system (required on Windows)
2173 ggml_time_init();
2174
2175 // initialize GELU, Quick GELU, SILU and EXP F32 tables
2176 {
2177 const uint64_t t_start = ggml_time_us(); UNUSED(t_start);
2178
2179 ggml_fp16_t ii;
2180 for (int i = 0; i < (1 << 16); ++i) {
2181 uint16_t ui = i;
2182 memcpy(&ii, &ui, sizeof(ii));
2183 const float f = ggml_table_f32_f16[i] = GGML_COMPUTE_FP16_TO_FP32(ii);
2184 ggml_table_gelu_f16[i] = GGML_FP32_TO_FP16(ggml_gelu_f32(f));
2185 ggml_table_gelu_quick_f16[i] = GGML_FP32_TO_FP16(ggml_gelu_quick_f32(f));
2186 ggml_table_silu_f16[i] = GGML_FP32_TO_FP16(ggml_silu_f32(f));
2187 ggml_table_exp_f16[i] = GGML_FP32_TO_FP16(expf(f));
2188 }
2189
2190 const uint64_t t_end = ggml_time_us(); UNUSED(t_end);
2191
2192 GGML_PRINT_DEBUG("%s: GELU, Quick GELU, SILU and EXP tables initialized in %f ms\n", __func__, (t_end - t_start)/1000.0f);
2193 }
2194
2195 // initialize g_state
2196 {
2197 const uint64_t t_start = ggml_time_us(); UNUSED(t_start);
2198
2199 g_state = (struct ggml_state) {
2200 /*.contexts =*/ { { 0 } },
2201 /*.numa =*/ {
2202 .n_nodes = 0,
2203 .total_cpus = 0,
2204 },
2205 };
2206
2207 for (int i = 0; i < GGML_MAX_CONTEXTS; ++i) {
2208 g_state.contexts[i].used = false;
2209 }
2210
2211 const uint64_t t_end = ggml_time_us(); UNUSED(t_end);
2212
2213 GGML_PRINT_DEBUG("%s: g_state initialized in %f ms\n", __func__, (t_end - t_start)/1000.0f);
2214 }
2215
2216#if defined(GGML_USE_CUBLAS)
2217 ggml_init_cublas();
2218#elif defined(GGML_USE_CLBLAST)
2219 ggml_cl_init();
2220#endif
2221
2222 ggml_setup_op_has_task_pass();

Callers 15

ggml_graph_importFunction · 0.70
ggml_opt_initFunction · 0.70
ggml_optFunction · 0.70
gguf_init_from_fileFunction · 0.70
llama_kv_cache_initFunction · 0.70
sum_gpu_indexFunction · 0.70
llm_load_tensorsFunction · 0.70
initMethod · 0.70

Calls 9

ggml_cl_initFunction · 0.85
ggml_time_initFunction · 0.70
ggml_time_usFunction · 0.70
ggml_gelu_f32Function · 0.70
ggml_gelu_quick_f32Function · 0.70
ggml_silu_f32Function · 0.70

Tested by 5

mainFunction · 0.40
mainFunction · 0.40
mainFunction · 0.40
mainFunction · 0.40
mainFunction · 0.40