ncnn

Tencent活跃维护

面向手机端的高性能神经网络推理框架,针对 ARM 平台深度优化,让 Caffe、ONNX 等模型能在 Android/iOS 上低延迟运行。

ncnn is a high-performance neural network inference framework optimized for the mobile platform

20261020发布于 2026-10-20 03:40 UTC24,033star +3 / 7 天4,545fork同步于 2026-11-10 11:23 UTC

怎么上手

由 README 提炼,执行前请确认
pip3 install pnnx
git clone --recursive https://github.com/Tencent/ncnn.git && cd ncnn && mkdir build && cd build && cmake -DCMAKE_BUILD_TYPE=Release -DNCNN_VULKAN=ON -DNCNN_BUILD_EXAMPLES=ON .. && cmake --build . -j$(nproc)
硬件要求按 README 说明

README 未给出具体显存或 GPU 型号要求;支持 CPU 与 Vulkan GPU 后端,覆盖手机、PC、浏览器和边缘设备,并列出 Android、iOS、HarmonyOS、Raspberry Pi、Jetson、WebAssembly 等构建目标。

下载:源码 zip·GitHub Releases(安装包)本站不镜像安装包

项目说明

由 README 自动翻译提炼

腾讯开源的高性能神经网络推理框架,无第三方运行时依赖,专为手机、嵌入式和桌面端部署优化

面向手机端的高性能神经网络推理框架,针对 ARM 平台深度优化,让 Caffe、ONNX 等模型能在 Android/iOS 上低延迟运行。

核心能力

  • 无第三方运行时依赖,不依赖 BLAS/NNPACK
  • 纯 C++ 实现,提供 C API 与 Python 绑定
  • 针对 ARM NEON 与多核调度优化 CPU 推理
  • 支持 Vulkan GPU 加速后端
  • 用 pnnx 将 PyTorch/ONNX 模型转成 ncnn 模型

容易踩的坑

模型需先用 pnnx 从 PyTorch/ONNX 转换,ncnn 不能直接加载原始模型文件;从源码构建需加 --recursive 拉取子模块,否则可能编译失败;Vulkan 加速需在 cmake 中显式开启 -DNCNN_VULKAN=ON,默认不启用。

内容由模型根据 README 生成,可能不完整或不准确,以官方文档为准。看原文 README

最近发版

5 个版本20261020
  1. 20261020android harmonyos ios macos linux windows webassembly watchos tvos visionos 预编译库 20261020 7e36d25最新正式版2026-10-20 · 2026-10-20 03:40 UTC

    编译版本,默认配置,android-ndk-r30,ohos-sdk-5.0.3,xcode 16.4,ubuntu-22.04,ubuntu-24.04,ubuntu-26.04,vs2015,vs2017,vs2019,vs2022,vs2026,emscripten-6.0.12

    filecontentarch
    ncnn-full-source.zip包含全部 submodule 代码的完整源码
    ncnn-android.zipandroid 静态库/动态库armeabi-v7a + arm64-v8a + x86 + x86_64 + riscv64
    ncnn-android-vulkan.zipandroid 静态库/动态库,支持 GPUarmeabi-v7a + arm64-v8a + x86 + x86_64 + riscv64
    ncnn-harmonyos.zipharmonyos 静态库/动态库armeabi-v7a + arm64-v8a + x86_64
    ncnn-harmonyos-vulkan.zipharmonyos 静态库/动态库,支持 GPUarmeabi-v7a + arm64-v8a + x86_64
    ncnn-apple.zipapple xcframework,ios + ios-simulator + macos + mac-catalyst + watchos + watchos-simulator + tvos + tvos-simulator + visionos + visionos-simulatorarm64 + arm64e + x86_64
    ncnn-apple-vulkan.zipapple xcframework,ios + ios-simulator + macos + mac-catalyst + watchos + watchos-simulator + tvos + tvos-simulator + visionos + visionos-simulator,支持 GPUarm64 + arm64e + x86_64
    ncnn-ios.zipios 静态库arm64
    ncnn-ios-vulkan.zipios 静态库,支持 GPUarm64
    ncnn-ios-simulator.zipios simulator 静态库x86_64 + arm64
    ncnn-ios-simulator-vulkan.zipios simulator 静态库,支持 GPUx86_64 + arm64
    ncnn-macos.zipmacos 静态库x86_64 + arm64
    ncnn-macos-vulkan.zipmacos 静态库,支持 GPUx86_64 + arm64
    ncnn-mac-catalyst.zipmac catalyst 静态库x86_64 + arm64
    ncnn-mac-catalyst-vulkan.zipmac catalyst 静态库,支持 GPUx86_64 + arm64
    ncnn-watchos.zipwatchos 静态库armv7k + arm64_32
    ncnn-watchos-simulator.zipwatchos simulator 静态库x86_64 + arm64
    ncnn-tvos.ziptvos 静态库x86_64 + arm64
    ncnn-tvos-vulkan.ziptvos 静态库,支持 GPUx86_64 + arm64
    ncnn-tvos-simulator.ziptvos simulator 静态库x86_64 + arm64
    ncnn-tvos-simulator-vulkan.ziptvos simulator 静态库,支持 GPUx86_64 + arm64
    ncnn-visionos.zipvisionos 静态库arm64
    ncnn-visionos-vulkan.zipvisionos 静态库,支持 GPUarm64
    ncnn-visionos-simulator.zipvisionos simulator 静态库x86_64 + arm64
    ncnn-visionos-simulator-vulkan.zipvisionos simulator 静态库,支持 GPUx86_64 + arm64
    ncnn-ubuntu.zipubuntu linux 静态库/动态库,支持 GPU,模型转换工具x86_64
    ncnn-windows.zipwindows 静态库/动态库,支持 GPU,模型转换工具x86 + x64 + arm + arm64
    ncnn-webassembly.zipwebassembly 静态库wasm32 + simd + threads + simd-threads
    ncnn-webassembly64.zipwebassembly64 静态库wasm64 + simd + threads + simd-threads

    重点概览

    • 新增原生 batch 推理基础设施,Mat/VkMat、CPU/Vulkan 调度、C/Python 接口和 pnnx 转换同步扩展;Reshape 支持 batch 与普通维度之间的重组,进一步完善动态 reshape、flatten、unflatten 的 batch 语义。(@futz12)
    • Vulkan 后端新增 Convolution、ConvolutionDepthWise、InnerProduct、GEMM 的 int8 推理路径,配套 integer dot product、cooperative matrix、Winograd 和 int8 packing,量化模型不再因存在 int8 层而整体关闭 GPU。
    • 新增面向 LLM 的 int4/int6/int8 块量化、ncnnllm2table / ncnnllm2int 工具和五大 CPU 后端的 int8 块量化优化,并引入会话级 KV cache allocator、容量复用及 bf16 模型权重存储。
    • x86 后端新增 fp32/bf16 SDPA FlashAttention prefill/decode,扩展 AVX2、AVX-NE-CONVERT、FMA/FMA4 dispatch,并补齐 CumulativeSum、Reduction、Normalize、Permute 的 SIMD 实现。(@crafcat7)
    • RISC-V 补齐 packed int8 Convolution、im2col GEMM、Winograd、SDPA/MultiHeadAttention,继续优化 fp16 GEMM 和常见激活,并新增 BF16 能力检测及 Cast/Clip 转换路径。(@Deepdive543443, @futz12, @darkavatar23)
    • Vulkan LayerNorm、RMSNorm、GroupNorm、InstanceNorm 新增 subgroup 归约,cooperative matrix 继续优化访存、对齐和 Adreno 兼容;同步修复 bf16 舍入、归一化系数精度及 Tanh/GELU 大输入溢出问题。(@futz12)
    • 模型、参数与图加载增加系统性校验,新增默认开启的 NCNN_VALIDATION,修复负数索引、长度/数值溢出、非法层参数、循环图、截断 mmap 权重及失败加载后的资源清理问题。(@aleff-github, @professor-moody, @beilzx, @kaltsit-10, @ktz03, @Dr3ladwyn, @FluxMind-O, @lxcxjxhx)
    • pnnx 完善 MelSpectrogram、多前导维度 Linear、全局池化布局、ONNX fp16/bool 常量和 Transformer attention 融合,修复插值与动态 batch 转换,CI 测试矩阵扩展至 PyTorch 2.14。(@futz12, @Lfan-ke, @ktz03, @giuliocorradi, @Acture, @xy200303)
    • 发布流程新增 Ubuntu 26.04、VS2026、wasm64 和 Android/iOS Python wheel,WebAssembly 更新至 Emscripten 6.0.12 并使用原生 LLVM OpenMP;Python 的 OpenCV 依赖改为可选项。

    Vulkan / GPU

    • 新增 Vulkan Convolution、ConvolutionDep
  2. 20260526android harmonyos ios macos linux windows webassembly watchos tvos visionos 预编译库 20260526 e54f7b12026-05-26 · 2026-05-26 13:57 UTC
    查看更新说明

    编译版本,默认配置,android-ndk-r29,ohos-sdk-5.0.3,xcode 16.4,ubuntu-22.04,ubuntu-24.04,vs2015,vs2017,vs2019,vs2022,emscripten-3.1.28

    filecontentarch
    ncnn-full-source.zip包含全部 submodule 代码的完整源码
    ncnn-android.zipandroid 静态库/动态库armeabi-v7a + arm64-v8a + x86 + x86_64 + riscv64
    ncnn-android-vulkan.zipandroid 静态库/动态库,支持 GPUarmeabi-v7a + arm64-v8a + x86 + x86_64 + riscv64
    ncnn-harmonyos.zipharmonyos 静态库/动态库armeabi-v7a + arm64-v8a + x86_64
    ncnn-harmonyos-vulkan.zipharmonyos 静态库/动态库,支持 GPUarmeabi-v7a + arm64-v8a + x86_64
    ncnn-apple.zipapple xcframework,ios + ios-simulator + macos + mac-catalyst + watchos + watchos-simulator + tvos + tvos-simulator + visionos + visionos-simulatorarm64 + arm64e + x86_64
    ncnn-apple-vulkan.zipapple xcframework,ios + ios-simulator + macos + mac-catalyst + watchos + watchos-simulator + tvos + tvos-simulator + visionos + visionos-simulator,支持 GPUarm64 + arm64e + x86_64
    ncnn-ios.zipios 静态库arm64
    ncnn-ios-vulkan.zipios 静态库,支持 GPUarm64
    ncnn-ios-simulator.zipios simulator 静态库x86_64 + arm64
    ncnn-ios-simulator-vulkan.zipios simulator 静态库,支持 GPUx86_64 + arm64
    ncnn-macos.zipmacos 静态库x86_64 + arm64
    ncnn-macos-vulkan.zipmacos 静态库,支持 GPUx86_64 + arm64
    ncnn-mac-catalyst.zipmac catalyst 静态库x86_64 + arm64
    ncnn-mac-catalyst-vulkan.zipmac catalyst 静态库,支持 GPUx86_64 + arm64
    ncnn-watchos.zipwatchos 静态库armv7k + arm64_32
    ncnn-watchos-simulator.zipwatchos simulator 静态库x86_64 + arm64
    ncnn-tvos.ziptvos 静态库x86_64 + arm64
    ncnn-tvos-vulkan.ziptvos 静态库,支持 GPUx86_64 + arm64
    ncnn-tvos-simulator.ziptvos simulator 静态库x86_64 + arm64
    ncnn-tvos-simulator-vulkan.ziptvos simulator 静态库,支持 GPUx86_64 + arm64
    ncnn-visionos.zipvisionos 静态库arm64
    ncnn-visionos-vulkan.zipvisionos 静态库,支持 GPUarm64
    ncnn-visionos-simulator.zipvisionos simulator 静态库x86_64 + arm64
    ncnn-visionos-simulator-vulkan.zipvisionos simulator 静态库,支持 GPUx86_64 + arm64
    ncnn-ubuntu.zipubuntu linux 静态库/动态库,支持 GPU,模型转换工具x86_64
    ncnn-windows.zipwindows 静态库/动态库,支持 GPU,模型转换工具x86 + x64 + arm + arm64
    ncnn-webassembly.zipwebassembly 静态库wasm32 + simd + threads + simd-threads

    重点概览

    • 新增 HarmonyOS 预编译包发布流程,release 产物覆盖 CPU/Vulkan、静态/动态库,以及 armeabi-v7a、arm64-v8a、x86_64 三种架构。(#6746)
    • Vulkan 后端新增 SDPA/FlashAttention、RotaryEmbed、GroupNorm、Reduction、Unfold、Softplus、Shrink 等算子,并引入持久化 pipeline cache、mmap 模型加载、host memory 权重驻留和逐层权重上传,明显面向大模型与长启动耗时优化。(@futz12, @CLV-Iclucia, #6514, #6702, #6537, #6531, #6534)
    • x86 后端大规模补齐 bf16 storage 路径,覆盖 GEMM、Convolution、InnerProduct、Deconvolution、Pooling、Interp、归一化、激活、逐元素、量化/反量化等层,并增加 AVX512BF16 dispatch 和多项 micro-kernel 优化。(#6598, #6624, #6626, #6680)
    • ARM 后端新增 ARM SDPA 实现,并为 ARMv8.4 BF16 优化 GEMM、Convolution im2col-GEMM、InnerProduct、MultiHeadAttention;同时补齐 ERF、ELU、GELU、SELU 的 NEON/fp16 SIMD 实现。(@Abandon-ht, @futz12, #6698, #6714, #6715, #6716, #6717, #6605)
    • RISC-V RVV、MIPS MSA、LoongArch LSX/LASX 后端继续扩展,重点补齐 packed convolution/deconvolution、GEMM、量化/反量化、常见 unary/binary op、bf16/int8 和 4D Mat 支持。(#6662, #6740, #6636, #6658, #6695)
    • pnnx 支持 .npy 真实输入、输出 FLOPS/memory OPS 统计,兼容 PyTorch 2.10/2.11,修复非对称 padding + conv 融合、Conv2d padding tuple 归一化、Erf 表达式落层等转换问题。(@MollySophia, @Yeuvoir, @crafcat7, #6700, #5836, #6592, #6701, #6694)
    • 新增 benchncnn_llm 和算子级 perf 基础设施,benchmark 覆盖 LLM prefill/decode 与更多 CPU/GPU 算子性能回归。(#6711, #6570, #6632)

    Vulkan / GPU

    • 新增 Vulkan SDPA 层和 FlashAttention 路径,基础实现包含 2x2 unroll 和 local memory 优化,后续补齐统一 cross-attention shader、cooperative matrix 与非 cooperative matrix 两套 FlashAttention 实现,支持 mask、KV cache concat 和 chunk 化输出调度。(#6514, #6521, #6528, #6538)
    • GEMM/SDPA cooperative matrix 和 subgroup 路径继续优化,加入 bf16/fp16 cooperative matrix、4x4 unroll、向量化加载、bank conflict 规避与 packed GEMM;后续限制 bf16 cooperative matrix 用法,避免不匹配的数据布局。(@futz12,
  3. 20260113android ios macos linux windows webassembly watchos tvos visionos 预编译库 20260113 e956fbf2026-01-13 · 2026-01-13 03:28 UTC
    查看更新说明

    编译版本,默认配置,android-ndk-r29,xcode 16.4,ubuntu-22.04,ubuntu-24.04,vs2015,vs2017,vs2019,vs2022,emscripten-3.1.28

    filecontentarch
    ncnn-full-source.zip包含全部 submodule 代码的完整源码
    ncnn-android.zipandroid 静态库/动态库armeabi-v7a + arm64-v8a + x86 + x86_64 + riscv64
    ncnn-android-vulkan.zipandroid 静态库/动态库,支持 GPUarmeabi-v7a + arm64-v8a + x86 + x86_64 + riscv64
    ncnn-apple.zipapple xcframework,ios + ios-simulator + macos + mac-catalyst + watchos + watchos-simulator + tvos + tvos-simulator + visionos + visionos-simulatorarm64 + arm64e + x86_64
    ncnn-apple-vulkan.zipapple xcframework,ios + ios-simulator + macos + mac-catalyst + watchos + watchos-simulator + tvos + tvos-simulator + visionos + visionos-simulator,支持 GPUarm64 + arm64e + x86_64
    ncnn-ios.zipios 静态库arm64
    ncnn-ios-vulkan.zipios 静态库,支持 GPUarm64
    ncnn-ios-simulator.zipios simulator 静态库x86_64 + arm64
    ncnn-ios-simulator-vulkan.zipios simulator 静态库,支持 GPUx86_64 + arm64
    ncnn-macos.zipmacos 静态库x86_64 + arm64
    ncnn-macos-vulkan.zipmacos 静态库,支持 GPUx86_64 + arm64
    ncnn-mac-catalyst.zipmac catalyst 静态库x86_64 + arm64
    ncnn-mac-catalyst-vulkan.zipmac catalyst 静态库,支持 GPUx86_64 + arm64
    ncnn-watchos.zipwatchos 静态库armv7k + arm64_32
    ncnn-watchos-simulator.zipwatchos simulator 静态库x86_64 + arm64
    ncnn-tvos.ziptvos 静态库x86_64 + arm64
    ncnn-tvos-vulkan.ziptvos 静态库,支持 GPUx86_64 + arm64
    ncnn-tvos-simulator.ziptvos simulator 静态库x86_64 + arm64
    ncnn-tvos-simulator-vulkan.ziptvos simulator 静态库,支持 GPUx86_64 + arm64
    ncnn-visionos.zipvisionos 静态库arm64
    ncnn-visionos-vulkan.zipvisionos 静态库,支持 GPUarm64
    ncnn-visionos-simulator.zipvisionos simulator 静态库x86_64 + arm64
    ncnn-visionos-simulator-vulkan.zipvisionos simulator 静态库,支持 GPUx86_64 + arm64
    ncnn-ubuntu.zipubuntu linux 静态库/动态库,支持 GPU,模型转换工具x86_64
    ncnn-windows.zipwindows 静态库/动态库,支持 GPU,模型转换工具x86 + x64 + arm + arm64
    ncnn-webassembly.zipwebassembly 静态库wasm32 + simd + threads + simd-threads

    新增sdpa layer和pnnx torch.scaled_dot_product_attention的转换,支持gqa合并 新增rotaryembed layer sdpa支持kvcache multiheadattention支持kvcache layer可选实现support_vulkan_packing layer可选实现support_vulkan_any_packing vulkan支持bf16开关,支持旧显卡模拟转换bf16 rmsnorm vulkan优化(@futz12) selu vulkan优化(@futz12) vulkan eltwise统一elempack shader 简化vulkan cast 改善M较小时在N上切块的多线程调度 gemm x86 avx512采用N维度16切块优化 sdpa x86使用gemm和softmax优化(@futz12) arm neon数学函数优先使用fma指令优化(@Abandon-ht) unaryop tan rvv优化(@ihb2032 @lyd1992) 新增cmake NCNN_WINXP开关,不再主动定义_WIN32_WINNT宏 c-api新增ncnn_version_number()接口返回数值 c-api新增更多option setter getter接口 net加载模型接口新增wchar_t参数类型 新增float8和bfloat8转换函数(@chloeee99) 格式化glsl文件 删除shader注释和额外的空格 不再编译onnx2ncnn benchncnn内置模型param,运行时不再需要param文件 修复modelwriter访问空bias数据崩溃问题(@csukuangfj) 修复param解析时尝试对已读取数据再次读取的逻辑错误(@futz12) 修复softmax多线程尾部余数的错误,优化倒数计算(@futz12) 修复msvc编译器x86 lstm int8开启vnni指令集时计算错误 修复x86 lstm int8越界读写问题 修复加载模型param出错时的退出逻辑(@Cat-myq) 修复vulkan驱动返回无效subgroup size导致加载卡死的问题(@Cat-myq) 修复加载模型时CRLF行尾解析逻辑错误(@chennevwin) 修复sdpa单通道attnmask的处理逻辑 修复ncnn2int8对仅有反量化的输出int8 scales保存崩溃问题 modelwriter支持tile层 ncnn2mem支持新的数组和字符串类型 x86上引用传参simd寄存器类型,函数无法接受对齐类型传值 检查gpu显存分配失败错误,返回错误码(@Upliner) simplevk支持查找高通windows vulkan驱动文件(@strongtz) simplevk支持apple平台动态加载vulkan驱动 simplevk支持VK_DRIVER_FILES环境变量加载vulkan驱动 禁用windows amd rdna2驱动的cooperative matrix软件模拟功能以提升性能 glslang更新到20260109 适配新windows-sdk的更多arm处理器特性检查功能 更新pybind 3.0.1,修复python-3.14使用pyncnn崩溃问题 更新pnnx到torch-2.9,支持onnx external data,支持dynamo-exported onnx pnnx支持转换torch.shrink Tensor.unflatten torch.flatten pnnx转换torch.flatten到ncnn支持多动态维度 pnnx支持转换F.interpolate nearest-exact pnnx修复转换Tensor.expand到ncnn缺失的repeats pnnx支持转换onnx gelu groupnorm rmsnorm gridsample pnnx支持合并更多transformer attention变种 pnnx支持合并更多sdpa attention变种 pnnx支持合并更多rmsnorm变种 pnnx合并连续permute,删除无用的permute pnnx添加dee

  4. 20250916android ios macos linux windows webassembly watchos tvos visionos 预编译库 20250916 c4193aa2025-09-16 · 2025-09-16 02:38 UTC
    查看更新说明

    编译版本,默认配置,android-ndk-r28c,xcode 15.2,ubuntu-22.04,ubuntu-24.04,vs2015,vs2017,vs2019,vs2022,emscripten-3.1.28

    filecontentarch
    ncnn-full-source.zip包含全部 submodule 代码的完整源码
    ncnn-android.zipandroid 静态库/动态库armeabi-v7a + arm64-v8a + x86 + x86_64 + riscv64
    ncnn-android-vulkan.zipandroid 静态库/动态库,支持 GPUarmeabi-v7a + arm64-v8a + x86 + x86_64 + riscv64
    ncnn-apple.zipapple xcframework,ios + ios-simulator + macos + mac-catalyst + watchos + watchos-simulator + tvos + tvos-simulator + visionos + visionos-simulatorarm64 + arm64e + x86_64
    ncnn-apple-vulkan.zipapple xcframework,ios + ios-simulator + macos + mac-catalyst + watchos + watchos-simulator + tvos + tvos-simulator + visionos + visionos-simulator,支持 GPUarm64 + arm64e + x86_64
    ncnn-ios.zipios 静态库arm64
    ncnn-ios-vulkan.zipios 静态库,支持 GPUarm64
    ncnn-ios-simulator.zipios simulator 静态库x86_64 + arm64
    ncnn-ios-simulator-vulkan.zipios simulator 静态库,支持 GPUx86_64 + arm64
    ncnn-macos.zipmacos 静态库x86_64 + arm64
    ncnn-macos-vulkan.zipmacos 静态库,支持 GPUx86_64 + arm64
    ncnn-mac-catalyst.zipmac catalyst 静态库x86_64 + arm64
    ncnn-mac-catalyst-vulkan.zipmac catalyst 静态库,支持 GPUx86_64 + arm64
    ncnn-watchos.zipwatchos 静态库armv7k + arm64_32
    ncnn-watchos-simulator.zipwatchos simulator 静态库x86_64 + arm64
    ncnn-tvos.ziptvos 静态库x86_64 + arm64
    ncnn-tvos-vulkan.ziptvos 静态库,支持 GPUx86_64 + arm64
    ncnn-tvos-simulator.ziptvos simulator 静态库x86_64 + arm64
    ncnn-tvos-simulator-vulkan.ziptvos simulator 静态库,支持 GPUx86_64 + arm64
    ncnn-visionos.zipvisionos 静态库arm64
    ncnn-visionos-vulkan.zipvisionos 静态库,支持 GPUarm64
    ncnn-visionos-simulator.zipvisionos simulator 静态库x86_64 + arm64
    ncnn-visionos-simulator-vulkan.zipvisionos simulator 静态库,支持 GPUx86_64 + arm64
    ncnn-ubuntu.zipubuntu linux 静态库/动态库,支持 GPU,模型转换工具x86_64
    ncnn-windows.zipwindows 静态库/动态库,支持 GPU,模型转换工具x86 + x64 + arm + arm64
    ncnn-webassembly.zipwebassembly 静态库wasm32 + simd + threads + simd-threads

    新增flip算子和pnnx torch.flip的转换 clip x86 avx512循环剩余优化 tanh和unaryop x86 avx512循环剩余优化(@lfalive) sigmoid x86 avx512循环剩余优化(@futz12) instancenorm x86优化(@futz12) groupnorm x86 sse2/avx/avx512优化 groupnorm arm neon优化(@mmyyy22) sigmoid和部分数学函数 loongarch lsx/lasx 优化(@AtomAlpaca) shufflechannel riscv rvv/zfh/zvfh/xtheadvector优化(@AtomAlpaca) layernorm riscv rvv/zfh/zvfh/xtheadvector优化(@Deepdive543443) layernorm vulkan优化(@futz12) 使用size_t类型改善超大尺寸tensor的支持 修复x86 convolution int8 在启用avx512vnni时崩溃 修复android asset datareader在新android系统和部分手机上崩溃的问题 初始化layer featmask为空 简化layernorm naive c实现 修复convdw int8 dequantize pack8 使用putenv和平台相关api修复llvm-mingw编译问题(@zhuzeitou) 使用combine_x用于sse/avx vector拼接 修复rnn/lstm/gru int8测试因rounding导致的差异 更新ruapu探测risc-v zfh zvfh xtheadvector和动态分发 删除已废弃的 Extractor::set_num_threads/set_vulkan_compute api 修复cmake时编译器支持avxvnniint16的探测 修复windows nt内核不存在GetLogicalProcessorInformationEx时的崩溃问题(@futz12) cmake find_package(ncnn)支持指定最低版本并输出ncnn版本号(@Willaaaaaaa) benchncnn跑GPU时跳过int8模型(@c8s-wk) 支持Windows XP目标平台编译和新增msvc/mingw/clang的windows-xp ci(@AtomAlpaca @Sugar-Baby) 修正ppocr中ctc decode后处理规则(@futz12) 改善benchncnn中printf对size_t类型格式化参数兼容(@whyb) 更新glslang 最大支持gpu数量到32(@tpoisonooo) 支持nvidia headless vulkan 检测vulkan扩展 VK_KHR_shader_integer_dot_product VK_KHR_shader_bfloat16 VK_KHR_shader_float_controls2 VK_NV_cooperative_vector VK_NV_cooperative_matrix2 VK_EXT_shader_float8 VK_KHR_vulkan_memory_model 支持任意 cooperative matrix MNK size查询 修复vulkan-sdk支持VK_KHR_acceleration_structure时的编译错误 1d/2d Mat和VkMat总是会分配对齐的size,调整cstep策略 删除全部layer中vkimagemat类型输入输出的forward实现 删除layer support_image_storage和option use_image_storage字段 删除全部layer中pack8 shader实现 支持无graphics queue的vulkan驱动 vulkan fp16 packed在pack1时也使用半精度存储 跳过vulkan 1d权重上传前的cpu-pack 修复当cpu支持avx512时vulkan上传pack16数据的错误 修复有关localsize非subgroupsize倍数的vulka

  5. 20250503android ios macos linux windows webassembly watchos tvos visionos 预编译库 20250503 305837f2025-05-03 · 2025-05-03 09:58 UTC
    查看更新说明

    no new features from 20250428 fix blacklist for amd radv coopmat workaround for qcom adreno turnip

用户点评

登录用户的真实使用记录,可按版本和硬件筛选
共 0 条

    还没有人点评。第一个说出真实体验的人最有价值。

    README 原文

    未翻译

    ncnn

    ncnn

    License Download Total Count codecov

    ncnn is a high-performance neural network inference framework optimized for mobile, embedded, and desktop deployment. It has no third-party runtime dependencies, runs across CPU and Vulkan GPU backends, and provides tools such as pnnx for converting PyTorch and ONNX models to ncnn. Developers can deploy deep learning models efficiently on phones, PCs, browsers, and edge devices. ncnn is currently being used in many Tencent applications, such as QQ, Qzone, WeChat, Pitu, and so on.

    ncnn 是一个面向移动端、嵌入式和桌面端部署优化的高性能神经网络推理框架。 ncnn 无第三方运行时依赖,支持 CPU 和 Vulkan GPU 后端,并提供 pnnx 等工具将 PyTorch 和 ONNX 模型转换为 ncnn 模型。 基于 ncnn,开发者可以将深度学习模型高效部署到手机、PC、浏览器和边缘设备上。 ncnn 目前已在腾讯多款应用中使用,如:QQ,Qzone,微信,天天 P 图等。


    Quick Start

    The recommended beginner path is PyTorch -> pnnx -> ncnn.

    Install pnnx in a PyTorch environment

    pip3 install pnnx
    

    Export a PyTorch model to ncnn

    import torch
    import torch.nn as nn
    import pnnx
    
    class Model(nn.Module):
        def __init__(self):
            super().__init__()
            self.conv = nn.Conv2d(3, 8, 1)
            self.relu = nn.ReLU()
            self.fc = nn.Linear(8, 4)
    
        def forward(self, x):
            x = self.conv(x)
            x = self.relu(x)
            x = x.mean((2, 3))
            return self.fc(x)
    
    model = Model().eval()
    
    x = torch.rand(1, 3, 224, 224)
    pnnx.export(model, "model.pt", (x,))
    

    This generates model.ncnn.param and model.ncnn.bin.

    Run with ncnn C++ API

    #include "net.h"
    
    ncnn::Net net;
    net.load_param("model.ncnn.param");
    net.load_model("model.ncnn.bin");
    
    ncnn::Mat in(224, 224, 3);
    
    auto ex = net.create_extractor();
    ex.input("in0", in);
    
    ncnn::Mat out;
    ex.extract("out0", out);
    

    Or use Python

    import numpy as np
    import ncnn
    
    net = ncnn.Net()
    net.load_param("model.ncnn.param")
    net.load_model("model.ncnn.bin")
    
    x = np.zeros((3, 224, 224), np.float32)
    mat = ncnn.Mat(x)
    
    ex = net.create_extractor()
    ex.input("in0", mat)
    
    ret, out = ex.extract("out0")
    print(np.array(out).shape)
    

    See pnnx, use ncnn with PyTorch or ONNX, Python API, and examples for complete workflows.


    Community

    https://t.me/ncnnyes

    https://discord.gg/YRsxgmF


    Download & Build status

    https://github.com/Tencent/ncnn/releases/latest

    how to build ncnn library on Linux / Windows / macOS / Raspberry Pi3, Pi4 / POWER / Android / NVIDIA Jetson / iOS / WebAssembly / AllWinner D1 / Loongson 2K1000


    Build

    Use the prebuilt packages above when possible. To build from source, see the full how to build ncnn library guide for Linux, Windows, macOS, Android, iOS, WebAssembly, HarmonyOS, Raspberry Pi, Jetson, and embedded targets.

    Common Linux build:

    git clone --recursive https://github.com/Tencent/ncnn.git
    cd ncnn
    mkdir build && cd build
    cmake -DCMAKE_BUILD_TYPE=Release -DNCNN_VULKAN=ON -DNCNN_BUILD_EXAMPLES=ON ..
    cmake --build . -j$(nproc)
    

    Model Conversion

    Source modelRecommended pathDocs
    PyTorchpnnx.export(model, "model.pt", (input_tensor,)) or pnnx model.pt inputshape=[...]pnnx, PyTorch / ONNX guide
    ONNXpnnx model.onnxpnnx, onnx tools
    ncnn model optimizationncnnoptimize model.param model.bin new.param new.bin flagquantization, model file spec
    Legacy Caffe / MXNet / DarknetUse compatibility converters when maintaining older modelscaffe, mxnet, darknet, AlexNet legacy tutorial

    Use Netron to inspect .param, .onnx, and .pnnx.param graphs.


    Features

    • No third-party runtime dependencies and no BLAS / NNPACK requirement.
    • Pure C++ implementation with C API and Python binding.
    • Optimized CPU inference for mobile and embedded processors, including ARM NEON and multi-core scheduling.
    • Vulkan GPU acceleration for supported platforms.
    • Low memory footprint with explicit blob/workspace allocator design.
    • Supports multi-input, multi-output, and multi-branch graphs.
    • PyTorch and ONNX conversion through pnnx, plus legacy converter support for older model formats.
    • Supports fp16 storage/arithmetic paths, int8 quantized inference, model optimization, and custom layers.
    • Direct memory reference loading for .param and .bin models.

    Model and Workload Coverage

    ncnn is still strong for classic and mobile CNN workloads, but current usage is broader than CNN-only deployment.

    For operator-level detail, see supported PyTorch operator status, supported ONNX operator status, and operation param weight table.


    Project Examples

    AreaProject
    Image generationzimage-ncnn-vulkan - Z-Image generation with ncnn and Vulkan
    LLM / embedding / vision-languagencnn_llm - LLM, embedding, and vision-language examples with ncnn
    Android classificationncnn-android-squeezenet
    Android style transferncnn-android-styletransfer
    Android detectionncnn-android-mobilenetssd, ncnn-android-yolov5, ncnn-android-yolov7, ncnn-android-scrfd
    Face detectionmtcnn_ncnn
    Qt / Android integrationqt_android_ncnn_lib_encrypt_example
    Colorizationncnn-colorization-siggraph17
    Fortran bindingncnn-fortran
    Speech recognitionsherpa - real-time speech recognition on embedded and mobile devices

    Documentation And FAQ

    TopicLinks
    Buildhow to build
    PyTorch / ONNX conversionuse ncnn with PyTorch or ONNX, pnnx, PyTorch converter notes
    API and examplesC++ examples, Python API, low-level operation API
    Model formatparam and model file spec, operation param weight table
    Extensioncustom layer guide, plugin tools
    FAQdeepwiki, throw error, wrong result, Vulkan
    Legacy beginner materialuse ncnn with AlexNet, AlexNet Chinese tutorial

    License

    BSD 3 Clause