OpenFlowLM-Next icon indicating copy to clipboard operation
OpenFlowLM-Next copied to clipboard

`oflm serve` asks the OpenMP runtime to stop spinning and never gets it, which costs a third of prefill

Open Cyronius opened this issue 2 months ago • 0 comments

Reading a prompt through oflm serve on the open engine is about 35% slower than the same code run from the standalone CLI. The reason is a setting the binary asks for and silently does not get.

The open engine does part of every layer on the CPU, in between NPU dispatches. Those CPU stages run on OpenMP worker threads. By default Microsoft's OpenMP runtime leaves the workers spinning after each parallel region instead of putting them to sleep. Spinning cores raise the package power, the NPU drops its clock to stay inside the budget, and the dispatches that follow run slower. So the cost lands on the NPU work, not on the CPU work. Setting OMP_WAIT_POLICY=PASSIVE puts the workers to sleep and gets it back.

The trouble is when the runtime reads that variable. It reads it once, as its DLL loads, and that happens before any code in oflm.exe runs. The engine sets the variable from a static initialiser, so it is always too late. For the standalone CLI we fixed this by delay-loading the OpenMP DLL, which moves its load to the first call into it. oflm.exe carries the same /DELAYLOAD:VCOMP140.DLL and it cannot help there, because eight of the closed model DLLs that oflm.exe links directly import the OpenMP runtime themselves:

qwen3_6_moe_npu, qwen3_5vl_npu, qwen3_5_omni_npu, qwen3vl_npu, gemma_npu, gemma4e_npu, gemma4_12b_npu, gpt_oss_npu

Any one of those loading brings the runtime in with it, and by then the variable has been read. The engine prints a warning about this at load. That warning is how we found it.

What it costs on the 35B with the batched prefill route, read off the server's own prefill timer, best of four rotating cycles per length:

prompt PASSIVE set before launch not set
662 tokens 4.8 s 6.5 s
1,122 7.8 10.5
2,593 17.4 24.1

With the variable set, the server matches the standalone CLI to within 2%, so nothing else is going on here.

There are three ways to fix it, and I would like your call on which, because the first one touches your DLLs.

  1. Delay-load those eight model DLLs as well. Each is only called once its family is actually being served, so on the open path nothing would pull the OpenMP runtime in early. The cost is a change in how a missing DLL fails: a delay-load fault at the first call instead of a clean refusal at startup.
  2. Have oflm re-exec itself once at the top of main with the variable set, guarded by a sentinel so it cannot loop. That works whatever the DLL graph does and costs one extra process spawn. It is also a surprising thing for a server to do.
  3. Leave the binary alone. Have the installer or the launcher export the variable, and keep the engine's warning as the backstop.

One thing worth knowing before you choose. The closed engine's own CPU work is OpenMP too, so every closed-engine number any of us has published was measured with its workers spinning as well. If PASSIVE helps it, the first two options would speed up both engines, and our open-against-closed prefill comparisons are flattering the open side by an amount nobody has measured.

Cyronius avatar Sep 21 '26 20:09 Cyronius