mirror of
https://github.com/saymrwulf/onnxruntime.git
synced 2026-07-19 19:00:47 +00:00
Support building Windows CUDA with Ninja (#20176)
### How to run it locally
1. conda install ninja
2. "C:\Program Files\Microsoft Visual
Studio\2022\Enterprise\VC\Auxiliary\Build\vcvarsall.bat" x64
3. python.exe {ort_repo}\tools\ci_build\build.py --config RelWithDebInfo
--build_dir {ort_repo}\build_cuda --skip_submodule_sync --build_csharp
--update --parallel --cmake_generator "Ninja" --build_shared_lib
--enable_onnx_tests --enable_pybind --build_java --build_nodejs
--use_cuda "--cuda_home=C:\Program Files\NVIDIA GPU Computing
Toolkit\CUDA\v11.8" --enable_cuda_profiling --cmake_extra_defines
CMAKE_CUDA_ARCHITECTURES=60
4. cd build_cuda\RelWithDebInfo
5. cmake --build . j16
### Motivation and Context
In packaging pipelines, we often come across a random issue that the
building with CUDA on Windows takes too much time.
Although it has been reduced much by moving the building to the CPU
machine.
We're planning to build with Ninja instead of msbuild in Packaging
pipelines, thus, nvcc can run parallelly.
It's the first step to support it locally.
This commit is contained in:
parent
fa1917b81b
commit
dae77e6014
4 changed files with 23 additions and 5 deletions
|
|
@ -1434,6 +1434,11 @@ if (onnxruntime_USE_CUDA)
|
|||
if (NOT WIN32)
|
||||
list(APPEND CUDA_NVCC_FLAGS --compiler-options -fPIC)
|
||||
endif()
|
||||
if(MSVC)
|
||||
if(CUDA_NVCC_FLAGS MATCHES "Zi")
|
||||
list(APPEND CUDA_NVCC_FLAGS "-Xcompiler" "-FS")
|
||||
endif()
|
||||
endif()
|
||||
# Options passed to cudafe
|
||||
set(CMAKE_CUDA_FLAGS "${CMAKE_CUDA_FLAGS} -Xcudafe \"--diag_suppress=bad_friend_decl\"")
|
||||
set(CMAKE_CUDA_FLAGS "${CMAKE_CUDA_FLAGS} -Xcudafe \"--diag_suppress=unsigned_compare_with_zero\"")
|
||||
|
|
|
|||
|
|
@ -88,7 +88,7 @@ add_custom_target(js_common_npm_ci ALL
|
|||
|
||||
add_custom_target(nodejs_binding_wrapper ALL
|
||||
COMMAND ${NPM_CLI} ci
|
||||
COMMAND ${NPM_CLI} run build -- --onnxruntime-build-dir=${CMAKE_CURRENT_BINARY_DIR} --config=${CMAKE_BUILD_TYPE}
|
||||
COMMAND ${NPM_CLI} run build -- --onnxruntime-build-dir=${CMAKE_CURRENT_BINARY_DIR} --config=${CMAKE_BUILD_TYPE} --onnxruntime-generator=${CMAKE_GENERATOR}
|
||||
--arch=${NODEJS_BINDING_ARCH} ${NODEJS_BINDING_USE_CUDA} ${NODEJS_BINDING_USE_DML} ${NODEJS_BINDING_USE_TENSORRT}
|
||||
${NODEJS_BINDING_USE_COREML}
|
||||
WORKING_DIRECTORY ${JS_NODE_ROOT}
|
||||
|
|
|
|||
|
|
@ -66,9 +66,17 @@ if(MSVC AND CMAKE_JS_NODELIB_DEF AND CMAKE_JS_NODELIB_TARGET)
|
|||
execute_process(COMMAND ${CMAKE_AR} /def:${CMAKE_JS_NODELIB_DEF} /out:${CMAKE_JS_NODELIB_TARGET} ${CMAKE_STATIC_LINKER_FLAGS})
|
||||
endif()
|
||||
|
||||
if (WIN32)
|
||||
if (${ONNXRUNTIME_GENERATOR} MATCHES "Ninja")
|
||||
set(ONNXRUNTIME_WIN_BIN_DIR ${ONNXRUNTIME_BUILD_DIR})
|
||||
else()
|
||||
set(ONNXRUNTIME_WIN_BIN_DIR ${ONNXRUNTIME_BUILD_DIR}/${CMAKE_BUILD_TYPE})
|
||||
endif()
|
||||
message(STATUS "onnxruntime dist dir: ${ONNXRUNTIME_WIN_BIN_DIR}")
|
||||
endif()
|
||||
# add libraries
|
||||
if (WIN32)
|
||||
target_link_directories(onnxruntime_binding PRIVATE ${ONNXRUNTIME_BUILD_DIR}/${CMAKE_BUILD_TYPE})
|
||||
target_link_directories(onnxruntime_binding PRIVATE ${ONNXRUNTIME_WIN_BIN_DIR})
|
||||
else()
|
||||
target_link_directories(onnxruntime_binding PRIVATE ${ONNXRUNTIME_BUILD_DIR})
|
||||
endif()
|
||||
|
|
@ -95,14 +103,14 @@ if (WIN32)
|
|||
add_custom_command(
|
||||
TARGET onnxruntime_binding POST_BUILD
|
||||
COMMAND ${CMAKE_COMMAND} -E copy
|
||||
${ONNXRUNTIME_BUILD_DIR}/${CMAKE_BUILD_TYPE}/onnxruntime.dll
|
||||
${ONNXRUNTIME_WIN_BIN_DIR}/onnxruntime.dll
|
||||
${dist_folder}
|
||||
)
|
||||
if (USE_DML)
|
||||
add_custom_command(
|
||||
TARGET onnxruntime_binding POST_BUILD
|
||||
COMMAND ${CMAKE_COMMAND} -E copy
|
||||
${ONNXRUNTIME_BUILD_DIR}/${CMAKE_BUILD_TYPE}/DirectML.dll
|
||||
${ONNXRUNTIME_WIN_BIN_DIR}/DirectML.dll
|
||||
${dist_folder}
|
||||
)
|
||||
endif ()
|
||||
|
|
@ -110,7 +118,7 @@ if (WIN32)
|
|||
add_custom_command(
|
||||
TARGET onnxruntime_binding POST_BUILD
|
||||
COMMAND ${CMAKE_COMMAND} -E copy
|
||||
${ONNXRUNTIME_BUILD_DIR}/${CMAKE_BUILD_TYPE}/onnxruntime.pdb
|
||||
${ONNXRUNTIME_WIN_BIN_DIR}/onnxruntime.pdb
|
||||
${dist_folder}
|
||||
COMMAND ${CMAKE_COMMAND} -E copy $<TARGET_FILE_DIR:onnxruntime_binding>/onnxruntime_binding.pdb ${dist_folder}
|
||||
)
|
||||
|
|
|
|||
|
|
@ -23,6 +23,8 @@ if (ARCH !== 'x64' && ARCH !== 'ia32' && ARCH !== 'arm64' && ARCH !== 'arm') {
|
|||
}
|
||||
// --onnxruntime-build-dir=
|
||||
const ONNXRUNTIME_BUILD_DIR = buildArgs['onnxruntime-build-dir'];
|
||||
// --onnxruntime-generator=
|
||||
const ONNXRUNTIME_GENERATOR = buildArgs['onnxruntime-generator'];
|
||||
// --rebuild
|
||||
const REBUILD = !!buildArgs.rebuild;
|
||||
// --use_dml
|
||||
|
|
@ -55,6 +57,9 @@ const args = [
|
|||
if (ONNXRUNTIME_BUILD_DIR && typeof ONNXRUNTIME_BUILD_DIR === 'string') {
|
||||
args.push(`--CDONNXRUNTIME_BUILD_DIR=${ONNXRUNTIME_BUILD_DIR}`);
|
||||
}
|
||||
if (ONNXRUNTIME_GENERATOR && typeof ONNXRUNTIME_GENERATOR === 'string') {
|
||||
args.push(`--CDONNXRUNTIME_GENERATOR=${ONNXRUNTIME_GENERATOR}`);
|
||||
}
|
||||
if (USE_DML) {
|
||||
args.push('--CDUSE_DML=ON');
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue