Fix building for GPU support. (#195)
This commit is contained in:
@@ -58,6 +58,15 @@ if(SHERPA_ONNX_ENABLE_JNI AND NOT BUILD_SHARED_LIBS)
|
|||||||
set(BUILD_SHARED_LIBS ON CACHE BOOL "" FORCE)
|
set(BUILD_SHARED_LIBS ON CACHE BOOL "" FORCE)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
if(SHERPA_ONNX_ENABLE_GPU)
|
||||||
|
message(WARNING "\
|
||||||
|
Compiling for NVIDIA GPU is enabled. Please make sure cudatoolkit
|
||||||
|
is installed on your system. Otherwise, you will get errors at runtime.
|
||||||
|
Hint: You don't need sudo permission to install CUDA toolkit. Please refer to
|
||||||
|
https://k2-fsa.github.io/k2/installation/cuda-cudnn.html
|
||||||
|
to install CUDA toolkit if you have not installed it.")
|
||||||
|
endif()
|
||||||
|
|
||||||
if(BUILD_SHARED_LIBS AND MSVC)
|
if(BUILD_SHARED_LIBS AND MSVC)
|
||||||
set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON)
|
set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON)
|
||||||
endif()
|
endif()
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ function(download_asio)
|
|||||||
if(EXISTS ${f})
|
if(EXISTS ${f})
|
||||||
set(asio_URL "${f}")
|
set(asio_URL "${f}")
|
||||||
file(TO_CMAKE_PATH "${asio_URL}" asio_URL)
|
file(TO_CMAKE_PATH "${asio_URL}" asio_URL)
|
||||||
|
message(STATUS "Found local downloaded asio: ${asio_URL}")
|
||||||
set(asio_URL2)
|
set(asio_URL2)
|
||||||
break()
|
break()
|
||||||
endif()
|
endif()
|
||||||
|
|||||||
@@ -18,6 +18,7 @@ function(download_cargs)
|
|||||||
if(EXISTS ${f})
|
if(EXISTS ${f})
|
||||||
set(cargs_URL "${f}")
|
set(cargs_URL "${f}")
|
||||||
file(TO_CMAKE_PATH "${cargs_URL}" cargs_URL)
|
file(TO_CMAKE_PATH "${cargs_URL}" cargs_URL)
|
||||||
|
message(STATUS "Found local downloaded cargs: ${cargs_URL}")
|
||||||
break()
|
break()
|
||||||
endif()
|
endif()
|
||||||
endforeach()
|
endforeach()
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ function(download_googltest)
|
|||||||
if(EXISTS ${f})
|
if(EXISTS ${f})
|
||||||
set(googletest_URL "${f}")
|
set(googletest_URL "${f}")
|
||||||
file(TO_CMAKE_PATH "${googletest_URL}" googletest_URL)
|
file(TO_CMAKE_PATH "${googletest_URL}" googletest_URL)
|
||||||
|
message(STATUS "Found local downloaded googletest: ${googletest_URL}")
|
||||||
set(googletest_URL2)
|
set(googletest_URL2)
|
||||||
break()
|
break()
|
||||||
endif()
|
endif()
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ function(download_json)
|
|||||||
if(EXISTS ${f})
|
if(EXISTS ${f})
|
||||||
set(json_URL "${f}")
|
set(json_URL "${f}")
|
||||||
file(TO_CMAKE_PATH "${json_URL}" json_URL)
|
file(TO_CMAKE_PATH "${json_URL}" json_URL)
|
||||||
|
message(STATUS "Found local downloaded json: ${json_URL}")
|
||||||
set(json_URL2)
|
set(json_URL2)
|
||||||
break()
|
break()
|
||||||
endif()
|
endif()
|
||||||
|
|||||||
@@ -23,6 +23,7 @@ function(download_kaldi_native_fbank)
|
|||||||
if(EXISTS ${f})
|
if(EXISTS ${f})
|
||||||
set(kaldi_native_fbank_URL "${f}")
|
set(kaldi_native_fbank_URL "${f}")
|
||||||
file(TO_CMAKE_PATH "${kaldi_native_fbank_URL}" kaldi_native_fbank_URL)
|
file(TO_CMAKE_PATH "${kaldi_native_fbank_URL}" kaldi_native_fbank_URL)
|
||||||
|
message(STATUS "Found local downloaded kaldi-native-fbank: ${kaldi_native_fbank_URL}")
|
||||||
set(kaldi_native_fbank_URL2 )
|
set(kaldi_native_fbank_URL2 )
|
||||||
break()
|
break()
|
||||||
endif()
|
endif()
|
||||||
|
|||||||
@@ -34,7 +34,17 @@ function(download_onnxruntime)
|
|||||||
# ./include
|
# ./include
|
||||||
# It contains all the needed header files
|
# It contains all the needed header files
|
||||||
if(SHERPA_ONNX_ENABLE_GPU)
|
if(SHERPA_ONNX_ENABLE_GPU)
|
||||||
set(onnxruntime_URL "https://github.com/microsoft/onnxruntime/releases/download/v1.14.1/onnxruntime-linux-x64-gpu-1.14.1.tgz")
|
set(onnxruntime_URL "https://github.com/microsoft/onnxruntime/releases/download/v1.14.0/onnxruntime-linux-x64-gpu-1.14.0.tgz")
|
||||||
|
set(onnxruntime_URL2 "https://huggingface.co/csukuangfj/sherpa-onnx-cmake-deps/resolve/main/onnxruntime-linux-x64-gpu-1.14.0.tgz")
|
||||||
|
set(onnxruntime_HASH "SHA256=d28fd59be62b9749071e2997c237b42f8e52661ae4d12862f77aa934750ead21")
|
||||||
|
|
||||||
|
set(possible_file_locations
|
||||||
|
$ENV{HOME}/Downloads/onnxruntime-linux-x64-gpu-1.14.0.tgz
|
||||||
|
${PROJECT_SOURCE_DIR}/onnxruntime-linux-x64-gpu-1.14.0.tgz
|
||||||
|
${PROJECT_BINARY_DIR}/onnxruntime-linux-x64-gpu-1.14.0.tgz
|
||||||
|
/tmp/onnxruntime-linux-x64-gpu-1.14.0.tgz
|
||||||
|
/star-fj/fangjun/download/github/onnxruntime-linux-x64-gpu-1.14.0.tgz
|
||||||
|
)
|
||||||
endif()
|
endif()
|
||||||
# After downloading, it contains:
|
# After downloading, it contains:
|
||||||
# ./lib/libonnxruntime.so.1.14.1
|
# ./lib/libonnxruntime.so.1.14.1
|
||||||
@@ -77,6 +87,10 @@ function(download_onnxruntime)
|
|||||||
set(onnxruntime_URL "https://github.com/microsoft/onnxruntime/releases/download/v1.14.0/onnxruntime-win-x86-1.14.0.zip")
|
set(onnxruntime_URL "https://github.com/microsoft/onnxruntime/releases/download/v1.14.0/onnxruntime-win-x86-1.14.0.zip")
|
||||||
set(onnxruntime_URL2 "https://huggingface.co/csukuangfj/sherpa-onnx-cmake-deps/resolve/main/onnxruntime-win-x86-1.14.0.zip")
|
set(onnxruntime_URL2 "https://huggingface.co/csukuangfj/sherpa-onnx-cmake-deps/resolve/main/onnxruntime-win-x86-1.14.0.zip")
|
||||||
set(onnxruntime_HASH "SHA256=4214b130db602cbf31a6f26f25377ab077af0cf03c4ddd4651283e1fb68f56cf")
|
set(onnxruntime_HASH "SHA256=4214b130db602cbf31a6f26f25377ab077af0cf03c4ddd4651283e1fb68f56cf")
|
||||||
|
|
||||||
|
if(SHERPA_ONNX_ENABLE_GPU)
|
||||||
|
message(FATAL_ERROR "GPU support for Win32 is not supported!")
|
||||||
|
endif()
|
||||||
else()
|
else()
|
||||||
# If you don't have access to the Internet,
|
# If you don't have access to the Internet,
|
||||||
# please pre-download onnxruntime
|
# please pre-download onnxruntime
|
||||||
@@ -92,6 +106,18 @@ function(download_onnxruntime)
|
|||||||
set(onnxruntime_URL "https://github.com/microsoft/onnxruntime/releases/download/v1.14.0/onnxruntime-win-x64-1.14.0.zip")
|
set(onnxruntime_URL "https://github.com/microsoft/onnxruntime/releases/download/v1.14.0/onnxruntime-win-x64-1.14.0.zip")
|
||||||
set(onnxruntime_URL2 "https://huggingface.co/csukuangfj/sherpa-onnx-cmake-deps/resolve/main/onnxruntime-win-x64-1.14.0.zip")
|
set(onnxruntime_URL2 "https://huggingface.co/csukuangfj/sherpa-onnx-cmake-deps/resolve/main/onnxruntime-win-x64-1.14.0.zip")
|
||||||
set(onnxruntime_HASH "SHA256=300eafef456748cde2743ee08845bd40ff1bab723697ff934eba6d4ce3519620")
|
set(onnxruntime_HASH "SHA256=300eafef456748cde2743ee08845bd40ff1bab723697ff934eba6d4ce3519620")
|
||||||
|
|
||||||
|
if(SHERPA_ONNX_ENABLE_GPU)
|
||||||
|
set(onnxruntime_URL "https://github.com/microsoft/onnxruntime/releases/download/v1.14.0/onnxruntime-win-x64-gpu-1.14.0.zip")
|
||||||
|
set(onnxruntime_URL2 "https://huggingface.co/csukuangfj/sherpa-onnx-cmake-deps/resolve/main/onnxruntime-win-x64-gpu-1.14.0.zip")
|
||||||
|
set(onnxruntime_HASH "SHA256=b42aac412ec96db92c182b9c8b02190da00072a5efc4adcbecf9b62e933c30d3")
|
||||||
|
set(possible_file_locations
|
||||||
|
$ENV{HOME}/Downloads/onnxruntime-win-x64-gpu-1.14.0.zip
|
||||||
|
${PROJECT_SOURCE_DIR}/onnxruntime-win-x64-gpu-1.14.0.zip
|
||||||
|
${PROJECT_BINARY_DIR}/onnxruntime-win-x64-gpu-1.14.0.zip
|
||||||
|
/tmp/onnxruntime-win-x64-gpu-1.14.0.zip
|
||||||
|
)
|
||||||
|
endif()
|
||||||
endif()
|
endif()
|
||||||
# After downloading, it contains:
|
# After downloading, it contains:
|
||||||
# ./lib/onnxruntime.{dll,lib,pdb}
|
# ./lib/onnxruntime.{dll,lib,pdb}
|
||||||
@@ -105,28 +131,22 @@ function(download_onnxruntime)
|
|||||||
message(FATAL_ERROR "Only support Linux, macOS, and Windows at present. Will support other OSes later")
|
message(FATAL_ERROR "Only support Linux, macOS, and Windows at present. Will support other OSes later")
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
if(NOT SHERPA_ONNX_ENABLE_GPU)
|
foreach(f IN LISTS possible_file_locations)
|
||||||
foreach(f IN LISTS possible_file_locations)
|
if(EXISTS ${f})
|
||||||
if(EXISTS ${f})
|
set(onnxruntime_URL "${f}")
|
||||||
set(onnxruntime_URL "${f}")
|
file(TO_CMAKE_PATH "${onnxruntime_URL}" onnxruntime_URL)
|
||||||
file(TO_CMAKE_PATH "${onnxruntime_URL}" onnxruntime_URL)
|
message(STATUS "Found local downloaded onnxruntime: ${onnxruntime_URL}")
|
||||||
set(onnxruntime_URL2)
|
set(onnxruntime_URL2)
|
||||||
break()
|
break()
|
||||||
endif()
|
endif()
|
||||||
endforeach()
|
endforeach()
|
||||||
|
|
||||||
FetchContent_Declare(onnxruntime
|
FetchContent_Declare(onnxruntime
|
||||||
URL
|
URL
|
||||||
${onnxruntime_URL}
|
${onnxruntime_URL}
|
||||||
${onnxruntime_URL2}
|
${onnxruntime_URL2}
|
||||||
URL_HASH ${onnxruntime_HASH}
|
URL_HASH ${onnxruntime_HASH}
|
||||||
)
|
)
|
||||||
else()
|
|
||||||
FetchContent_Declare(onnxruntime
|
|
||||||
URL
|
|
||||||
${onnxruntime_URL}
|
|
||||||
)
|
|
||||||
endif()
|
|
||||||
|
|
||||||
FetchContent_GetProperties(onnxruntime)
|
FetchContent_GetProperties(onnxruntime)
|
||||||
if(NOT onnxruntime_POPULATED)
|
if(NOT onnxruntime_POPULATED)
|
||||||
@@ -150,7 +170,7 @@ function(download_onnxruntime)
|
|||||||
INTERFACE_INCLUDE_DIRECTORIES "${onnxruntime_SOURCE_DIR}/include"
|
INTERFACE_INCLUDE_DIRECTORIES "${onnxruntime_SOURCE_DIR}/include"
|
||||||
)
|
)
|
||||||
|
|
||||||
if(SHERPA_ONNX_ENABLE_GPU)
|
if(SHERPA_ONNX_ENABLE_GPU AND NOT WIN32)
|
||||||
find_library(location_onnxruntime_cuda_lib onnxruntime_providers_cuda
|
find_library(location_onnxruntime_cuda_lib onnxruntime_providers_cuda
|
||||||
PATHS
|
PATHS
|
||||||
"${onnxruntime_SOURCE_DIR}/lib"
|
"${onnxruntime_SOURCE_DIR}/lib"
|
||||||
@@ -172,6 +192,24 @@ function(download_onnxruntime)
|
|||||||
DESTINATION
|
DESTINATION
|
||||||
${CMAKE_BINARY_DIR}/bin/${CMAKE_BUILD_TYPE}
|
${CMAKE_BINARY_DIR}/bin/${CMAKE_BUILD_TYPE}
|
||||||
)
|
)
|
||||||
|
if(SHERPA_ONNX_ENABLE_GPU)
|
||||||
|
add_library(onnxruntime_providers_cuda SHARED IMPORTED)
|
||||||
|
|
||||||
|
set_target_properties(onnxruntime_providers_cuda PROPERTIES
|
||||||
|
IMPORTED_LOCATION ${location_onnxruntime}
|
||||||
|
INTERFACE_INCLUDE_DIRECTORIES "${onnxruntime_SOURCE_DIR}/include"
|
||||||
|
)
|
||||||
|
|
||||||
|
set_property(TARGET onnxruntime_providers_cuda
|
||||||
|
PROPERTY
|
||||||
|
IMPORTED_IMPLIB "${onnxruntime_SOURCE_DIR}/lib/onnxruntime_providers_cuda.lib"
|
||||||
|
)
|
||||||
|
|
||||||
|
file(COPY ${onnxruntime_SOURCE_DIR}/lib/onnxruntime_providers_cuda.dll
|
||||||
|
DESTINATION
|
||||||
|
${CMAKE_BINARY_DIR}/bin/${CMAKE_BUILD_TYPE}
|
||||||
|
)
|
||||||
|
endif()
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
if(UNIX AND NOT APPLE)
|
if(UNIX AND NOT APPLE)
|
||||||
|
|||||||
@@ -20,6 +20,7 @@ function(download_portaudio)
|
|||||||
if(EXISTS ${f})
|
if(EXISTS ${f})
|
||||||
set(portaudio_URL "${f}")
|
set(portaudio_URL "${f}")
|
||||||
file(TO_CMAKE_PATH "${portaudio_URL}" portaudio_URL)
|
file(TO_CMAKE_PATH "${portaudio_URL}" portaudio_URL)
|
||||||
|
message(STATUS "Found local downloaded portaudio: ${portaudio_URL}")
|
||||||
set(portaudio_URL2)
|
set(portaudio_URL2)
|
||||||
break()
|
break()
|
||||||
endif()
|
endif()
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ function(download_pybind11)
|
|||||||
if(EXISTS ${f})
|
if(EXISTS ${f})
|
||||||
set(pybind11_URL "${f}")
|
set(pybind11_URL "${f}")
|
||||||
file(TO_CMAKE_PATH "${pybind11_URL}" pybind11_URL)
|
file(TO_CMAKE_PATH "${pybind11_URL}" pybind11_URL)
|
||||||
|
message(STATUS "Found local downloaded pybind11: ${pybind11_URL}")
|
||||||
set(pybind11_URL2)
|
set(pybind11_URL2)
|
||||||
break()
|
break()
|
||||||
endif()
|
endif()
|
||||||
|
|||||||
@@ -20,6 +20,7 @@ function(download_websocketpp)
|
|||||||
if(EXISTS ${f})
|
if(EXISTS ${f})
|
||||||
set(websocketpp_URL "${f}")
|
set(websocketpp_URL "${f}")
|
||||||
file(TO_CMAKE_PATH "${websocketpp_URL}" websocketpp_URL)
|
file(TO_CMAKE_PATH "${websocketpp_URL}" websocketpp_URL)
|
||||||
|
message(STATUS "Found local downloaded websocketpp: ${websocketpp_URL}")
|
||||||
set(websocketpp_URL2)
|
set(websocketpp_URL2)
|
||||||
break()
|
break()
|
||||||
endif()
|
endif()
|
||||||
|
|||||||
Reference in New Issue
Block a user