├── .clang-format
├── .coveragerc
├── .flake8
├── .gitattributes
├── .gitignore
├── .isort.cfg
├── .markdownlint.jsonc
├── .pre-commit-config.yaml
├── .pre-commit-license-header.txt
├── .shellcheckrc
├── LICENSE
├── README.md
├── apps
├── android
│ ├── ChatApp
│ │ ├── README.md
│ │ ├── assets
│ │ │ ├── ai-hub-qnn-version.png
│ │ │ ├── chatapp_demo_1.mov
│ │ │ └── chatapp_demo_2.mov
│ │ ├── build.gradle
│ │ └── src
│ │ │ └── main
│ │ │ ├── AndroidManifest.xml
│ │ │ ├── assets
│ │ │ ├── README.txt
│ │ │ ├── htp_config
│ │ │ │ ├── qualcomm-snapdragon-8-elite.json
│ │ │ │ ├── qualcomm-snapdragon-8-gen2.json
│ │ │ │ └── qualcomm-snapdragon-8-gen3.json
│ │ │ └── models
│ │ │ │ └── llama3_2_3b
│ │ │ │ └── genie_config.json
│ │ │ ├── cpp
│ │ │ ├── CMakeLists.txt
│ │ │ ├── GenieLib.cpp
│ │ │ ├── GenieWrapper.cpp
│ │ │ ├── GenieWrapper.hpp
│ │ │ ├── PromptHandler.cpp
│ │ │ └── PromptHandler.hpp
│ │ │ ├── ic_launcher-playstore.png
│ │ │ ├── java
│ │ │ └── com
│ │ │ │ └── quicinc
│ │ │ │ └── chatapp
│ │ │ │ ├── ChatMessage.java
│ │ │ │ ├── Conversation.java
│ │ │ │ ├── GenieWrapper.java
│ │ │ │ ├── MainActivity.java
│ │ │ │ ├── MessageSender.java
│ │ │ │ ├── Message_RecyclerViewAdapter.java
│ │ │ │ └── StringCallback.java
│ │ │ └── res
│ │ │ ├── drawable
│ │ │ ├── bot_response.xml
│ │ │ ├── ic_launcher_background.xml
│ │ │ ├── ic_launcher_foreground.xml
│ │ │ ├── text_rounded_corner.xml
│ │ │ └── user_input.xml
│ │ │ ├── layout
│ │ │ ├── activity_main.xml
│ │ │ ├── chat.xml
│ │ │ └── chat_row.xml
│ │ │ ├── mipmap-anydpi-v26
│ │ │ ├── ic_launcher.xml
│ │ │ └── ic_launcher_round.xml
│ │ │ ├── mipmap-hdpi
│ │ │ ├── ic_launcher.webp
│ │ │ ├── ic_launcher_foreground.webp
│ │ │ └── ic_launcher_round.webp
│ │ │ ├── mipmap-mdpi
│ │ │ ├── ic_launcher.webp
│ │ │ ├── ic_launcher_foreground.webp
│ │ │ └── ic_launcher_round.webp
│ │ │ ├── mipmap-xhdpi
│ │ │ ├── ic_launcher.webp
│ │ │ ├── ic_launcher_foreground.webp
│ │ │ └── ic_launcher_round.webp
│ │ │ ├── mipmap-xxhdpi
│ │ │ ├── ic_launcher.webp
│ │ │ ├── ic_launcher_foreground.webp
│ │ │ └── ic_launcher_round.webp
│ │ │ ├── mipmap-xxxhdpi
│ │ │ ├── ic_launcher.webp
│ │ │ ├── ic_launcher_foreground.webp
│ │ │ └── ic_launcher_round.webp
│ │ │ ├── values-night
│ │ │ └── themes.xml
│ │ │ ├── values
│ │ │ ├── colors.xml
│ │ │ ├── strings.xml
│ │ │ └── themes.xml
│ │ │ └── xml
│ │ │ ├── backup_rules.xml
│ │ │ └── data_extraction_rules.xml
│ ├── ImageClassification
│ │ ├── README.md
│ │ ├── build.gradle
│ │ └── src
│ │ │ └── main
│ │ │ ├── AndroidManifest.xml
│ │ │ ├── assets
│ │ │ ├── README.txt
│ │ │ ├── images
│ │ │ │ ├── Sample1.png
│ │ │ │ ├── Sample2.png
│ │ │ │ └── Sample3.png
│ │ │ └── labels.txt
│ │ │ ├── java
│ │ │ └── com
│ │ │ │ └── quicinc
│ │ │ │ ├── ImageProcessing.java
│ │ │ │ ├── imageclassification
│ │ │ │ ├── ImageClassification.java
│ │ │ │ └── MainActivity.java
│ │ │ │ └── tflite
│ │ │ │ ├── AIHubDefaults.java
│ │ │ │ └── TFLiteHelpers.java
│ │ │ └── res
│ │ │ ├── drawable-v24
│ │ │ └── ic_launcher_foreground.xml
│ │ │ ├── drawable
│ │ │ ├── ic_launcher_background.xml
│ │ │ └── image_classification_icon.png
│ │ │ ├── layout
│ │ │ └── main_activity.xml
│ │ │ ├── mipmap-anydpi-v26
│ │ │ ├── ic_launcher.xml
│ │ │ └── ic_launcher_round.xml
│ │ │ ├── mipmap-hdpi
│ │ │ ├── ic_launcher.png
│ │ │ ├── ic_launcher_foreground.png
│ │ │ └── ic_launcher_round.png
│ │ │ ├── mipmap-mdpi
│ │ │ ├── ic_launcher.png
│ │ │ ├── ic_launcher_foreground.png
│ │ │ └── ic_launcher_round.png
│ │ │ ├── mipmap-xhdpi
│ │ │ ├── ic_launcher.png
│ │ │ ├── ic_launcher_foreground.png
│ │ │ └── ic_launcher_round.png
│ │ │ ├── mipmap-xxhdpi
│ │ │ ├── ic_launcher.png
│ │ │ ├── ic_launcher_foreground.png
│ │ │ └── ic_launcher_round.png
│ │ │ ├── mipmap-xxxhdpi
│ │ │ ├── ic_launcher.png
│ │ │ ├── ic_launcher_foreground.png
│ │ │ └── ic_launcher_round.png
│ │ │ ├── values-night
│ │ │ └── themes.xml
│ │ │ └── values
│ │ │ ├── colors.xml
│ │ │ ├── ic_launcher_background.xml
│ │ │ ├── strings.xml
│ │ │ ├── styles.xml
│ │ │ └── themes.xml
│ ├── SemanticSegmentation
│ │ ├── .gitattributes
│ │ ├── README.md
│ │ ├── build.gradle
│ │ └── src
│ │ │ └── main
│ │ │ ├── AndroidManifest.xml
│ │ │ ├── assets
│ │ │ └── README.txt
│ │ │ ├── ic_launcher-playstore.png
│ │ │ ├── java
│ │ │ └── com
│ │ │ │ └── quicinc
│ │ │ │ ├── semanticsegmentation
│ │ │ │ ├── CameraFragment.java
│ │ │ │ ├── FragmentRender.java
│ │ │ │ ├── MainActivity.java
│ │ │ │ └── SemanticSegmentation.java
│ │ │ │ └── tflite
│ │ │ │ ├── AIHubDefaults.java
│ │ │ │ └── TFLiteHelpers.java
│ │ │ └── res
│ │ │ ├── layout
│ │ │ ├── fragment_camera.xml
│ │ │ └── main_activity.xml
│ │ │ ├── mipmap-anydpi-v26
│ │ │ ├── ic_launcher.xml
│ │ │ └── ic_launcher_round.xml
│ │ │ ├── mipmap-hdpi
│ │ │ ├── ic_launcher.png
│ │ │ ├── ic_launcher_background.png
│ │ │ ├── ic_launcher_foreground.png
│ │ │ └── ic_launcher_round.png
│ │ │ ├── mipmap-mdpi
│ │ │ ├── ic_launcher.png
│ │ │ ├── ic_launcher_background.png
│ │ │ ├── ic_launcher_foreground.png
│ │ │ └── ic_launcher_round.png
│ │ │ ├── mipmap-xhdpi
│ │ │ ├── ic_launcher.png
│ │ │ ├── ic_launcher_background.png
│ │ │ ├── ic_launcher_foreground.png
│ │ │ └── ic_launcher_round.png
│ │ │ ├── mipmap-xxhdpi
│ │ │ ├── ic_launcher.png
│ │ │ ├── ic_launcher_background.png
│ │ │ ├── ic_launcher_foreground.png
│ │ │ └── ic_launcher_round.png
│ │ │ ├── mipmap-xxxhdpi
│ │ │ ├── ic_launcher.png
│ │ │ ├── ic_launcher_background.png
│ │ │ ├── ic_launcher_foreground.png
│ │ │ └── ic_launcher_round.png
│ │ │ └── values
│ │ │ ├── colors.xml
│ │ │ ├── dimen.xml
│ │ │ ├── strings.xml
│ │ │ └── styles.xml
│ ├── SuperResolution
│ │ ├── README.md
│ │ ├── build.gradle
│ │ └── src
│ │ │ └── main
│ │ │ ├── AndroidManifest.xml
│ │ │ ├── assets
│ │ │ ├── README.txt
│ │ │ └── images
│ │ │ │ ├── Sample1.jpg
│ │ │ │ └── Sample2.jpg
│ │ │ ├── java
│ │ │ └── com
│ │ │ │ └── quicinc
│ │ │ │ ├── ImageProcessing.java
│ │ │ │ ├── superresolution
│ │ │ │ ├── MainActivity.java
│ │ │ │ └── SuperResolution.java
│ │ │ │ └── tflite
│ │ │ │ ├── AIHubDefaults.java
│ │ │ │ └── TFLiteHelpers.java
│ │ │ └── res
│ │ │ ├── drawable-v24
│ │ │ └── ic_launcher_foreground.xml
│ │ │ ├── drawable
│ │ │ ├── ic_launcher_background.xml
│ │ │ └── super_resolution_icon.png
│ │ │ ├── layout
│ │ │ └── main_activity.xml
│ │ │ ├── mipmap-anydpi-v26
│ │ │ ├── ic_launcher.xml
│ │ │ └── ic_launcher_round.xml
│ │ │ ├── mipmap-hdpi
│ │ │ ├── ic_launcher.png
│ │ │ ├── ic_launcher_foreground.png
│ │ │ └── ic_launcher_round.png
│ │ │ ├── mipmap-mdpi
│ │ │ ├── ic_launcher.png
│ │ │ ├── ic_launcher_foreground.png
│ │ │ └── ic_launcher_round.png
│ │ │ ├── mipmap-xhdpi
│ │ │ ├── ic_launcher.png
│ │ │ ├── ic_launcher_foreground.png
│ │ │ └── ic_launcher_round.png
│ │ │ ├── mipmap-xxhdpi
│ │ │ ├── ic_launcher.png
│ │ │ ├── ic_launcher_foreground.png
│ │ │ └── ic_launcher_round.png
│ │ │ ├── mipmap-xxxhdpi
│ │ │ ├── ic_launcher.png
│ │ │ ├── ic_launcher_foreground.png
│ │ │ └── ic_launcher_round.png
│ │ │ ├── values-night
│ │ │ └── themes.xml
│ │ │ └── values
│ │ │ ├── colors.xml
│ │ │ ├── ic_launcher_background.xml
│ │ │ ├── strings.xml
│ │ │ ├── styles.xml
│ │ │ └── themes.xml
│ ├── WhisperKit
│ │ └── README.md
│ ├── build.gradle
│ ├── gradle.properties
│ ├── gradle
│ │ └── wrapper
│ │ │ └── gradle-wrapper.properties
│ ├── image_preprocessing_helpers
│ │ └── ImageProcessing.java
│ ├── settings.gradle
│ └── tflite_helpers
│ │ ├── AIHubDefaults.java
│ │ └── TFLiteHelpers.java
└── windows
│ ├── cpp
│ ├── ChatApp
│ │ ├── .gitignore
│ │ ├── ChatApp.cpp
│ │ ├── ChatApp.hpp
│ │ ├── ChatApp.sln
│ │ ├── ChatApp.vcxproj
│ │ ├── ChatApp.vcxproj.filters
│ │ ├── ChatApp.vcxproj.user
│ │ ├── Main.cpp
│ │ ├── PromptHandler.cpp
│ │ ├── PromptHandler.hpp
│ │ ├── README.md
│ │ └── assets
│ │ │ └── images
│ │ │ ├── ai-hub-qnn-version.png
│ │ │ ├── sample-qnn-sdk-check.png
│ │ │ └── sample_output.png
│ ├── Classification
│ │ ├── Classification.sln
│ │ ├── Classification.vcxproj
│ │ ├── Classification.vcxproj.filters
│ │ ├── Classification.vcxproj.user
│ │ ├── ClassificationApp.cpp
│ │ ├── ClassificationApp.hpp
│ │ ├── Main.cpp
│ │ ├── README.md
│ │ ├── Utilities.cpp
│ │ ├── Utilities.hpp
│ │ ├── assets
│ │ │ ├── images
│ │ │ │ ├── classificationOutput.png
│ │ │ │ └── keyboard.jpg
│ │ │ └── models
│ │ │ │ └── README.md
│ │ ├── packages.config
│ │ ├── synset.txt
│ │ ├── vcpkg-configuration.json
│ │ └── vcpkg.json
│ ├── ObjectDetection
│ │ ├── Main.cpp
│ │ ├── ObjectDetection.sln
│ │ ├── ObjectDetection.vcxproj
│ │ ├── ObjectDetection.vcxproj.filters
│ │ ├── ObjectDetection.vcxproj.user
│ │ ├── ObjectDetectionApp.cpp
│ │ ├── ObjectDetectionApp.hpp
│ │ ├── README.md
│ │ ├── Utilities.cpp
│ │ ├── Utilities.hpp
│ │ ├── assets
│ │ │ ├── images
│ │ │ │ ├── keyboard.jpg
│ │ │ │ ├── kitchen.jpg
│ │ │ │ └── sample_outputs
│ │ │ │ │ └── kitchen_output.jpg
│ │ │ └── models
│ │ │ │ └── README.md
│ │ ├── packages.config
│ │ ├── vcpkg-configuration.json
│ │ └── vcpkg.json
│ └── SuperResolution
│ │ ├── Main.cpp
│ │ ├── README.md
│ │ ├── SuperResolution.sln
│ │ ├── SuperResolution.vcxproj
│ │ ├── SuperResolution.vcxproj.filters
│ │ ├── SuperResolution.vcxproj.user
│ │ ├── SuperResolutionApp.cpp
│ │ ├── SuperResolutionApp.hpp
│ │ ├── Utilities.cpp
│ │ ├── Utilities.hpp
│ │ ├── assets
│ │ ├── images
│ │ │ ├── Doll.jpg
│ │ │ └── UpscaledImage.png
│ │ └── models
│ │ │ └── README.md
│ │ ├── packages.config
│ │ ├── vcpkg-configuration.json
│ │ └── vcpkg.json
│ └── python
│ ├── BringYourOwnModel
│ └── README.md
│ ├── StableDiffusion
│ ├── README.md
│ └── demo.py
│ ├── Whisper
│ ├── README.md
│ └── demo.py
│ ├── activate_venv.ps1
│ ├── install_platform_deps.ps1
│ └── install_python_deps.ps1
├── mypy.ini
├── tutorials
├── deploy
│ └── onnx
│ │ ├── README.md
│ │ ├── build_deployable_asset.py
│ │ └── requirements.txt
└── llm_on_genie
│ ├── README.md
│ ├── configs
│ ├── genie
│ │ ├── baichuan2_7b.json
│ │ ├── ibm_granite_v3_1_8b_instruct.json
│ │ ├── llama_v2_7b_chat.json
│ │ ├── llama_v3_1_8b_instruct.json
│ │ ├── llama_v3_2_3b_instruct.json
│ │ ├── llama_v3_8b_instruct.json
│ │ ├── llama_v3_taide_8b_chat.json
│ │ ├── mistral_7b_instruct_v0_3.json
│ │ ├── phi_3_5_mini_instruct.json
│ │ └── qwen2_7b_instruct.json
│ └── htp
│ │ └── htp_backend_ext_config.json.template
│ └── powershell
│ ├── LlmUtils.ps1
│ ├── README.md
│ └── RunLlm.ps1
└── version_info.py
/.clang-format:
--------------------------------------------------------------------------------
1 | ---
2 | Language: Json
3 | BasedOnStyle: llvm
4 | DisableFormat: true
5 | ---
6 | Language: Cpp
7 | BasedOnStyle: LLVM
8 | AllowAllParametersOfDeclarationOnNextLine: false
9 | AllowShortIfStatementsOnASingleLine: false
10 | AllowShortBlocksOnASingleLine: false
11 | AllowShortFunctionsOnASingleLine: false
12 | AllowShortLoopsOnASingleLine: false
13 | AlwaysBreakBeforeMultilineStrings: false
14 | BinPackParameters: false
15 | BreakBeforeBraces: Allman
16 | BreakConstructorInitializers: BeforeComma
17 | ColumnLimit: 120
18 | IndentCaseLabels: false
19 | IndentWidth: 4
20 | PointerAlignment: Left
21 | Standard: c++17
22 | ---
23 | Language: Proto
24 | DisableFormat: true
25 | ---
26 | Language: Java
27 | DisableFormat: true
28 | ...
29 |
--------------------------------------------------------------------------------
/.coveragerc:
--------------------------------------------------------------------------------
1 | [run]
2 | omit = */test_*,*/test,*/test/*,build/*,src/customer/*,/private/*,/tmp/*
3 |
4 | [report]
5 | ignore_errors = True
6 |
--------------------------------------------------------------------------------
/.flake8:
--------------------------------------------------------------------------------
1 | [flake8]
2 | ignore = E501,W503,E203,E266,E265,F811
3 | # E501 line too long
4 | # W503 clang-formatter can produce line break before binary operator
5 | # E203 False positive "whitespaces before :" especially when slicing list, arrays etc.
6 | # E266 Too many leading '#' for block comment
7 | # E265 Block comment should start with '# '
8 | # F811 A module has been imported twice, but seen when importing functions for fixtures in pytest files.
9 | exclude = **/*_pb2.py
10 |
--------------------------------------------------------------------------------
/.gitattributes:
--------------------------------------------------------------------------------
1 | *.jpg filter=lfs diff=lfs merge=lfs -text
2 | *.png filter=lfs diff=lfs merge=lfs -text
3 | *.jar filter=lfs diff=lfs merge=lfs -text
4 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # Byte-compiled / optimized / DLL files
2 | __pycache__/
3 | *.py[cod]
4 | *$py.class
5 |
6 | # Distribution / packaging
7 | .Python
8 | /bench/
9 | build/
10 | dist/
11 | demo_artifacts/
12 | develop-eggs/
13 | downloads/
14 | eggs/
15 | .eggs/
16 | parts/
17 | sdist/
18 | var/
19 | wheels/
20 | pip-wheel-metadata/
21 | share/python-wheels/
22 | *.egg-info/
23 | .installed.cfg
24 | *.egg
25 | MANIFEST
26 | **/.idea
27 | **/local.properties
28 |
29 | # PyInstaller
30 | # Usually these files are written by a python script from a template
31 | # before PyInstaller builds the exe, so as to inject date/other infos into it.
32 | *.manifest
33 | *.spec
34 | **/.gradle
35 | **/gradle
36 | **/gradlew*
37 |
38 | # Installer logs
39 | pip-log.txt
40 | pip-delete-this-directory.txt
41 |
42 | # Unit test / coverage reports
43 | htmlcov/
44 | .tox/
45 | .nox/
46 | .coverage
47 | .coverage.*
48 | .cache
49 | nosetests.xml
50 | coverage.xml
51 | *.cover
52 | *.py,cover
53 | .hypothesis/
54 | .pytest_cache/
55 |
56 | # Translations
57 | *.mo
58 | *.pot
59 |
60 | # PyBuilder
61 | target/
62 |
63 | # Jupyter Notebook
64 | .ipynb_checkpoints
65 |
66 | # IPython
67 | profile_default/
68 | ipython_config.py
69 |
70 | # pyenv
71 | .python-version
72 | qaiha-dev
73 |
74 | # pipenv
75 | # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
76 | # However, in case of collaboration, if having platform-specific dependencies or dependencies
77 | # having no cross-platform support, pipenv may install dependencies that don't work, or not
78 | # install all needed dependencies.
79 | #Pipfile.lock
80 |
81 | # PEP 582; used by e.g. github.com/David-OConnor/pyflow
82 | __pypackages__/
83 |
84 | # Environments
85 | .venv
86 | env/
87 | envs/
88 | venv/
89 | ENV/
90 | env.bak/
91 | venv.bak/
92 |
93 | # JetBrains things
94 | .idea/
95 |
96 | # mypy
97 | .mypy_cache/
98 | .dmypy.json
99 | dmypy.json
100 |
101 | # Pyre type checker
102 | .pyre/
103 |
104 | *build/*
105 | *.bin
106 | *.cxx/
107 | *.onnx
108 | *.mlmodelc*
109 | *.pt
110 | *.wav
111 | *.npy
112 | *.csv
113 | *.dylib
114 | *.fpie
115 | *bin/ADSP_Inference_Test
116 | *.DS_Store
117 |
118 | # Hub exports
119 | **/*.mlmodel
120 | **/*.tflite
121 |
--------------------------------------------------------------------------------
/.isort.cfg:
--------------------------------------------------------------------------------
1 | [settings]
2 | profile=black
3 |
--------------------------------------------------------------------------------
/.markdownlint.jsonc:
--------------------------------------------------------------------------------
1 | {
2 | "MD013": false, // No line length limit
3 | "MD033": false // Allow inline HTML
4 | }
5 |
--------------------------------------------------------------------------------
/.pre-commit-config.yaml:
--------------------------------------------------------------------------------
1 | # exclude:
2 | # * third_party folders
3 | # * CloudFormation templates don't pass the yaml-check hook (a known issue)
4 |
5 | exclude: |
6 | (?x)(
7 | /build/
8 | )
9 |
10 | repos:
11 | - repo: https://github.com/Lucas-C/pre-commit-hooks
12 | rev: v1.5.5
13 | hooks:
14 | - id: insert-license
15 | files: \.py|\.sh$
16 | args:
17 | - --license-filepath
18 | - .pre-commit-license-header.txt
19 | - --allow-past-years
20 | - --no-extra-eol
21 | - id: insert-license
22 | files: \.java$
23 | args:
24 | - --license-filepath
25 | - .pre-commit-license-header.txt
26 | - --comment-style
27 | - //
28 | - --allow-past-years
29 | - --no-extra-eol
30 |
31 | - repo: https://github.com/pre-commit/pre-commit-hooks
32 | rev: v4.1.0
33 | hooks:
34 | - id: check-yaml
35 | args: [--allow-multiple-documents]
36 | - id: trailing-whitespace
37 | exclude: '\.diff$'
38 | - id: check-added-large-files
39 | args: ['--maxkb=1024']
40 | - id: check-merge-conflict
41 | - id: detect-aws-credentials
42 | args: [--allow-missing-credentials]
43 | - id: end-of-file-fixer
44 | exclude: |
45 | (?x)(
46 | \.diff$
47 | )
48 | - id: fix-byte-order-marker
49 | - repo: https://github.com/rhysd/actionlint
50 | rev: v1.6.26
51 | hooks:
52 | - id: actionlint
53 | - repo: https://github.com/shellcheck-py/shellcheck-py
54 | rev: v0.9.0.6
55 | hooks:
56 | - id: shellcheck
57 | exclude: gradlew
58 | - repo: https://github.com/pycqa/isort
59 | rev: 5.12.0
60 | hooks:
61 | - id: isort
62 | args: ["--filter-files"]
63 | - repo: https://github.com/psf/black
64 | rev: 22.1.0
65 | hooks:
66 | - id: black
67 | additional_dependencies: ['click==8.0.4']
68 | - repo: https://github.com/pre-commit/mirrors-clang-format
69 | rev: v13.0.1
70 | hooks:
71 | - id: clang-format
72 | types_or: [c++, c, c#, cuda, objective-c, proto]
73 | - repo: https://github.com/pycqa/flake8
74 | rev: 6.1.0
75 | hooks:
76 | - id: flake8
77 | - repo: local
78 | hooks:
79 | - id: mypy
80 | name: mypy
81 | files: \.(py|pyi|ipynb|proto|fbs)$
82 | entry: scripts/util/run_mypy.sh
83 | language: system
84 |
--------------------------------------------------------------------------------
/.pre-commit-license-header.txt:
--------------------------------------------------------------------------------
1 | ---------------------------------------------------------------------
2 | Copyright (c) 2024 Qualcomm Innovation Center, Inc. All rights reserved.
3 | SPDX-License-Identifier: BSD-3-Clause
4 | ---------------------------------------------------------------------
5 |
--------------------------------------------------------------------------------
/.shellcheckrc:
--------------------------------------------------------------------------------
1 | ## How to update these rules
2 | ##
3 | ## From repo root, `pre-commit run -a shellcheck` to run shellcheck across all files in the repo. By default, the commit hook
4 | ## will only run on your patch. However, CI runs it across all files, so if you're going to touch this file, I
5 | ## recommend forcing it to run.
6 | ##
7 | ## To run on and fix a specific file, run:
8 | ## shellcheck -x -f diff {filename} | apply
9 | ##
10 |
11 | external-sources=true
12 |
13 | ## Issue 7533: [shellcheck] Explore miscellaneous checks
14 | disable=SC2003 # expr is antiquated. Consider rewriting this using `$((..))`, `${}` or `[[ ]]`.
15 | disable=SC2005 # Useless `echo`? Instead of `echo $(cmd)`, just use `cmd`
16 | disable=SC2012 # Use `find` instead of `ls` to better handle non-alphanumeric filenames.
17 | disable=SC2116 # Useless echo? Instead of `cmd $(echo foo)`, just use `cmd foo`.
18 | disable=SC2155 # Declare and assign separately to avoid masking return values.
19 | disable=SC2166 # Prefer `[ p ] && [ q ]` as `[ p -a q ]` is not well defined.
20 |
21 |
22 | ## things we probably don't care about ever fixing.
23 |
24 | disable=SC1083 # This `{`/`}` is literal. Check if `;` is missing or quote the expression.
25 |
26 | disable=SC2001 # See if you can use `${variable//search/replace}` instead.
27 | disable=SC2064 # Use single quotes, otherwise this expands now rather than when signalled.
28 | disable=SC2129 # Consider using `{ cmd1; cmd2; } >> file` instead of individual redirects.
29 | disable=SC2143 # Use `grep -q` instead of comparing output with `[ -n .. ]`.
30 | disable=SC2148 # Tips depend on target shell and yours is unknown. Add a shebang.
31 | disable=SC2162 # `read` without `-r` will mangle backslashes.
32 | disable=SC2164 # Use `cd ... || exit` in case `cd` fails.
33 | disable=SC2181 # Check exit code directly with e.g. `if mycmd;`, not indirectly with `$?`.
34 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | Copyright 2024 Qualcomm Innovation Center, Inc.
2 |
3 | Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
4 |
5 | 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
6 |
7 | 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
8 |
9 | 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
10 |
11 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS “AS IS” AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
12 |
--------------------------------------------------------------------------------
/apps/android/ChatApp/assets/ai-hub-qnn-version.png:
--------------------------------------------------------------------------------
1 | version https://git-lfs.github.com/spec/v1
2 | oid sha256:46380cfb7f50a5b5db155fa6b8188c4ebd766234920fb9705738b0d9eb6ae3bd
3 | size 216680
4 |
--------------------------------------------------------------------------------
/apps/android/ChatApp/assets/chatapp_demo_1.mov:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/quic/ai-hub-apps/f9b38777e2071bf9c46197015b63c976fe5ab4c2/apps/android/ChatApp/assets/chatapp_demo_1.mov
--------------------------------------------------------------------------------
/apps/android/ChatApp/assets/chatapp_demo_2.mov:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/quic/ai-hub-apps/f9b38777e2071bf9c46197015b63c976fe5ab4c2/apps/android/ChatApp/assets/chatapp_demo_2.mov
--------------------------------------------------------------------------------
/apps/android/ChatApp/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
14 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
26 |
27 |
28 |
31 |
34 |
35 |
36 |
--------------------------------------------------------------------------------
/apps/android/ChatApp/src/main/assets/README.txt:
--------------------------------------------------------------------------------
1 | Place QNN context binaries and tokenizer here
2 |
--------------------------------------------------------------------------------
/apps/android/ChatApp/src/main/assets/htp_config/qualcomm-snapdragon-8-elite.json:
--------------------------------------------------------------------------------
1 | {
2 | "devices": [
3 | {
4 | "soc_model": 69,
5 | "dsp_arch": "v79",
6 | "cores": [
7 | {
8 | "core_id": 0,
9 | "perf_profile": "burst",
10 | "rpc_control_latency": 100
11 | }
12 | ]
13 | }
14 | ],
15 | "memory": {
16 | "mem_type": "shared_buffer"
17 | },
18 | "groupContext": {
19 | "share_resources": true
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/apps/android/ChatApp/src/main/assets/htp_config/qualcomm-snapdragon-8-gen2.json:
--------------------------------------------------------------------------------
1 | {
2 | "devices": [
3 | {
4 | "soc_model": 43,
5 | "dsp_arch": "v73",
6 | "cores": [
7 | {
8 | "core_id": 0,
9 | "perf_profile": "burst",
10 | "rpc_control_latency": 100
11 | }
12 | ]
13 | }
14 | ],
15 | "memory": {
16 | "mem_type": "shared_buffer"
17 | },
18 | "groupContext": {
19 | "share_resources": true
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/apps/android/ChatApp/src/main/assets/htp_config/qualcomm-snapdragon-8-gen3.json:
--------------------------------------------------------------------------------
1 | {
2 | "devices": [
3 | {
4 | "soc_model": 57,
5 | "dsp_arch": "v75",
6 | "cores": [
7 | {
8 | "core_id": 0,
9 | "perf_profile": "burst",
10 | "rpc_control_latency": 100
11 | }
12 | ]
13 | }
14 | ],
15 | "memory": {
16 | "mem_type": "shared_buffer"
17 | },
18 | "groupContext": {
19 | "share_resources": true
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/apps/android/ChatApp/src/main/assets/models/llama3_2_3b/genie_config.json:
--------------------------------------------------------------------------------
1 | {
2 | "dialog": {
3 | "version": 1,
4 | "type": "basic",
5 | "context": {
6 | "version": 1,
7 | "size": 2048,
8 | "n-vocab": 128256,
9 | "bos-token": -1,
10 | "eos-token": [128001, 128009, 128008]
11 | },
12 | "sampler": {
13 | "version": 1,
14 | "seed": 42,
15 | "temp": 0.8,
16 | "top-k": 40,
17 | "top-p": 0.95
18 | },
19 | "tokenizer": {
20 | "version": 1,
21 | "path": ""
22 | },
23 | "engine": {
24 | "version": 1,
25 | "n-threads": 3,
26 | "backend": {
27 | "version": 1,
28 | "type": "QnnHtp",
29 | "QnnHtp": {
30 | "version": 1,
31 | "use-mmap": true,
32 | "spill-fill-bufsize": 0,
33 | "mmap-budget": 0,
34 | "poll": true,
35 | "cpu-mask": "0xe0",
36 | "kv-dim": 128,
37 | "allow-async-init": false
38 | },
39 | "extensions": ""
40 | },
41 | "model": {
42 | "version": 1,
43 | "type": "binary",
44 | "binary": {
45 | "version": 1,
46 | "ctx-bins": [
47 | "/llama_v3_2_3b_instruct_part_1_of_3.bin",
48 | "/llama_v3_2_3b_instruct_part_2_of_3.bin",
49 | "/llama_v3_2_3b_instruct_part_3_of_3.bin"
50 | ]
51 | },
52 | "positional-encoding": {
53 | "type": "rope",
54 | "rope-dim": 64,
55 | "rope-theta": 500000,
56 | "rope-scaling": {
57 | "rope-type": "llama3",
58 | "factor": 8.0,
59 | "low-freq-factor": 1.0,
60 | "high-freq-factor": 4.0,
61 | "original-max-position-embeddings": 8192
62 | }
63 | }
64 | }
65 | }
66 | }
67 | }
68 |
--------------------------------------------------------------------------------
/apps/android/ChatApp/src/main/cpp/CMakeLists.txt:
--------------------------------------------------------------------------------
1 | # For more information about using CMake with Android Studio, read the
2 | # documentation: https://d.android.com/studio/projects/add-native-code.html.
3 | # For more examples on how to use CMake, see https://github.com/android/ndk-samples.
4 |
5 | # Sets the minimum CMake version required for this project.
6 | cmake_minimum_required(VERSION 3.22.1)
7 |
8 | # Declares the project name. The project name can be accessed via ${ PROJECT_NAME},
9 | # Since this is the top level CMakeLists.txt, the project name is also accessible
10 | # with ${CMAKE_PROJECT_NAME} (both CMake variables are in-sync within the top level
11 | # build script scope).
12 | project("chatapp")
13 |
14 | set(GENIE_HEADERS_PATH "${QNN_SDK_ROOT_PATH}/include/Genie")
15 | set(GENIE_LIB_PATH "${QNN_SDK_ROOT_PATH}/lib/aarch64-android/libGenie.so")
16 |
17 | include_directories("includes")
18 |
19 | # Include Genie headers here
20 | include_directories(${GENIE_HEADERS_PATH})
21 |
22 | add_library(${CMAKE_PROJECT_NAME} SHARED
23 | # List C/C++ source files with relative paths to this CMakeLists.txt.
24 | PromptHandler.cpp
25 | GenieWrapper.cpp
26 | GenieLib.cpp)
27 |
28 | # Link libGenie.so here
29 | target_link_libraries(${CMAKE_PROJECT_NAME}
30 | "${GENIE_LIB_PATH}"
31 | android
32 | log)
33 |
--------------------------------------------------------------------------------
/apps/android/ChatApp/src/main/cpp/GenieLib.cpp:
--------------------------------------------------------------------------------
1 | // ---------------------------------------------------------------------
2 | // Copyright (c) 2024 Qualcomm Innovation Center, Inc. All rights reserved.
3 | // SPDX-License-Identifier: BSD-3-Clause
4 | // ---------------------------------------------------------------------
5 | #include
6 | #include
7 | #include
8 | #include
9 |
10 | #include "GenieWrapper.hpp"
11 |
12 | extern "C" JNIEXPORT jlong JNICALL Java_com_quicinc_chatapp_GenieWrapper_loadModel(JNIEnv* env,
13 | jobject /* this */,
14 | jstring model_dir_path,
15 | jstring htp_config_path)
16 | {
17 |
18 | try
19 | {
20 | std::string model_dir = std::string(env->GetStringUTFChars(model_dir_path, 0));
21 | std::string htp_config = std::string(env->GetStringUTFChars(htp_config_path, 0));
22 | std::filesystem::path model_config_path = std::filesystem::path(model_dir) / "genie_config.json";
23 | std::filesystem::path tokenizer_path = std::filesystem::path(model_dir) / "tokenizer.json";
24 |
25 | App::GenieWrapper* chatApp =
26 | new App::GenieWrapper(model_config_path.string(), model_dir, htp_config, tokenizer_path.string());
27 | return reinterpret_cast(chatApp);
28 | }
29 | catch (std::exception& e)
30 | {
31 | jclass exception_cls = env->FindClass("java/lang/RuntimeException");
32 | env->ThrowNew(exception_cls, e.what());
33 | }
34 | }
35 |
36 | extern "C" JNIEXPORT void JNICALL Java_com_quicinc_chatapp_GenieWrapper_getResponseForPrompt(JNIEnv* env,
37 | jobject /* this */,
38 | jlong genie_wrapper_handle,
39 | jstring user_question,
40 | jobject callback)
41 | {
42 | try
43 | {
44 | // Get callback method
45 | jclass callbackClass = env->GetObjectClass(callback);
46 | jmethodID onNewStringMethod = env->GetMethodID(callbackClass, "onNewString", "(Ljava/lang/String;)V");
47 |
48 | std::string user_input = env->GetStringUTFChars(user_question, 0);
49 |
50 | // Get response from Genie
51 | App::GenieWrapper* myClass = reinterpret_cast(genie_wrapper_handle);
52 | auto response = myClass->GetResponseForPrompt(user_input, env, callback, onNewStringMethod);
53 | }
54 | catch (std::exception& e)
55 | {
56 | jclass exception_cls = env->FindClass("java/lang/RuntimeException");
57 | env->ThrowNew(exception_cls, e.what());
58 | }
59 | }
60 |
61 | extern "C" JNIEXPORT void JNICALL Java_com_quicinc_chatapp_GenieWrapper_freeModel(JNIEnv* env,
62 | jobject /* this */,
63 | jlong genie_wrapper_handle)
64 | {
65 | try
66 | {
67 | App::GenieWrapper* genie_wrapper = reinterpret_cast(genie_wrapper_handle);
68 | delete genie_wrapper;
69 | }
70 | catch (std::exception& e)
71 | {
72 | jclass exception_cls = env->FindClass("java/lang/RuntimeException");
73 | env->ThrowNew(exception_cls, e.what());
74 | }
75 | }
76 |
--------------------------------------------------------------------------------
/apps/android/ChatApp/src/main/cpp/GenieWrapper.hpp:
--------------------------------------------------------------------------------
1 | // ---------------------------------------------------------------------
2 | // Copyright (c) 2024 Qualcomm Innovation Center, Inc. All rights reserved.
3 | // SPDX-License-Identifier: BSD-3-Clause
4 | // ---------------------------------------------------------------------
5 | #pragma once
6 |
7 | #include
8 | #include
9 |
10 | #include "GenieCommon.h"
11 | #include "GenieDialog.h"
12 | #include "PromptHandler.hpp"
13 |
14 | namespace App
15 | {
16 | constexpr const char* c_exit_prompt = "exit";
17 | constexpr const char* c_bot_name = "Qbot";
18 |
19 | class GenieWrapper
20 | {
21 | private:
22 | GenieDialogConfig_Handle_t m_config_handle = nullptr;
23 | GenieDialog_Handle_t m_dialog_handle = nullptr;
24 | std::string m_user_name;
25 | AppUtils::PromptHandler prompt_handler;
26 |
27 | public:
28 | /**
29 | * GenieWrapper: Initializes GenieWrapper
30 | * - Loads Model config with provided model path, htp config and tokenizer
31 | * - Creates handle for Genie
32 | *
33 | * @param model_config_path: local path to model Genie config file
34 | * @param models_path: local path to directory that contains model context binaries (e.g., downloaded from AI Hub)
35 | * @param htp_config_path: local path to backend htp configuration
36 | * @param tokenizer_path: local path to tokenizer to use
37 | *
38 | * @thows on failure to create handle for Genie config, dialog
39 | *
40 | */
41 | GenieWrapper(const std::string& model_config_path,
42 | const std::string& models_path,
43 | const std::string& htp_config_path,
44 | const std::string& tokenizer_path);
45 | GenieWrapper() = delete;
46 | GenieWrapper(const GenieWrapper&) = delete;
47 | GenieWrapper(GenieWrapper&&) = delete;
48 | GenieWrapper& operator=(const GenieWrapper&) = delete;
49 | GenieWrapper& operator=(GenieWrapper&&) = delete;
50 | ~GenieWrapper();
51 |
52 | /**
53 | * GetResponseForPrompt: Gets response from Genie for provided user prompt and callback
54 | *
55 | * @param user_prompt: User prompt provided by user
56 | * @param env: JNIEnv required to create intermediate output to pass via callback
57 | * @param callback: callback object
58 | * @param onNewStringMethod callback method to tunnel intermediate output string
59 | *
60 | * @throws on failure to query model response during chat
61 | *
62 | */
63 | std::string
64 | GetResponseForPrompt(const std::string& user_prompt, JNIEnv* env, jobject callback, jmethodID onNewStringMethod);
65 | };
66 | } // namespace App
67 |
--------------------------------------------------------------------------------
/apps/android/ChatApp/src/main/cpp/PromptHandler.cpp:
--------------------------------------------------------------------------------
1 | // ---------------------------------------------------------------------
2 | // Copyright (c) 2024 Qualcomm Innovation Center, Inc. All rights reserved.
3 | // SPDX-License-Identifier: BSD-3-Clause
4 | // ---------------------------------------------------------------------
5 | #include "PromptHandler.hpp"
6 | #include "GenieWrapper.hpp"
7 |
8 | using namespace AppUtils;
9 |
10 | // Llama3 prompt
11 | constexpr const std::string_view c_bot_name = "QBot";
12 | constexpr const std::string_view c_first_prompt_prefix_part_1 =
13 | "<|begin_of_text|><|start_header_id|>system<|end_header_id|>\n\nYour name is ";
14 | constexpr const std::string_view c_first_prompt_prefix_part_2 =
15 | "and you are a helpful AI assistant. Please keep answers concise and to the point. <|eot_id|>";
16 | constexpr const std::string_view c_prompt_prefix = "<|start_header_id|>user<|end_header_id|>\n\n";
17 | constexpr const std::string_view c_end_of_prompt = "<|eot_id|>";
18 | constexpr const std::string_view c_assistant_header = "<|start_header_id|>assistant<|end_header_id|>\n\n";
19 |
20 | PromptHandler::PromptHandler()
21 | : m_is_first_prompt(true)
22 | {
23 | }
24 |
25 | std::string PromptHandler::GetPromptWithTag(const std::string& user_prompt)
26 | {
27 | // Ref: https://www.llama.com/docs/model-cards-and-prompt-formats/meta-llama-3/
28 | if (m_is_first_prompt)
29 | {
30 | m_is_first_prompt = false;
31 | return std::string(c_first_prompt_prefix_part_1) + c_bot_name.data() + c_first_prompt_prefix_part_2.data() +
32 | c_prompt_prefix.data() + user_prompt + c_end_of_prompt.data() + c_assistant_header.data();
33 | }
34 | return std::string(c_prompt_prefix) + user_prompt.data() + c_end_of_prompt.data() + c_assistant_header.data();
35 | }
36 |
--------------------------------------------------------------------------------
/apps/android/ChatApp/src/main/cpp/PromptHandler.hpp:
--------------------------------------------------------------------------------
1 | //
2 | // Created by Bhushan Sonawane on 10/6/24.
3 | //
4 |
5 | // ---------------------------------------------------------------------
6 | // Copyright (c) 2024 Qualcomm Innovation Center, Inc. All rights reserved.
7 | // SPDX-License-Identifier: BSD-3-Clause
8 | // ---------------------------------------------------------------------
9 | #pragma once
10 |
11 | #include
12 |
13 | namespace AppUtils
14 | {
15 |
16 | class PromptHandler
17 | {
18 | private:
19 | bool m_is_first_prompt;
20 |
21 | public:
22 | PromptHandler();
23 | std::string GetPromptWithTag(const std::string& user_prompt);
24 | };
25 |
26 | } // namespace AppUtils
27 |
--------------------------------------------------------------------------------
/apps/android/ChatApp/src/main/ic_launcher-playstore.png:
--------------------------------------------------------------------------------
1 | version https://git-lfs.github.com/spec/v1
2 | oid sha256:0cb9369989424268b34ffc02bc948695bd6837e43869ee56e3ba3665b4220712
3 | size 41705
4 |
--------------------------------------------------------------------------------
/apps/android/ChatApp/src/main/java/com/quicinc/chatapp/ChatMessage.java:
--------------------------------------------------------------------------------
1 | // ---------------------------------------------------------------------
2 | // Copyright (c) 2024 Qualcomm Innovation Center, Inc. All rights reserved.
3 | // SPDX-License-Identifier: BSD-3-Clause
4 | // ---------------------------------------------------------------------
5 | package com.quicinc.chatapp;
6 |
7 | /**
8 | * ChatMessage: Holds information about each message within Chat
9 | */
10 | public class ChatMessage {
11 |
12 | public String mMessage;
13 | public int mLength;
14 | public MessageSender mSender;
15 |
16 | public ChatMessage(String msg, MessageSender sender) {
17 | mMessage = msg;
18 | mLength = msg.length();
19 | mSender = sender;
20 | }
21 |
22 | public boolean isMessageFromUser() {
23 | return mSender == MessageSender.USER;
24 | }
25 |
26 | public String getMessage() {
27 | return mMessage;
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/apps/android/ChatApp/src/main/java/com/quicinc/chatapp/GenieWrapper.java:
--------------------------------------------------------------------------------
1 | // ---------------------------------------------------------------------
2 | // Copyright (c) 2024 Qualcomm Innovation Center, Inc. All rights reserved.
3 | // SPDX-License-Identifier: BSD-3-Clause
4 | // ---------------------------------------------------------------------
5 | package com.quicinc.chatapp;
6 |
7 | /**
8 | * GenieWrapper: Class to connect JNI GenieWrapper and Java code
9 | */
10 | public class GenieWrapper {
11 | long genieWrapperNativeHandle;
12 |
13 | /**
14 | * GenieWrapper: Loads model at provided path with provided htp config
15 | *
16 | * @param modelDirPath directory path on system pointing to model bundle
17 | * @param htpConfigPath HTP config file to use
18 | */
19 | GenieWrapper(String modelDirPath, String htpConfigPath) {
20 | genieWrapperNativeHandle = loadModel(modelDirPath, htpConfigPath);
21 | }
22 |
23 | /**
24 | * getResponseForPrompt: Generates response for provided user input
25 | *
26 | * @param userInput user input to generate response for
27 | * @param callback callback to tunnel each generated token to
28 | */
29 | public void getResponseForPrompt(String userInput, StringCallback callback) {
30 | getResponseForPrompt(genieWrapperNativeHandle, userInput, callback);
31 | }
32 |
33 | /**
34 | * finalize: Free previously loaded model
35 | */
36 | @Override
37 | protected void finalize() {
38 | freeModel(genieWrapperNativeHandle);
39 | }
40 |
41 | /**
42 | * loadModel: JNI method to load model using Genie C++ APIs
43 | *
44 | * @param modelDirPath directory path on system pointing to model bundle
45 | * @param htpConfigPath HTP config file to use
46 | * @return pointer to Genie C++ Wrapper to generate future responses
47 | */
48 | private native long loadModel(String modelDirPath, String htpConfigPath);
49 |
50 | /**
51 | * getResponseForPrompt: JNI method to generate response for provided user input
52 | *
53 | * @param nativeHandle native handle captured before with LoadModel
54 | * @param userInput user input to generate response for
55 | * @param callback callback to tunnel each generated token to
56 | */
57 | private native void getResponseForPrompt(long nativeHandle, String userInput, StringCallback callback);
58 |
59 | /**
60 | * FreeModel: JNI method to free previously loaded model
61 | *
62 | * @param nativeHandle native handle captured before with LoadModel
63 | */
64 | private native void freeModel(long nativeHandle);
65 | }
66 |
--------------------------------------------------------------------------------
/apps/android/ChatApp/src/main/java/com/quicinc/chatapp/MessageSender.java:
--------------------------------------------------------------------------------
1 | // ---------------------------------------------------------------------
2 | // Copyright (c) 2024 Qualcomm Innovation Center, Inc. All rights reserved.
3 | // SPDX-License-Identifier: BSD-3-Clause
4 | // ---------------------------------------------------------------------
5 | package com.quicinc.chatapp;
6 |
7 | /**
8 | * MessageSender: Enum to represent if message is from BOT or user
9 | */
10 | enum MessageSender {
11 | BOT,
12 | USER,
13 | };
14 |
--------------------------------------------------------------------------------
/apps/android/ChatApp/src/main/java/com/quicinc/chatapp/StringCallback.java:
--------------------------------------------------------------------------------
1 | // ---------------------------------------------------------------------
2 | // Copyright (c) 2024 Qualcomm Innovation Center, Inc. All rights reserved.
3 | // SPDX-License-Identifier: BSD-3-Clause
4 | // ---------------------------------------------------------------------
5 | package com.quicinc.chatapp;
6 |
7 | /**
8 | * StringCallBack - Callback to tunnel JNI output into Java
9 | */
10 | public interface StringCallback {
11 | void onNewString(String str);
12 | }
13 |
--------------------------------------------------------------------------------
/apps/android/ChatApp/src/main/res/drawable/bot_response.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/apps/android/ChatApp/src/main/res/drawable/ic_launcher_foreground.xml:
--------------------------------------------------------------------------------
1 |
7 |
8 |
9 |
15 |
18 |
21 |
22 |
23 |
24 |
30 |
31 |
--------------------------------------------------------------------------------
/apps/android/ChatApp/src/main/res/drawable/text_rounded_corner.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/apps/android/ChatApp/src/main/res/drawable/user_input.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/apps/android/ChatApp/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
7 |
8 |
20 |
21 |
29 |
30 |
31 |
32 |
--------------------------------------------------------------------------------
/apps/android/ChatApp/src/main/res/layout/chat.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
8 |
9 |
15 |
16 |
23 |
24 |
25 |
31 |
32 |
47 |
48 |
58 |
59 |
60 |
61 |
--------------------------------------------------------------------------------
/apps/android/ChatApp/src/main/res/layout/chat_row.xml:
--------------------------------------------------------------------------------
1 |
2 |
9 |
10 |
21 |
22 |
32 |
33 |
34 |
43 |
44 |
54 |
55 |
56 |
57 |
--------------------------------------------------------------------------------
/apps/android/ChatApp/src/main/res/mipmap-anydpi-v26/ic_launcher.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/apps/android/ChatApp/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/apps/android/ChatApp/src/main/res/mipmap-hdpi/ic_launcher.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/quic/ai-hub-apps/f9b38777e2071bf9c46197015b63c976fe5ab4c2/apps/android/ChatApp/src/main/res/mipmap-hdpi/ic_launcher.webp
--------------------------------------------------------------------------------
/apps/android/ChatApp/src/main/res/mipmap-hdpi/ic_launcher_foreground.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/quic/ai-hub-apps/f9b38777e2071bf9c46197015b63c976fe5ab4c2/apps/android/ChatApp/src/main/res/mipmap-hdpi/ic_launcher_foreground.webp
--------------------------------------------------------------------------------
/apps/android/ChatApp/src/main/res/mipmap-hdpi/ic_launcher_round.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/quic/ai-hub-apps/f9b38777e2071bf9c46197015b63c976fe5ab4c2/apps/android/ChatApp/src/main/res/mipmap-hdpi/ic_launcher_round.webp
--------------------------------------------------------------------------------
/apps/android/ChatApp/src/main/res/mipmap-mdpi/ic_launcher.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/quic/ai-hub-apps/f9b38777e2071bf9c46197015b63c976fe5ab4c2/apps/android/ChatApp/src/main/res/mipmap-mdpi/ic_launcher.webp
--------------------------------------------------------------------------------
/apps/android/ChatApp/src/main/res/mipmap-mdpi/ic_launcher_foreground.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/quic/ai-hub-apps/f9b38777e2071bf9c46197015b63c976fe5ab4c2/apps/android/ChatApp/src/main/res/mipmap-mdpi/ic_launcher_foreground.webp
--------------------------------------------------------------------------------
/apps/android/ChatApp/src/main/res/mipmap-mdpi/ic_launcher_round.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/quic/ai-hub-apps/f9b38777e2071bf9c46197015b63c976fe5ab4c2/apps/android/ChatApp/src/main/res/mipmap-mdpi/ic_launcher_round.webp
--------------------------------------------------------------------------------
/apps/android/ChatApp/src/main/res/mipmap-xhdpi/ic_launcher.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/quic/ai-hub-apps/f9b38777e2071bf9c46197015b63c976fe5ab4c2/apps/android/ChatApp/src/main/res/mipmap-xhdpi/ic_launcher.webp
--------------------------------------------------------------------------------
/apps/android/ChatApp/src/main/res/mipmap-xhdpi/ic_launcher_foreground.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/quic/ai-hub-apps/f9b38777e2071bf9c46197015b63c976fe5ab4c2/apps/android/ChatApp/src/main/res/mipmap-xhdpi/ic_launcher_foreground.webp
--------------------------------------------------------------------------------
/apps/android/ChatApp/src/main/res/mipmap-xhdpi/ic_launcher_round.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/quic/ai-hub-apps/f9b38777e2071bf9c46197015b63c976fe5ab4c2/apps/android/ChatApp/src/main/res/mipmap-xhdpi/ic_launcher_round.webp
--------------------------------------------------------------------------------
/apps/android/ChatApp/src/main/res/mipmap-xxhdpi/ic_launcher.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/quic/ai-hub-apps/f9b38777e2071bf9c46197015b63c976fe5ab4c2/apps/android/ChatApp/src/main/res/mipmap-xxhdpi/ic_launcher.webp
--------------------------------------------------------------------------------
/apps/android/ChatApp/src/main/res/mipmap-xxhdpi/ic_launcher_foreground.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/quic/ai-hub-apps/f9b38777e2071bf9c46197015b63c976fe5ab4c2/apps/android/ChatApp/src/main/res/mipmap-xxhdpi/ic_launcher_foreground.webp
--------------------------------------------------------------------------------
/apps/android/ChatApp/src/main/res/mipmap-xxhdpi/ic_launcher_round.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/quic/ai-hub-apps/f9b38777e2071bf9c46197015b63c976fe5ab4c2/apps/android/ChatApp/src/main/res/mipmap-xxhdpi/ic_launcher_round.webp
--------------------------------------------------------------------------------
/apps/android/ChatApp/src/main/res/mipmap-xxxhdpi/ic_launcher.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/quic/ai-hub-apps/f9b38777e2071bf9c46197015b63c976fe5ab4c2/apps/android/ChatApp/src/main/res/mipmap-xxxhdpi/ic_launcher.webp
--------------------------------------------------------------------------------
/apps/android/ChatApp/src/main/res/mipmap-xxxhdpi/ic_launcher_foreground.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/quic/ai-hub-apps/f9b38777e2071bf9c46197015b63c976fe5ab4c2/apps/android/ChatApp/src/main/res/mipmap-xxxhdpi/ic_launcher_foreground.webp
--------------------------------------------------------------------------------
/apps/android/ChatApp/src/main/res/mipmap-xxxhdpi/ic_launcher_round.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/quic/ai-hub-apps/f9b38777e2071bf9c46197015b63c976fe5ab4c2/apps/android/ChatApp/src/main/res/mipmap-xxxhdpi/ic_launcher_round.webp
--------------------------------------------------------------------------------
/apps/android/ChatApp/src/main/res/values-night/themes.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
16 |
17 |
--------------------------------------------------------------------------------
/apps/android/ChatApp/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #FFBB86FC
4 | #FF6200EE
5 | #FF3700B3
6 | #FF03DAC5
7 | #FF018786
8 | #FF000000
9 | #FFFFFFFF
10 | #9A9C27B0
11 | #2196F3
12 | #00FFFFFF
13 |
14 |
--------------------------------------------------------------------------------
/apps/android/ChatApp/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | ChatApp
3 | Chat with Llama 3.2 3B
4 | What\'s on your mind?
5 | Sends user message
6 |
7 |
--------------------------------------------------------------------------------
/apps/android/ChatApp/src/main/res/values/themes.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
16 |
17 |
--------------------------------------------------------------------------------
/apps/android/ChatApp/src/main/res/xml/backup_rules.xml:
--------------------------------------------------------------------------------
1 |
8 |
9 |
13 |
14 |
--------------------------------------------------------------------------------
/apps/android/ChatApp/src/main/res/xml/data_extraction_rules.xml:
--------------------------------------------------------------------------------
1 |
6 |
7 |
8 |
12 |
13 |
19 |
20 |
--------------------------------------------------------------------------------
/apps/android/ImageClassification/build.gradle:
--------------------------------------------------------------------------------
1 | plugins {
2 | id 'com.android.application'
3 | }
4 |
5 | android {
6 | compileSdk Integer.valueOf(androidCompileSDK)
7 |
8 | defaultConfig {
9 | applicationId "com.quicinc.imageclassification"
10 | minSdk Integer.valueOf(androidMinSDK)
11 | targetSdk Integer.valueOf(androidTargetSDK)
12 | versionCode 1
13 | versionName "1.0"
14 | testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
15 | resValue( "string", "tfLiteModelAsset", project.properties['classification_tfLiteModelAsset'])
16 | resValue( "string", "tfLiteLabelsAsset", project.properties["classification_tfLiteLabelsAsset"])
17 | }
18 |
19 | buildTypes {
20 | release {
21 | minifyEnabled false
22 | proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
23 | }
24 | }
25 |
26 | compileOptions {
27 | sourceCompatibility JavaVersion.valueOf("VERSION_$javaSourceCompatibilityVersion")
28 | targetCompatibility JavaVersion.valueOf("VERSION_$javaTargetCompatibilityVersion")
29 | }
30 |
31 | preBuild.doFirst {
32 | if (!file("./src/main/assets/" + project.properties["classification_tfLiteModelAsset"]).exists()) {
33 | throw new RuntimeException(missingModelErrorMsg)
34 | }
35 |
36 | for (int i = 1; i <= 3; ++i) {
37 | String filename = "./src/main/assets/images/Sample${i}.png"
38 | File fp = file(filename)
39 | // If the image is too small, it is likely an ascii file with LFS information
40 | if (!fp.exists() || fp.length() < 1000) {
41 | throw new RuntimeException(missingLfsErrorMsg)
42 | }
43 | }
44 | }
45 |
46 | namespace 'com.quicinc.imageclassification'
47 | }
48 |
49 | dependencies {
50 | implementation 'androidx.appcompat:appcompat:1.7.0'
51 | implementation 'com.google.android.material:material:1.12.0'
52 | implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
53 | api 'org.tensorflow:tensorflow-lite:2.16.1'
54 | api 'org.tensorflow:tensorflow-lite-support:0.4.4'
55 | implementation 'org.tensorflow:tensorflow-lite-gpu:2.16.1'
56 | implementation 'org.tensorflow:tensorflow-lite-gpu-api:2.16.1'
57 | implementation 'org.tensorflow:tensorflow-lite-gpu-delegate-plugin:0.4.4'
58 | implementation "com.qualcomm.qti:qnn-runtime:$qnnVersion"
59 | implementation "com.qualcomm.qti:qnn-litert-delegate:$qnnVersion"
60 | }
61 |
62 | if (System.getProperty("user.dir") != project.rootDir.path) {
63 | throw new RuntimeException("This project should be opened from the `android` directory (parent of ImageClassification directory), NOT the ImageClassification directory.")
64 | }
65 |
--------------------------------------------------------------------------------
/apps/android/ImageClassification/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
6 |
7 |
16 |
17 |
20 |
21 |
22 |
25 |
26 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
--------------------------------------------------------------------------------
/apps/android/ImageClassification/src/main/assets/README.txt:
--------------------------------------------------------------------------------
1 | Place TFLite asset here
2 |
--------------------------------------------------------------------------------
/apps/android/ImageClassification/src/main/assets/images/Sample1.png:
--------------------------------------------------------------------------------
1 | version https://git-lfs.github.com/spec/v1
2 | oid sha256:8649d7ebb60c7e52ef496739616111a1ecd9797e7ecec3e1881504449a648077
3 | size 3155242
4 |
--------------------------------------------------------------------------------
/apps/android/ImageClassification/src/main/assets/images/Sample2.png:
--------------------------------------------------------------------------------
1 | version https://git-lfs.github.com/spec/v1
2 | oid sha256:05c16f067b92a272e3c23fb109bae853fc2483c2f3f471d71a059b73fff87f7f
3 | size 2146918
4 |
--------------------------------------------------------------------------------
/apps/android/ImageClassification/src/main/assets/images/Sample3.png:
--------------------------------------------------------------------------------
1 | version https://git-lfs.github.com/spec/v1
2 | oid sha256:6c18dc2c8ef40fddddf2a68367ba2a434427518beae80f83777036d08e9c04e1
3 | size 1335289
4 |
--------------------------------------------------------------------------------
/apps/android/ImageClassification/src/main/java/com/quicinc/ImageProcessing.java:
--------------------------------------------------------------------------------
1 | // ---------------------------------------------------------------------
2 | // Copyright (c) 2024 Qualcomm Innovation Center, Inc. All rights reserved.
3 | // SPDX-License-Identifier: BSD-3-Clause
4 | // ---------------------------------------------------------------------
5 | package com.quicinc;
6 |
7 | import android.graphics.Bitmap;
8 | import android.graphics.Canvas;
9 | import android.graphics.RectF;
10 |
11 | public class ImageProcessing {
12 | /**
13 | * Resize a bitmap while respecting its aspect ratio.
14 | * If the output image cannot fit perfectly within the requested output height / width,
15 | * padding is added such that the output bitmap will be the requested size.
16 | *
17 | * @param image Image to resize
18 | * @param outputBitmapWidth Final width
19 | * @param outputBitmapHeight Final height
20 | * @param paddingValue Value to use for padding (usually 0 or 0xFF)
21 | * @return Resized & padded bitmap
22 | */
23 | public static Bitmap resizeAndPadMaintainAspectRatio(
24 | Bitmap image,
25 | int outputBitmapWidth,
26 | int outputBitmapHeight,
27 | int paddingValue) {
28 | int width = image.getWidth();
29 | int height = image.getHeight();
30 | float ratioBitmap = (float) width / (float) height;
31 | float ratioMax = (float) outputBitmapWidth / (float) outputBitmapHeight;
32 |
33 | int finalWidth = outputBitmapWidth;
34 | int finalHeight = outputBitmapHeight;
35 | if (ratioMax > ratioBitmap) {
36 | finalWidth = (int) ((float)outputBitmapHeight * ratioBitmap);
37 | } else {
38 | finalHeight = (int) ((float)outputBitmapWidth / ratioBitmap);
39 | }
40 |
41 | Bitmap outputImage = Bitmap.createBitmap(outputBitmapWidth, outputBitmapHeight, Bitmap.Config.ARGB_8888);
42 | Canvas can = new Canvas(outputImage);
43 | can.drawARGB(0xFF, paddingValue, paddingValue, paddingValue);
44 | int left = (outputBitmapWidth - finalWidth) / 2;
45 | int top = (outputBitmapHeight - finalHeight) / 2;
46 | can.drawBitmap(image, null, new RectF(left, top, finalWidth + left, finalHeight + top), null);
47 | return outputImage;
48 | }
49 | }
50 |
--------------------------------------------------------------------------------
/apps/android/ImageClassification/src/main/java/com/quicinc/tflite/AIHubDefaults.java:
--------------------------------------------------------------------------------
1 | // ---------------------------------------------------------------------
2 | // Copyright (c) 2024 Qualcomm Innovation Center, Inc. All rights reserved.
3 | // SPDX-License-Identifier: BSD-3-Clause
4 | // ---------------------------------------------------------------------
5 | package com.quicinc.tflite;
6 |
7 | import java.util.Arrays;
8 | import java.util.HashSet;
9 | import java.util.Set;
10 |
11 | public class AIHubDefaults {
12 | // Delegates enabled to replicate AI Hub's defaults on Qualcomm devices.
13 | public static final Set enabledDelegates = new HashSet<>(Arrays.asList(
14 | TFLiteHelpers.DelegateType.QNN_NPU,
15 | TFLiteHelpers.DelegateType.GPUv2
16 | ));
17 |
18 | // Number of threads AI Hub uses by default for layers running on CPU.
19 | // https://app.aihub.qualcomm.com/docs/hub/api.html#profile-inference-options
20 | public static final int numCPUThreads = Runtime.getRuntime().availableProcessors() / 2;
21 |
22 | // The default delegate registry order for AI Hub.
23 | // For more details, see the JavaDoc for TFLiteHelpers::CreateInterpreterAndDelegatesFromOptions.
24 | public static final TFLiteHelpers.DelegateType[][] delegatePriorityOrder = new TFLiteHelpers.DelegateType[][] {
25 | // 1. QNN_NPU + GPUv2 + XNNPack
26 | // https://app.aihub.qualcomm.com/docs/hub/api.html#profile-inference-options
27 | // Similar to AI Hub "compute_unit=all", or "compute_unit=npu,gpu,cpu" on QC devices that support QNN
28 | // AI Hub sets some GPUv2 settings that are not accessible via the Java API.
29 | { TFLiteHelpers.DelegateType.QNN_NPU, TFLiteHelpers.DelegateType.GPUv2 },
30 |
31 | // 2. GPUv2 + XNNPack
32 | // https://app.aihub.qualcomm.com/docs/hub/api.html#profile-inference-options
33 | // Similar to AI Hub "compute_unit=gpu" on all devices
34 | // AI Hub sets some GPU settings that are not accessible via the Java API.
35 | { TFLiteHelpers.DelegateType.GPUv2 },
36 |
37 | // 3. XNNPack (final, CPU-only fallback)
38 | // https://app.aihub.qualcomm.com/docs/hub/api.html#profile-inference-options
39 | // Same as AI Hub "compute_unit=cpu" on all devices
40 | { }
41 |
42 | // ------
43 | //
44 | // Additional delegates (eg. NNAPI, or something targeting non-Qualcomm hardware) could be added here or above,
45 | // if you desire to define a custom delegate selection order.
46 | //
47 | // ------
48 | };
49 |
50 | // Create a version of the above delegate priority order that can only use the provided delegates.
51 | public static TFLiteHelpers.DelegateType[][] delegatePriorityOrderForDelegates(Set enabledDelegates) {
52 | return Arrays.stream(delegatePriorityOrder).filter(x -> enabledDelegates.containsAll(Arrays.asList(x))).toArray(TFLiteHelpers.DelegateType[][]::new);
53 | }
54 | }
55 |
--------------------------------------------------------------------------------
/apps/android/ImageClassification/src/main/res/drawable-v24/ic_launcher_foreground.xml:
--------------------------------------------------------------------------------
1 |
7 |
8 |
9 |
15 |
18 |
21 |
22 |
23 |
24 |
30 |
31 |
--------------------------------------------------------------------------------
/apps/android/ImageClassification/src/main/res/drawable/image_classification_icon.png:
--------------------------------------------------------------------------------
1 | version https://git-lfs.github.com/spec/v1
2 | oid sha256:00ad10231fc468403e59bc2b9e5ae9a282cb0151662c1d83df21eba500e55360
3 | size 23370
4 |
--------------------------------------------------------------------------------
/apps/android/ImageClassification/src/main/res/mipmap-anydpi-v26/ic_launcher.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/apps/android/ImageClassification/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/apps/android/ImageClassification/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
1 | version https://git-lfs.github.com/spec/v1
2 | oid sha256:0564d62d3c5abd27527a2d5a85a4facc6e751f3bcdb5135a926cd0435009d567
3 | size 2128
4 |
--------------------------------------------------------------------------------
/apps/android/ImageClassification/src/main/res/mipmap-hdpi/ic_launcher_foreground.png:
--------------------------------------------------------------------------------
1 | version https://git-lfs.github.com/spec/v1
2 | oid sha256:ce0ccc39b4af252f149f0ec5b36bbe1509f02502c888cbe22844a279767e60c5
3 | size 2607
4 |
--------------------------------------------------------------------------------
/apps/android/ImageClassification/src/main/res/mipmap-hdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
1 | version https://git-lfs.github.com/spec/v1
2 | oid sha256:983646f1f774db4ac981d231777ea4edbe69febb6beaba4d2869dfae73cd35d5
3 | size 4163
4 |
--------------------------------------------------------------------------------
/apps/android/ImageClassification/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
1 | version https://git-lfs.github.com/spec/v1
2 | oid sha256:b2cba118f597bbe8112a9c53fc17e5985a90eeafb3a7f0bef946498729d6eb8b
3 | size 1344
4 |
--------------------------------------------------------------------------------
/apps/android/ImageClassification/src/main/res/mipmap-mdpi/ic_launcher_foreground.png:
--------------------------------------------------------------------------------
1 | version https://git-lfs.github.com/spec/v1
2 | oid sha256:af3b915e0d0444d1835870cfbf4408cd9b1f88752920dc7781af746fe544b306
3 | size 1592
4 |
--------------------------------------------------------------------------------
/apps/android/ImageClassification/src/main/res/mipmap-mdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
1 | version https://git-lfs.github.com/spec/v1
2 | oid sha256:208a0f637b0967808bdabd6fe972470d5eff82cca7832132f60641a90eebb599
3 | size 2564
4 |
--------------------------------------------------------------------------------
/apps/android/ImageClassification/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
1 | version https://git-lfs.github.com/spec/v1
2 | oid sha256:d22b02a9acc35f29c4d3e7bfd1369da33d44d67a16905d93d7af626a6567815d
3 | size 2504
4 |
--------------------------------------------------------------------------------
/apps/android/ImageClassification/src/main/res/mipmap-xhdpi/ic_launcher_foreground.png:
--------------------------------------------------------------------------------
1 | version https://git-lfs.github.com/spec/v1
2 | oid sha256:41a1a524252519fe0714106cd303d63297314a56757266e3822427ea891cfcbc
3 | size 3669
4 |
--------------------------------------------------------------------------------
/apps/android/ImageClassification/src/main/res/mipmap-xhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
1 | version https://git-lfs.github.com/spec/v1
2 | oid sha256:09fa5fdd32b6823369c0928d91c6c0e3b1076b950601654057981fc4f37cb54f
3 | size 5455
4 |
--------------------------------------------------------------------------------
/apps/android/ImageClassification/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
1 | version https://git-lfs.github.com/spec/v1
2 | oid sha256:fd0cb42a14f723984871c0bc6b0ab0b93153c06cfd467c7d520d829c2dc3d896
3 | size 4126
4 |
--------------------------------------------------------------------------------
/apps/android/ImageClassification/src/main/res/mipmap-xxhdpi/ic_launcher_foreground.png:
--------------------------------------------------------------------------------
1 | version https://git-lfs.github.com/spec/v1
2 | oid sha256:2cbae7c08f5d74a432188cedfa7e36b93a6186b3e8f7a8a8a1cf9ae5403284d5
3 | size 6370
4 |
--------------------------------------------------------------------------------
/apps/android/ImageClassification/src/main/res/mipmap-xxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
1 | version https://git-lfs.github.com/spec/v1
2 | oid sha256:6c8edc9f169a769df299a320576a46f6eca9f97da5b500545e0f321f0f15bb4f
3 | size 8913
4 |
--------------------------------------------------------------------------------
/apps/android/ImageClassification/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
1 | version https://git-lfs.github.com/spec/v1
2 | oid sha256:1258d9607d9b269f2ccb043ab207d519ce56fea28335c86037a9e2a659fbf9c1
3 | size 6637
4 |
--------------------------------------------------------------------------------
/apps/android/ImageClassification/src/main/res/mipmap-xxxhdpi/ic_launcher_foreground.png:
--------------------------------------------------------------------------------
1 | version https://git-lfs.github.com/spec/v1
2 | oid sha256:cc19eb9e75c34aa2ef115b5d7a097e0ca7f0e6d06f45bfd05ea6a32edeac28ae
3 | size 9273
4 |
--------------------------------------------------------------------------------
/apps/android/ImageClassification/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
1 | version https://git-lfs.github.com/spec/v1
2 | oid sha256:22565fa107eaf8dfa59401c1819e0ea53cf0c13866785a9e16a6e8bc9243f833
3 | size 14011
4 |
--------------------------------------------------------------------------------
/apps/android/ImageClassification/src/main/res/values-night/themes.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
17 |
18 |
--------------------------------------------------------------------------------
/apps/android/ImageClassification/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | #6D1683
5 | #FFBB86FC
6 | #FF6200EE
7 | #FF3700B3
8 | #FF03DAC5
9 | #FF018786
10 | #FF000000
11 | #FFFFFFFF
12 |
13 |
--------------------------------------------------------------------------------
/apps/android/ImageClassification/src/main/res/values/ic_launcher_background.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #FFFFFF
4 |
5 |
--------------------------------------------------------------------------------
/apps/android/ImageClassification/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | Image_Classification
3 |
4 |
--------------------------------------------------------------------------------
/apps/android/ImageClassification/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
8 |
9 |
14 |
15 |
--------------------------------------------------------------------------------
/apps/android/ImageClassification/src/main/res/values/themes.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
18 |
19 |
--------------------------------------------------------------------------------
/apps/android/SemanticSegmentation/.gitattributes:
--------------------------------------------------------------------------------
1 | opencv45/native/3rdparty/libs/**/*.a filter=lfs diff=lfs merge=lfs -text
2 | opencv45/** filter=lfs diff=lfs merge=lfs -text
3 | snpe-release/** filter=lfs diff=lfs merge=lfs -text
4 | app/src/main/assets/* filter=lfs diff=lfs merge=lfs -text
5 | sdk/** filter=lfs diff=lfs merge=lfs -text
6 | app/src/main/jniLibs/** filter=lfs diff=lfs merge=lfs -text
7 | AIMET_4W8A_hrnet_posnet.onnx filter=lfs diff=lfs merge=lfs -text
8 |
--------------------------------------------------------------------------------
/apps/android/SemanticSegmentation/build.gradle:
--------------------------------------------------------------------------------
1 | plugins {
2 | id 'com.android.application'
3 | }
4 |
5 | android {
6 | compileSdk Integer.valueOf(androidCompileSDK)
7 |
8 | defaultConfig {
9 | applicationId "com.quicinc.semanticsegmentation"
10 | minSdk Integer.valueOf(androidMinSDK)
11 | targetSdk Integer.valueOf(androidTargetSDK)
12 | versionCode 1
13 | versionName "1.0"
14 | testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
15 | resValue( "string", "tfLiteModelAsset", project.properties['semanticsegmentation_tfLiteModelAsset'])
16 | }
17 |
18 | buildTypes {
19 | release {
20 | minifyEnabled false
21 | proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
22 | }
23 | }
24 |
25 | compileOptions {
26 | sourceCompatibility JavaVersion.valueOf("VERSION_$javaSourceCompatibilityVersion")
27 | targetCompatibility JavaVersion.valueOf("VERSION_$javaTargetCompatibilityVersion")
28 | }
29 |
30 | preBuild.doFirst {
31 | if (!file("./src/main/assets/" + project.properties["semanticsegmentation_tfLiteModelAsset"]).exists()) {
32 | throw new RuntimeException(missingModelErrorMsg)
33 | }
34 | }
35 |
36 | namespace 'com.quicinc.semanticsegmentation'
37 | }
38 |
39 | dependencies {
40 | implementation 'androidx.appcompat:appcompat:1.7.0'
41 | implementation 'com.google.android.material:material:1.12.0'
42 | implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
43 | api 'org.tensorflow:tensorflow-lite:2.16.1'
44 | implementation 'org.tensorflow:tensorflow-lite-gpu:2.16.1'
45 | implementation 'org.tensorflow:tensorflow-lite-gpu-api:2.16.1'
46 | implementation 'org.tensorflow:tensorflow-lite-gpu-delegate-plugin:0.4.4'
47 | implementation 'org.opencv:opencv:4.10.0'
48 | implementation "com.qualcomm.qti:qnn-runtime:$qnnVersion"
49 | implementation "com.qualcomm.qti:qnn-litert-delegate:$qnnVersion"
50 | }
51 |
52 | if (System.getProperty("user.dir") != project.rootDir.path) {
53 | throw new RuntimeException("This project should be opened from the `android` directory (parent of SemanticSegmentation directory), NOT the SemanticSegmentation directory.")
54 | }
55 |
--------------------------------------------------------------------------------
/apps/android/SemanticSegmentation/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
6 |
7 |
17 |
18 |
21 |
22 |
23 |
26 |
27 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
--------------------------------------------------------------------------------
/apps/android/SemanticSegmentation/src/main/assets/README.txt:
--------------------------------------------------------------------------------
1 | Place TFLite asset here
2 |
--------------------------------------------------------------------------------
/apps/android/SemanticSegmentation/src/main/ic_launcher-playstore.png:
--------------------------------------------------------------------------------
1 | version https://git-lfs.github.com/spec/v1
2 | oid sha256:f054af127a947db8306964f9edf3640408d4b2c1b06b04d3ec105382987d4212
3 | size 126146
4 |
--------------------------------------------------------------------------------
/apps/android/SemanticSegmentation/src/main/java/com/quicinc/tflite/AIHubDefaults.java:
--------------------------------------------------------------------------------
1 | // ---------------------------------------------------------------------
2 | // Copyright (c) 2024 Qualcomm Innovation Center, Inc. All rights reserved.
3 | // SPDX-License-Identifier: BSD-3-Clause
4 | // ---------------------------------------------------------------------
5 | package com.quicinc.tflite;
6 |
7 | import java.util.Arrays;
8 | import java.util.HashSet;
9 | import java.util.Set;
10 |
11 | public class AIHubDefaults {
12 | // Delegates enabled to replicate AI Hub's defaults on Qualcomm devices.
13 | public static final Set enabledDelegates = new HashSet<>(Arrays.asList(
14 | TFLiteHelpers.DelegateType.QNN_NPU,
15 | TFLiteHelpers.DelegateType.GPUv2
16 | ));
17 |
18 | // Number of threads AI Hub uses by default for layers running on CPU.
19 | // https://app.aihub.qualcomm.com/docs/hub/api.html#profile-inference-options
20 | public static final int numCPUThreads = Runtime.getRuntime().availableProcessors() / 2;
21 |
22 | // The default delegate registry order for AI Hub.
23 | // For more details, see the JavaDoc for TFLiteHelpers::CreateInterpreterAndDelegatesFromOptions.
24 | public static final TFLiteHelpers.DelegateType[][] delegatePriorityOrder = new TFLiteHelpers.DelegateType[][] {
25 | // 1. QNN_NPU + GPUv2 + XNNPack
26 | // https://app.aihub.qualcomm.com/docs/hub/api.html#profile-inference-options
27 | // Similar to AI Hub "compute_unit=all", or "compute_unit=npu,gpu,cpu" on QC devices that support QNN
28 | // AI Hub sets some GPUv2 settings that are not accessible via the Java API.
29 | { TFLiteHelpers.DelegateType.QNN_NPU, TFLiteHelpers.DelegateType.GPUv2 },
30 |
31 | // 2. GPUv2 + XNNPack
32 | // https://app.aihub.qualcomm.com/docs/hub/api.html#profile-inference-options
33 | // Similar to AI Hub "compute_unit=gpu" on all devices
34 | // AI Hub sets some GPU settings that are not accessible via the Java API.
35 | { TFLiteHelpers.DelegateType.GPUv2 },
36 |
37 | // 3. XNNPack (final, CPU-only fallback)
38 | // https://app.aihub.qualcomm.com/docs/hub/api.html#profile-inference-options
39 | // Same as AI Hub "compute_unit=cpu" on all devices
40 | { }
41 |
42 | // ------
43 | //
44 | // Additional delegates (eg. NNAPI, or something targeting non-Qualcomm hardware) could be added here or above,
45 | // if you desire to define a custom delegate selection order.
46 | //
47 | // ------
48 | };
49 |
50 | // Create a version of the above delegate priority order that can only use the provided delegates.
51 | public static TFLiteHelpers.DelegateType[][] delegatePriorityOrderForDelegates(Set enabledDelegates) {
52 | return Arrays.stream(delegatePriorityOrder).filter(x -> enabledDelegates.containsAll(Arrays.asList(x))).toArray(TFLiteHelpers.DelegateType[][]::new);
53 | }
54 | }
55 |
--------------------------------------------------------------------------------
/apps/android/SemanticSegmentation/src/main/res/layout/fragment_camera.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
15 |
16 |
21 |
22 |
28 |
29 |
--------------------------------------------------------------------------------
/apps/android/SemanticSegmentation/src/main/res/layout/main_activity.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
13 |
14 |
15 |
21 |
22 |
23 |
24 |
--------------------------------------------------------------------------------
/apps/android/SemanticSegmentation/src/main/res/mipmap-anydpi-v26/ic_launcher.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/apps/android/SemanticSegmentation/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/apps/android/SemanticSegmentation/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
1 | version https://git-lfs.github.com/spec/v1
2 | oid sha256:138a83d4c1ae32fb6880a1cac29c5d723614d9fc01fe1850069688a00584bbbf
3 | size 5047
4 |
--------------------------------------------------------------------------------
/apps/android/SemanticSegmentation/src/main/res/mipmap-hdpi/ic_launcher_background.png:
--------------------------------------------------------------------------------
1 | version https://git-lfs.github.com/spec/v1
2 | oid sha256:da09092788a576728686dde242487b1086a4ddc7a8f93f6ab07df128914d5457
3 | size 557
4 |
--------------------------------------------------------------------------------
/apps/android/SemanticSegmentation/src/main/res/mipmap-hdpi/ic_launcher_foreground.png:
--------------------------------------------------------------------------------
1 | version https://git-lfs.github.com/spec/v1
2 | oid sha256:751ee1836e9253ddd574d7a32314514cf211b8ca09c2148bcf53664778bddbe3
3 | size 15195
4 |
--------------------------------------------------------------------------------
/apps/android/SemanticSegmentation/src/main/res/mipmap-hdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
1 | version https://git-lfs.github.com/spec/v1
2 | oid sha256:c3ca92a9976e5206b4841934b4bcdcd6e886793e1960de48e251409910f99296
3 | size 6757
4 |
--------------------------------------------------------------------------------
/apps/android/SemanticSegmentation/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
1 | version https://git-lfs.github.com/spec/v1
2 | oid sha256:062bcc9366029f9e3e7cb9402165dee7e77a2f8edb5d1cefdd49694bfa8914da
3 | size 3034
4 |
--------------------------------------------------------------------------------
/apps/android/SemanticSegmentation/src/main/res/mipmap-mdpi/ic_launcher_background.png:
--------------------------------------------------------------------------------
1 | version https://git-lfs.github.com/spec/v1
2 | oid sha256:f093f5df0b1d0ac7b8f21b3ffd0a18536ec98c57ef71dce6d3609ffe37d2ac31
3 | size 388
4 |
--------------------------------------------------------------------------------
/apps/android/SemanticSegmentation/src/main/res/mipmap-mdpi/ic_launcher_foreground.png:
--------------------------------------------------------------------------------
1 | version https://git-lfs.github.com/spec/v1
2 | oid sha256:88b1fb542ed152cc7160fd362394189470f181096f5d6a86dfb5b2ec687fd17f
3 | size 8253
4 |
--------------------------------------------------------------------------------
/apps/android/SemanticSegmentation/src/main/res/mipmap-mdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
1 | version https://git-lfs.github.com/spec/v1
2 | oid sha256:5b2dda4e546f631cee1af56434175cc522b7f3a2beb4a2386cff1f1fb1e12e02
3 | size 3910
4 |
--------------------------------------------------------------------------------
/apps/android/SemanticSegmentation/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
1 | version https://git-lfs.github.com/spec/v1
2 | oid sha256:b4f5689580246a9082570547fdef9f5477049f27816f0209825130ef6a5d0043
3 | size 7640
4 |
--------------------------------------------------------------------------------
/apps/android/SemanticSegmentation/src/main/res/mipmap-xhdpi/ic_launcher_background.png:
--------------------------------------------------------------------------------
1 | version https://git-lfs.github.com/spec/v1
2 | oid sha256:38914ee4a2ded87282c0e0b7808264080bde21989989ac4a83c2b3e5938596cb
3 | size 751
4 |
--------------------------------------------------------------------------------
/apps/android/SemanticSegmentation/src/main/res/mipmap-xhdpi/ic_launcher_foreground.png:
--------------------------------------------------------------------------------
1 | version https://git-lfs.github.com/spec/v1
2 | oid sha256:1a106cf1f68fc4067ce7a448b3f32232c360ce8a2912908aaf5b6f8cfef0c142
3 | size 23903
4 |
--------------------------------------------------------------------------------
/apps/android/SemanticSegmentation/src/main/res/mipmap-xhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
1 | version https://git-lfs.github.com/spec/v1
2 | oid sha256:3253ee017d2141ba20e7ff9e2d22d9c69a6c101e5d18b780fd4d066b68f8c578
3 | size 10255
4 |
--------------------------------------------------------------------------------
/apps/android/SemanticSegmentation/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
1 | version https://git-lfs.github.com/spec/v1
2 | oid sha256:c20958f85c1f878b8f758ab5d7d7f88d1e6af5a396ae54cda017976251d46ea2
3 | size 13336
4 |
--------------------------------------------------------------------------------
/apps/android/SemanticSegmentation/src/main/res/mipmap-xxhdpi/ic_launcher_background.png:
--------------------------------------------------------------------------------
1 | version https://git-lfs.github.com/spec/v1
2 | oid sha256:2889dcc42c7b52bf0abad8ad24df8a0615f8f7697228d97a890eb54636e6a297
3 | size 1157
4 |
--------------------------------------------------------------------------------
/apps/android/SemanticSegmentation/src/main/res/mipmap-xxhdpi/ic_launcher_foreground.png:
--------------------------------------------------------------------------------
1 | version https://git-lfs.github.com/spec/v1
2 | oid sha256:6c8305ec598bc98b414e46d39898fdd5bd0cd98b38ccab1c0a2fa7ebe51b6126
3 | size 44519
4 |
--------------------------------------------------------------------------------
/apps/android/SemanticSegmentation/src/main/res/mipmap-xxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
1 | version https://git-lfs.github.com/spec/v1
2 | oid sha256:f099367578d0409d6d732ba223e4293ce77fd015533c150e1324f7fd2379a86c
3 | size 17896
4 |
--------------------------------------------------------------------------------
/apps/android/SemanticSegmentation/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
1 | version https://git-lfs.github.com/spec/v1
2 | oid sha256:1d0cbc9dab1d457f00ad25422841d961f1676dda322aca0fef7735264f2f0336
3 | size 20115
4 |
--------------------------------------------------------------------------------
/apps/android/SemanticSegmentation/src/main/res/mipmap-xxxhdpi/ic_launcher_background.png:
--------------------------------------------------------------------------------
1 | version https://git-lfs.github.com/spec/v1
2 | oid sha256:018bac7b7b2ad618e7d192a73861e87a6c12ed6aef3d6ee92ca2cfc36e46b70b
3 | size 1748
4 |
--------------------------------------------------------------------------------
/apps/android/SemanticSegmentation/src/main/res/mipmap-xxxhdpi/ic_launcher_foreground.png:
--------------------------------------------------------------------------------
1 | version https://git-lfs.github.com/spec/v1
2 | oid sha256:de12dd490531c88be426fa64a19e6f0482a80e2217c512194a99ab1716b8a879
3 | size 71363
4 |
--------------------------------------------------------------------------------
/apps/android/SemanticSegmentation/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
1 | version https://git-lfs.github.com/spec/v1
2 | oid sha256:ee4b8b7338015f4a59d54031bdfa54d5fe9f51d4228cee44b08b463fef2334bd
3 | size 26974
4 |
--------------------------------------------------------------------------------
/apps/android/SemanticSegmentation/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #4CAF50
4 | #246E27
5 | #D81B60
6 |
7 |
--------------------------------------------------------------------------------
/apps/android/SemanticSegmentation/src/main/res/values/dimen.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
--------------------------------------------------------------------------------
/apps/android/SemanticSegmentation/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | Image Segmentation
3 | This app needs camera permission
4 | This device doesn\'t support Camera2 API.
5 |
6 |
--------------------------------------------------------------------------------
/apps/android/SemanticSegmentation/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/apps/android/SuperResolution/build.gradle:
--------------------------------------------------------------------------------
1 | plugins {
2 | id 'com.android.application'
3 | }
4 |
5 | android {
6 | compileSdk Integer.valueOf(androidCompileSDK)
7 |
8 | defaultConfig {
9 | applicationId "com.quicinc.superresolution"
10 | minSdk Integer.valueOf(androidMinSDK)
11 | targetSdk Integer.valueOf(androidTargetSDK)
12 | versionCode 1
13 | versionName "1.0"
14 | testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
15 | resValue( "string", "tfLiteModelAsset", project.properties['superresolution_tfLiteModelAsset'])
16 | }
17 |
18 | buildTypes {
19 | release {
20 | minifyEnabled false
21 | proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
22 | }
23 | }
24 |
25 | compileOptions {
26 | sourceCompatibility JavaVersion.valueOf("VERSION_$javaSourceCompatibilityVersion")
27 | targetCompatibility JavaVersion.valueOf("VERSION_$javaTargetCompatibilityVersion")
28 | }
29 |
30 | preBuild.doFirst {
31 | if (!file("./src/main/assets/" + project.properties['superresolution_tfLiteModelAsset']).exists()) {
32 | throw new RuntimeException(missingModelErrorMsg)
33 | }
34 |
35 | for (int i = 1; i <= 2; ++i) {
36 | String filename = "./src/main/assets/images/Sample${i}.jpg"
37 | File fp = file(filename)
38 | // If the image is too small, it is likely an ascii file with LFS information
39 | if (!fp.exists() || fp.length() < 1000) {
40 | throw new RuntimeException(missingLfsErrorMsg)
41 | }
42 | }
43 | }
44 |
45 | namespace 'com.quicinc.superresolution'
46 | }
47 |
48 | dependencies {
49 | implementation 'androidx.appcompat:appcompat:1.7.0'
50 | implementation 'com.google.android.material:material:1.12.0'
51 | implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
52 | api 'org.tensorflow:tensorflow-lite:2.16.1'
53 | api 'org.tensorflow:tensorflow-lite-support:0.4.4'
54 | implementation 'org.tensorflow:tensorflow-lite-gpu:2.16.1'
55 | implementation 'org.tensorflow:tensorflow-lite-gpu-api:2.16.1'
56 | implementation 'org.tensorflow:tensorflow-lite-gpu-delegate-plugin:0.4.4'
57 | implementation "com.qualcomm.qti:qnn-runtime:$qnnVersion"
58 | implementation "com.qualcomm.qti:qnn-litert-delegate:$qnnVersion"
59 | }
60 |
61 | if (System.getProperty("user.dir") != project.rootDir.path) {
62 | throw new RuntimeException("This project should be opened from the `android` directory (parent of SuperResolution directory), NOT the SuperResolution directory.")
63 | }
64 |
--------------------------------------------------------------------------------
/apps/android/SuperResolution/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
6 |
7 |
16 |
17 |
20 |
21 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
--------------------------------------------------------------------------------
/apps/android/SuperResolution/src/main/assets/README.txt:
--------------------------------------------------------------------------------
1 | Place TFLite asset here
2 |
--------------------------------------------------------------------------------
/apps/android/SuperResolution/src/main/assets/images/Sample1.jpg:
--------------------------------------------------------------------------------
1 | version https://git-lfs.github.com/spec/v1
2 | oid sha256:811f0c08ff16ef506de4855ca2b609ba6c67622f5d65550896cdd7e60c200db2
3 | size 17244
4 |
--------------------------------------------------------------------------------
/apps/android/SuperResolution/src/main/assets/images/Sample2.jpg:
--------------------------------------------------------------------------------
1 | version https://git-lfs.github.com/spec/v1
2 | oid sha256:1916e20918eb069c147377b581647c0d86277fdf01ba8e2ed07cf995e2a86cee
3 | size 13864
4 |
--------------------------------------------------------------------------------
/apps/android/SuperResolution/src/main/java/com/quicinc/ImageProcessing.java:
--------------------------------------------------------------------------------
1 | // ---------------------------------------------------------------------
2 | // Copyright (c) 2024 Qualcomm Innovation Center, Inc. All rights reserved.
3 | // SPDX-License-Identifier: BSD-3-Clause
4 | // ---------------------------------------------------------------------
5 | package com.quicinc;
6 |
7 | import android.graphics.Bitmap;
8 | import android.graphics.Canvas;
9 | import android.graphics.RectF;
10 |
11 | public class ImageProcessing {
12 | /**
13 | * Resize a bitmap while respecting its aspect ratio.
14 | * If the output image cannot fit perfectly within the requested output height / width,
15 | * padding is added such that the output bitmap will be the requested size.
16 | *
17 | * @param image Image to resize
18 | * @param outputBitmapWidth Final width
19 | * @param outputBitmapHeight Final height
20 | * @param paddingValue Value to use for padding (usually 0 or 0xFF)
21 | * @return Resized & padded bitmap
22 | */
23 | public static Bitmap resizeAndPadMaintainAspectRatio(
24 | Bitmap image,
25 | int outputBitmapWidth,
26 | int outputBitmapHeight,
27 | int paddingValue) {
28 | int width = image.getWidth();
29 | int height = image.getHeight();
30 | float ratioBitmap = (float) width / (float) height;
31 | float ratioMax = (float) outputBitmapWidth / (float) outputBitmapHeight;
32 |
33 | int finalWidth = outputBitmapWidth;
34 | int finalHeight = outputBitmapHeight;
35 | if (ratioMax > ratioBitmap) {
36 | finalWidth = (int) ((float)outputBitmapHeight * ratioBitmap);
37 | } else {
38 | finalHeight = (int) ((float)outputBitmapWidth / ratioBitmap);
39 | }
40 |
41 | Bitmap outputImage = Bitmap.createBitmap(outputBitmapWidth, outputBitmapHeight, Bitmap.Config.ARGB_8888);
42 | Canvas can = new Canvas(outputImage);
43 | can.drawARGB(0xFF, paddingValue, paddingValue, paddingValue);
44 | int left = (outputBitmapWidth - finalWidth) / 2;
45 | int top = (outputBitmapHeight - finalHeight) / 2;
46 | can.drawBitmap(image, null, new RectF(left, top, finalWidth + left, finalHeight + top), null);
47 | return outputImage;
48 | }
49 | }
50 |
--------------------------------------------------------------------------------
/apps/android/SuperResolution/src/main/java/com/quicinc/tflite/AIHubDefaults.java:
--------------------------------------------------------------------------------
1 | // ---------------------------------------------------------------------
2 | // Copyright (c) 2024 Qualcomm Innovation Center, Inc. All rights reserved.
3 | // SPDX-License-Identifier: BSD-3-Clause
4 | // ---------------------------------------------------------------------
5 | package com.quicinc.tflite;
6 |
7 | import java.util.Arrays;
8 | import java.util.HashSet;
9 | import java.util.Set;
10 |
11 | public class AIHubDefaults {
12 | // Delegates enabled to replicate AI Hub's defaults on Qualcomm devices.
13 | public static final Set enabledDelegates = new HashSet<>(Arrays.asList(
14 | TFLiteHelpers.DelegateType.QNN_NPU,
15 | TFLiteHelpers.DelegateType.GPUv2
16 | ));
17 |
18 | // Number of threads AI Hub uses by default for layers running on CPU.
19 | // https://app.aihub.qualcomm.com/docs/hub/api.html#profile-inference-options
20 | public static final int numCPUThreads = Runtime.getRuntime().availableProcessors() / 2;
21 |
22 | // The default delegate registry order for AI Hub.
23 | // For more details, see the JavaDoc for TFLiteHelpers::CreateInterpreterAndDelegatesFromOptions.
24 | public static final TFLiteHelpers.DelegateType[][] delegatePriorityOrder = new TFLiteHelpers.DelegateType[][] {
25 | // 1. QNN_NPU + GPUv2 + XNNPack
26 | // https://app.aihub.qualcomm.com/docs/hub/api.html#profile-inference-options
27 | // Similar to AI Hub "compute_unit=all", or "compute_unit=npu,gpu,cpu" on QC devices that support QNN
28 | // AI Hub sets some GPUv2 settings that are not accessible via the Java API.
29 | { TFLiteHelpers.DelegateType.QNN_NPU, TFLiteHelpers.DelegateType.GPUv2 },
30 |
31 | // 2. GPUv2 + XNNPack
32 | // https://app.aihub.qualcomm.com/docs/hub/api.html#profile-inference-options
33 | // Similar to AI Hub "compute_unit=gpu" on all devices
34 | // AI Hub sets some GPU settings that are not accessible via the Java API.
35 | { TFLiteHelpers.DelegateType.GPUv2 },
36 |
37 | // 3. XNNPack (final, CPU-only fallback)
38 | // https://app.aihub.qualcomm.com/docs/hub/api.html#profile-inference-options
39 | // Same as AI Hub "compute_unit=cpu" on all devices
40 | { }
41 |
42 | // ------
43 | //
44 | // Additional delegates (eg. NNAPI, or something targeting non-Qualcomm hardware) could be added here or above,
45 | // if you desire to define a custom delegate selection order.
46 | //
47 | // ------
48 | };
49 |
50 | // Create a version of the above delegate priority order that can only use the provided delegates.
51 | public static TFLiteHelpers.DelegateType[][] delegatePriorityOrderForDelegates(Set enabledDelegates) {
52 | return Arrays.stream(delegatePriorityOrder).filter(x -> enabledDelegates.containsAll(Arrays.asList(x))).toArray(TFLiteHelpers.DelegateType[][]::new);
53 | }
54 | }
55 |
--------------------------------------------------------------------------------
/apps/android/SuperResolution/src/main/res/drawable-v24/ic_launcher_foreground.xml:
--------------------------------------------------------------------------------
1 |
7 |
8 |
9 |
15 |
18 |
21 |
22 |
23 |
24 |
30 |
31 |
--------------------------------------------------------------------------------
/apps/android/SuperResolution/src/main/res/drawable/super_resolution_icon.png:
--------------------------------------------------------------------------------
1 | version https://git-lfs.github.com/spec/v1
2 | oid sha256:45bf7e8e50b4ab59d395f1131f30009b53e44fd718e894ddf64bc6000aef7d34
3 | size 71394
4 |
--------------------------------------------------------------------------------
/apps/android/SuperResolution/src/main/res/mipmap-anydpi-v26/ic_launcher.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/apps/android/SuperResolution/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/apps/android/SuperResolution/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
1 | version https://git-lfs.github.com/spec/v1
2 | oid sha256:5009e5bc33bcce60569fe8c8f08dc3bb72433dc7f934519112a6570b522e3b90
3 | size 3500
4 |
--------------------------------------------------------------------------------
/apps/android/SuperResolution/src/main/res/mipmap-hdpi/ic_launcher_foreground.png:
--------------------------------------------------------------------------------
1 | version https://git-lfs.github.com/spec/v1
2 | oid sha256:50ae510e51a4a659ab193d0f9838a136b5d522c62577ad109d772bbad6b450d8
3 | size 8038
4 |
--------------------------------------------------------------------------------
/apps/android/SuperResolution/src/main/res/mipmap-hdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
1 | version https://git-lfs.github.com/spec/v1
2 | oid sha256:8b792135a4ec3d9d1b56efa01050e935496128b3584d251cc400aa294b286eff
3 | size 6006
4 |
--------------------------------------------------------------------------------
/apps/android/SuperResolution/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
1 | version https://git-lfs.github.com/spec/v1
2 | oid sha256:9832a7686e60d184b56ed95a9f7b1bb4b8318a5e0712e811464df66c5ad7d872
3 | size 2100
4 |
--------------------------------------------------------------------------------
/apps/android/SuperResolution/src/main/res/mipmap-mdpi/ic_launcher_foreground.png:
--------------------------------------------------------------------------------
1 | version https://git-lfs.github.com/spec/v1
2 | oid sha256:2c89402b441b1b4f79304f2dd1721489ed0681bd16b205c8b67e78188683d686
3 | size 4075
4 |
--------------------------------------------------------------------------------
/apps/android/SuperResolution/src/main/res/mipmap-mdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
1 | version https://git-lfs.github.com/spec/v1
2 | oid sha256:f7a9bf4e9d4ac162e6cbc6c608a4dff51dd0d6c2326dfece66443f9b530b9105
3 | size 3458
4 |
--------------------------------------------------------------------------------
/apps/android/SuperResolution/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
1 | version https://git-lfs.github.com/spec/v1
2 | oid sha256:7f13934939e1b26092fcff9fe22c7e60a3ee772629c12df5db69ecae85457a46
3 | size 5248
4 |
--------------------------------------------------------------------------------
/apps/android/SuperResolution/src/main/res/mipmap-xhdpi/ic_launcher_foreground.png:
--------------------------------------------------------------------------------
1 | version https://git-lfs.github.com/spec/v1
2 | oid sha256:1ac25d6b6313f74e37fc25267af80e78661b340367ffe0574e1ac23eabc01098
3 | size 11832
4 |
--------------------------------------------------------------------------------
/apps/android/SuperResolution/src/main/res/mipmap-xhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
1 | version https://git-lfs.github.com/spec/v1
2 | oid sha256:6bac0c42e751a8143a7089e26c038cab05ed82db241182d97089a829636ff256
3 | size 8978
4 |
--------------------------------------------------------------------------------
/apps/android/SuperResolution/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
1 | version https://git-lfs.github.com/spec/v1
2 | oid sha256:99c6c00a704e17a1a78ee9de141aa9f1d31ec5f019620e7d139f52f28c252759
3 | size 9901
4 |
--------------------------------------------------------------------------------
/apps/android/SuperResolution/src/main/res/mipmap-xxhdpi/ic_launcher_foreground.png:
--------------------------------------------------------------------------------
1 | version https://git-lfs.github.com/spec/v1
2 | oid sha256:a5308948289aee69dda55305b4007735c85347375023353f63767ab808f6a053
3 | size 21896
4 |
--------------------------------------------------------------------------------
/apps/android/SuperResolution/src/main/res/mipmap-xxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
1 | version https://git-lfs.github.com/spec/v1
2 | oid sha256:2b9e41d426a606d6de6724d97aa887f7390955dda2cf8853a7cbc7f62a73fbde
3 | size 16031
4 |
--------------------------------------------------------------------------------
/apps/android/SuperResolution/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
1 | version https://git-lfs.github.com/spec/v1
2 | oid sha256:c5e2a3313cb99476cb678e7a2ca6a9e0a01433a77479cc0c174fe2f10bb71a83
3 | size 14803
4 |
--------------------------------------------------------------------------------
/apps/android/SuperResolution/src/main/res/mipmap-xxxhdpi/ic_launcher_foreground.png:
--------------------------------------------------------------------------------
1 | version https://git-lfs.github.com/spec/v1
2 | oid sha256:001765311abcecc5afa30418cdf8a16435cd3e0e2c0572d78b1d5ebe8df63ae2
3 | size 32566
4 |
--------------------------------------------------------------------------------
/apps/android/SuperResolution/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
1 | version https://git-lfs.github.com/spec/v1
2 | oid sha256:e4798707e93a30144714a7df5db98583e753a62c88fdbbb2043ae5ef5b1c1004
3 | size 24307
4 |
--------------------------------------------------------------------------------
/apps/android/SuperResolution/src/main/res/values-night/themes.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
17 |
18 |
--------------------------------------------------------------------------------
/apps/android/SuperResolution/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | #6D1683
5 | #FFBB86FC
6 | #FF6200EE
7 | #FF3700B3
8 | #FF03DAC5
9 | #FF018786
10 | #FF000000
11 | #FFFFFFFF
12 |
13 |
--------------------------------------------------------------------------------
/apps/android/SuperResolution/src/main/res/values/ic_launcher_background.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #FFFFFF
4 |
5 |
--------------------------------------------------------------------------------
/apps/android/SuperResolution/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | Super Resolution
3 |
4 |
--------------------------------------------------------------------------------
/apps/android/SuperResolution/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
8 |
9 |
14 |
15 |
--------------------------------------------------------------------------------
/apps/android/SuperResolution/src/main/res/values/themes.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
18 |
19 |
--------------------------------------------------------------------------------
/apps/android/WhisperKit/README.md:
--------------------------------------------------------------------------------
1 | [](https://aihub.qualcomm.com)
2 |
3 | # WhisperKit, by Argmax
4 |
5 | Our SDK collaborator, [Argmax](https://www.takeargmax.com/), presents [WhisperKit](https://github.com/argmaxinc/WhisperKitAndroid), a state-of-the-art on-device speech-to-text solution.
6 |
7 | WhisperKit supports Qualcomm Devices on the Android Operating System.
8 |
--------------------------------------------------------------------------------
/apps/android/build.gradle:
--------------------------------------------------------------------------------
1 | // Top-level build file where you can add configuration options common to all sub-projects/modules.
2 | plugins {
3 | id 'com.android.application' version '8.9.1' apply false
4 | }
5 |
--------------------------------------------------------------------------------
/apps/android/gradle.properties:
--------------------------------------------------------------------------------
1 |
2 | # Project-wide Gradle settings.
3 | # IDE (e.g. Android Studio) users:
4 | # Gradle settings configured through the IDE *will override*
5 | # any settings specified in this file.
6 | # For more details on how to configure your build environment visit
7 | # http://www.gradle.org/docs/current/userguide/build_environment.html
8 | # Specifies the JVM arguments used for the daemon process.
9 | # The setting is particularly useful for tweaking memory settings.
10 | org.gradle.jvmargs=-Xmx4G -Dfile.encoding=UTF-8
11 | # When configured, Gradle will run in incubating parallel mode.
12 | # This option should only be used with decoupled projects. More details, visit
13 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
14 | # org.gradle.parallel=true
15 | # AndroidX package structure to make it clearer which packages are bundled with the
16 | # Android operating system, and which are packaged with your app"s APK
17 | # https://developer.android.com/topic/libraries/support-library/androidx-rn
18 | android.useAndroidX=true
19 | # Automatically convert third-party libraries to use AndroidX
20 | #android.enableJetifier=true
21 | android.nonTransitiveRClass=true
22 |
23 | # Model Missing Error Message
24 | missingModelErrorMsg="ML model file(s) are missing. Please refer to the app README for instructions on how to compile and place the model(s)."
25 |
26 | # Repository was likely not cloned with LFS Error Message (some assets are ascii files)
27 | missingLfsErrorMsg = "Project assets are missing. Please make sure the git repository is cloned with LFS (https://git-lfs.com/) enabled."
28 |
29 | # Java Settings
30 | javaSourceCompatibilityVersion=11
31 | javaTargetCompatibilityVersion=11
32 |
33 | # Android Settings
34 | # Minimum is Android 11 Red Velvet Cake
35 | # Target is Android 14 Upside Down Cake (API v34)
36 | androidMinSDK=30
37 | androidTargetSDK=34
38 | androidCompileSDK=34
39 |
40 | # QNN Settings
41 | qnnVersion=2.28.2
42 |
43 | # Classifier Application Settings
44 | includeClassificationApp=true
45 | classification_tfLiteModelAsset=classification.tflite
46 | classification_tfLiteLabelsAsset=labels.txt
47 |
48 | # Semantic Segmentation Application Settings
49 | includeSemanticSegmentationApp=true
50 | semanticsegmentation_tfLiteModelAsset=segmentation.tflite
51 |
52 | # Super Resolution Application Settings
53 | includeSuperResolutionApp=true
54 | superresolution_tfLiteModelAsset=superresolution.tflite
55 |
56 | # ChatApp Application Settings
57 | includeChatApp=true
58 |
--------------------------------------------------------------------------------
/apps/android/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Thu Jun 27 15:41:09 PDT 2024
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | distributionUrl=https\://services.gradle.org/distributions/gradle-8.11.1-bin.zip
5 | networkTimeout=10000
6 | validateDistributionUrl=true
7 | zipStoreBase=GRADLE_USER_HOME
8 | zipStorePath=wrapper/dists
9 |
--------------------------------------------------------------------------------
/apps/android/image_preprocessing_helpers/ImageProcessing.java:
--------------------------------------------------------------------------------
1 | // ---------------------------------------------------------------------
2 | // Copyright (c) 2024 Qualcomm Innovation Center, Inc. All rights reserved.
3 | // SPDX-License-Identifier: BSD-3-Clause
4 | // ---------------------------------------------------------------------
5 | package com.quicinc;
6 |
7 | import android.graphics.Bitmap;
8 | import android.graphics.Canvas;
9 | import android.graphics.RectF;
10 |
11 | public class ImageProcessing {
12 | /**
13 | * Resize a bitmap while respecting its aspect ratio.
14 | * If the output image cannot fit perfectly within the requested output height / width,
15 | * padding is added such that the output bitmap will be the requested size.
16 | *
17 | * @param image Image to resize
18 | * @param outputBitmapWidth Final width
19 | * @param outputBitmapHeight Final height
20 | * @param paddingValue Value to use for padding (usually 0 or 0xFF)
21 | * @return Resized & padded bitmap
22 | */
23 | public static Bitmap resizeAndPadMaintainAspectRatio(
24 | Bitmap image,
25 | int outputBitmapWidth,
26 | int outputBitmapHeight,
27 | int paddingValue) {
28 | int width = image.getWidth();
29 | int height = image.getHeight();
30 | float ratioBitmap = (float) width / (float) height;
31 | float ratioMax = (float) outputBitmapWidth / (float) outputBitmapHeight;
32 |
33 | int finalWidth = outputBitmapWidth;
34 | int finalHeight = outputBitmapHeight;
35 | if (ratioMax > ratioBitmap) {
36 | finalWidth = (int) ((float)outputBitmapHeight * ratioBitmap);
37 | } else {
38 | finalHeight = (int) ((float)outputBitmapWidth / ratioBitmap);
39 | }
40 |
41 | Bitmap outputImage = Bitmap.createBitmap(outputBitmapWidth, outputBitmapHeight, Bitmap.Config.ARGB_8888);
42 | Canvas can = new Canvas(outputImage);
43 | can.drawARGB(0xFF, paddingValue, paddingValue, paddingValue);
44 | int left = (outputBitmapWidth - finalWidth) / 2;
45 | int top = (outputBitmapHeight - finalHeight) / 2;
46 | can.drawBitmap(image, null, new RectF(left, top, finalWidth + left, finalHeight + top), null);
47 | return outputImage;
48 | }
49 | }
50 |
--------------------------------------------------------------------------------
/apps/android/settings.gradle:
--------------------------------------------------------------------------------
1 | pluginManagement {
2 | repositories {
3 | gradlePluginPortal()
4 | google()
5 | mavenCentral()
6 | }
7 | }
8 |
9 | dependencyResolutionManagement {
10 | repositories {
11 | google()
12 | mavenCentral()
13 | }
14 | }
15 |
16 | /** Project Name **/
17 | rootProject.name = "Qualcomm AI Hub Android Sample Apps"
18 |
19 | /** Applications **/
20 | if (Boolean.valueOf(properties["includeClassificationApp"])) {
21 | include ':ImageClassification'
22 | }
23 | if (Boolean.valueOf(properties["includeSuperResolutionApp"])) {
24 | include ':SuperResolution'
25 | }
26 |
27 | if (Boolean.valueOf(properties["includeSemanticSegmentationApp"])) {
28 | include ':SemanticSegmentation'
29 | }
30 |
31 | if (Boolean.valueOf(properties["includeChatApp"])) {
32 | include ':ChatApp'
33 | }
34 |
--------------------------------------------------------------------------------
/apps/android/tflite_helpers/AIHubDefaults.java:
--------------------------------------------------------------------------------
1 | // ---------------------------------------------------------------------
2 | // Copyright (c) 2024 Qualcomm Innovation Center, Inc. All rights reserved.
3 | // SPDX-License-Identifier: BSD-3-Clause
4 | // ---------------------------------------------------------------------
5 | package com.quicinc.tflite;
6 |
7 | import java.util.Arrays;
8 | import java.util.HashSet;
9 | import java.util.Set;
10 |
11 | public class AIHubDefaults {
12 | // Delegates enabled to replicate AI Hub's defaults on Qualcomm devices.
13 | public static final Set enabledDelegates = new HashSet<>(Arrays.asList(
14 | TFLiteHelpers.DelegateType.QNN_NPU,
15 | TFLiteHelpers.DelegateType.GPUv2
16 | ));
17 |
18 | // Number of threads AI Hub uses by default for layers running on CPU.
19 | // https://app.aihub.qualcomm.com/docs/hub/api.html#profile-inference-options
20 | public static final int numCPUThreads = Runtime.getRuntime().availableProcessors() / 2;
21 |
22 | // The default delegate registry order for AI Hub.
23 | // For more details, see the JavaDoc for TFLiteHelpers::CreateInterpreterAndDelegatesFromOptions.
24 | public static final TFLiteHelpers.DelegateType[][] delegatePriorityOrder = new TFLiteHelpers.DelegateType[][] {
25 | // 1. QNN_NPU + GPUv2 + XNNPack
26 | // https://app.aihub.qualcomm.com/docs/hub/api.html#profile-inference-options
27 | // Similar to AI Hub "compute_unit=all", or "compute_unit=npu,gpu,cpu" on QC devices that support QNN
28 | // AI Hub sets some GPUv2 settings that are not accessible via the Java API.
29 | { TFLiteHelpers.DelegateType.QNN_NPU, TFLiteHelpers.DelegateType.GPUv2 },
30 |
31 | // 2. GPUv2 + XNNPack
32 | // https://app.aihub.qualcomm.com/docs/hub/api.html#profile-inference-options
33 | // Similar to AI Hub "compute_unit=gpu" on all devices
34 | // AI Hub sets some GPU settings that are not accessible via the Java API.
35 | { TFLiteHelpers.DelegateType.GPUv2 },
36 |
37 | // 3. XNNPack (final, CPU-only fallback)
38 | // https://app.aihub.qualcomm.com/docs/hub/api.html#profile-inference-options
39 | // Same as AI Hub "compute_unit=cpu" on all devices
40 | { }
41 |
42 | // ------
43 | //
44 | // Additional delegates (eg. NNAPI, or something targeting non-Qualcomm hardware) could be added here or above,
45 | // if you desire to define a custom delegate selection order.
46 | //
47 | // ------
48 | };
49 |
50 | // Create a version of the above delegate priority order that can only use the provided delegates.
51 | public static TFLiteHelpers.DelegateType[][] delegatePriorityOrderForDelegates(Set enabledDelegates) {
52 | return Arrays.stream(delegatePriorityOrder).filter(x -> enabledDelegates.containsAll(Arrays.asList(x))).toArray(TFLiteHelpers.DelegateType[][]::new);
53 | }
54 | }
55 |
--------------------------------------------------------------------------------
/apps/windows/cpp/ChatApp/.gitignore:
--------------------------------------------------------------------------------
1 | /.vs/
2 | /ARM64/
3 | /ChatApp/
4 |
--------------------------------------------------------------------------------
/apps/windows/cpp/ChatApp/ChatApp.hpp:
--------------------------------------------------------------------------------
1 | // ---------------------------------------------------------------------
2 | // Copyright (c) 2024 Qualcomm Innovation Center, Inc. All rights reserved.
3 | // SPDX-License-Identifier: BSD-3-Clause
4 | // ---------------------------------------------------------------------
5 | #pragma once
6 |
7 | #include
8 |
9 | #include "GenieCommon.h"
10 | #include "GenieDialog.h"
11 |
12 | namespace App
13 | {
14 | constexpr const std::string_view c_exit_prompt = "exit";
15 |
16 | class ChatApp
17 | {
18 | private:
19 | GenieDialogConfig_Handle_t m_config_handle = nullptr;
20 | GenieDialog_Handle_t m_dialog_handle = nullptr;
21 | std::string m_user_name;
22 |
23 | public:
24 | /**
25 | * ChatApp: Initializes ChatApp
26 | * - Uses provided Genie configuration string
27 | * - Creates handle for Genie
28 | *
29 | * @param config: JSON string containing Genie configuration
30 | *
31 | * @throws on failure to create handle for Genie config, dialog
32 | *
33 | */
34 | ChatApp(const std::string& config);
35 | ChatApp() = delete;
36 | ChatApp(const ChatApp&) = delete;
37 | ChatApp(ChatApp&&) = delete;
38 | ChatApp& operator=(const ChatApp&) = delete;
39 | ChatApp& operator=(ChatApp&&) = delete;
40 | ~ChatApp();
41 |
42 | /**
43 | * ChatWithUser: Starts Chat with user using previously loaded config
44 | *
45 | * @param user_name: User name to use during chat
46 | *
47 | * @throws on failure to query model response during chat
48 | *
49 | */
50 | void ChatLoop();
51 | };
52 | } // namespace App
53 |
--------------------------------------------------------------------------------
/apps/windows/cpp/ChatApp/ChatApp.sln:
--------------------------------------------------------------------------------
1 | Microsoft Visual Studio Solution File, Format Version 12.00
2 | # Visual Studio Version 17
3 | VisualStudioVersion = 17.11.35219.272
4 | MinimumVisualStudioVersion = 10.0.40219.1
5 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ChatApp", "ChatApp.vcxproj", "{6AECF6D0-1B11-483D-A9ED-44026305F3BE}"
6 | EndProject
7 | Global
8 | GlobalSection(SolutionConfigurationPlatforms) = preSolution
9 | Debug|ARM64 = Debug|ARM64
10 | Release|ARM64 = Release|ARM64
11 | EndGlobalSection
12 | GlobalSection(ProjectConfigurationPlatforms) = postSolution
13 | {6AECF6D0-1B11-483D-A9ED-44026305F3BE}.Debug|ARM64.ActiveCfg = Debug|ARM64
14 | {6AECF6D0-1B11-483D-A9ED-44026305F3BE}.Debug|ARM64.Build.0 = Debug|ARM64
15 | {6AECF6D0-1B11-483D-A9ED-44026305F3BE}.Release|ARM64.ActiveCfg = Release|ARM64
16 | {6AECF6D0-1B11-483D-A9ED-44026305F3BE}.Release|ARM64.Build.0 = Release|ARM64
17 | EndGlobalSection
18 | GlobalSection(SolutionProperties) = preSolution
19 | HideSolutionNode = FALSE
20 | EndGlobalSection
21 | GlobalSection(ExtensibilityGlobals) = postSolution
22 | SolutionGuid = {3EEC2CD0-F0DA-42ED-970E-1440F93328A7}
23 | EndGlobalSection
24 | EndGlobal
25 |
--------------------------------------------------------------------------------
/apps/windows/cpp/ChatApp/ChatApp.vcxproj.filters:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF}
6 | cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx
7 |
8 |
9 | {93995380-89BD-4b04-88EB-625FBE52EBFB}
10 | h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd
11 |
12 |
13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01}
14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms
15 |
16 |
17 |
18 |
19 | Source Files
20 |
21 |
22 | Source Files
23 |
24 |
25 | Source Files
26 |
27 |
28 |
29 |
30 | Header Files
31 |
32 |
33 | Header Files
34 |
35 |
36 |
37 |
38 | Source Files
39 |
40 |
41 |
42 |
--------------------------------------------------------------------------------
/apps/windows/cpp/ChatApp/ChatApp.vcxproj.user:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | --genie-config .\\genie_bundle\\genie_config.json --base-dir .\\genie_bundle\\
5 | WindowsLocalDebugger
6 |
7 |
8 | --genie-config .\\genie_bundle\\genie_config.json --base-dir .\\genie_bundle\\
9 | WindowsLocalDebugger
10 |
11 |
12 |
--------------------------------------------------------------------------------
/apps/windows/cpp/ChatApp/PromptHandler.cpp:
--------------------------------------------------------------------------------
1 | // ---------------------------------------------------------------------
2 | // Copyright (c) 2024 Qualcomm Innovation Center, Inc. All rights reserved.
3 | // SPDX-License-Identifier: BSD-3-Clause
4 | // ---------------------------------------------------------------------
5 | #include "PromptHandler.hpp"
6 | #include "ChatApp.hpp"
7 |
8 | using namespace AppUtils;
9 |
10 | // Prompt formats: LLAMA3, LLAMA3_TAIDE, LLAMA2
11 | #define LLAMA3
12 |
13 | #ifdef LLAMA3
14 | // Llama3 prompt
15 | // Ref: https://www.llama.com/docs/model-cards-and-prompt-formats/meta-llama-3/
16 | constexpr const std::string_view c_begin_system =
17 | "<|begin_of_text|><|start_header_id|>system<|end_header_id|>\n\nYour name is Qbot and you are a helpful AI "
18 | "assistant. Please keep answers concise and to the point. <|eot_id|>\n\n";
19 | constexpr const std::string_view c_begin_user = "<|start_header_id|>user<|end_header_id|>\n\n";
20 | constexpr const std::string_view c_end_user = "<|eot_id|>";
21 | constexpr const std::string_view c_begin_assistant = "<|start_header_id|>assistant<|end_header_id|>\n\n";
22 | constexpr const std::string_view c_end_assistant = "<|eot_id|>";
23 |
24 | #elif defined LLAMA3_TAIDE
25 | // Llama3-TAIDE
26 | constexpr const std::string_view c_begin_system =
27 | "<|begin_of_text|><|start_header_id|>system<|end_header_id|>\n\n你是一個來自台灣的AI助理,你的名字是 "
28 | "TAIDE,樂於以台灣人的立場幫助使用者,會用繁體中文回答問題<|eot_id|>\n\n";
29 | constexpr const std::string_view c_begin_user = "<|start_header_id|>user<|end_header_id|>\n\n";
30 | constexpr const std::string_view c_end_user = "<|eot_id|>";
31 | constexpr const std::string_view c_begin_assistant = "<|start_header_id|>assistant<|end_header_id|>\n\n";
32 | constexpr const std::string_view c_end_assistant = "<|eot_id|>";
33 |
34 | #elif defined LLAMA2
35 | // Llama2 system prompt
36 | // Ref: https://www.llama.com/docs/model-cards-and-prompt-formats/meta-llama-2/
37 | constexpr const std::string_view c_begin_system =
38 | "[INST] <>\nYour name is Qbot and you are a helpful AI assistant. Please keep answers concise and to the "
39 | "point.\n<>\n\n";
40 | constexpr const std::string_view c_begin_assistant = "";
41 | constexpr const std::string_view c_end_assistant = "\n\n";
42 | constexpr const std::string_view c_begin_user = "[INST] ";
43 | constexpr const std::string_view c_end_user = " [/INST] ";
44 | #endif
45 |
46 | PromptHandler::PromptHandler()
47 | : m_is_first_prompt(true)
48 | {
49 | }
50 |
51 | std::string PromptHandler::GetPromptWithTag(const std::string& user_prompt)
52 | {
53 | if (m_is_first_prompt)
54 | {
55 | m_is_first_prompt = false;
56 | return std::string(c_begin_system) + c_begin_user.data() + user_prompt.data() + c_end_user.data() +
57 | c_begin_assistant.data();
58 | }
59 | return std::string(c_end_assistant) + c_begin_user.data() + user_prompt.data() + c_end_user.data() +
60 | c_begin_assistant.data();
61 | }
62 |
--------------------------------------------------------------------------------
/apps/windows/cpp/ChatApp/PromptHandler.hpp:
--------------------------------------------------------------------------------
1 | // ---------------------------------------------------------------------
2 | // Copyright (c) 2024 Qualcomm Innovation Center, Inc. All rights reserved.
3 | // SPDX-License-Identifier: BSD-3-Clause
4 | // ---------------------------------------------------------------------
5 | #pragma once
6 |
7 | #include
8 | namespace AppUtils
9 | {
10 |
11 | class PromptHandler
12 | {
13 | private:
14 | bool m_is_first_prompt;
15 |
16 | public:
17 | PromptHandler();
18 |
19 | std::string GetPromptWithTag(const std::string& user_prompt);
20 | };
21 |
22 | } // namespace AppUtils
23 |
--------------------------------------------------------------------------------
/apps/windows/cpp/ChatApp/assets/images/ai-hub-qnn-version.png:
--------------------------------------------------------------------------------
1 | version https://git-lfs.github.com/spec/v1
2 | oid sha256:46380cfb7f50a5b5db155fa6b8188c4ebd766234920fb9705738b0d9eb6ae3bd
3 | size 216680
4 |
--------------------------------------------------------------------------------
/apps/windows/cpp/ChatApp/assets/images/sample-qnn-sdk-check.png:
--------------------------------------------------------------------------------
1 | version https://git-lfs.github.com/spec/v1
2 | oid sha256:62c978e40e90eebac8f33056be991c4aaae890eb0a7745959469623cc90120f0
3 | size 84881
4 |
--------------------------------------------------------------------------------
/apps/windows/cpp/ChatApp/assets/images/sample_output.png:
--------------------------------------------------------------------------------
1 | version https://git-lfs.github.com/spec/v1
2 | oid sha256:f525a6cf40c4702b1bf5aa0d47e610928f56af905f632be3c96eaebceab15ca9
3 | size 102601
4 |
--------------------------------------------------------------------------------
/apps/windows/cpp/Classification/Classification.sln:
--------------------------------------------------------------------------------
1 |
2 | Microsoft Visual Studio Solution File, Format Version 12.00
3 | # Visual Studio Version 17
4 | VisualStudioVersion = 17.10.35122.118
5 | MinimumVisualStudioVersion = 10.0.40219.1
6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Classification", "Classification.vcxproj", "{7EEB9A59-C1BC-4230-9AEE-D3D8C2B77CAB}"
7 | EndProject
8 | Global
9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution
10 | Debug|ARM64 = Debug|ARM64
11 | Release|ARM64 = Release|ARM64
12 | EndGlobalSection
13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution
14 | {7EEB9A59-C1BC-4230-9AEE-D3D8C2B77CAB}.Debug|ARM64.ActiveCfg = Debug|ARM64
15 | {7EEB9A59-C1BC-4230-9AEE-D3D8C2B77CAB}.Debug|ARM64.Build.0 = Debug|ARM64
16 | {7EEB9A59-C1BC-4230-9AEE-D3D8C2B77CAB}.Release|ARM64.ActiveCfg = Release|ARM64
17 | {7EEB9A59-C1BC-4230-9AEE-D3D8C2B77CAB}.Release|ARM64.Build.0 = Release|ARM64
18 | EndGlobalSection
19 | GlobalSection(SolutionProperties) = preSolution
20 | HideSolutionNode = FALSE
21 | EndGlobalSection
22 | GlobalSection(ExtensibilityGlobals) = postSolution
23 | SolutionGuid = {37822254-B877-4E09-BB47-892580A478FE}
24 | EndGlobalSection
25 | EndGlobal
26 |
--------------------------------------------------------------------------------
/apps/windows/cpp/Classification/Classification.vcxproj.filters:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF}
6 | cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx
7 |
8 |
9 | {93995380-89BD-4b04-88EB-625FBE52EBFB}
10 | h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd
11 |
12 |
13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01}
14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms
15 |
16 |
17 |
18 |
19 | Source Files
20 |
21 |
22 | Source Files
23 |
24 |
25 | Source Files
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 | Header Files
40 |
41 |
42 | Header Files
43 |
44 |
45 |
46 |
47 |
48 |
49 |
--------------------------------------------------------------------------------
/apps/windows/cpp/Classification/Classification.vcxproj.user:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | --backend npu --model $(ProjectDir)/assets/models/mobilenet_v2.onnx --image $(ProjectDir)/assets/images/keyboard.jpg
5 | WindowsLocalDebugger
6 |
7 |
8 | false
9 |
10 |
11 | $(TargetPath)
12 | WindowsLocalDebugger
13 | --backend npu --model $(ProjectDir)/assets/models/mobilenet_v2.onnx --image $(ProjectDir)/assets/images/keyboard.jpg
14 |
15 |
16 |
--------------------------------------------------------------------------------
/apps/windows/cpp/Classification/ClassificationApp.hpp:
--------------------------------------------------------------------------------
1 | // ---------------------------------------------------------------------
2 | // Copyright (c) 2024 Qualcomm Innovation Center, Inc. All rights reserved.
3 | // SPDX-License-Identifier: BSD-3-Clause
4 | // ---------------------------------------------------------------------
5 | #pragma once
6 |
7 | #include
8 | #include
9 | #include
10 |
11 | #include
12 |
13 | #include
14 |
15 | const size_t output_data_size = 1000;
16 | constexpr const char* label_file = "synset.txt";
17 |
18 | namespace App
19 | {
20 |
21 | enum Precision
22 | {
23 | Fp32 = 0,
24 | Fp16 = 1
25 | };
26 |
27 | enum BackendOption
28 | {
29 | Cpu = 0,
30 | Npu = 2,
31 | };
32 |
33 | class ClassificationApp
34 | {
35 | private:
36 | // model io pointing to loaded data
37 | std::vector m_inputs;
38 | std::vector m_outputs;
39 |
40 | std::vector m_input_names;
41 | // Keep io names alive returned by session
42 | std::vector m_io_data_ptr;
43 |
44 | // model metadata
45 | uint32_t m_model_input_ht, m_model_input_wt;
46 | std::string m_model_path;
47 |
48 | Ort::Env m_env;
49 | std::unique_ptr m_session;
50 | Ort::AllocatorWithDefaultOptions m_allocator;
51 |
52 | void ClearInputsAndOutputs();
53 |
54 | public:
55 | ClassificationApp(std::string model_path, uint32_t model_input_ht, uint32_t model_input_wt);
56 | ClassificationApp() = delete;
57 | ClassificationApp(const ClassificationApp&) = delete;
58 | ClassificationApp(ClassificationApp&&) = delete;
59 | ClassificationApp& operator=(const ClassificationApp&) = delete;
60 | ClassificationApp& operator=(ClassificationApp&&) = delete;
61 |
62 | /**
63 | * PrepareModelForInference: Prepares model for inference with ORT
64 | * - initializes ORT Session
65 | * - sets backend, precision and qnn_options for execution provider
66 | *
67 | * @param backend: backend for model execution.
68 | * @param precision: preferred precision for model execution.
69 | * @param qnn_options: QNN Execution provider options.
70 | * refer to
71 | * https://onnxruntime.ai/docs/execution-providers/QNN-ExecutionProvider.html#configuration-options
72 | * for all supported options.
73 | *
74 | */
75 | void PrepareModelForInference(const App::BackendOption backend,
76 | const App::Precision precision,
77 | std::unordered_map qnn_options);
78 |
79 | /**
80 | * LoadInputs: Load and prepare local image for model inference
81 | * - Loads image with opencv
82 | * - Converts image to Ort::OrtTensor to use during model inference
83 | *
84 | * @param image_path: local path to image to load.
85 | *
86 | */
87 | void LoadInputs(const std::string& image_path);
88 |
89 | /**
90 | * RunInference: Execute prepared model
91 | * - Runs inference and cache output
92 | *
93 | * @throws if model is not prepared with PrepareModelForInference before
94 | * @throws if inputs are not loaded with LoadInputs before
95 | *
96 | */
97 | void RunInference();
98 |
99 | /**
100 | * ProcessOutput: Process cached model output to show results
101 | *
102 | * @param input_image_path input image to add bounding boxes and labels.
103 | * @param display_output_image if true, shows output image in window using
104 | * opencv.
105 | * @param output_image_path if provided, serializes output image locally.
106 | *
107 | */
108 | void ProcessOutput(const std::string& input_image_path,
109 | std::optional output_image_path = std::nullopt,
110 | bool display_output_image = true);
111 | };
112 | } // namespace App
113 |
--------------------------------------------------------------------------------
/apps/windows/cpp/Classification/Utilities.cpp:
--------------------------------------------------------------------------------
1 | // ---------------------------------------------------------------------
2 | // Copyright (c) 2024 Qualcomm Innovation Center, Inc. All rights reserved.
3 | // SPDX-License-Identifier: BSD-3-Clause
4 | // ---------------------------------------------------------------------
5 | #include
6 | #include
7 | #include
8 | #include
9 | #include
10 | #include
11 | #include
12 |
13 | #include "Utilities.hpp"
14 |
15 | namespace Utils
16 | {
17 |
18 | void AddText(const cv::Mat& img, const std::string& msg)
19 | {
20 | int font_face = cv::FONT_HERSHEY_SIMPLEX;
21 | double font_scale = 2;
22 | int thickness = 3;
23 | int baseline = 0;
24 |
25 | cv::Size text_size = cv::getTextSize(msg, font_face, font_scale, thickness, &baseline);
26 | cv::Point text_position((img.cols - text_size.width) / 2, text_size.height + 10);
27 | cv::rectangle(img, text_position + cv::Point(0, baseline),
28 | text_position + cv::Point(text_size.width, -text_size.height), cv::Scalar(255, 255, 255), cv::FILLED);
29 | cv::putText(img, msg, text_position, font_face, font_scale, cv::Scalar(0, 0, 0), thickness);
30 | }
31 |
32 | std::vector LoadImageFile(const std::string& image_path, uint32_t input_image_height, uint32_t input_image_width)
33 | {
34 | cv::Mat image = cv::imread(image_path);
35 |
36 | if (image.empty())
37 | {
38 | std::ostringstream msg;
39 | msg << "Input image not found at " << image_path << ".\n Please provide full path to input image.";
40 | throw std::runtime_error(msg.str());
41 | }
42 |
43 | cvtColor(image, image, cv::COLOR_BGR2RGB);
44 | resize(image, image, cv::Size(input_image_height, input_image_width));
45 | image = image.reshape(1, 1);
46 |
47 | std::vector vec;
48 | image.convertTo(vec, CV_32FC1, 1. / 255);
49 |
50 | std::vector output;
51 | output.reserve(vec.size());
52 |
53 | // Transposing channel
54 | for (size_t ch = 0; ch < 3; ++ch)
55 | {
56 | for (size_t i = ch; i < vec.size(); i += 3)
57 | {
58 | output.push_back(vec[i]);
59 | }
60 | }
61 | return output;
62 | }
63 |
64 | std::string RemoveFirstWord(const std::string& input)
65 | {
66 | size_t pos = input.find(' '); // Find the first space
67 | if (pos == std::string::npos)
68 | {
69 | return ""; // If no space is found, return an empty string
70 | }
71 | return input.substr(pos + 1); // Return the substring after the first space
72 | }
73 |
74 | std::unordered_map ReadLabelFile(std::string filepath, const size_t label_size)
75 | {
76 | std::fstream label_file(filepath, std::ios::in);
77 | if (!label_file.is_open())
78 | {
79 | throw std::runtime_error("Error: File not found or unable to open the file.");
80 | }
81 |
82 | std::unordered_map label_table;
83 | label_table.reserve(label_size);
84 | int i = 0;
85 | std::string line;
86 | while (std::getline(label_file, line))
87 | {
88 | // Remove the synset ID as it is not the actual class label
89 | label_table.emplace(i++, RemoveFirstWord(line));
90 | }
91 | return label_table;
92 | }
93 |
94 | } // namespace Utils
95 |
--------------------------------------------------------------------------------
/apps/windows/cpp/Classification/Utilities.hpp:
--------------------------------------------------------------------------------
1 | // ---------------------------------------------------------------------
2 | // Copyright (c) 2024 Qualcomm Innovation Center, Inc. All rights reserved.
3 | // SPDX-License-Identifier: BSD-3-Clause
4 | // ---------------------------------------------------------------------
5 | #pragma once
6 |
7 | #include
8 | #include
9 |
10 | namespace Utils
11 | {
12 |
13 | void AddText(const cv::Mat& img, const std::string& msg);
14 |
15 | std::vector
16 | LoadImageFile(const std::string& image_path, uint32_t input_image_height, uint32_t input_image_width);
17 |
18 | std::unordered_map ReadLabelFile(std::string filepath, const size_t label_size);
19 |
20 | } // namespace Utils
21 |
--------------------------------------------------------------------------------
/apps/windows/cpp/Classification/assets/images/classificationOutput.png:
--------------------------------------------------------------------------------
1 | version https://git-lfs.github.com/spec/v1
2 | oid sha256:2023f0e9675c38535cff563ac0f8243591a990e1afb6ef46e5981f5757c2d18f
3 | size 1187493
4 |
--------------------------------------------------------------------------------
/apps/windows/cpp/Classification/assets/images/keyboard.jpg:
--------------------------------------------------------------------------------
1 | version https://git-lfs.github.com/spec/v1
2 | oid sha256:651b4d94a462899df173647f7af22b71d5b3e4735533c072bbf81557a1ac1524
3 | size 2338267
4 |
--------------------------------------------------------------------------------
/apps/windows/cpp/Classification/assets/models/README.md:
--------------------------------------------------------------------------------
1 | # Model assets for Classification CLI app
2 |
3 | Please download [MobileNet-V2 ONNX model from AI Hub](https://aihub.qualcomm.com/compute/models/mobilenet_v2]) and place it in here.
4 |
--------------------------------------------------------------------------------
/apps/windows/cpp/Classification/packages.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/apps/windows/cpp/Classification/vcpkg-configuration.json:
--------------------------------------------------------------------------------
1 | {
2 | "default-registry": {
3 | "kind": "git",
4 | "baseline": "7f9f0e44db287e8e67c0e888141bfa200ab45121",
5 | "repository": "https://github.com/microsoft/vcpkg"
6 | },
7 | "registries": [
8 | {
9 | "kind": "artifact",
10 | "location": "https://github.com/microsoft/vcpkg-ce-catalog/archive/refs/heads/main.zip",
11 | "name": "microsoft"
12 | }
13 | ]
14 | }
15 |
--------------------------------------------------------------------------------
/apps/windows/cpp/Classification/vcpkg.json:
--------------------------------------------------------------------------------
1 | {
2 | "dependencies": [
3 | "opencv"
4 | ],
5 | "overrides": [
6 | {
7 | "name": "liblzma",
8 | "version": "5.4.4"
9 | }
10 | ]
11 | }
12 |
--------------------------------------------------------------------------------
/apps/windows/cpp/ObjectDetection/ObjectDetection.sln:
--------------------------------------------------------------------------------
1 | Microsoft Visual Studio Solution File, Format Version 12.00
2 | # Visual Studio Version 17
3 | VisualStudioVersion = 17.10.35027.167
4 | MinimumVisualStudioVersion = 10.0.40219.1
5 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ObjectDetection", "ObjectDetection.vcxproj", "{4D400CBA-74A5-48B2-BE18-A8DB8477BC08}"
6 | EndProject
7 | Global
8 | GlobalSection(SolutionConfigurationPlatforms) = preSolution
9 | Debug|ARM64 = Debug|ARM64
10 | Release|ARM64 = Release|ARM64
11 | EndGlobalSection
12 | GlobalSection(ProjectConfigurationPlatforms) = postSolution
13 | {4D400CBA-74A5-48B2-BE18-A8DB8477BC08}.Debug|ARM64.ActiveCfg = Debug|ARM64
14 | {4D400CBA-74A5-48B2-BE18-A8DB8477BC08}.Debug|ARM64.Build.0 = Debug|ARM64
15 | {4D400CBA-74A5-48B2-BE18-A8DB8477BC08}.Release|ARM64.ActiveCfg = Release|ARM64
16 | {4D400CBA-74A5-48B2-BE18-A8DB8477BC08}.Release|ARM64.Build.0 = Release|ARM64
17 | EndGlobalSection
18 | GlobalSection(SolutionProperties) = preSolution
19 | HideSolutionNode = FALSE
20 | EndGlobalSection
21 | GlobalSection(ExtensibilityGlobals) = postSolution
22 | SolutionGuid = {308BCC89-CC6D-455D-B293-40B64FAE6119}
23 | EndGlobalSection
24 | EndGlobal
25 |
--------------------------------------------------------------------------------
/apps/windows/cpp/ObjectDetection/ObjectDetection.vcxproj.filters:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF}
6 | cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx
7 |
8 |
9 | {93995380-89BD-4b04-88EB-625FBE52EBFB}
10 | h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd
11 |
12 |
13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01}
14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms
15 |
16 |
17 |
18 |
19 | Source Files
20 |
21 |
22 | Source Files
23 |
24 |
25 | Source Files
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 | Header Files
40 |
41 |
42 | Header Files
43 |
44 |
45 |
46 |
--------------------------------------------------------------------------------
/apps/windows/cpp/ObjectDetection/ObjectDetection.vcxproj.user:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | --backend npu --model $(ProjectDir)/assets/models/yolov8_det.onnx --image $(ProjectDir)/assets/images/kitchen.jpg
5 | WindowsLocalDebugger
6 |
7 |
8 | false
9 |
10 |
11 | $(TargetPath)
12 | WindowsLocalDebugger
13 | --backend npu --model $(ProjectDir)/assets/models/yolov8_det.onnx --image $(ProjectDir)/assets/images/kitchen.jpg
14 |
15 |
16 |
--------------------------------------------------------------------------------
/apps/windows/cpp/ObjectDetection/ObjectDetectionApp.hpp:
--------------------------------------------------------------------------------
1 | // ---------------------------------------------------------------------
2 | // Copyright (c) 2024 Qualcomm Innovation Center, Inc. All rights reserved.
3 | // SPDX-License-Identifier: BSD-3-Clause
4 | // ---------------------------------------------------------------------
5 | #pragma once
6 |
7 | #include
8 | #include
9 | #include
10 |
11 | #include
12 |
13 | #include
14 |
15 | namespace App
16 | {
17 |
18 | enum Precision
19 | {
20 | Fp32 = 0,
21 | Fp16 = 1
22 | };
23 |
24 | enum BackendOption
25 | {
26 | Cpu = 0,
27 | Npu = 2,
28 | };
29 |
30 | class ObjectDetectionApp
31 | {
32 | private:
33 | // model io pointing to loaded data
34 | std::vector m_inputs;
35 | std::vector m_outputs;
36 |
37 | std::vector m_input_names;
38 | // Keep io names alive returned by session
39 | std::vector m_io_data_ptr;
40 |
41 | // model metadata
42 | uint32_t m_model_input_ht, m_model_input_wt;
43 | std::string m_model_path;
44 |
45 | Ort::Env m_env;
46 | std::unique_ptr m_session;
47 | Ort::AllocatorWithDefaultOptions m_allocator;
48 |
49 | void ClearInputsAndOutputs();
50 |
51 | public:
52 | ObjectDetectionApp(std::string model_path, uint32_t model_input_ht, uint32_t model_input_wt);
53 | ObjectDetectionApp() = delete;
54 | ObjectDetectionApp(const ObjectDetectionApp&) = delete;
55 | ObjectDetectionApp(ObjectDetectionApp&&) = delete;
56 | ObjectDetectionApp& operator=(const ObjectDetectionApp&) = delete;
57 | ObjectDetectionApp& operator=(ObjectDetectionApp&&) = delete;
58 |
59 | /**
60 | * PrepareModelForInference: Prepares model for inference with ORT
61 | * - initializes ORT Session
62 | * - sets backend, precision and qnn_options for execution provider
63 | *
64 | * @param backend: backend for model execution.
65 | * @param precision: preferred precision for model execution.
66 | * @param qnn_options: QNN Execution provider options.
67 | * refer to
68 | * https://onnxruntime.ai/docs/execution-providers/QNN-ExecutionProvider.html#configuration-options
69 | * for all supported options.
70 | *
71 | */
72 | void PrepareModelForInference(const App::BackendOption backend,
73 | const App::Precision precision,
74 | std::unordered_map qnn_options);
75 |
76 | /**
77 | * LoadInputs: Load and prepare local image for model inference
78 | * - Loads image with opencv
79 | * - Converts image to Ort::OrtTensor to use during model inference
80 | *
81 | * @param image_path: local path to image to load.
82 | *
83 | */
84 | void LoadInputs(const std::string& image_path);
85 |
86 | /**
87 | * RunInference: Execute prepared model
88 | * - Runs inference and cache output
89 | *
90 | * @throws if model is not prepared with PrepareModelForInference before
91 | * @throws if inputs are not loaded with LoadInputs before
92 | *
93 | */
94 | void RunInference();
95 |
96 | /**
97 | * ProcessOutput: Process cached model output to show results
98 | *
99 | * @param input_image_path input image to add bounding boxes and labels.
100 | * @param display_output_image if true, shows output image in window using
101 | * opencv.
102 | * @param output_image_path if provided, serializes output image locally.
103 | *
104 | */
105 | void ProcessOutput(const std::string& input_image_path,
106 | std::optional output_image_path = std::nullopt,
107 | bool display_output_image = true);
108 | };
109 | } // namespace App
110 |
--------------------------------------------------------------------------------
/apps/windows/cpp/ObjectDetection/Utilities.hpp:
--------------------------------------------------------------------------------
1 | // ---------------------------------------------------------------------
2 | // Copyright (c) 2024 Qualcomm Innovation Center, Inc. All rights reserved.
3 | // SPDX-License-Identifier: BSD-3-Clause
4 | // ---------------------------------------------------------------------
5 | #pragma once
6 |
7 | #include
8 | #include
9 |
10 | namespace Utils
11 | {
12 |
13 | class BoxCornerEncoding
14 | {
15 |
16 | public:
17 | int x1;
18 | int y1;
19 | int x2;
20 | int y2;
21 | float score;
22 | std::string obj_label;
23 |
24 | BoxCornerEncoding(int a, int b, int c, int d, float sc, std::string name = "default");
25 | };
26 |
27 | std::vector
28 | LoadImageFile(const std::string& image_path, uint32_t input_image_height, uint32_t input_image_width);
29 |
30 | float ComputeIntersectionOverUnion(const BoxCornerEncoding& box_i, const BoxCornerEncoding& box_j);
31 |
32 | std::vector NonMaxSuppression(std::vector boxes, const float iou_threshold);
33 |
34 | void AddBoundingBoxAndLabel(cv::Mat& image, const BoxCornerEncoding& result, const float ratio_h, const float ratio_w);
35 | } // namespace Utils
36 |
--------------------------------------------------------------------------------
/apps/windows/cpp/ObjectDetection/assets/images/keyboard.jpg:
--------------------------------------------------------------------------------
1 | version https://git-lfs.github.com/spec/v1
2 | oid sha256:651b4d94a462899df173647f7af22b71d5b3e4735533c072bbf81557a1ac1524
3 | size 2338267
4 |
--------------------------------------------------------------------------------
/apps/windows/cpp/ObjectDetection/assets/images/kitchen.jpg:
--------------------------------------------------------------------------------
1 | version https://git-lfs.github.com/spec/v1
2 | oid sha256:f23d37c2829edd4308e17a39a35a748a903a37e02855abaafb22da6ec53411fe
3 | size 3300891
4 |
--------------------------------------------------------------------------------
/apps/windows/cpp/ObjectDetection/assets/images/sample_outputs/kitchen_output.jpg:
--------------------------------------------------------------------------------
1 | version https://git-lfs.github.com/spec/v1
2 | oid sha256:b94c6697d19461f0f7cf31ea42f21a6c2ab38889c7a841707ce526208bc80eb7
3 | size 3457397
4 |
--------------------------------------------------------------------------------
/apps/windows/cpp/ObjectDetection/assets/models/README.md:
--------------------------------------------------------------------------------
1 | # Model assets for Object Detection CLI app
2 |
3 | Please download [YoloV8 Detection ONNX model from AI Hub](https://aihub.qualcomm.com/compute/models/yolov8_det]) and place it in here.
4 |
--------------------------------------------------------------------------------
/apps/windows/cpp/ObjectDetection/packages.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/apps/windows/cpp/ObjectDetection/vcpkg-configuration.json:
--------------------------------------------------------------------------------
1 | {
2 | "default-registry": {
3 | "kind": "git",
4 | "baseline": "7f9f0e44db287e8e67c0e888141bfa200ab45121",
5 | "repository": "https://github.com/microsoft/vcpkg"
6 | },
7 | "registries": [
8 | {
9 | "kind": "artifact",
10 | "location": "https://github.com/microsoft/vcpkg-ce-catalog/archive/refs/heads/main.zip",
11 | "name": "microsoft"
12 | }
13 | ]
14 | }
15 |
--------------------------------------------------------------------------------
/apps/windows/cpp/ObjectDetection/vcpkg.json:
--------------------------------------------------------------------------------
1 | {
2 | "dependencies": [
3 | "opencv"
4 | ],
5 | "overrides": [
6 | {
7 | "name": "liblzma",
8 | "version": "5.4.4"
9 | }
10 | ]
11 | }
12 |
--------------------------------------------------------------------------------
/apps/windows/cpp/SuperResolution/SuperResolution.sln:
--------------------------------------------------------------------------------
1 | Microsoft Visual Studio Solution File, Format Version 12.00
2 | # Visual Studio Version 17
3 | VisualStudioVersion = 17.10.35122.118
4 | MinimumVisualStudioVersion = 10.0.40219.1
5 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "SuperResolution", "SuperResolution.vcxproj", "{9FBEC759-7D77-40FC-A26F-57D9EFAC9570}"
6 | EndProject
7 | Global
8 | GlobalSection(SolutionConfigurationPlatforms) = preSolution
9 | Debug|ARM64 = Debug|ARM64
10 | Release|ARM64 = Release|ARM64
11 | EndGlobalSection
12 | GlobalSection(ProjectConfigurationPlatforms) = postSolution
13 | {9FBEC759-7D77-40FC-A26F-57D9EFAC9570}.Debug|ARM64.ActiveCfg = Debug|ARM64
14 | {9FBEC759-7D77-40FC-A26F-57D9EFAC9570}.Debug|ARM64.Build.0 = Debug|ARM64
15 | {9FBEC759-7D77-40FC-A26F-57D9EFAC9570}.Release|ARM64.ActiveCfg = Release|ARM64
16 | {9FBEC759-7D77-40FC-A26F-57D9EFAC9570}.Release|ARM64.Build.0 = Release|ARM64
17 | EndGlobalSection
18 | GlobalSection(SolutionProperties) = preSolution
19 | HideSolutionNode = FALSE
20 | EndGlobalSection
21 | GlobalSection(ExtensibilityGlobals) = postSolution
22 | SolutionGuid = {61D3F9A3-0614-4037-9983-21060BB2B0E0}
23 | EndGlobalSection
24 | EndGlobal
25 |
--------------------------------------------------------------------------------
/apps/windows/cpp/SuperResolution/SuperResolution.vcxproj.filters:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF}
6 | cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx
7 |
8 |
9 | {93995380-89BD-4b04-88EB-625FBE52EBFB}
10 | h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd
11 |
12 |
13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01}
14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms
15 |
16 |
17 |
18 |
19 | Source Files
20 |
21 |
22 | Source Files
23 |
24 |
25 | Source Files
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 | Header Files
40 |
41 |
42 | Header Files
43 |
44 |
45 |
46 |
--------------------------------------------------------------------------------
/apps/windows/cpp/SuperResolution/SuperResolution.vcxproj.user:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | --backend npu --model $(ProjectDir)/assets/models/xlsr.onnx --image $(ProjectDir)/assets/images/Doll.jpg
5 | WindowsLocalDebugger
6 |
7 |
8 | false
9 |
10 |
11 | $(TargetPath)
12 | WindowsLocalDebugger
13 | --backend npu --model $(ProjectDir)/assets/models/xlsr.onnx --image $(ProjectDir)/assets/images/Doll.jpg
14 |
15 |
16 |
--------------------------------------------------------------------------------
/apps/windows/cpp/SuperResolution/SuperResolutionApp.hpp:
--------------------------------------------------------------------------------
1 | // ---------------------------------------------------------------------
2 | // Copyright (c) 2024 Qualcomm Innovation Center, Inc. All rights reserved.
3 | // SPDX-License-Identifier: BSD-3-Clause
4 | // ---------------------------------------------------------------------
5 | #pragma once
6 |
7 | #include
8 | #include
9 | #include
10 |
11 | #include
12 |
13 | #include
14 |
15 | namespace App
16 | {
17 |
18 | enum Precision
19 | {
20 | Fp32 = 0,
21 | Fp16 = 1
22 | };
23 |
24 | enum BackendOption
25 | {
26 | Cpu = 0,
27 | Npu = 2,
28 | };
29 |
30 | class SuperResolutionApp
31 | {
32 | private:
33 | // model io pointing to loaded data
34 | std::vector m_inputs;
35 | std::vector m_outputs;
36 |
37 | std::vector m_input_names;
38 | // Keep io names alive returned by session
39 | std::vector m_io_data_ptr;
40 |
41 | // model metadata
42 | uint32_t m_model_input_ht, m_model_input_wt, m_model_scale;
43 | std::string m_model_path;
44 |
45 | Ort::Env m_env;
46 | std::unique_ptr m_session;
47 | Ort::AllocatorWithDefaultOptions m_allocator;
48 |
49 | void ClearInputsAndOutputs();
50 |
51 | public:
52 | SuperResolutionApp(std::string model_path, uint32_t model_input_ht, uint32_t model_input_wt, uint32_t model_Scale);
53 | SuperResolutionApp() = delete;
54 | SuperResolutionApp(const SuperResolutionApp&) = delete;
55 | SuperResolutionApp(SuperResolutionApp&&) = delete;
56 | SuperResolutionApp& operator=(const SuperResolutionApp&) = delete;
57 | SuperResolutionApp& operator=(SuperResolutionApp&&) = delete;
58 |
59 | /**
60 | * PrepareModelForInference: Prepares model for inference with ORT
61 | * - initializes ORT Session
62 | * - sets backend, precision and qnn_options for execution provider
63 | *
64 | * @param backend: backend for model execution.
65 | * @param precision: preferred precision for model execution.
66 | * @param qnn_options: QNN Execution provider options.
67 | * refer to
68 | * https://onnxruntime.ai/docs/execution-providers/QNN-ExecutionProvider.html#configuration-options
69 | * for all supported options.
70 | *
71 | */
72 | void PrepareModelForInference(const App::BackendOption backend,
73 | const App::Precision precision,
74 | std::unordered_map qnn_options);
75 |
76 | /**
77 | * LoadInputs: Load and prepare local image for model inference
78 | * - Loads image with opencv
79 | * - Converts image to Ort::OrtTensor to use during model inference
80 | *
81 | * @param image_path: local path to image to load.
82 | *
83 | */
84 | void LoadInputs(const std::string& image_path);
85 |
86 | /**
87 | * RunInference: Execute prepared model
88 | * - Runs inference and cache output
89 | *
90 | * @throws if model is not prepared with PrepareModelForInference before
91 | * @throws if inputs are not loaded with LoadInputs before
92 | *
93 | */
94 | void RunInference();
95 |
96 | /**
97 | * ProcessOutput: Process cached model output to show results
98 | *
99 | * @param input_image_path input image to add bounding boxes and labels.
100 | * @param display_output_image if true, shows output image in window using
101 | * opencv.
102 | * @param output_image_path if provided, serializes output image locally.
103 | *
104 | */
105 | void ProcessOutput(const std::string& input_image_path,
106 | std::optional output_image_path = std::nullopt,
107 | bool display_output_image = true);
108 | };
109 | } // namespace App
110 |
--------------------------------------------------------------------------------
/apps/windows/cpp/SuperResolution/Utilities.cpp:
--------------------------------------------------------------------------------
1 | // ---------------------------------------------------------------------
2 | // Copyright (c) 2024 Qualcomm Innovation Center, Inc. All rights reserved.
3 | // SPDX-License-Identifier: BSD-3-Clause
4 | // ---------------------------------------------------------------------
5 | #include
6 | #include
7 | #include
8 | #include
9 | #include
10 | #include
11 |
12 | #include "Utilities.hpp"
13 |
14 | namespace Utils
15 | {
16 |
17 | void AddText(const cv::Mat& img, const std::string& msg)
18 | {
19 | int font_face = cv::FONT_HERSHEY_SIMPLEX;
20 | double font_scale = 1;
21 | int thickness = 2;
22 | int baseline = 0;
23 |
24 | cv::Size text_size = cv::getTextSize(msg, font_face, font_scale, thickness, &baseline);
25 | cv::Point text_position((img.cols - text_size.width) / 2, text_size.height + 10);
26 | cv::rectangle(img, text_position + cv::Point(0, baseline),
27 | text_position + cv::Point(text_size.width, -text_size.height), cv::Scalar(255, 255, 255), cv::FILLED);
28 | cv::putText(img, msg, text_position, font_face, font_scale, cv::Scalar(0, 0, 0), thickness);
29 | }
30 |
31 | std::vector LoadImageFile(const std::string& image_path, uint32_t input_image_height, uint32_t input_image_width)
32 | {
33 | cv::Mat image = cv::imread(image_path);
34 |
35 | if (image.empty())
36 | {
37 | std::ostringstream msg;
38 | msg << "Input image not found at " << image_path << ".\n Please provide full path to input image.";
39 | throw std::runtime_error(msg.str());
40 | }
41 |
42 | // Convert the image from BGR to RGB color space and resizing to the specified dimensions
43 | cvtColor(image, image, cv::COLOR_BGR2RGB);
44 | resize(image, image, cv::Size(input_image_width, input_image_height));
45 |
46 | // Flatten the image to a single row (1 x (height * width * channels))
47 | image = image.reshape(1, 1);
48 |
49 | std::vector vec;
50 |
51 | // Convert the image to a vector of floats and normalize pixel values to [0, 1]
52 | image.convertTo(vec, CV_32FC1, 1.0 / 255.0);
53 |
54 | std::vector output;
55 | output.reserve(vec.size());
56 |
57 | // Transpose the image data to (channels x height x width)
58 | for (size_t ch = 0; ch < 3; ++ch)
59 | {
60 | for (size_t i = ch; i < vec.size(); i += 3)
61 | {
62 | output.push_back(vec[i]);
63 | }
64 | }
65 | return output;
66 | }
67 |
68 | } // namespace Utils
69 |
--------------------------------------------------------------------------------
/apps/windows/cpp/SuperResolution/Utilities.hpp:
--------------------------------------------------------------------------------
1 | // ---------------------------------------------------------------------
2 | // Copyright (c) 2024 Qualcomm Innovation Center, Inc. All rights reserved.
3 | // SPDX-License-Identifier: BSD-3-Clause
4 | // ---------------------------------------------------------------------
5 | #pragma once
6 |
7 | #include
8 | #include
9 |
10 | namespace Utils
11 | {
12 |
13 | void AddText(const cv::Mat& img, const std::string& msg);
14 |
15 | std::vector
16 | LoadImageFile(const std::string& image_path, uint32_t input_image_height, uint32_t input_image_width);
17 |
18 | } // namespace Utils
19 |
--------------------------------------------------------------------------------
/apps/windows/cpp/SuperResolution/assets/images/Doll.jpg:
--------------------------------------------------------------------------------
1 | version https://git-lfs.github.com/spec/v1
2 | oid sha256:811f0c08ff16ef506de4855ca2b609ba6c67622f5d65550896cdd7e60c200db2
3 | size 17244
4 |
--------------------------------------------------------------------------------
/apps/windows/cpp/SuperResolution/assets/images/UpscaledImage.png:
--------------------------------------------------------------------------------
1 | version https://git-lfs.github.com/spec/v1
2 | oid sha256:0eab02dcb01a25a9c6493cc74c933d7b0b6bfafa34b47c4698e60d1db1c209da
3 | size 339479
4 |
--------------------------------------------------------------------------------
/apps/windows/cpp/SuperResolution/assets/models/README.md:
--------------------------------------------------------------------------------
1 | # Model assets for SuperResolution CLI app
2 |
3 | Please download [XLSR ONNX model from AI Hub](https://aihub.qualcomm.com/compute/models/xlsr]) and place it in here.
4 |
--------------------------------------------------------------------------------
/apps/windows/cpp/SuperResolution/packages.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/apps/windows/cpp/SuperResolution/vcpkg-configuration.json:
--------------------------------------------------------------------------------
1 | {
2 | "default-registry": {
3 | "kind": "git",
4 | "baseline": "7f9f0e44db287e8e67c0e888141bfa200ab45121",
5 | "repository": "https://github.com/microsoft/vcpkg"
6 | },
7 | "registries": [
8 | {
9 | "kind": "artifact",
10 | "location": "https://github.com/microsoft/vcpkg-ce-catalog/archive/refs/heads/main.zip",
11 | "name": "microsoft"
12 | }
13 | ]
14 | }
15 |
--------------------------------------------------------------------------------
/apps/windows/cpp/SuperResolution/vcpkg.json:
--------------------------------------------------------------------------------
1 | {
2 | "dependencies": [
3 | "opencv"
4 | ],
5 | "overrides": [
6 | {
7 | "name": "liblzma",
8 | "version": "5.4.4"
9 | }
10 | ]
11 | }
12 |
--------------------------------------------------------------------------------
/apps/windows/python/BringYourOwnModel/README.md:
--------------------------------------------------------------------------------
1 | ## Bring your own PyTorch Model and run it on Snapdragon X Elite
2 |
3 | [Find the README and instructions here.](https://tinyurl.com/QCOMBuildDemo)
4 | This demo is temporarily available for Microsoft build.
5 |
--------------------------------------------------------------------------------
/apps/windows/python/StableDiffusion/README.md:
--------------------------------------------------------------------------------
1 | ## Run Stable Diffusion on Snapdragon X Elite
2 |
3 | Follow instructions to run the demo:
4 |
5 | 1. Download ONNX model files from https://aihub.qualcomm.com/models/stable_diffusion_v2_1:
6 | * Unzip each file.
7 | * Move each file to `.\models`
8 | * Rename each FOLDER to `text_encoder.onnx`, `unet.onnx`, and `vae_decoder.onnx`, respectively.
9 |
10 | In the end, your `.\models` folder should look like this:
11 | ```
12 | models\
13 | text_encoder.onnx\
14 | model.bin
15 | model.onnx
16 | unet.onnx\
17 | model.bin
18 | model.onnx
19 | vae_decoder.onnx\
20 | model.bin
21 | model.onnx
22 | ```
23 |
24 | 2. Enable PowerShell Scripts. Open PowerShell in administrator mode, and run:
25 |
26 | ```powershell
27 | Set-ExecutionPolicy -Scope CurrentUser Unrestricted -Force
28 | ```
29 |
30 | 3. Open Anaconda PowerShell Prompt in this folder. If you don't have Anaconda PowerShell, use regular PowerShell.
31 |
32 | 4. Install platform dependencies:
33 |
34 | ```powershell
35 | ..\install_platform_deps.ps1
36 | ```
37 |
38 | The above script will install:
39 | * Anaconda for x86-64. We use x86-64 Python for compatibility with other Python packages. However, inference in ONNX Runtime will, for the most part, run natively with ARM64 code.
40 | * Git for Windows. This is required to load the AI Hub Models package, which contains the application code used by this demo.
41 |
42 | 5. Open (or re-open) Anaconda Powershell Prompt to continue.
43 |
44 | 6. Create & activate your python environment:
45 |
46 | ```powershell
47 | ..\activate_venv.ps1 -name AI_Hub
48 | ```
49 |
50 | 7. Install python packages:
51 |
52 | ```powershell
53 | ..\install_python_deps.ps1 -model stable-diffusion-v2-1-quantized
54 | ```
55 |
56 | In your currently active python environment, the above script will install:
57 | * AI Hub Models and model dependencies for stable diffusion.
58 | * The onnxruntime-qnn package, both to enable native ARM64 ONNX inference, as well as to enable targeting Qualcomm NPUs.
59 |
60 | 8. Run demo:
61 |
62 | ```powershell
63 | python demo.py --prompt "A girl taking a walk at sunset" --num-steps 20
64 | ```
65 |
--------------------------------------------------------------------------------
/apps/windows/python/StableDiffusion/demo.py:
--------------------------------------------------------------------------------
1 | # ---------------------------------------------------------------------
2 | # Copyright (c) 2024 Qualcomm Innovation Center, Inc. All rights reserved.
3 | # SPDX-License-Identifier: BSD-3-Clause
4 | # ---------------------------------------------------------------------
5 | import argparse
6 |
7 | import numpy as np
8 | from diffusers import EulerDiscreteScheduler
9 | from PIL import Image
10 | from qai_hub_models.models._shared.stable_diffusion.app import StableDiffusionApp
11 | from qai_hub_models.utils.args import add_output_dir_arg
12 | from qai_hub_models.utils.display import display_or_save_image, to_uint8
13 | from qai_hub_models.utils.onnx_torch_wrapper import (
14 | OnnxModelTorchWrapper,
15 | OnnxSessionOptions,
16 | )
17 | from transformers import CLIPTokenizer
18 |
19 | DEFAULT_PROMPT = "A girl taking a walk at sunset"
20 | HF_REPO = "stabilityai/stable-diffusion-2-1-base"
21 |
22 |
23 | def main():
24 | parser = argparse.ArgumentParser(
25 | formatter_class=argparse.ArgumentDefaultsHelpFormatter,
26 | conflict_handler="error",
27 | )
28 | parser.add_argument(
29 | "--prompt",
30 | type=str,
31 | default=DEFAULT_PROMPT,
32 | help="Prompt for stable diffusion",
33 | )
34 | parser.add_argument(
35 | "--num-steps",
36 | type=int,
37 | default=20,
38 | help="Number of diffusion steps",
39 | )
40 | parser.add_argument(
41 | "--seed",
42 | type=int,
43 | default=42,
44 | help="Random generator seed",
45 | )
46 | parser.add_argument(
47 | "--text-encoder",
48 | type=str,
49 | default="models\\text_encoder.onnx\\model.onnx",
50 | help="Text Encoder ONNX model path",
51 | )
52 | parser.add_argument(
53 | "--unet",
54 | type=str,
55 | default="models\\unet.onnx\\model.onnx",
56 | help="UNET ONNX model path",
57 | )
58 | parser.add_argument(
59 | "--vae-decoder",
60 | type=str,
61 | default="models\\vae_decoder.onnx\\model.onnx",
62 | help="VAE Decoder ONNX model path",
63 | )
64 | add_output_dir_arg(parser)
65 | args = parser.parse_args()
66 |
67 | # Disable compile caching becuase Stable Diffusion is Pre-Compiled
68 | # This is needed due to a bug in onnxruntime 1.22, and can be removed after the next ORT release.
69 | options = OnnxSessionOptions.aihub_defaults()
70 | options.context_enable = False
71 |
72 | # Load model
73 | print("Loading model and app...")
74 | sdapp = StableDiffusionApp(
75 | OnnxModelTorchWrapper.OnNPU(args.text_encoder, options),
76 | OnnxModelTorchWrapper.OnNPU(args.vae_decoder, options),
77 | OnnxModelTorchWrapper.OnNPU(args.unet, options),
78 | CLIPTokenizer.from_pretrained(HF_REPO, subfolder="tokenizer"),
79 | EulerDiscreteScheduler.from_pretrained(HF_REPO, subfolder="scheduler"),
80 | channel_last_latent=True,
81 | )
82 |
83 | # Generate image
84 | print("Generating image...")
85 | image = sdapp.generate_image(args.prompt, args.num_steps, args.seed)
86 | pil_img = Image.fromarray(to_uint8(np.asarray(image))[0])
87 | display_or_save_image(pil_img, args.output_dir)
88 |
89 |
90 | if __name__ == "__main__":
91 | main()
92 |
--------------------------------------------------------------------------------
/apps/windows/python/Whisper/README.md:
--------------------------------------------------------------------------------
1 | ## Run Whisper on Snapdragon X Elite
2 |
3 | Follow instructions to run the demo:
4 |
5 | 1. Enable PowerShell Scripts. Open PowerShell in administrator mode, and run:
6 |
7 | ```powershell
8 | Set-ExecutionPolicy -Scope CurrentUser Unrestricted -Force
9 | ```
10 |
11 | 2. Open Anaconda PowerShell Prompt in this folder. If you don't have Anaconda PowerShell, use regular PowerShell.
12 |
13 | 3. Install platform dependencies:
14 |
15 | ```powershell
16 | ..\install_platform_deps.ps1 -extra_pkgs ffmpeg
17 | ```
18 |
19 | The above script will install:
20 | * Anaconda for x86-64. We use x86-64 Python for compatibility with other Python packages. However, inference in ONNX Runtime will, for the most part, run natively with ARM64 code.
21 | * Git for Windows. This is required to load the AI Hub Models package, which contains the application code used by this demo.
22 | * ffmpeg for reading audio files (Note that as of writing this, WinGet does not have an ARM64 distribution of ffmpeg. You will install a slower emulated x86-64 ffmpeg distribution instead.)
23 |
24 | 4. Open (or re-open) Anaconda Powershell Prompt to continue.
25 |
26 | 5. Create & activate your python environment:
27 |
28 | ```powershell
29 | ..\activate_venv.ps1 -name AI_Hub
30 | ```
31 |
32 | 6. Install python packages:
33 |
34 | ```powershell
35 | ..\install_python_deps.ps1 -model whisper-base-en
36 | ```
37 |
38 | In your currently active python environment, the above script will install:
39 | * AI Hub Models and dependencies for whisper.
40 | * The onnxruntime-qnn package, both to enable native ARM64 ONNX inference, as well as to enable targeting Qualcomm NPUs.
41 |
42 | 7. Export model:
43 |
44 | ```powershell
45 | python -m qai_hub_models.models.whisper_base_en.export --target-runtime onnx --device "Snapdragon X Elite CRD" --skip-profiling --skip-inferencing
46 | ```
47 |
48 | 8. Get microphone device number:
49 |
50 | ```powershell
51 | python demo.py --list-audio-devices
52 | ```
53 |
54 | 9. Stream whisper from your microphone:
55 |
56 | ```powershell
57 | python demo.py --stream-audio-device
58 | ```
59 |
--------------------------------------------------------------------------------
/apps/windows/python/Whisper/demo.py:
--------------------------------------------------------------------------------
1 | # ---------------------------------------------------------------------
2 | # Copyright (c) 2024 Qualcomm Innovation Center, Inc. All rights reserved.
3 | # SPDX-License-Identifier: BSD-3-Clause
4 | # ---------------------------------------------------------------------
5 | import argparse
6 | from datetime import datetime
7 |
8 | import sounddevice as sd
9 | from qai_hub_models.models._shared.whisper.app import WhisperApp
10 | from qai_hub_models.utils.onnx_torch_wrapper import OnnxModelTorchWrapper
11 |
12 |
13 | def main():
14 | parser = argparse.ArgumentParser(
15 | formatter_class=argparse.ArgumentDefaultsHelpFormatter,
16 | conflict_handler="error",
17 | )
18 | parser.add_argument(
19 | "--audio-file",
20 | type=str,
21 | default=None,
22 | help="Audio file path or URL",
23 | )
24 | parser.add_argument(
25 | "--stream-audio-device",
26 | type=int,
27 | default=None,
28 | help="Audio device (number) to stream from.",
29 | )
30 | parser.add_argument(
31 | "--stream-audio-chunk-size",
32 | type=int,
33 | default=10,
34 | help="For audio streaming, the number of seconds to record between each transcription attempt. A minimum of around 10 seconds is recommended for best accuracy.",
35 | )
36 | parser.add_argument(
37 | "--list-audio-devices",
38 | action="store_true",
39 | help="Pass this to list audio devices and exit.",
40 | )
41 | parser.add_argument(
42 | "--encoder-path",
43 | type=str,
44 | default="build\\whisper_base_en\\WhisperEncoderInf.onnx",
45 | help="Encoder model path",
46 | )
47 | parser.add_argument(
48 | "--decoder-path",
49 | type=str,
50 | default="build\\whisper_base_en\\WhisperDecoderInf.onnx",
51 | help="Decoder model path",
52 | )
53 | args = parser.parse_args()
54 |
55 | if args.list_audio_devices:
56 | print(sd.query_devices())
57 | return
58 |
59 | print("Loading model...")
60 | app = WhisperApp(
61 | OnnxModelTorchWrapper.OnNPU(args.encoder_path),
62 | OnnxModelTorchWrapper.OnNPU(args.decoder_path),
63 | num_decoder_blocks=6,
64 | num_decoder_heads=8,
65 | attention_dim=512,
66 | mean_decode_len=224,
67 | )
68 |
69 | if args.stream_audio_device:
70 | app.stream(args.stream_audio_device, args.stream_audio_chunk_size)
71 | else:
72 | audio = args.audio_file
73 | assert (
74 | audio is not None
75 | ), "No audio file selected. Pass --audio-file or stream from a microphone using --stream-audio-device"
76 |
77 | # Perform transcription
78 | print("Before transcription: " + str(datetime.now().astimezone()))
79 | transcription = app.transcribe(audio)
80 | print(f"Transcription: {transcription}")
81 | print("After transcription: " + str(datetime.now().astimezone()))
82 |
83 |
84 | if __name__ == "__main__":
85 | main()
86 |
--------------------------------------------------------------------------------
/apps/windows/python/activate_venv.ps1:
--------------------------------------------------------------------------------
1 | param (
2 | [string]$name = "AI_Hub",
3 | [string]$python = "3.10"
4 | )
5 |
6 | # Check if conda is available
7 | if (-not (Get-Command conda -ErrorAction SilentlyContinue)) {
8 | Write-Host "Anaconda could not be found!"
9 | Write-Host "Run install_platform_deps.ps1 to install miniconda3. Open Anaconda PowerShell Prompt and re-run this script to continue."
10 | } else {
11 | # Create & activate environment
12 | $condaEnvExists = conda env list | Select-String -Pattern $name
13 | if (-not $condaEnvExists) {
14 | Write-Host "Conda environment '$name' does not exist. Creating it now..."
15 | conda create -n $name -y python=$python
16 | Write-Host "Conda environment '$name' created."
17 | }
18 | conda activate $name
19 | Write-Host "Your environment is activated and ready to run demos!"
20 | }
21 |
--------------------------------------------------------------------------------
/apps/windows/python/install_platform_deps.ps1:
--------------------------------------------------------------------------------
1 | param (
2 | [string]$extra_pkgs = ""
3 | )
4 |
5 | # Add winget to system path if it's missing.
6 | $windowsAppsPath = "$env:userprofile\AppData\Local\Microsoft\WindowsApps"
7 | if (-not (Get-Command winget -ErrorAction SilentlyContinue) -and (Test-Path "$windowsAppsPath\winget.exe")) {
8 | Write-Host "Found WinGet on your system, but it is not in the PATH. This is required to install demo dependencies."
9 | $response = Read-Host "Do you want add WinGet to your PATH? (y/n)"
10 | if ($response -eq 'y' -or $response -eq 'Y' -or $response -eq 'yes' -or $response -eq 'Yes') {
11 | [System.Environment]::SetEnvironmentVariable("PATH", "$env:Path;$windowsAppsPath", [System.EnvironmentVariableTarget]::User)
12 | $env:Path += ";$windowsAppsPath"
13 | Write-Host "WinGet added to PATH successfully."
14 | }
15 | }
16 |
17 | if (Get-Command winget -ErrorAction SilentlyContinue) {
18 | $missing_deps = $false
19 |
20 | $choice = Read-Host "Install miniconda3? (y/n)"
21 | if ($choice -eq "y") {
22 | $spaceCount = ($env:userprofile -split " ").Length - 1
23 | if ($spaceCount -gt 0) {
24 | # Anaconda PowerShell breaks when there is a space in the base install path.
25 | #
26 | # The installation directory that winget uses includes the current username. If the current username
27 | # has a space, we need to elevate privileges and install globally, so conda is installed in C:\ProgramFiles instead.
28 | Write-Output "`n!!!!!`n"
29 | Write-Output "Your home directory has a space, which can break conda packages. Conda must be installed globally to avoid this."
30 | Write-Output "Open PowerShell in administrator mode and run:`n"
31 | Write-Output " winget install miniconda3 --architecture X64 --scope machine"
32 | Write-Output "`nto install conda."
33 | Write-Output "`n!!!!!`n"
34 | $missing_deps = $true
35 | } else {
36 | winget install miniconda3 --architecture X64
37 | }
38 | } else {
39 | $missing_deps = $true
40 | }
41 |
42 | $choice = Read-Host "Install Git (Microsoft.Git)? (y/n)"
43 | if ($choice -eq "y") {
44 | winget install Microsoft.Git
45 | } else {
46 | $missing_deps = $true
47 | }
48 |
49 | if ($extra_pkgs -ne "") {
50 | $choice = Read-Host "Install packages: $extra_pkgs ? (y/n)"
51 | if ($choice -eq "y") {
52 | winget install $extra_pkgs
53 | } else {
54 | $missing_deps = $true
55 | }
56 | }
57 |
58 | if ($missing_deps) {
59 | Write-Output "`n!!!!!`n"
60 | Write-Host "Some dependencies were not installed."
61 | Write-Output "`n!!!!!`n"
62 | } else {
63 | Write-Host "`nAll platform dependencies installed.`n"
64 | }
65 | Write-Host "Open Anaconda PowerShell Prompt in a NEW WINDOW to continue.`n"
66 | } else {
67 | Write-Host "WinGet could not be found. We need it to install demo dependencies. You can get it in the Windows Store: https://apps.microsoft.com/detail/9nblggh4nns1"
68 | }
69 |
--------------------------------------------------------------------------------
/apps/windows/python/install_python_deps.ps1:
--------------------------------------------------------------------------------
1 | param (
2 | [string]$model,
3 | [string]$extra_reqs_file = ""
4 | )
5 |
6 | python -m pip install "qai_hub_models[$model]==0.29"
7 | # Onnxruntime and onnxruntime-qnn conflict because they install the same binaries.
8 | # Uninstall both to avoid conflicts. Then reinstall qnn to make sure we have the right binaries.
9 | python -m pip uninstall --yes onnxruntime onnxruntime-qnn
10 | python -m pip install onnxruntime-qnn==1.22
11 |
12 | if ($extra_reqs_file -ne "") {
13 | python -m pip install $extra_reqs_file
14 | }
15 |
--------------------------------------------------------------------------------
/mypy.ini:
--------------------------------------------------------------------------------
1 | [mypy]
2 | # https://mypy.readthedocs.io/en/stable/config_file.html#import-discovery
3 |
--------------------------------------------------------------------------------
/tutorials/deploy/onnx/README.md:
--------------------------------------------------------------------------------
1 | ## Deployable ONNX Asset
2 |
3 | Users can use the script `build_deployable_asset.py` to convert their quantized ONNX models to the deployable asset for their applications.
4 |
5 | ## Future Work
6 |
7 | AI Hub's profile and inference jobs, the ONNX graph (if it is quantized) would be transformed to op-centric quantized representation that has a one-to-one mapping with a QOp representation. The weights would be stored quantized which helps map cleanly to QOp. This leads to better performance on device and reduces the memory footprint of the model.
8 |
9 | ### Example to run the script
10 |
11 | 1. Install the dependencies to run the script.
12 |
13 | ```bash
14 | cd deploy/onnx && pip install -r requirements.txt
15 | ```
16 |
17 | 1. Export AI Hub Model which uses Quantize Jobs and target ONNX as the runtime.
18 |
19 | ```bash
20 | python qai_hub_models/models/googlenet_quantized/export.py --target-runtime onnx
21 | ```
22 |
23 | The export script downloads the compiled asset to your local machine.
24 |
25 | 1. Use the compiled asset and convert to a deployable ONNX asset.
26 |
27 | ```bash
28 | python build_deployable_asset.py -f /path/to/compiled/onnx/asset
29 | ```
30 |
31 | The modified model will be saved in the same path provided. This ONNX model can be moved to your application and deployed.
32 |
--------------------------------------------------------------------------------
/tutorials/deploy/onnx/requirements.txt:
--------------------------------------------------------------------------------
1 | onnx-graphsurgeon==0.5.2
2 | onnx==1.17.0
3 | numpy==1.24.3
4 | qai-hub-models
5 |
--------------------------------------------------------------------------------
/tutorials/llm_on_genie/configs/genie/baichuan2_7b.json:
--------------------------------------------------------------------------------
1 | {
2 | "dialog": {
3 | "version": 1,
4 | "type": "basic",
5 | "context": {
6 | "version": 1,
7 | "size": 4096,
8 | "n-vocab": 125696,
9 | "bos-token": 1,
10 | "eos-token": 2
11 | },
12 | "sampler": {
13 | "version": 1,
14 | "seed": 42,
15 | "temp": 0.8,
16 | "top-k": 40,
17 | "top-p": 0.95
18 | },
19 | "tokenizer": {
20 | "version": 1,
21 | "path": "tokenizer.json"
22 | },
23 | "engine": {
24 | "version": 1,
25 | "n-threads": 3,
26 | "backend": {
27 | "version": 1,
28 | "type": "QnnHtp",
29 | "QnnHtp": {
30 | "version": 1,
31 | "use-mmap": true,
32 | "spill-fill-bufsize": 0,
33 | "mmap-budget": 0,
34 | "poll": false,
35 | "cpu-mask": "0xe0",
36 | "kv-dim": 128,
37 | "rope-theta": 10000,
38 | "pos-id-dim" : 64,
39 | "allow-async-init": false
40 | },
41 | "extensions": "htp_backend_ext_config.json"
42 | },
43 | "model": {
44 | "version": 1,
45 | "type": "binary",
46 | "binary": {
47 | "version": 1,
48 | "ctx-bins": [
49 | "weight_sharing_model_1_of_5.serialized.bin",
50 | "weight_sharing_model_2_of_5.serialized.bin",
51 | "weight_sharing_model_3_of_5.serialized.bin",
52 | "weight_sharing_model_4_of_5.serialized.bin",
53 | "weight_sharing_model_5_of_5.serialized.bin"
54 | ]
55 | }
56 | }
57 | }
58 | }
59 | }
60 |
--------------------------------------------------------------------------------
/tutorials/llm_on_genie/configs/genie/ibm_granite_v3_1_8b_instruct.json:
--------------------------------------------------------------------------------
1 | {
2 | "dialog": {
3 | "version": 1,
4 | "type": "basic",
5 | "context": {
6 | "version": 1,
7 | "size": 4096,
8 | "n-vocab": 49155,
9 | "bos-token": 0,
10 | "eos-token": 0,
11 | "pad-token": 0
12 | },
13 | "sampler": {
14 | "version": 1,
15 | "seed": 42,
16 | "temp": 0.8,
17 | "top-k": 40,
18 | "top-p": 0.95
19 | },
20 | "tokenizer": {
21 | "version": 1,
22 | "path": "tokenizer.json"
23 | },
24 | "engine": {
25 | "version": 1,
26 | "n-threads": 3,
27 | "backend": {
28 | "version": 1,
29 | "type": "QnnHtp",
30 | "QnnHtp": {
31 | "version": 1,
32 | "use-mmap": true,
33 | "spill-fill-bufsize": 0,
34 | "mmap-budget": 0,
35 | "poll": true,
36 | "cpu-mask": "0xe0",
37 | "kv-dim": 128,
38 | "allow-async-init": false
39 | },
40 | "extensions": "htp_backend_ext_config.json"
41 | },
42 | "model": {
43 | "version": 1,
44 | "type": "binary",
45 | "binary": {
46 | "version": 1,
47 | "ctx-bins": [
48 | "weight_sharing_model_1_of_5.serialized.bin",
49 | "weight_sharing_model_2_of_5.serialized.bin",
50 | "weight_sharing_model_3_of_5.serialized.bin",
51 | "weight_sharing_model_4_of_5.serialized.bin",
52 | "weight_sharing_model_5_of_5.serialized.bin"
53 | ]
54 | },
55 | "positional-encoding": {
56 | "type": "rope",
57 | "rope-dim": 64,
58 | "rope-theta": 10000000
59 | }
60 | }
61 | }
62 | }
63 | }
64 |
--------------------------------------------------------------------------------
/tutorials/llm_on_genie/configs/genie/llama_v2_7b_chat.json:
--------------------------------------------------------------------------------
1 | {
2 | "dialog": {
3 | "version": 1,
4 | "type": "basic",
5 | "context": {
6 | "version": 1,
7 | "size": 1024,
8 | "n-vocab": 32000,
9 | "bos-token": 1,
10 | "eos-token": 2
11 | },
12 | "sampler": {
13 | "version": 1,
14 | "seed": 42,
15 | "temp": 0.8,
16 | "top-k": 40,
17 | "top-p": 0.95
18 | },
19 | "tokenizer": {
20 | "version": 1,
21 | "path": "tokenizer.json"
22 | },
23 | "engine": {
24 | "version": 1,
25 | "n-threads": 4,
26 | "backend": {
27 | "version": 1,
28 | "type": "QnnHtp",
29 | "QnnHtp": {
30 | "version": 1,
31 | "spill-fill-bufsize": 0,
32 | "use-mmap": true,
33 | "mmap-budget": 0,
34 | "poll": true,
35 | "pos-id-dim": 64,
36 | "cpu-mask": "0xe0",
37 | "kv-dim": 128,
38 | "allow-async-init": false
39 | },
40 | "extensions": "htp_backend_ext_config.json"
41 | },
42 | "model": {
43 | "version": 1,
44 | "type": "binary",
45 | "binary": {
46 | "version": 1,
47 | "ctx-bins": [
48 | "Llama2_Part1.bin",
49 | "Llama2_Part2.bin",
50 | "Llama2_Part3.bin",
51 | "Llama2_Part4.bin"
52 | ]
53 | }
54 | }
55 | }
56 | }
57 | }
58 |
--------------------------------------------------------------------------------
/tutorials/llm_on_genie/configs/genie/llama_v3_1_8b_instruct.json:
--------------------------------------------------------------------------------
1 | {
2 | "dialog": {
3 | "version": 1,
4 | "type": "basic",
5 | "context": {
6 | "version": 1,
7 | "size": 4096,
8 | "n-vocab": 128256,
9 | "bos-token": -1,
10 | "eos-token": [128001, 128009, 128008]
11 | },
12 | "sampler": {
13 | "version": 1,
14 | "seed": 42,
15 | "temp": 0.8,
16 | "top-k": 40,
17 | "top-p": 0.95
18 | },
19 | "tokenizer": {
20 | "version": 1,
21 | "path": "tokenizer.json"
22 | },
23 | "engine": {
24 | "version": 1,
25 | "n-threads": 3,
26 | "backend": {
27 | "version": 1,
28 | "type": "QnnHtp",
29 | "QnnHtp": {
30 | "version": 1,
31 | "use-mmap": true,
32 | "spill-fill-bufsize": 0,
33 | "mmap-budget": 0,
34 | "poll": true,
35 | "cpu-mask": "0xe0",
36 | "kv-dim": 128,
37 | "allow-async-init": false
38 | },
39 | "extensions": "htp_backend_ext_config.json"
40 | },
41 | "model": {
42 | "version": 1,
43 | "type": "binary",
44 | "binary": {
45 | "version": 1,
46 | "ctx-bins": [
47 | "llama_v3_1_8b_instruct_part_1_of_5.bin",
48 | "llama_v3_1_8b_instruct_part_2_of_5.bin",
49 | "llama_v3_1_8b_instruct_part_3_of_5.bin",
50 | "llama_v3_1_8b_instruct_part_4_of_5.bin",
51 | "llama_v3_1_8b_instruct_part_5_of_5.bin"
52 | ]
53 | },
54 | "positional-encoding": {
55 | "type": "rope",
56 | "rope-dim": 64,
57 | "rope-theta": 500000,
58 | "rope-scaling": {
59 | "rope-type": "llama3",
60 | "factor": 8.0,
61 | "low-freq-factor": 1.0,
62 | "high-freq-factor": 4.0,
63 | "original-max-position-embeddings": 8192
64 | }
65 | }
66 | }
67 | }
68 | }
69 | }
70 |
--------------------------------------------------------------------------------
/tutorials/llm_on_genie/configs/genie/llama_v3_2_3b_instruct.json:
--------------------------------------------------------------------------------
1 | {
2 | "dialog": {
3 | "version": 1,
4 | "type": "basic",
5 | "context": {
6 | "version": 1,
7 | "size": 4096,
8 | "n-vocab": 128256,
9 | "bos-token": -1,
10 | "eos-token": [128001, 128009, 128008]
11 | },
12 | "sampler": {
13 | "version": 1,
14 | "seed": 42,
15 | "temp": 0.8,
16 | "top-k": 40,
17 | "top-p": 0.95
18 | },
19 | "tokenizer": {
20 | "version": 1,
21 | "path": "tokenizer.json"
22 | },
23 | "engine": {
24 | "version": 1,
25 | "n-threads": 3,
26 | "backend": {
27 | "version": 1,
28 | "type": "QnnHtp",
29 | "QnnHtp": {
30 | "version": 1,
31 | "use-mmap": true,
32 | "spill-fill-bufsize": 0,
33 | "mmap-budget": 0,
34 | "poll": true,
35 | "cpu-mask": "0xe0",
36 | "kv-dim": 128,
37 | "allow-async-init": false
38 | },
39 | "extensions": "htp_backend_ext_config.json"
40 | },
41 | "model": {
42 | "version": 1,
43 | "type": "binary",
44 | "binary": {
45 | "version": 1,
46 | "ctx-bins": [
47 | "llama_v3_2_3b_instruct_part_1_of_3.bin",
48 | "llama_v3_2_3b_instruct_part_2_of_3.bin",
49 | "llama_v3_2_3b_instruct_part_3_of_3.bin"
50 | ]
51 | },
52 | "positional-encoding": {
53 | "type": "rope",
54 | "rope-dim": 64,
55 | "rope-theta": 500000,
56 | "rope-scaling": {
57 | "rope-type": "llama3",
58 | "factor": 8.0,
59 | "low-freq-factor": 1.0,
60 | "high-freq-factor": 4.0,
61 | "original-max-position-embeddings": 8192
62 | }
63 | }
64 | }
65 | }
66 | }
67 | }
68 |
--------------------------------------------------------------------------------
/tutorials/llm_on_genie/configs/genie/llama_v3_8b_instruct.json:
--------------------------------------------------------------------------------
1 | {
2 | "dialog": {
3 | "version": 1,
4 | "type": "basic",
5 | "context": {
6 | "version": 1,
7 | "size": 4096,
8 | "n-vocab": 128256,
9 | "bos-token": 128000,
10 | "eos-token": 128001,
11 | "eot-token": 128009
12 | },
13 | "sampler": {
14 | "version": 1,
15 | "seed": 42,
16 | "temp": 0.8,
17 | "top-k": 40,
18 | "top-p": 0.95
19 | },
20 | "tokenizer": {
21 | "version": 1,
22 | "path": "tokenizer.json"
23 | },
24 | "engine": {
25 | "version": 1,
26 | "n-threads": 3,
27 | "backend": {
28 | "version": 1,
29 | "type": "QnnHtp",
30 | "QnnHtp": {
31 | "version": 1,
32 | "use-mmap": true,
33 | "spill-fill-bufsize": 0,
34 | "mmap-budget": 0,
35 | "poll": true,
36 | "pos-id-dim": 64,
37 | "cpu-mask": "0xe0",
38 | "kv-dim": 128,
39 | "rope-theta": 500000,
40 | "allow-async-init": false
41 | },
42 | "extensions": "htp_backend_ext_config.json"
43 | },
44 | "model": {
45 | "version": 1,
46 | "type": "binary",
47 | "binary": {
48 | "version": 1,
49 | "ctx-bins": [
50 | "llama_v3_8b_instruct_part_1_of_5.bin",
51 | "llama_v3_8b_instruct_part_2_of_5.bin",
52 | "llama_v3_8b_instruct_part_3_of_5.bin",
53 | "llama_v3_8b_instruct_part_4_of_5.bin",
54 | "llama_v3_8b_instruct_part_5_of_5.bin"
55 | ]
56 | }
57 | }
58 | }
59 | }
60 | }
61 |
--------------------------------------------------------------------------------
/tutorials/llm_on_genie/configs/genie/llama_v3_taide_8b_chat.json:
--------------------------------------------------------------------------------
1 | {
2 | "dialog": {
3 | "version": 1,
4 | "type": "basic",
5 | "context": {
6 | "version": 1,
7 | "size": 4096,
8 | "n-vocab": 128256,
9 | "bos-token": 128000,
10 | "eos-token": 128001,
11 | "eot-token": 128009
12 | },
13 | "sampler": {
14 | "version": 1,
15 | "seed": 42,
16 | "temp": 0.8,
17 | "top-k": 40,
18 | "top-p": 0.95
19 | },
20 | "tokenizer": {
21 | "version": 1,
22 | "path": "tokenizer.json"
23 | },
24 | "engine": {
25 | "version": 1,
26 | "n-threads": 3,
27 | "backend": {
28 | "version": 1,
29 | "type": "QnnHtp",
30 | "QnnHtp": {
31 | "version": 1,
32 | "use-mmap": true,
33 | "spill-fill-bufsize": 0,
34 | "mmap-budget": 0,
35 | "poll": true,
36 | "pos-id-dim": 64,
37 | "cpu-mask": "0xe0",
38 | "kv-dim": 128,
39 | "rope-theta": 500000,
40 | "allow-async-init": false
41 | },
42 | "extensions": "htp_backend_ext_config.json"
43 | },
44 | "model": {
45 | "version": 1,
46 | "type": "binary",
47 | "binary": {
48 | "version": 1,
49 | "ctx-bins": [
50 | "llama_v3_taide_8b_chat_part_1_of_5.bin",
51 | "llama_v3_taide_8b_chat_part_2_of_5.bin",
52 | "llama_v3_taide_8b_chat_part_3_of_5.bin",
53 | "llama_v3_taide_8b_chat_part_4_of_5.bin",
54 | "llama_v3_taide_8b_chat_part_5_of_5.bin"
55 | ]
56 | }
57 | }
58 | }
59 | }
60 | }
61 |
--------------------------------------------------------------------------------
/tutorials/llm_on_genie/configs/genie/mistral_7b_instruct_v0_3.json:
--------------------------------------------------------------------------------
1 | {
2 | "dialog": {
3 | "version": 1,
4 | "type": "basic",
5 | "context": {
6 | "version": 1,
7 | "size": 4096,
8 | "n-vocab": 128256,
9 | "bos-token": 1,
10 | "eos-token": 2,
11 | "eot-token": 128009
12 | },
13 | "sampler": {
14 | "version": 1,
15 | "seed": 42,
16 | "temp": 0.8,
17 | "top-k": 40,
18 | "top-p": 0.95
19 | },
20 | "tokenizer": {
21 | "version": 1,
22 | "path": "tokenizer.json"
23 | },
24 | "engine": {
25 | "version": 1,
26 | "n-threads": 3,
27 | "backend": {
28 | "version": 1,
29 | "type": "QnnHtp",
30 | "QnnHtp": {
31 | "version": 1,
32 | "spill-fill-bufsize": 0,
33 | "use-mmap": true,
34 | "mmap-budget": 0,
35 | "poll": true,
36 | "pos-id-dim": 64,
37 | "cpu-mask": "0xe0",
38 | "kv-dim": 128,
39 | "rope-theta": 10000,
40 | "allow-async-init": false
41 | },
42 | "extensions": "htp_backend_ext_config.json"
43 | },
44 | "model": {
45 | "version": 1,
46 | "type": "binary",
47 | "binary": {
48 | "version": 1,
49 | "ctx-bins": [
50 | "weight_sharing_model_1_of_4.serialized.bin",
51 | "weight_sharing_model_2_of_4.serialized.bin",
52 | "weight_sharing_model_3_of_4.serialized.bin",
53 | "weight_sharing_model_4_of_4.serialized.bin"
54 | ]
55 | }
56 | }
57 | }
58 | }
59 | }
60 |
--------------------------------------------------------------------------------
/tutorials/llm_on_genie/configs/genie/qwen2_7b_instruct.json:
--------------------------------------------------------------------------------
1 | {
2 | "dialog": {
3 | "version": 1,
4 | "type": "basic",
5 | "context": {
6 | "version": 1,
7 | "size": 4096,
8 | "n-vocab": 152064,
9 | "bos-token": -1,
10 | "eos-token": 151645
11 | },
12 | "sampler": {
13 | "version": 1,
14 | "seed": 42,
15 | "temp": 0.8,
16 | "top-k": 40,
17 | "top-p": 0.95
18 | },
19 | "tokenizer": {
20 | "version": 1,
21 | "path": "tokenizer.json"
22 | },
23 | "engine": {
24 | "version": 1,
25 | "n-threads": 3,
26 | "backend": {
27 | "version": 1,
28 | "type": "QnnHtp",
29 | "QnnHtp": {
30 | "version": 1,
31 | "use-mmap": true,
32 | "spill-fill-bufsize": 0,
33 | "mmap-budget": 0,
34 | "poll": false,
35 | "pos-id-dim": 64,
36 | "cpu-mask": "0xe0",
37 | "kv-dim": 128,
38 | "rope-theta": 1000000,
39 | "allow-async-init": false
40 | },
41 | "extensions": "htp_backend_ext_config.json"
42 | },
43 | "model": {
44 | "version": 1,
45 | "type": "binary",
46 | "binary": {
47 | "version": 1,
48 | "ctx-bins": [
49 | "weight_sharing_model_1_of_4.serialized.bin",
50 | "weight_sharing_model_2_of_4.serialized.bin",
51 | "weight_sharing_model_3_of_4.serialized.bin",
52 | "weight_sharing_model_4_of_4.serialized.bin"
53 | ]
54 | }
55 | }
56 | }
57 | }
58 | }
59 |
--------------------------------------------------------------------------------
/tutorials/llm_on_genie/configs/htp/htp_backend_ext_config.json.template:
--------------------------------------------------------------------------------
1 | {
2 | "devices": [
3 | {
4 | "soc_model": ,
5 | "dsp_arch": "",
6 | "cores": [
7 | {
8 | "core_id": 0,
9 | "perf_profile": "burst",
10 | "rpc_control_latency": 100
11 | }
12 | ]
13 | }
14 | ],
15 | "memory": {
16 | "mem_type": "shared_buffer"
17 | },
18 | "context": {
19 | "weight_sharing_enabled": true
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/tutorials/llm_on_genie/powershell/README.md:
--------------------------------------------------------------------------------
1 | # Genie PowerShell script for Windows
2 |
3 | This script simplifies the steps in the [LLM On-Device Deployment](..)
4 | tutorial. It is assumed that you have followed the tutorial and prepared a
5 | Genie bundle with the context binaries and tokenizer.
6 |
7 | From the parent directory (`llm_on_genie`), please run the command in a
8 | PowerShell terminal:
9 |
10 | ```powershell
11 | .\powershell\RunLlm1.ps1
12 | ```
13 |
14 | For more information, run:
15 |
16 | ```powershell
17 | Get-Help .\powershell\RunLlm1.ps1
18 | ```
19 |
20 | If it says that you do not have permission to run PowerShell scripts, you may
21 | need to enable this first with this command:
22 |
23 | ```powershell
24 | Set-ExecutionPolicy -Scope CurrentUser Unrestricted -Force
25 | ```
26 |
27 | ## UTF-8 support
28 |
29 | If you want to use Unicode characters in your prompts, we recommend globally
30 | enabling UTF-8 on Windows:
31 |
32 | * Open Control Panel -> Region -> Administrative -> Change system locale...
33 | * Tick the "Beta: Use Unicode UTF-8 for worldwide language support"
34 | * Restart Windows
35 |
36 | If you want to change this only for a single PowerShell session, execute:
37 |
38 | ```powershell
39 | chcp 65001
40 | [Console]::OutputEncoding = [System.Text.Encoding]::UTF8]
41 | ```
42 |
--------------------------------------------------------------------------------
/version_info.py:
--------------------------------------------------------------------------------
1 | # ---------------------------------------------------------------------
2 | # Copyright (c) 2024 Qualcomm Innovation Center, Inc. All rights reserved.
3 | # SPDX-License-Identifier: BSD-3-Clause
4 | # ---------------------------------------------------------------------
5 | __version__ = "0.8.33"
6 |
--------------------------------------------------------------------------------