Skip to content

Commit 52dec9d

Browse files
schnkmwtJeff Linjeffli-xilinxiswaryaalex
authored
vitisai : add VitisAI Plugin for AMD Ryzen AI NPU encoder offload (#3608)
* Add VitisAI Plugin * Added VitisAI encoder module placeholder files * VitisAI build integration * VitisAI encoder offload functional * Clean up vitisai integration * Add c++17 requirement for Windows * Enabled preemption for windows runs * Add model cache override option * Remove vitisai premature log message * Add rai support through file mapping * Fixed flatbuffer loading * Fixed Windows file mapping issue * Update FlexmlRT resolution * Use Flexmlrt wheel pkg to build VitisAI plugin * Clean up * Remove prints * Change flexmlrt target from Shared to Interface * Add c++17 requirement for Windows * Enabled preemption for windows runs * Add rai support through file mapping * Fixed flatbuffer loading * Fixed Windows file mapping issue * Update FlexmlRT resolution * Use Flexmlrt wheel pkg to build VitisAI plugin * Clean up * Remove prints * Change flexmlrt target from Shared to Interface * Cleanup FlexmlRT integration * format fix * Adding AMD Licenses * Update CMakeLists.txt Co-authored-by: Kumawat, Sachin <sachin.kumawat@amd.com> * Update src/CMakeLists.txt Co-authored-by: Kumawat, Sachin <sachin.kumawat@amd.com> * Update whisper.cpp * Added VitisAI encoder readme section * Remove license headers from common files to whisper.cpp --------- Co-authored-by: Sachin Kumawat <sachink@amd.com> Co-authored-by: Jeff Lin <jeffylin@xilinx.com> Co-authored-by: Lin <jefflin@amd.com> Co-authored-by: Lin, Jeff (DCG-ENG) <jeff.lin@amd.com> Co-authored-by: Iswarya Alex <iswaryaalex96@gmail.com> Co-authored-by: Alex, Iswarya <Iswarya.Alex@amd.com> * Update README.md - RAI EULA Links - Updated for RAI Whisper instructions * Cleanup and add runtime print debug guard * turn off profiling * Add VitisAI Plugin * Added VitisAI encoder module placeholder files * VitisAI build integration * VitisAI encoder offload functional * Clean up vitisai integration * Add c++17 requirement for Windows * Enabled preemption for windows runs * Add model cache override option * Remove vitisai premature log message * Add rai support through file mapping * Fixed flatbuffer loading * Fixed Windows file mapping issue * Update FlexmlRT resolution * Use Flexmlrt wheel pkg to build VitisAI plugin * Clean up * Remove prints * Change flexmlrt target from Shared to Interface * Add c++17 requirement for Windows * Enabled preemption for windows runs * Add rai support through file mapping * Fixed flatbuffer loading * Fixed Windows file mapping issue * Update FlexmlRT resolution * Use Flexmlrt wheel pkg to build VitisAI plugin * Clean up * Remove prints * Change flexmlrt target from Shared to Interface * Cleanup FlexmlRT integration * format fix * Adding AMD Licenses * Update CMakeLists.txt Co-authored-by: Kumawat, Sachin <sachin.kumawat@amd.com> * Update src/CMakeLists.txt Co-authored-by: Kumawat, Sachin <sachin.kumawat@amd.com> * Update whisper.cpp * Added VitisAI encoder readme section * Remove license headers from common files to whisper.cpp --------- Co-authored-by: Sachin Kumawat <sachink@amd.com> Co-authored-by: Jeff Lin <jeffylin@xilinx.com> Co-authored-by: Lin <jefflin@amd.com> Co-authored-by: Lin, Jeff (DCG-ENG) <jeff.lin@amd.com> Co-authored-by: Iswarya Alex <iswaryaalex96@gmail.com> Co-authored-by: Alex, Iswarya <Iswarya.Alex@amd.com> * Cleanup and add runtime print debug guard * Update README.md - RAI EULA Links - Updated for RAI Whisper instructions * turn off profiling * Let flexmlrt detect device type * Add VitisAI model download scripts * Add encoder + cross projection layer offload * Add self hosted runner for amd npu * Update runner * Update workflow for linux * Update workflow for linux * Update flexmlrt packages for linux * Update flexmlrt packages for linux * Updated README * readme: clarify xrt * readme: clarify xrt * ci: update test config * Added supported plarform details with python 3.12 requirement for Linux * Use refactored helpers * Deprecate cross_proj .rai naming and cleanup * Remove stale function code * Fix: formatting --------- Co-authored-by: Jeff Lin <jeffylin@xilinx.com> Co-authored-by: Lin <jefflin@amd.com> Co-authored-by: Lin, Jeff (DCG-ENG) <jeff.lin@amd.com> Co-authored-by: Iswarya Alex <iswaryaalex96@gmail.com> Co-authored-by: Alex, Iswarya <Iswarya.Alex@amd.com> Co-authored-by: Iswarya Alex <47045679+iswaryaalex@users.noreply.github.com>
1 parent 233fe1f commit 52dec9d

12 files changed

Lines changed: 2072 additions & 3 deletions

.github/workflows/build-self-hosted.yml

Lines changed: 143 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,3 +114,146 @@ jobs:
114114
run: |
115115
vulkaninfo --summary
116116
GG_BUILD_VULKAN=1 bash ./ci/run.sh ~/results/whisper.cpp ~/mnt/whisper.cpp
117+
118+
npu-amd-windows:
119+
runs-on: [self-hosted, Windows, X64, stx, rai300-400]
120+
timeout-minutes: 60
121+
continue-on-error: true # advisory while the runner pool is new; revisit later
122+
123+
env:
124+
FLEXML_URL: https://github.com/lemonade-sdk/whisper.cpp-rocm/releases/download/deps/flexmlrt-1.7.0-win.zip
125+
MODEL: base
126+
127+
steps:
128+
- name: Clone
129+
uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6
130+
131+
- uses: microsoft/setup-msbuild@v2
132+
133+
- name: Install CMake if not available
134+
shell: powershell
135+
run: |
136+
$installed = Get-Command cmake -ErrorAction SilentlyContinue
137+
if (-not $installed) {
138+
$ver = "3.28.1"
139+
$url = "https://github.com/Kitware/CMake/releases/download/v$ver/cmake-$ver-windows-x86_64.msi"
140+
Invoke-WebRequest -Uri $url -OutFile cmake.msi
141+
Start-Process msiexec.exe -ArgumentList "/i cmake.msi /quiet /norestart" -Wait
142+
$p = "C:\Program Files\CMake\bin"
143+
$env:PATH = "$p;$env:PATH"
144+
echo $p >> $env:GITHUB_PATH
145+
cmake --version
146+
if ($LASTEXITCODE -ne 0) { Write-Error "CMake install failed"; exit 1 }
147+
} else { cmake --version }
148+
149+
- name: Download FlexML runtime
150+
shell: powershell
151+
run: |
152+
Invoke-WebRequest -Uri "${{ env.FLEXML_URL }}" -OutFile flexmlrt.zip
153+
if (-Not (Test-Path "flexmlrt.zip")) { Write-Error "flexmlrt.zip not downloaded"; exit 1 }
154+
if ((Get-Item "flexmlrt.zip").Length -eq 0) { Write-Error "flexmlrt.zip is empty"; exit 1 }
155+
tar xf flexmlrt.zip
156+
if ($LASTEXITCODE -ne 0) { Write-Error "Extraction failed"; exit 1 }
157+
if (-not (Test-Path "flexmlrt")) { Write-Error "No flexmlrt directory after extraction"; exit 1 }
158+
159+
- name: Setup FlexML, configure and build
160+
shell: cmd
161+
run: |
162+
cd flexmlrt
163+
call setup.bat
164+
if errorlevel 1 ( echo ERROR: FlexML setup.bat failed & exit /b 1 )
165+
cd ..
166+
cmake -B build -A x64 -DCMAKE_BUILD_TYPE=Release -DWHISPER_VITISAI=ON
167+
if errorlevel 1 ( echo ERROR: CMake configure failed & exit /b 1 )
168+
cmake --build build --config Release -j
169+
if errorlevel 1 ( echo ERROR: Build failed & exit /b 1 )
170+
171+
- name: Copy FlexML DLLs to build output
172+
shell: powershell
173+
run: |
174+
foreach ($d in "flexmlrt/bin", "flexmlrt/lib") {
175+
if (Test-Path "$d/*.dll") { Copy-Item "$d/*.dll" "build/bin/Release/" -Force }
176+
}
177+
if (-not (Test-Path "build/bin/Release/flexmlrt.dll")) {
178+
Write-Error "flexmlrt.dll not staged next to binaries"; exit 1
179+
}
180+
181+
- name: Download ggml model
182+
shell: cmd
183+
run: |
184+
call models\download-ggml-model.cmd %MODEL% models
185+
if not exist models\ggml-%MODEL%.bin ( echo ERROR: model download failed & exit /b 1 )
186+
187+
- name: Download NPU encoder cache
188+
shell: cmd
189+
run: |
190+
.\models\download-vitisai-model.cmd %MODEL%
191+
if not exist models\ggml-%MODEL%-encoder-vitisai.rai ( echo ERROR: VitisAI encoder cache download failed & exit /b 1 )
192+
193+
- name: Run NPU smoke test
194+
shell: cmd
195+
run: |
196+
build\bin\Release\whisper-cli.exe -m models\ggml-%MODEL%.bin -f samples\jfk.wav > vitisai.log 2>&1
197+
type vitisai.log
198+
findstr /I /C:"vitisai" vitisai.log || ( echo ERROR: no VitisAI activity - encoder likely fell back to CPU & exit /b 1 )
199+
findstr /I /C:"ask not what your country" vitisai.log || ( echo ERROR: incorrect transcription & exit /b 1 )
200+
201+
- name: Upload smoke test log
202+
if: always()
203+
uses: actions/upload-artifact@v4
204+
with:
205+
name: vitisai-smoke-log-windows
206+
path: vitisai.log
207+
208+
npu-amd-linux:
209+
runs-on: [self-hosted, Linux, X64, stx, rai300-400]
210+
timeout-minutes: 60
211+
continue-on-error: true # advisory while the runner pool is new; revisit later
212+
213+
env:
214+
FLEXML_LINUX_URL: https://github.com/lemonade-sdk/whisper.cpp-rocm/releases/download/deps/flexmlrt-1.8.0-linux.tar.gz
215+
MODEL: base
216+
217+
steps:
218+
- name: Clone
219+
uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6
220+
221+
- name: Verify NPU device
222+
run: |
223+
lsmod | grep -q amdxdna || { echo "ERROR: amdxdna driver not loaded"; exit 1; }
224+
ls /dev/accel/accel* || { echo "ERROR: no NPU accel device node"; exit 1; }
225+
226+
- name: Download FlexML runtime (Linux)
227+
run: |
228+
curl -L --fail -o flexmlrt.tar.gz "$FLEXML_LINUX_URL"
229+
tar xf flexmlrt.tar.gz
230+
source flexmlrt/setup.sh
231+
echo "FlexmlRT_DIR=$PWD/flexmlrt/share/cmake/FlexmlRT" >> $GITHUB_ENV
232+
echo "LD_LIBRARY_PATH=$PWD/flexmlrt/lib:$LD_LIBRARY_PATH" >> $GITHUB_ENV
233+
234+
- name: Configure and build
235+
run: |
236+
cmake -B build -DCMAKE_BUILD_TYPE=Release -DWHISPER_VITISAI=ON
237+
cmake --build build --config Release -j $(nproc)
238+
239+
- name: Download ggml model
240+
run: |
241+
./models/download-ggml-model.sh $MODEL
242+
243+
- name: Download NPU encoder cache
244+
run: |
245+
sh ./models/download-vitisai-model.sh $MODEL
246+
[ -f "models/ggml-$MODEL-encoder-vitisai.rai" ] || { echo "ERROR: VitisAI encoder cache download failed"; exit 1; }
247+
248+
- name: Run NPU smoke test
249+
run: |
250+
./build/bin/whisper-cli -m "models/ggml-$MODEL.bin" -f samples/jfk.wav 2>&1 | tee vitisai.log
251+
grep -qi "vitisai" vitisai.log || { echo "ERROR: no VitisAI activity - CPU fallback?"; exit 1; }
252+
grep -qi "ask not what your country" vitisai.log || { echo "ERROR: incorrect transcription"; exit 1; }
253+
254+
- name: Upload smoke test log
255+
if: always()
256+
uses: actions/upload-artifact@v4
257+
with:
258+
name: vitisai-smoke-log-linux
259+
path: vitisai.log

CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ endif()
115115
option(WHISPER_COREML "whisper: enable Core ML framework" OFF)
116116
option(WHISPER_COREML_ALLOW_FALLBACK "whisper: allow non-CoreML fallback" OFF)
117117
option(WHISPER_OPENVINO "whisper: support for OpenVINO" OFF)
118+
option(WHISPER_VITISAI "whisper: support for AMD Vitis AI" OFF)
118119

119120
# Required for relocatable CMake package
120121
include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/build-info.cmake)

README.md

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ High-performance inference of [OpenAI's Whisper](https://github.com/openai/whisp
2121
- Support for CPU-only inference
2222
- [Efficient GPU support for NVIDIA](#nvidia-gpu-support)
2323
- [AMD ROCm GPU support](#amd-rocm-gpu-support)
24+
- [AMD Ryzen AI NPU Support](#amd-ryzen-ai-npu-support)
2425
- [OpenVINO Support](#openvino-support)
2526
- [Ascend NPU Support](#ascend-npu-support)
2627
- [Moore Threads GPU Support](#moore-threads-gpu-support)
@@ -312,6 +313,87 @@ This can result in significant speedup in encoder performance. Here are the inst
312313

313314
For more information about the OpenVINO implementation please refer to PR [#1037](https://github.com/ggml-org/whisper.cpp/pull/1037).
314315

316+
## AMD Ryzen™ AI NPU support
317+
318+
On AMD Ryzen™ AI 300 and 400 Series processors with a dedicated NPU, whisper.cpp can fully offload the Whisper encoder to the NPU via VitisAI, delivering significant speedup over CPU-only inference.
319+
320+
### Prerequisites
321+
322+
Supported Platforms
323+
324+
- **Windows 11**
325+
- **Linux** (Ubuntu 24.04 LTS, Python 3.12)
326+
327+
Install the XRT runtime and FlexML runtime for your platform:
328+
329+
- **XRT**: provides the NPU kernel driver and `xrt-smi` diagnostic tool — on Windows this is bundled with the NPU driver; on Linux install it separately following the [NPU driver installation guide](https://ryzenai.docs.amd.com/en/latest/linux.html#install-npu-drivers)
330+
- **FlexML runtime** (`flexmlrt`): VitisAI inference engine used by whisper.cpp — download from the [FlexML runtime releases](https://github.com/lemonade-sdk/whisper.cpp-rocm/releases/tag/deps)
331+
332+
After installing, source the setup scripts in every shell you use to build or run whisper.cpp:
333+
334+
```bash
335+
# Linux
336+
source /opt/xilinx/xrt/setup.sh
337+
source /path/to/flexmlrt/setup.sh
338+
```
339+
340+
```cmd
341+
:: Windows
342+
cd /path/to/flexmlrt && call setup.bat
343+
```
344+
345+
You can verify the NPU is visible with:
346+
347+
```bash
348+
xrt-smi examine
349+
```
350+
351+
### Download models
352+
353+
Download the ggml model and the matching prebuilt VitisAI encoder cache:
354+
355+
```bash
356+
# Linux / macOS
357+
sh ./models/download-ggml-model.sh base
358+
sh ./models/download-vitisai-model.sh base
359+
```
360+
361+
```cmd
362+
:: Windows
363+
.\models\download-ggml-model.cmd base
364+
.\models\download-vitisai-model.cmd base
365+
```
366+
367+
Use the same model name with both scripts. To see all available VitisAI encoder caches:
368+
369+
```bash
370+
sh ./models/download-vitisai-model.sh --list
371+
```
372+
373+
```cmd
374+
.\models\download-vitisai-model.cmd --list
375+
```
376+
377+
The VitisAI script queries the [AMD Ryzen AI Whisper NPU collection on Hugging Face](https://huggingface.co/collections/amd/ryzen-ai-whisper-npu-optimized-onnx-models) and downloads the `.rai` encoder cache as `models/ggml-<model>-encoder-vitisai.rai`.
378+
379+
> Depending on the `.rai` cache, VitisAI may offload the encoder only, or the encoder plus cross-projection layers. whisper.cpp detects this at runtime and logs the selected offload mode during model initialization.
380+
381+
### Build
382+
383+
```bash
384+
cmake -B build -DWHISPER_VITISAI=1
385+
cmake --build build -j --config Release
386+
```
387+
388+
### Run
389+
390+
```bash
391+
./build/bin/whisper-cli -m models/ggml-base.bin -f samples/jfk.wav
392+
```
393+
394+
For more information see the [Ryzen AI documentation](https://ryzenai.docs.amd.com/en/latest/).
395+
396+
315397
## NVIDIA GPU support
316398

317399
With NVIDIA cards the processing of the models is done efficiently on the GPU via cuBLAS and custom CUDA kernels.

models/download-vitisai-model.cmd

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
@echo off
2+
setlocal
3+
4+
set "script=%~dp0download-vitisai-model.ps1"
5+
6+
if "%~1"=="" (
7+
PowerShell -NoProfile -ExecutionPolicy Bypass -File "%script%"
8+
exit /b %ERRORLEVEL%
9+
)
10+
11+
if /I "%~1"=="--list" (
12+
PowerShell -NoProfile -ExecutionPolicy Bypass -File "%script%" -List
13+
exit /b %ERRORLEVEL%
14+
)
15+
16+
if /I "%~1"=="-l" (
17+
PowerShell -NoProfile -ExecutionPolicy Bypass -File "%script%" -List
18+
exit /b %ERRORLEVEL%
19+
)
20+
21+
if /I "%~1"=="list" (
22+
PowerShell -NoProfile -ExecutionPolicy Bypass -File "%script%" -List
23+
exit /b %ERRORLEVEL%
24+
)
25+
26+
if "%~2"=="" (
27+
PowerShell -NoProfile -ExecutionPolicy Bypass -File "%script%" -Model "%~1"
28+
) else (
29+
PowerShell -NoProfile -ExecutionPolicy Bypass -File "%script%" -Model "%~1" -ModelsPath "%~2"
30+
)
31+
32+
exit /b %ERRORLEVEL%

0 commit comments

Comments
 (0)