Exp 2026 06 23 Hardware Chaining Debug - oRKLLM/ork-driver GitHub Wiki
Hardware Chaining Debug (INT4/INT8)
Current Status
- Both
ork_mm_run_chain_i4andork_mm_run_chain_i8are failing during theRKNPU_SUBMITioctl phase. - We observe
errno=22(Invalid argument) orerrno=110(Timeout) when attempting to submit multiple independent matmuls in a single ioctl call (task_number > 1).
Validation Methodology
During the debugging session, we adopted the following validation strategies:
- Isolated Testing Executable (
test_chain_i4_s1.c): Created a standalone test focused exclusively on theork_mm_run_chain_i4execution path for a single chaining task (S=1). This drastically reduced the noise and setup time compared to running the fulltest_matmulsuite. - Overlap Guards (
test_overlap_guards): Added active tests insidetest_matmul.cto ensure that our chained implementation does not silently ignore or mishandle overlapping input (A) and output (C) buffers, which would violate the hardware execution constraints. - Target Device Validation: Synchronized source files locally and compiled/executed directly on the Rock 5B target board (
10.3.0.236) usingmake test_chain_i4_s1andsudo ./test_chain_i4_s1to ensure actual kernel ioctl behavior was captured, as the macOS host cannot run these. - Ioctl Parameter Tracing: Intercepted the exact arguments passed to the
DRM_IOCTL_RKNPU_SUBMITcall by inserting debug print statements directly intosrc/npu.c. We observedsub.flags,sub.task_number,sub.core_mask,t[0].regcfg_amount, andt[0].regcmd_addrjust before kernel entry to confirm memory alignment and configuration correctness.
Recent Discoveries & Work Done
- Unified Submission Logic: We restructured
run_chain_i4andrun_chain_i8to use a cleaner, unified approach for buffer creation (bcreate), synchronization (bsync), andioctlsubmission. - Buffer Flags: We experimented with
bcreateflags for therknpu_taskarray, testing0x403vs0x40b(IOMMU related), but the timeouts persist. - Register Configuration:
regcfg_amountis correctly set to116fori4and108fori8.synth_i4andsynth_i8are correctly generating theregcmdbuffers for each individual matmul task.
- The
probe_batchWarning: A previous note insrc/npu.c(ork_npu_probe_batch) indicates that naive multi-task batching (task_number > 1) historically TIMES OUT. The NPU dispatches no tasks, and the kernel soft-resets. This suggests the hardware or DRM driver might not natively support cross-matmul batching via thetask[]array in the way we are attempting.
Ideas for Next Steps
- Investigate Subcore Tasks vs. Independent Tasks:
The closed-source runtime (
librkllmrt) handles large matmuls by splitting them into sub-tasks (e.g., 4 sub-tasks × 3 subcores = 12 tasks) within a single logical matmul. It might not support batching entirely independent matmuls viatask_number > 1. We may need to investigate if chaining independent matmuls is actually possible, or if we need to emulate it. - Emulate Chaining via Sequential Submits:
If true hardware-level chaining of independent matmuls is impossible,
ork_mm_run_chain_*might need to be rewritten to issue sequential, single-taskioctlcalls (similar to a loop ofork_mm_run_i8), potentially optimizing by preparing allregcmdbuffers in advance to minimize CPU overhead between submits. - Kernel Logs (dmesg):
When we resume, we should check
dmesgon the Rock 5B board immediately after anerrno=110(Timeout) orerrno=22(Invalid argument) to see exactly what therknpuDRM driver is complaining about. It often logs specific validation failures (e.g., memory alignment, invalid core masks, or badregcmdjumps). - Compare with Multi-Core Split:
Examine how
ork_npu_mc_timingand the multi-core worker (i4_mcworker) successfully split a single task across cores. We might be missing a specificenable_mask,int_mask, or PC-jump configuration required to link thetask[]entries together.