using sccache and ninja to speed up windows gpu compilation

This commit is contained in:
qinzheng4 2023-03-18 21:22:56 +08:00
parent cb288ae32e
commit 16657cc25a
2 changed files with 29 additions and 7 deletions

View File

@ -48,6 +48,15 @@ IF %errorlevel% == 0 (
echo "use mingw compiler"
)
set USE_SCCACHE=off
where sccache
IF %errorlevel% == 0 (
set USE_SCCACHE=on
echo "use sccache to speed up compilation"
) ELSE (
echo "sccache doesn't exist"
)
IF NOT EXIST "%BUILD_PATH%" (
md "build"
)
@ -71,18 +80,21 @@ IF "%1%" == "lite" (
) ELSE (
IF "%1%" == "ms_vs_gpu" (
echo "======Start gen VS2019 Project for MS gpu ======"
cmake -DCMAKE_BUILD_TYPE=Release -DENABLE_CPU=ON -DENABLE_GPU=ON -DGPU_BACKEND_CUDA=ON -DMS_REQUIRE_CUDA_VERSION=11.1 -DENABLE_MINDDATA=ON -DUSE_GLOG=ON -DENABLE_GITEE=%ENABLE_GITEE% ^
-G "Visual Studio 16 2019" -A x64 ../..
for /f "delims=" %%i in ('powershell.exe -ExecutionPolicy Bypass -Command "Get-ChildItem HKLM:\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall | foreach { Get-ItemProperty $_.PsPath } | where { $_.DisplayName -like '*Visual Studio*' -and $_.InstallLocation.Length -gt 0 } | sort InstallDate -Descending | foreach { Join-Path $_.InstallLocation 'VC\Auxiliary\Build'}"') do (call "%%i\vcvars64.bat")
IF %USE_SCCACHE% == on (
cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_C_COMPILER_LAUNCHER=sccache -DCMAKE_CXX_COMPILER_LAUNCHER=sccache -DCMAKE_CUDA_COMPILER_LAUNCHER=sccache -DENABLE_CPU=ON -DENABLE_GPU=ON -DGPU_BACKEND_CUDA=ON -DMS_REQUIRE_CUDA_VERSION=11.1 -DENABLE_MINDDATA=ON -DUSE_GLOG=ON -DENABLE_GITEE=%ENABLE_GITEE% ^
-G Ninja ../..
) ELSE (
cmake -DCMAKE_BUILD_TYPE=Release -DENABLE_CPU=ON -DENABLE_GPU=ON -DGPU_BACKEND_CUDA=ON -DMS_REQUIRE_CUDA_VERSION=11.1 -DENABLE_MINDDATA=ON -DUSE_GLOG=ON -DENABLE_GITEE=%ENABLE_GITEE% ^
-G Ninja ../..
)
) ELSE IF "%1%" == "ms_vs_cpu" (
echo "======Start gen VS2019 Project for MS cpu ======"
for /f "delims=" %%i in ('powershell.exe -ExecutionPolicy Bypass -Command "Get-ChildItem HKLM:\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall | foreach { Get-ItemProperty $_.PsPath } | where { $_.DisplayName -like '*Visual Studio*' -and $_.InstallLocation.Length -gt 0 } | sort InstallDate -Descending | foreach { Join-Path $_.InstallLocation 'VC\Auxiliary\Build'}"') do (call "%%i\vcvars64.bat")
where sccache
IF !errorlevel! == 0 (
echo "use sccache to speed up compile"
IF %USE_SCCACHE% == on (
cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_C_COMPILER_LAUNCHER=sccache -DCMAKE_CXX_COMPILER_LAUNCHER=sccache -DENABLE_CPU=ON -DENABLE_MINDDATA=ON -DUSE_GLOG=ON -DENABLE_GITEE=%ENABLE_GITEE% ^
-G Ninja ../..
) ELSE (
echo "fail to find sccache"
cmake -DCMAKE_BUILD_TYPE=Release -DENABLE_CPU=ON -DENABLE_MINDDATA=ON -DUSE_GLOG=ON -DENABLE_GITEE=%ENABLE_GITEE% ^
-G Ninja ../..
)

View File

@ -33,7 +33,17 @@ if(ENABLE_GPU)
else()
target_compile_options(cuda_common_obj PRIVATE "/std:c++17")
endif()
cuda_add_library(cuda_ops SHARED ${CUDA_OPS_SRC_LIST} $<TARGET_OBJECTS:cuda_common_obj>)
if(WIN32)
list(JOIN CUDA_NVCC_FLAGS " " tmp_nvcc_flags)
# CUDA_NVCC_FLAGS is not valid for add_library(), use CMAKE_CUDA_FLAGS instead.
string(APPEND CMAKE_CUDA_FLAGS " ${tmp_nvcc_flags}")
add_compile_definitions(_ENABLE_EXTENDED_ALIGNED_STORAGE)
# cuda_add_library() doesn't support ccache or sccache and it is deprecated for cmake v3.10+
add_library(cuda_ops SHARED ${CUDA_OPS_SRC_LIST} $<TARGET_OBJECTS:cuda_common_obj>)
else()
cuda_add_library(cuda_ops SHARED ${CUDA_OPS_SRC_LIST} $<TARGET_OBJECTS:cuda_common_obj>)
endif()
if(NOT BUILD_LITE)
set_target_properties(cuda_ops PROPERTIES SOVERSION ${CUDA_VERSION_MAJOR})
endif()