fix(rknpu2): improve NPU stability with error propagation and IOVA fragmentation fixes - #3
Conversation
…ment - Fixed get_matmul_ctx() to properly map core_id to correct RKNN_NPU_CORE mask - core_id 0 -> RKNN_NPU_CORE_0 (mask 1) - core_id 1 -> RKNN_NPU_CORE_1 (mask 2) - core_id 2 -> RKNN_NPU_CORE_2 (mask 4) - This enables parallel matrix segmentation across all 3 NPU cores Docs: - Add multi-core NPU support note to README - Add OS compatibility warning for RadxaOS kernel issues - Recommend Armbian for stable NPU driver support Fixes: EFAULT errors from spinlock recursion bug in RKNPU 0.9.x Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- Add rknn_matmul_run error propagation - Add RKNN_CORE_MASK environment variable for core selection - Add RKNN_DEVICE environment variable for device selection - Add memory context failure logging - Add B-matrix memcpy guard assertion Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- Split B-matrix into num_cores * split_factor segments - Round-robin core assignment (i % num_cores) preserves parallelization - Reduces max contiguous IOVA requirement per segment - Helps avoid ENOMEM/"Bad address" errors on fragmented CMA Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- Add RKNN_DEVICE, RKNN_CORE_MASK, RKNN_SPLIT_FACTOR to README - Update IOVA_EXHAUSTION.md with solution Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
|
Warning Rate limit exceeded
⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout. Please see our FAQ for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (4)
✨ Finishing Touches🧪 Generate unit tests (beta)
📝 Coding Plan
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Summary
Implements TraycerAI's suggested improvements from issue #2 plus an IOVA fragmentation fix for large models (>9B parameters) on RK3588.
Changes
Error Handling Improvements:
rknn_matmul_runerror propagation - errors now properly fail instead of silently continuingEnvironment Variables:
RKNN_DEVICE- Select device (e.g., "RK3588")RKNN_CORE_MASK- NPU core affinity ("0", "1", "2", "auto")RKNN_SPLIT_FACTOR- Split B-matrix into smaller segments to reduce IOVA allocation sizeIOVA Fragmentation Fix:
The RK3588 NPU uses IOMMU for address translation. Large models like Qwen 9B require ~11-17MB contiguous IOVA allocations which fail when other peripherals (RGA, VPU, JPEG) have fragmented the address space.
RKNN_SPLIT_FACTOR=Nsplits each core's segments into N pieces, reducing the max contiguous allocation by Nx while maintaining parallelization via round-robin core assignment.Test Commands
Commits
36132380afix(rknpu2): implement TraycerAI suggested improvementsbf93a5b01fix(rknpu2): add RKNN_SPLIT_FACTOR to reduce IOVA allocation size7c8e767d6docs: document RKNN environment variables and IOVA exhaustion fixTest plan
cmake --build buildRKNN_SPLIT_FACTOR=4dmesgRKNN_CORE_MASK=1for single-core execution🤖 Generated with Claude Code