-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Switched to DirectML as GPU provider on Windows
- Loading branch information
Showing
7 changed files
with
152 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,40 +1,61 @@ | ||
include(FetchContent) | ||
|
||
if(WIN32) | ||
set(OS win) | ||
set(EXT zip) | ||
else() | ||
set(OS linux) | ||
set(EXT tgz) | ||
endif() | ||
set(PREFIX ${CMAKE_SHARED_LIBRARY_PREFIX}) | ||
set(SUFFIX ${CMAKE_SHARED_LIBRARY_SUFFIX}) | ||
# Use onnxruntime with DirectML | ||
|
||
# DirectML.dll is installed with windows, but the version is typically too old. | ||
FetchContent_Declare( | ||
directml | ||
URL https://www.nuget.org/api/v2/package/Microsoft.AI.DirectML/1.12.0 | ||
DOWNLOAD_EXTRACT_TIMESTAMP true | ||
) | ||
FetchContent_Declare( | ||
onnxruntime | ||
URL https://github.com/microsoft/onnxruntime/releases/download/v1.15.1/Microsoft.ML.OnnxRuntime.DirectML.1.15.1.zip | ||
DOWNLOAD_EXTRACT_TIMESTAMP true | ||
) | ||
FetchContent_MakeAvailable(directml onnxruntime) | ||
|
||
add_library(directml SHARED IMPORTED GLOBAL) | ||
set_target_properties(directml PROPERTIES | ||
IMPORTED_LOCATION ${directml_SOURCE_DIR}/bin/x64-win/DirectML.dll | ||
IMPORTED_IMPLIB ${directml_SOURCE_DIR}/bin/x64-win/DirectML.lib | ||
) | ||
add_library(onnxruntime SHARED IMPORTED GLOBAL) | ||
set_target_properties(onnxruntime PROPERTIES | ||
IMPORTED_LOCATION ${onnxruntime_SOURCE_DIR}/runtimes/win-x64/native/onnxruntime.dll | ||
IMPORTED_IMPLIB ${onnxruntime_SOURCE_DIR}/runtimes/win-x64/native/onnxruntime.lib | ||
INTERFACE_INCLUDE_DIRECTORIES ${onnxruntime_SOURCE_DIR}/build/native/include | ||
) | ||
add_dependencies(onnxruntime directml) | ||
set(ONNX_RUNTIME_DEPENDENCIES | ||
$<TARGET_FILE:onnxruntime> | ||
$<TARGET_FILE:directml> | ||
PARENT_SCOPE) | ||
|
||
FetchContent_Declare( | ||
onnxruntime | ||
URL https://github.com/microsoft/onnxruntime/releases/download/v1.15.1/onnxruntime-${OS}-x64-gpu-1.15.1.${EXT} | ||
DOWNLOAD_EXTRACT_TIMESTAMP true | ||
) | ||
FetchContent_MakeAvailable(onnxruntime) | ||
else() # Linux | ||
# Use onnxruntime with CUDA | ||
|
||
add_library(onnxruntime_providers_shared SHARED IMPORTED GLOBAL) | ||
set_target_properties(onnxruntime_providers_shared PROPERTIES | ||
IMPORTED_LOCATION ${onnxruntime_SOURCE_DIR}/lib/${PREFIX}onnxruntime_providers_shared${SUFFIX} | ||
) | ||
add_library(onnxruntime_providers_cuda SHARED IMPORTED GLOBAL) | ||
set_target_properties(onnxruntime_providers_cuda PROPERTIES | ||
IMPORTED_LOCATION ${onnxruntime_SOURCE_DIR}/lib/${PREFIX}onnxruntime_providers_cuda${SUFFIX} | ||
) | ||
add_library(onnxruntime SHARED IMPORTED GLOBAL) | ||
set_target_properties(onnxruntime PROPERTIES | ||
IMPORTED_LOCATION ${onnxruntime_SOURCE_DIR}/lib/${PREFIX}onnxruntime${SUFFIX} | ||
IMPORTED_IMPLIB ${onnxruntime_SOURCE_DIR}/lib/onnxruntime.lib | ||
INTERFACE_INCLUDE_DIRECTORIES ${onnxruntime_SOURCE_DIR}/include | ||
) | ||
add_dependencies(onnxruntime onnxruntime_providers_shared onnxruntime_providers_cuda) | ||
FetchContent_Declare( | ||
onnxruntime | ||
URL https://github.com/microsoft/onnxruntime/releases/download/v1.15.1/onnxruntime-linux-x64-gpu-1.15.1.tgz | ||
DOWNLOAD_EXTRACT_TIMESTAMP true | ||
) | ||
FetchContent_MakeAvailable(onnxruntime) | ||
|
||
set(ONNX_RUNTIME_DEPENDENCIES | ||
$<TARGET_FILE:onnxruntime> | ||
$<TARGET_FILE:onnxruntime_providers_shared> | ||
$<TARGET_FILE:onnxruntime_providers_cuda> | ||
PARENT_SCOPE) | ||
add_library(onnxruntime_providers_shared SHARED IMPORTED GLOBAL) | ||
set_target_properties(onnxruntime_providers_shared PROPERTIES | ||
IMPORTED_LOCATION ${onnxruntime_SOURCE_DIR}/lib/libonnxruntime_providers_shared.so | ||
) | ||
add_library(onnxruntime_providers_cuda SHARED IMPORTED GLOBAL) | ||
set_target_properties(onnxruntime_providers_cuda PROPERTIES | ||
IMPORTED_LOCATION ${onnxruntime_SOURCE_DIR}/lib/libonnxruntime_providers_cuda.so | ||
) | ||
add_library(onnxruntime SHARED IMPORTED GLOBAL) | ||
set_target_properties(onnxruntime PROPERTIES | ||
IMPORTED_LOCATION ${onnxruntime_SOURCE_DIR}/lib/libonnxruntime.so | ||
INTERFACE_INCLUDE_DIRECTORIES ${onnxruntime_SOURCE_DIR}/include | ||
) | ||
add_dependencies(onnxruntime onnxruntime_providers_shared onnxruntime_providers_cuda) | ||
|
||
endif() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
#pragma once | ||
|
||
namespace dlimg { | ||
|
||
#ifdef _WIN32 | ||
constexpr bool is_windows = true; | ||
#else | ||
constexpr bool is_windows = false; | ||
#endif | ||
constexpr bool is_linux = !is_windows; | ||
|
||
} // namespace dlimg |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters