MCPcopy Create free account
hub / github.com/antirez/ds4 / cpu_decode_scratch_init

Function cpu_decode_scratch_init

ds4.c:8358–8431  ·  view source on GitHub ↗

Allocate all CPU decode temporaries once. This keeps generation deterministic * from the VM's point of view and makes accidental hot-loop malloc visible. */

Source from the content-addressed store, hash-verified

8356 !l ||
8357 il < DS4_N_LEADING_DENSE ||
8358 !l->ffn_gate_exps ||
8359 !l->ffn_up_exps ||
8360 !l->ffn_down_exps) {
8361 return false;
8362 }
8363 if (l->ffn_gate_exps->type == DS4_TENSOR_IQ2_XXS &&
8364 l->ffn_up_exps->type == DS4_TENSOR_IQ2_XXS &&
8365 (l->ffn_down_exps->type == DS4_TENSOR_IQ2_XXS ||
8366 l->ffn_down_exps->type == DS4_TENSOR_Q2_K)) {
8367 return true;
8368 }
8369 return l->ffn_gate_exps->type == l->ffn_up_exps->type &&
8370 l->ffn_gate_exps->type == l->ffn_down_exps->type &&
8371 (l->ffn_gate_exps->type == DS4_TENSOR_Q2_K ||
8372 l->ffn_gate_exps->type == DS4_TENSOR_Q4_K);
8373}
8374
8375static uint32_t g_glm_streaming_full_resident_start;
8376static uint32_t g_glm_streaming_full_resident_layers;
8377static bool g_glm_streaming_runtime_static_map_enabled;
8378
8379static bool glm_stream_resident_decode_layer_enabled(
8380 const ds4_layer_weights *l,
8381 uint32_t il) {
8382 if (!glm_stream_resident_decode_layer_supported(l, il)) return false;
8383 return g_glm_streaming_full_resident_layers != 0 &&
8384 il >= g_glm_streaming_full_resident_start &&
8385 il - g_glm_streaming_full_resident_start <
8386 g_glm_streaming_full_resident_layers;
8387}
8388
8389static bool glm_stream_expert_cache_addr_layout_supported(
8390 const ds4_weights *w,
8391 const ds4_layer_weights *l,
8392 uint32_t il) {
8393 if (DS4_MODEL_FAMILY != DS4_MODEL_FAMILY_GLM_DSA ||
8394 !w ||
8395 !l ||
8396 il >= DS4_N_LAYER ||
8397 il < DS4_N_LEADING_DENSE ||
8398 !l->ffn_gate_exps ||
8399 !l->ffn_up_exps ||
8400 !l->ffn_down_exps ||
8401 DS4_N_EXPERT_USED == 0 ||
8402 DS4_N_EXPERT_USED > 8 ||
8403 DS4_N_EXPERT < 128 ||
8404 glm_graph_env_present("DS4_ROCM_GLM_DISABLE_STREAMING_EXPERT_CACHE",
8405 "DS4_METAL_GLM_DISABLE_STREAMING_EXPERT_CACHE")) {
8406 return false;
8407 }
8408 if (!weights_streaming_layer_experts_uniform(w, il)) return false;
8409
8410 if (l->ffn_gate_exps->type != l->ffn_up_exps->type) return false;
8411 const bool q2_addr =
8412 l->ffn_gate_exps->type == DS4_TENSOR_Q2_K &&
8413 l->ffn_down_exps->type == DS4_TENSOR_Q2_K;
8414 const bool q4_addr =
8415 l->ffn_gate_exps->type == DS4_TENSOR_Q4_K &&

Callers 4

prefill_layer_major_cpuFunction · 0.85
generate_raw_swa_cpuFunction · 0.85
ds4_session_createFunction · 0.85

Calls 2

ds4_default_raw_capFunction · 0.85
xmallocFunction · 0.70

Tested by

no test coverage detected