vulkan-optimize

Optimizes MNN Vulkan backend kernels and integrates new Vulkan features on mobile GPUs.

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

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Optimizing GPU compute shaders in the MNN Vulkan backend is error-prone: edited GLSL .comp files silently do nothing without regenerating SPIR-V arrays, stale pipeline caches cause segfaults, and prefill is often CPU-scheduling-bound rather than GPU-bound, so naive kernel tuning yields no end-to-end gain. This Skill provides a disciplined benchmark-optimize-integrate workflow with correctness oracles and interleaved A/B measurement on real Android devices.

Core Features & Use Cases

  • Guided optimization workflow: Three tracks—model-level profiling, targeted operator optimization, and new Vulkan feature integration (cooperative matrix, subgroup, extensions)—each with explicit pass criteria.
  • Vulkan-specific diagnostics: Distinguishes CPU command-recording bottlenecks from GPU kernel bottlenecks, reads MNN's op-level and shader-level profilers, and catalogs pitfalls like makeshader pollution, buffer/image backend mismatch, and thermal drift.
  • Surgical shader regeneration: Regenerates only the changed shader arrays in AllShader.cpp instead of running full makeshader, keeping diffs clean.
  • Use Case: An engineer wants to speed up conv1x1 int4 inference on an Adreno device. The Skill walks them through profiling, identifying the cooperative-matrix dispatch path, applying epilogue coalescing with N-gated fusion, verifying token-level correctness against a frozen baseline, and producing a performance report.

Quick Start

Ask the AI to profile and optimize the Vulkan attention or convolution kernels of an MNN LLM on your connected Android device, following the benchmark, kernel optimization, and integration steps.

Frequently Asked Questions about vulkan-optimize

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

FAQPage Schema
How do I optimize Vulkan compute shader performance in MNN?

Profile with MNN_GPU_TIME_PROFILE=ON to get op-level and shader-level GPU timings, then determine whether the bottleneck is CPU command recording or GPU kernels. Apply matched techniques such as cooperative matrix, subgroup reductions, or epilogue fusion, verifying each with interleaved A/B benchmarks.

Why do my GLSL .comp shader changes have no effect in MNN?

MNN does not compile .comp files at build time; it loads SPIR-V byte arrays embedded in AllShader.cpp by makeshader. You must regenerate the arrays for changed shaders, and confirm you edited the correct buffer or image backend tree selected by MNN_VULKAN_IMAGE.

Why does MNN Vulkan segfault after changing a shader?

The persisted VkPipelineCache in tmp/mnn_cachefile.bin becomes stale when shaders change, causing a segfault on load. Delete the cache file with rm tmp/mnn_cachefile.bin before every test run after modifying shaders.

Does cooperative matrix work on all Vulkan devices?

No. Cooperative matrix in MNN is gated to Adreno GPUs reporting supportCoopMat, and it only has hardware definitions for int8 and int4 weights. Unsupported devices must fall back to the original shader path via runtime feature detection.

Why did my Vulkan kernel optimization not improve end-to-end inference speed?

MNN Vulkan prefill is often CPU-scheduling-bound, so GPU kernel speedups show no end-to-end gain. Compare cumulative GPU kernel time against wall time first; if CPU-bound, use indirect batch recording or operator fusion instead of kernel tuning.

How should I benchmark Vulkan performance changes on Android?

Use interleaved A/B testing where baseline and optimized builds alternate back-to-back, because device thermal drift causes 8-10% variance across sessions. Warm up first, clear the pipeline cache each round, and measure clean builds without the GPU profiler enabled.