Skip to content

Latest commit

 

History

History
154 lines (88 loc) · 5.74 KB

README-qnn.md

File metadata and controls

154 lines (88 loc) · 5.74 KB

llama.cpp for QNN

Background

Android maintained its position as the leading mobile operating system worldwide in the fourth quarter of 2023 with a market share of 70.1 percent . Qualcomm is No.1 mobile SoC semiconductor company in our planet currently.

QNN(Qualcomm Neural Network, aka Qualcomm AI Engine Direct) SDK is verified to work with the following versions of the ML frameworks:

  • TensorFlow: tf-1.15.0, or tf-2.10.1
  • TFLite: tflite-2.3.0
  • PyTorch: torch-1.13.1
  • ONNX: onnx-1.11.0

The Qualcomm® AI Engine Direct architecture is designed to be modular and allows for clean separation in the software for different hardware cores/accelerators such as the CPU, GPU and DSP that are designated as backends. Learn more about Qualcomm® AI Engine Direct backends here.

Screenshot from 2024-04-14 11-42-14

The Qualcomm® AI Engine Direct backends for different hardware cores/accelerators are compiled into individual core-specific libraries that come packaged with the SDK.

One of the key highlights of Qualcomm® AI Engine Direct is that it provides a unified API to delegate operations such as graph creation and execution across all hardware accelerator backends. This allows users to treat Qualcomm® AI Engine Direct as a hardware abstraction API and port applications easily to different cores.

The Qualcomm® AI Engine Direct API is designed to support an efficient execution model with capabilities such as graph optimizations to be taken care of internally. At the same time however, it leaves out broader functionality such as model parsing and network partitioning to higher level frameworks.

Qualcomm® AI Engine Direct API and the associated software stack provides all the constructs required by an application to construct, optimize and execute network models on the desired hardware accelerator core. Key constructs are illustrated by the Qualcomm AI Engine Direct Components - High Level View diagram.

qnn-arch

Llama.cpp + QNN

The llama.cpp QNN backend is intented to support Qualcomm mobile SoC firstly.

News

OS

OS Status Verified
Android Support Android 10, Android 14
Windows over ARM TBD TBD

Hardware

Qualcomm mobile SoC based Android phone

Verified devices

Qualcom mobile SoC Status Verified Vendor
Qualcomm SM8650-AB Snapdragon 8 Gen 3 Support Xiaomi 14
Qualcomm low-end mobile SoC Series Support Vivo

Qualcomm SoC based Windows

TBD

Android

1. Setup Environment

Any mainstream Android phone based on Qualcomm's mobile SoC should be supported by llama.cpp + QNN. Qualcomm SM8650-AB Snapdragon 8 Gen 3 based Android phone is preferred.

2. Run QNN backend in command line mode on Android phone

  • for QNN backend developers, download and install QNN SDK from Qualcomm offcial website
  https://qpm.qualcomm.com/#/main/tools/details/qualcomm_ai_engine_direct

  https://developer.qualcomm.com/software/hexagon-dsp-sdk/tools

the default installation path is /opt/qcom/aistack/qnn/2.20.0.240223/

  • for programmers, using test-backend-ops.cpp to verify QNN backend on Qualcomm mobile SoC based Android phone
  cd core/ggml/llamacpp/tests/ggml-qnn/

  ./build-ggml-qnn.sh

  ./run-ggml-qnn.sh

3. Run QNN backend in Android APK on Android phone

pls refer to README.md

504893116

Windows

TBD

Q&A

TBD

GitHub contribution:

Please add the [ggml-qnn] prefix/tag in issues/PRs titles to help the community check/address them without delay.

TODO

  • only support FP32 / FP16 and the input and output tensors must be of the same data type

  • lack of implementation of other GGML-OPs using QNN API

  • multithreading not working with QNN GPU&HTP (aka DSP) backend

  • QNN's RPC feature(which useful for QNN HTP(aka DSP) backend) not used

  • multi QNN backend(CPU/GPU/DSP) simultaneously not support