Skip to content

Commit a45384b

Browse files
authored
Provide pre-compiled whls for cuda 12.x on Linux x64 and Windows x64 (k2-fsa#2601)
1 parent aa66810 commit a45384b

11 files changed

Lines changed: 63 additions & 143 deletions

.github/workflows/build-wheels-linux-cuda.yaml

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,14 @@ concurrency:
1515

1616
jobs:
1717
build_wheels_linux_cuda:
18-
name: ${{ matrix.manylinux }} ${{ matrix.python-version }}
18+
name: ${{ matrix.manylinux }} ${{ matrix.python-version }} ${{ matrix.onnxruntime_version }}
1919
runs-on: ${{ matrix.os }}
2020
strategy:
2121
fail-fast: false
2222
matrix:
2323
os: [ubuntu-22.04]
2424
python-version: ["3.7", "3.8", "3.9", "3.10", "3.11", "3.12", "3.13"]
25+
onnxruntime_version: ["1.17.1", "1.22.0"]
2526

2627
steps:
2728
- uses: actions/checkout@v4
@@ -69,6 +70,16 @@ jobs:
6970
export SHERPA_ONNX_ENABLE_ALSA=1
7071
export SHERPA_ONNX_CMAKE_ARGS="-DSHERPA_ONNX_ENABLE_GPU=ON"
7172
73+
onnxruntime_version=${{ matrix.onnxruntime_version }}
74+
if [[ $onnxruntime_version == "1.22.0" ]]; then
75+
curl -SL -O https://github.com/csukuangfj/onnxruntime-libs/releases/download/v1.22.0/onnxruntime-linux-x64-gpu-1.22.0-patched.zip
76+
unzip onnxruntime-linux-x64-gpu-1.22.0-patched.zip
77+
78+
export SHERPA_ONNXRUNTIME_LIB_DIR=$PWD/onnxruntime-linux-x64-gpu-1.22.0-patched/lib
79+
export SHERPA_ONNXRUNTIME_INCLUDE_DIR=$PWD/onnxruntime-linux-x64-gpu-1.22.0-patched/include
80+
export SHERPA_ONNX_CUDA_VERSION="12.cudnn9"
81+
fi
82+
7283
python3 setup.py bdist_wheel
7384
7485
ls -lh dist
@@ -80,6 +91,8 @@ jobs:
8091
run: |
8192
ls -lh ./wheelhouse/
8293
94+
unzip -l ./wheelhouse/*.whl
95+
8396
- name: Install patchelf
8497
shell: bash
8598
run: |
@@ -97,9 +110,10 @@ jobs:
97110
rm -rf ./wheelhouse
98111
mv ./wheels ./wheelhouse
99112
113+
100114
- uses: actions/upload-artifact@v4
101115
with:
102-
name: wheel-cuda-${{ matrix.python-version }}
116+
name: wheel-cuda-${{ matrix.python-version }}-${{ matrix.onnxruntime_version }}
103117
path: ./wheelhouse/*.whl
104118

105119
- name: Publish to huggingface

.github/workflows/build-wheels-win64-cuda.yaml

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,14 @@ concurrency:
1515

1616
jobs:
1717
build_wheels_win64_cuda:
18-
name: ${{ matrix.python-version }}
18+
name: ${{ matrix.python-version }} ${{ matrix.onnxruntime_version }}
1919
runs-on: ${{ matrix.os }}
2020
strategy:
2121
fail-fast: false
2222
matrix:
2323
os: [windows-2022]
2424
python-version: ["3.7", "3.8", "3.9", "3.10", "3.11", "3.12", "3.13"]
25+
onnxruntime_version: ["1.17.1", "1.22.0"]
2526

2627
steps:
2728
- uses: actions/checkout@v4
@@ -44,6 +45,17 @@ jobs:
4445
4546
export SHERPA_ONNX_CMAKE_ARGS="-DSHERPA_ONNX_ENABLE_GPU=ON"
4647
48+
onnxruntime_version=${{ matrix.onnxruntime_version }}
49+
if [[ $onnxruntime_version == "1.22.0" ]]; then
50+
curl -SL -O https://github.com/microsoft/onnxruntime/releases/download/v1.22.0/onnxruntime-win-x64-gpu-1.22.0.zip
51+
unzip onnxruntime-win-x64-gpu-1.22.0.zip
52+
53+
export SHERPA_ONNXRUNTIME_LIB_DIR=$PWD/onnxruntime-win-x64-gpu-1.22.0/lib
54+
export SHERPA_ONNXRUNTIME_INCLUDE_DIR=$PWD/onnxruntime-win-x64-gpu-1.22.0/include
55+
56+
export SHERPA_ONNX_CUDA_VERSION="12.cudnn9"
57+
fi
58+
4759
python3 setup.py bdist_wheel
4860
4961
ls -lh ./dist/
@@ -54,10 +66,11 @@ jobs:
5466
shell: bash
5567
run: |
5668
ls -lh ./wheelhouse/
69+
unzip -l ./wheelhouse/*.whl
5770
5871
- uses: actions/upload-artifact@v4
5972
with:
60-
name: wheel-${{ matrix.python-version }}
73+
name: wheel-${{ matrix.python-version }}-${{ matrix.onnxruntime_version }}
6174
path: ./wheelhouse/*.whl
6275

6376
- name: Publish to huggingface

.github/workflows/linux-gpu.yaml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -100,11 +100,6 @@ jobs:
100100
ls -lh lib
101101
ls -lh bin
102102
103-
if [[ $onnxruntime_version == "1.22.0" ]]; then
104-
cp -v $SHERPA_ONNXRUNTIME_LIB_DIR/libonnxruntime* ./lib/
105-
cp -v $SHERPA_ONNXRUNTIME_LIB_DIR/libonnxruntime* install/lib/
106-
fi
107-
108103
echo "----"
109104
ls -lh install/lib
110105

.github/workflows/windows-x64-cuda.yaml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -76,10 +76,6 @@ jobs:
7676
ls -lh ./bin/Release/sherpa-onnx.exe
7777
7878
onnxruntime_version=${{ matrix.onnxruntime_version }}
79-
if [[ $onnxruntime_version == "1.22.0" ]]; then
80-
cp -v ../onnxruntime-win-x64-gpu-1.22.0/lib/*.dll ./bin/Release/
81-
cp -v ../onnxruntime-win-x64-gpu-1.22.0/lib/*.dll ./install/bin/
82-
fi
8379
8480
- name: Copy files
8581
shell: bash

cmake/cmake_extension.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import sys
1010
from pathlib import Path
1111

12+
import glob
1213
import setuptools
1314
from setuptools.command.build_ext import build_ext
1415

@@ -251,8 +252,6 @@ def build_extension(self, ext: setuptools.extension.Extension):
251252
os.system(f"mkdir {dst}")
252253
os.system(f"dir {dst}")
253254

254-
import glob
255-
256255
ext = "pyd" if sys.platform.startswith("win") else "so"
257256
pattern = os.path.join(self.build_temp, "**", f"_sherpa_onnx.*.{ext}")
258257
matches = glob.glob(pattern, recursive=True)

cmake/onnxruntime-linux-aarch64-gpu.cmake

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -117,30 +117,6 @@ set_target_properties(onnxruntime PROPERTIES
117117
INTERFACE_INCLUDE_DIRECTORIES "${onnxruntime_SOURCE_DIR}/include"
118118
)
119119

120-
find_library(location_onnxruntime_cuda_lib onnxruntime_providers_cuda
121-
PATHS
122-
"${onnxruntime_SOURCE_DIR}/lib"
123-
NO_CMAKE_SYSTEM_PATH
124-
)
125-
126-
add_library(onnxruntime_providers_cuda SHARED IMPORTED)
127-
set_target_properties(onnxruntime_providers_cuda PROPERTIES
128-
IMPORTED_LOCATION ${location_onnxruntime_cuda_lib}
129-
)
130-
message(STATUS "location_onnxruntime_cuda_lib: ${location_onnxruntime_cuda_lib}")
131-
132-
# for libonnxruntime_providers_shared.so
133-
find_library(location_onnxruntime_providers_shared_lib onnxruntime_providers_shared
134-
PATHS
135-
"${onnxruntime_SOURCE_DIR}/lib"
136-
NO_CMAKE_SYSTEM_PATH
137-
)
138-
add_library(onnxruntime_providers_shared SHARED IMPORTED)
139-
set_target_properties(onnxruntime_providers_shared PROPERTIES
140-
IMPORTED_LOCATION ${location_onnxruntime_providers_shared_lib}
141-
)
142-
message(STATUS "location_onnxruntime_providers_shared_lib: ${location_onnxruntime_providers_shared_lib}")
143-
144120
file(GLOB onnxruntime_lib_files "${onnxruntime_SOURCE_DIR}/lib/libonnxruntime*")
145121
message(STATUS "onnxruntime lib files: ${onnxruntime_lib_files}")
146122
install(FILES ${onnxruntime_lib_files} DESTINATION lib)

cmake/onnxruntime-linux-x86_64-gpu.cmake

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -73,30 +73,6 @@ set_target_properties(onnxruntime PROPERTIES
7373
INTERFACE_INCLUDE_DIRECTORIES "${onnxruntime_SOURCE_DIR}/include"
7474
)
7575

76-
find_library(location_onnxruntime_cuda_lib onnxruntime_providers_cuda
77-
PATHS
78-
"${onnxruntime_SOURCE_DIR}/lib"
79-
NO_CMAKE_SYSTEM_PATH
80-
)
81-
82-
add_library(onnxruntime_providers_cuda SHARED IMPORTED)
83-
set_target_properties(onnxruntime_providers_cuda PROPERTIES
84-
IMPORTED_LOCATION ${location_onnxruntime_cuda_lib}
85-
)
86-
message(STATUS "location_onnxruntime_cuda_lib: ${location_onnxruntime_cuda_lib}")
87-
88-
# for libonnxruntime_providers_shared.so
89-
find_library(location_onnxruntime_providers_shared_lib onnxruntime_providers_shared
90-
PATHS
91-
"${onnxruntime_SOURCE_DIR}/lib"
92-
NO_CMAKE_SYSTEM_PATH
93-
)
94-
add_library(onnxruntime_providers_shared SHARED IMPORTED)
95-
set_target_properties(onnxruntime_providers_shared PROPERTIES
96-
IMPORTED_LOCATION ${location_onnxruntime_providers_shared_lib}
97-
)
98-
message(STATUS "location_onnxruntime_providers_shared_lib: ${location_onnxruntime_providers_shared_lib}")
99-
10076
file(GLOB onnxruntime_lib_files "${onnxruntime_SOURCE_DIR}/lib/libonnxruntime*")
10177
message(STATUS "onnxruntime lib files: ${onnxruntime_lib_files}")
10278
install(FILES ${onnxruntime_lib_files} DESTINATION lib)

cmake/onnxruntime-win-x64-gpu.cmake

Lines changed: 0 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -82,52 +82,6 @@ file(COPY ${onnxruntime_SOURCE_DIR}/lib/onnxruntime.dll
8282
${CMAKE_BINARY_DIR}/bin/${CMAKE_BUILD_TYPE}
8383
)
8484

85-
# for onnxruntime_providers_cuda.dll
86-
87-
find_library(location_onnxruntime_providers_cuda_lib onnxruntime_providers_cuda
88-
PATHS
89-
"${onnxruntime_SOURCE_DIR}/lib"
90-
NO_CMAKE_SYSTEM_PATH
91-
)
92-
message(STATUS "location_onnxruntime_providers_cuda_lib: ${location_onnxruntime_providers_cuda_lib}")
93-
94-
add_library(onnxruntime_providers_cuda SHARED IMPORTED)
95-
set_target_properties(onnxruntime_providers_cuda PROPERTIES
96-
IMPORTED_LOCATION ${location_onnxruntime_providers_cuda_lib}
97-
INTERFACE_INCLUDE_DIRECTORIES "${onnxruntime_SOURCE_DIR}/include"
98-
)
99-
100-
set_property(TARGET onnxruntime_providers_cuda
101-
PROPERTY
102-
IMPORTED_IMPLIB "${onnxruntime_SOURCE_DIR}/lib/onnxruntime_providers_cuda.lib"
103-
)
104-
105-
# for onnxruntime_providers_shared.dll
106-
107-
find_library(location_onnxruntime_providers_shared_lib onnxruntime_providers_shared
108-
PATHS
109-
"${onnxruntime_SOURCE_DIR}/lib"
110-
NO_CMAKE_SYSTEM_PATH
111-
)
112-
message(STATUS "location_onnxruntime_providers_shared_lib: ${location_onnxruntime_providers_shared_lib}")
113-
add_library(onnxruntime_providers_shared SHARED IMPORTED)
114-
set_target_properties(onnxruntime_providers_shared PROPERTIES
115-
IMPORTED_LOCATION ${location_onnxruntime_providers_shared_lib}
116-
INTERFACE_INCLUDE_DIRECTORIES "${onnxruntime_SOURCE_DIR}/include"
117-
)
118-
set_property(TARGET onnxruntime_providers_shared
119-
PROPERTY
120-
IMPORTED_IMPLIB "${onnxruntime_SOURCE_DIR}/lib/onnxruntime_providers_shared.lib"
121-
)
122-
123-
file(
124-
COPY
125-
${onnxruntime_SOURCE_DIR}/lib/onnxruntime_providers_cuda.dll
126-
${onnxruntime_SOURCE_DIR}/lib/onnxruntime_providers_shared.dll
127-
DESTINATION
128-
${CMAKE_BINARY_DIR}/bin/${CMAKE_BUILD_TYPE}
129-
)
130-
13185
file(GLOB onnxruntime_lib_files "${onnxruntime_SOURCE_DIR}/lib/*.dll")
13286

13387
message(STATUS "onnxruntime lib files: ${onnxruntime_lib_files}")

cmake/onnxruntime.cmake

Lines changed: 26 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,7 @@ if(SHERPA_ONNX_USE_PRE_INSTALLED_ONNXRUNTIME_IF_AVAILABLE)
155155
elseif(WIN32)
156156
if(SHERPA_ONNX_ENABLE_GPU)
157157
set(location_onnxruntime_lib $ENV{SHERPA_ONNXRUNTIME_LIB_DIR}/onnxruntime.dll)
158+
set(location_onnxruntime_lib2 $ENV{SHERPA_ONNXRUNTIME_LIB_DIR}/onnxruntime.lib)
158159
else()
159160
set(location_onnxruntime_lib $ENV{SHERPA_ONNXRUNTIME_LIB_DIR}/onnxruntime.lib)
160161
if(SHERPA_ONNX_ENABLE_DIRECTML)
@@ -175,56 +176,48 @@ if(SHERPA_ONNX_USE_PRE_INSTALLED_ONNXRUNTIME_IF_AVAILABLE)
175176
set(onnxruntime_lib_files $ENV{SHERPA_ONNXRUNTIME_LIB_DIR}/libonnxruntime.a)
176177
message("Use static lib: ${onnxruntime_lib_files}")
177178
endif()
178-
179-
if(SHERPA_ONNX_ENABLE_GPU)
180-
if(WIN32)
181-
set(location_onnxruntime_cuda_lib $ENV{SHERPA_ONNXRUNTIME_LIB_DIR}/onnxruntime_providers_cuda.dll)
182-
else()
183-
set(location_onnxruntime_cuda_lib $ENV{SHERPA_ONNXRUNTIME_LIB_DIR}/libonnxruntime_providers_cuda.so)
184-
endif()
185-
186-
if(NOT EXISTS ${location_onnxruntime_cuda_lib})
187-
set(location_onnxruntime_cuda_lib $ENV{SHERPA_ONNXRUNTIME_LIB_DIR}/libonnxruntime_providers_cuda.a)
188-
endif()
189-
endif()
190179
else()
191180
find_library(location_onnxruntime_lib onnxruntime
192181
PATHS
193182
/lib
194183
/usr/lib
195184
/usr/local/lib
196185
)
197-
198-
if(SHERPA_ONNX_ENABLE_GPU)
199-
find_library(location_onnxruntime_cuda_lib onnxruntime_providers_cuda
200-
PATHS
201-
/lib
202-
/usr/lib
203-
/usr/local/lib
204-
)
205-
endif()
206186
endif()
207187

208188
message(STATUS "location_onnxruntime_lib: ${location_onnxruntime_lib}")
209-
if(SHERPA_ONNX_ENABLE_GPU)
210-
message(STATUS "location_onnxruntime_cuda_lib: ${location_onnxruntime_cuda_lib}")
211-
endif()
212189
endif()
213190

214191
if(location_onnxruntime_header_dir AND location_onnxruntime_lib)
215192
if(NOT DEFINED onnxruntime_lib_files)
216193
add_library(onnxruntime SHARED IMPORTED)
217-
set_target_properties(onnxruntime PROPERTIES
218-
IMPORTED_LOCATION ${location_onnxruntime_lib}
219-
IMPORTED_IMPLIB ${location_onnxruntime_lib}
220-
INTERFACE_INCLUDE_DIRECTORIES "${location_onnxruntime_header_dir}"
221-
)
222-
if(SHERPA_ONNX_ENABLE_GPU AND location_onnxruntime_cuda_lib)
223-
add_library(onnxruntime_providers_cuda SHARED IMPORTED)
224-
set_target_properties(onnxruntime_providers_cuda PROPERTIES
225-
IMPORTED_LOCATION ${location_onnxruntime_cuda_lib}
194+
195+
if(WIN32)
196+
set_target_properties(onnxruntime PROPERTIES
197+
IMPORTED_LOCATION ${location_onnxruntime_lib}
198+
IMPORTED_IMPLIB ${location_onnxruntime_lib2}
199+
INTERFACE_INCLUDE_DIRECTORIES "${location_onnxruntime_header_dir}"
200+
)
201+
else()
202+
set_target_properties(onnxruntime PROPERTIES
203+
IMPORTED_LOCATION ${location_onnxruntime_lib}
204+
INTERFACE_INCLUDE_DIRECTORIES "${location_onnxruntime_header_dir}"
226205
)
227206
endif()
207+
208+
if(WIN32)
209+
file(GLOB onnxruntime_lib_files "$ENV{SHERPA_ONNXRUNTIME_LIB_DIR}/*.dll")
210+
else()
211+
file(GLOB onnxruntime_lib_files "$ENV{SHERPA_ONNXRUNTIME_LIB_DIR}/libonnxruntime*")
212+
endif()
213+
214+
message(STATUS "onnxruntime lib files: ${onnxruntime_lib_files}")
215+
216+
install(FILES ${onnxruntime_lib_files} DESTINATION lib)
217+
218+
if(WIN32)
219+
install(FILES ${onnxruntime_lib_files} DESTINATION bin)
220+
endif()
228221
endif()
229222
else()
230223
if(SHERPA_ONNX_USE_PRE_INSTALLED_ONNXRUNTIME_IF_AVAILABLE)

setup.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,10 @@ def get_package_version():
3434
if "-DSHERPA_ONNX_ENABLE_GPU=ON" in cmake_args:
3535
extra_version = "+cuda"
3636

37+
cuda_version = os.environ.get("SHERPA_ONNX_CUDA_VERSION", "")
38+
if cuda_version:
39+
extra_version += cuda_version
40+
3741
latest_version += extra_version
3842

3943
return latest_version

0 commit comments

Comments
 (0)