Voice/AI · voice
Portal NPU Runtime — Hexagon DSP FastRPC
Safe Rust wrappers around the Qualcomm Hexagon CDSP FastRPC kernel interface. Provides DMA-BUF allocation and remote DSP invocation for voice, LLM, and other NPU consumers.
Architecture
Overview
portal-npu-runtime provides the low-level NPU abstraction layer that all QNN/DSP consumers in Portal build on. It wraps the Qualcomm FastRPC kernel interface (/dev/fastrpc-cdsp-secure) with safe Rust types, handling DMA-BUF memory allocation (page-aligned, max 256MB per allocation), remote DSP domain invocation (CDSP_SECURE_DEVICE = domain 3), and shell binary verification for DSP code loading. The FastRpcSession type manages the kernel session lifecycle with proper ioctl serialization (mutex-guarded to avoid FastRPC race conditions). The crate also includes fastrpc_ffi with raw FFI bindings to the kernel interface constants and structures.
Key Types
Modules
device
NpuDevice — higher-level NPU operations wrapping FastRpcSession: DMA allocation, buffer mapping, DSP invocation.
fastrpc_ffi
Raw FFI bindings to FastRPC kernel interface — device paths (/dev/fastrpc-cdsp-secure), ioctl constants, domain IDs (CDSP_SECURE_DEVICE = 3).
shell_verify
Shell binary verification — validates DSP .so files before loading to prevent crashes from malformed code.
llm
LLM-specific DSP operations (feature-gated) — manages the Qwen3 model context on Hexagon.
Data Flow
portal-voiced/portal-llmd → NpuDevice → FastRpcSession → /dev/fastrpc-cdsp-secure → kernel FastRPC → Hexagon CDSP → QNN model execution
Dependencies
External (6)
Platform-specific: Qualcomm X Elite only. Depends on libc for fd management. Constants: PAGE_SIZE=4096, MAX_DMA_ALLOC=256MB. Enforces # Safety sections on all pub unsafe fn.