Summary
skainet-backend-cpu/src/jvmMain/.../ParallelFor.kt implements parallelChunks as runBlocking(Dispatchers.Default) { coroutineScope { launch { … } } } with a hard-coded availableProcessors() fan-out. Consequences:
- The calling thread parks for the whole region while all chunks run on
Dispatchers.Default — one core idle per matmul.
- A caller that already runs on
Dispatchers.Default (e.g. launch(Dispatchers.Default) { runtime.forward(...) }) parks a pool thread while its own children queue behind it; with cores concurrent forwards the pool deadlocks.
- Parallelism can neither be switched off nor observed: there is no way to run a kernel single-threaded for a parity check, and no trace of what ran.
Callers: JvmVectorKernels.matmulFloatBlockedMemSeg, JvmQuantizedVectorKernels.matmulQ8_0Vec/matmulQ4_KVec/matmulQ6_KVec, PanamaVectorQ4KMatmulKernel, PanamaVectorQ5_KMatmulKernel.
Fix (in feature/skeep-005-schedules, SKEEP-005)
parallelChunks(outputDim, schedule) delegates to a Schedule carried by the ops (ExecutionContext.schedule). The JVM CoroutineSchedule runs the first chunk on the calling thread, runs nested regions inline (thread-local guard), and offers dedicated(n) with its own pool for callers on Dispatchers.Default. Regions are visible as TraceEvent.ScheduleRegion; Schedule.Sequential makes any kernel single-threaded. Tests: CoroutineScheduleTest (incl. a region started from inside a Default worker).
Summary
skainet-backend-cpu/src/jvmMain/.../ParallelFor.ktimplementsparallelChunksasrunBlocking(Dispatchers.Default) { coroutineScope { launch { … } } }with a hard-codedavailableProcessors()fan-out. Consequences:Dispatchers.Default— one core idle per matmul.Dispatchers.Default(e.g.launch(Dispatchers.Default) { runtime.forward(...) }) parks a pool thread while its own children queue behind it; withcoresconcurrent forwards the pool deadlocks.Callers:
JvmVectorKernels.matmulFloatBlockedMemSeg,JvmQuantizedVectorKernels.matmulQ8_0Vec/matmulQ4_KVec/matmulQ6_KVec,PanamaVectorQ4KMatmulKernel,PanamaVectorQ5_KMatmulKernel.Fix (in
feature/skeep-005-schedules, SKEEP-005)parallelChunks(outputDim, schedule)delegates to aSchedulecarried by the ops (ExecutionContext.schedule). The JVMCoroutineScheduleruns the first chunk on the calling thread, runs nested regions inline (thread-local guard), and offersdedicated(n)with its own pool for callers onDispatchers.Default. Regions are visible asTraceEvent.ScheduleRegion;Schedule.Sequentialmakes any kernel single-threaded. Tests:CoroutineScheduleTest(incl. a region started from inside a Default worker).