hexagon-optimization

Optimizes and validates MNN Hexagon DSP backend kernels with device-measured profiling.

16.0k|2.4k|Updated Apr 15, 2019
One-click install
npx skills add https://github.com/alibaba/MNN --skill hexagon-optimization
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: hexagon-optimization
Source: https://github.com/alibaba/MNN/tree/main/skills/hexagon
Command: npx skills add https://github.com/alibaba/MNN --skill hexagon-optimization

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Optimizing MNN's Hexagon/HVX/HMX DSP backend is error-prone: intuition-driven micro-optimizations often fail, host/DSP build mismatches silently corrupt measurements, and v79/v81 architecture differences invalidate conclusions. This Skill encodes hard-won measurement discipline, phase-level profiling, and verified bottleneck patterns so changes are driven by real device data.

Core Features & Use Cases

  • Phase-level profiling guidance: Use gated profilers (HTP_MM_PHASE_PROFILE, HTP_QATTN_PHASE_PROFILE, HTP_WATTN_PHASE_PROFILE) to decompose operator time before optimizing.
  • Build and measurement discipline: Enforces host+DSP rebuild pairing, noise-band awareness, baseline re-testing, and per-architecture (v79/v81) validation.
  • Known bottleneck patterns and disproven directions: Documents DMA transfer-count costs, issue-bound writebacks, VTCM sizing hazards, and optimizations already measured to fail.
  • cDSP crash diagnosis: Provides logcat, tombstone, and ramdump inspection procedures for qurt/cDSP failures.
  • Use Case: When a matmul operator on Hexagon seems slow, use this Skill to discover via phase profiling that only 4% of time is actual compute while 49% is output writeback, then optimize the real bottleneck.

Quick Start

Use the hexagon-optimization skill to analyze the DSPOpType profile output of my MNN model and identify which phase of the prefill GEMM operator to optimize.

Frequently Asked Questions about hexagon-optimization

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I profile MNN Hexagon DSP operator performance?

Enable the gated phase profilers (HTP_MM_PHASE_PROFILE, HTP_QATTN_PHASE_PROFILE, HTP_WATTN_PHASE_PROFILE) in both paired files, rebuild, and read the pseudo-operator entries in the DSPOpType table. Keep profilers off when reporting throughput numbers.

How to optimize Hexagon HVX/HMX kernels in MNN?

Measure first with phase decomposition, then target the dominant phase: merge small DMA transfers into fewer larger ones, fix issue-bound writebacks with more parallel issue, and avoid partial-slot writes that degrade to read-modify-write. Validate on both v79 and v81 architectures.

Why do Hexagon benchmark results differ between runs?

Real devices have one-sided noise from background system services, with prefill around ±4% and decode ±7%. Use best-of-N or median instead of mean, re-test baselines at the start and end of a session, and always rebuild host code for every measurement point.

Does MNN Hexagon behave differently on v79 vs v81?

Yes. Per-operator v79/v81 time ratios cluster around 1.1-1.3x, HMX locking differs (shared on v79, exclusive on v81), and weight layouts are architecture-specific. Task partition counts must not collide with thread counts or wave quantization can erase algorithmic gains.

Why does my Hexagon DSP test crash or the device go offline?

cDSP crashes can come from VTCM over-allocation (vtcm_seq_alloc has no bounds checking), stale cache lines overwriting host uploads, or 4096-token prefills that hard-reboot the device. Check tombstones and ramdumps under /data/tombstones and /data/vendor/ before concluding anything.

What optimizations should I avoid on the Hexagon backend?

Do not use CPU fallback or operator fusion as an optimization, do not gate code paths on environment variables, and do not retry disproven directions like dmlink chained DMA, non-temporal stores in prefill GEMM, or weight staging double-buffering, which previously caused device reboots.