build.bat 5.9 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120
@ECHO OFF
SETLOCAL 
set source_path=%1
set PYTHON_DIR=%2
set WITH_GPU=%3
set WITH_MKL=%4
set ON_INFER=%5
set PADDLE_VERSION=%6
set BATDIR=%7
set CUDA_DIR=%8

set RETRY_TIMES=3

set CUDA_DIR_WIN=%CUDA_DIR:/=\%
set PATH=%CUDA_DIR_WIN%\nvvm\bin\;%CUDA_DIR_WIN%\bin;%PATH%


for /f "tokens=1,2,* delims=\\" %%a in ("%PYTHON_DIR%") do (
	set c1=%%a
	set c2=%%b
)
set PYTHONV=%c2%

echo %CUDA_DIR% | findstr 10.0 > NULL
if %errorlevel% == 0 (set PADDLE_VERSION=%PADDLE_VERSION%
set CUDAV=v10.0)
echo %CUDA_DIR% | findstr 9.2 > NULL
if %errorlevel% == 0 (set PADDLE_VERSION=%PADDLE_VERSION%.post97
set CUDAV=v9.2)
echo %CUDA_DIR% | findstr 9.0 > NULL
if %errorlevel% == 0 (set PADDLE_VERSION=%PADDLE_VERSION%.post97
set CUDAV=v9.0)
echo %CUDA_DIR% | findstr 8.0 > NULL
if %errorlevel% == 0 (set PADDLE_VERSION=%PADDLE_VERSION%.post87
set CUDAV=v8.0)
set PLAT=GPU
if "%WITH_GPU%"=="OFF" (
    set PLAT=CPU
    set CUDAV=CPU
)

if "%WITH_MKL%"=="ON" (
    set BLAS=MKL
) else (
    set BLAS=OPEN
)

if "%ON_INFER%"=="ON" (
    goto :INFERENCE_LIBRARY
)

echo "begin to do build noavx ..."

set "dst_path=%source_path%\build_%PYTHONV%_%PLAT%_%BLAS%_%CUDAV%_noavx"

if exist %dst_path% rmdir /q /s %dst_path%
mkdir %dst_path%

cd /d %dst_path%
echo Current directory : %cd%

call:rest_env

echo cmake %dst_path%\..\Paddle -G "Visual Studio 14 2015 Win64" -DWITH_GPU=%WITH_GPU% -DWITH_MKL=%WITH_MKL% -DWITH_AVX=OFF -DPYTHON_INCLUDE_DIR=%PYTHON_DIR%\include\ -DPYTHON_LIBRARY=%PYTHON_DIR%\libs\ -DPYTHON_EXECUTABLE=%PYTHON_DIR%\python.exe -DCMAKE_BUILD_TYPE=Release -DWITH_TESTING=OFF -DWITH_PYTHON=ON -DCUDA_TOOLKIT_ROOT_DIR=%CUDA_DIR% -DCUDA_ARCH_NAME=All
cmake %dst_path%\..\Paddle -G "Visual Studio 14 2015 Win64" -DWITH_GPU=%WITH_GPU% -DWITH_MKL=%WITH_MKL% -DWITH_AVX=OFF -DPYTHON_INCLUDE_DIR=%PYTHON_DIR%\include\ -DPYTHON_LIBRARY=%PYTHON_DIR%\libs\ -DPYTHON_EXECUTABLE=%PYTHON_DIR%\python.exe -DCMAKE_BUILD_TYPE=Release -DWITH_TESTING=OFF -DWITH_PYTHON=ON -DCUDA_TOOLKIT_ROOT_DIR=%CUDA_DIR% -DCUDA_ARCH_NAME=All

set  MSBUILDDISABLENODEREUSE=1

set BUILD_TYPE=NO_AVX
call:Build

REM -------------------------------------------------------------------------

echo "begin to do build avx ..."
set "dst_path=%source_path%\build_%PYTHONV%_%PLAT%_%BLAS%_%CUDAV%"

if exist %dst_path% rmdir /q /s %dst_path%
mkdir %dst_path%

cd /d %dst_path%
echo Current directory : %cd%

call:rest_env

echo cmake %dst_path%\..\Paddle -G "Visual Studio 14 2015 Win64" -DWITH_GPU=%WITH_GPU% -DWITH_MKL=%WITH_MKL% -DWITH_AVX=ON -DPYTHON_INCLUDE_DIR=%PYTHON_DIR%\include\ -DPYTHON_LIBRARY=%PYTHON_DIR%\libs\ -DPYTHON_EXECUTABLE=%PYTHON_DIR%\python.exe -DCMAKE_BUILD_TYPE=Release -DWITH_TESTING=OFF -DWITH_PYTHON=ON -DCUDA_TOOLKIT_ROOT_DIR=%CUDA_DIR% -DCUDA_ARCH_NAME=All -DNOAVX_CORE_FILE=%dst_path%_noavx\python\paddle\fluid\core_noavx.pyd
cmake %dst_path%\..\Paddle -G "Visual Studio 14 2015 Win64" -DWITH_GPU=%WITH_GPU% -DWITH_MKL=%WITH_MKL% -DWITH_AVX=ON -DPYTHON_INCLUDE_DIR=%PYTHON_DIR%\include\ -DPYTHON_LIBRARY=%PYTHON_DIR%\libs\ -DPYTHON_EXECUTABLE=%PYTHON_DIR%\python.exe -DCMAKE_BUILD_TYPE=Release -DWITH_TESTING=OFF -DWITH_PYTHON=ON -DCUDA_TOOLKIT_ROOT_DIR=%CUDA_DIR% -DCUDA_ARCH_NAME=All -DNOAVX_CORE_FILE=%dst_path%_noavx\python\paddle\fluid\core_noavx.pyd

set  MSBUILDDISABLENODEREUSE=1

set BUILD_TYPE=AVX
call:Build

echo BUILD WHL PACKAGE COMPLETE
goto :END
REM -------------------------------------------------------------------------

:INFERENCE_LIBRARY

echo "begin to do build inference library ..."
set "dst_path=%source_path%\build_INFERENCE_LIBRARY_%PLAT%_%BLAS%_%CUDAV%"

if exist %dst_path% rmdir /q /s %dst_path%
mkdir %dst_path%

cd /d %dst_path%
echo Current directory : %cd%

call:rest_env

echo cmake %dst_path%\..\Paddle -G "Visual Studio 14 2015 Win64" -DWITH_GPU=%WITH_GPU% -DWITH_MKL=%WITH_MKL% -DCMAKE_BUILD_TYPE=Release -DWITH_PYTHON=OFF -DON_INFER=ON -DCUDA_TOOLKIT_ROOT_DIR=%CUDA_DIR% -DCUDA_ARCH_NAME=All
cmake %dst_path%\..\Paddle -G "Visual Studio 14 2015 Win64" -DWITH_GPU=%WITH_GPU% -DWITH_MKL=%WITH_MKL% -DCMAKE_BUILD_TYPE=Release -DWITH_PYTHON=OFF -DON_INFER=ON  -DCUDA_TOOLKIT_ROOT_DIR=%CUDA_DIR%  -DCUDA_ARCH_NAME=All

set  MSBUILDDISABLENODEREUSE=1

set BUILD_TYPE=INFERENCE LIBRARY
call:Build

echo PACKAGE INFERENCE LIBRARY

mkdir inference_dist
121 122
%PYTHON_DIR%\python.exe -c "import shutil;shutil.make_archive('inference_dist/paddle_inference_install_dir', 'zip', root_dir='paddle_inference_install_dir')"
%PYTHON_DIR%\python.exe -c "import shutil;shutil.make_archive('inference_dist/paddle_install_dir', 'zip', root_dir='paddle_install_dir')"
123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187

echo BUILD INFERENCE LIBRARY COMPLETE
goto :END


:Rest_env
echo "Reset Build Environment ..."
taskkill /f /im cmake.exe   2>NUL
taskkill /f /im msbuild.exe 2>NUL
taskkill /f /im git.exe 2>NUL
taskkill /f /im cl.exe 2>NUL
taskkill /f /im lib.exe 2>NUL
taskkill /f /im git-remote-https.exe 2>NUL
taskkill /f /im vctip.exe 2>NUL
goto:eof

:Build
set build_times=1
:build_thirdparty

echo Build %BUILD_TYPE% Third Party Libraries, Round : %build_times%

echo msbuild /m /p:Configuration=Release third_party.vcxproj ^>^> build_thirdparty_%build_times%.log
msbuild /m /p:Configuration=Release third_party.vcxproj >> build_thirdparty_%build_times%.log

IF %ERRORLEVEL% NEQ 0 (
    echo Build %BUILD_TYPE% Third Party Libraries, Round : %build_times% Failed!
    set /a build_times=%build_times%+1

    if %build_times% GTR %RETRY_TIMES% (
      goto :FAILURE
  ) else (
      goto :build_thirdparty
  )
)

set build_times=1
:build_paddle

echo Build %BUILD_TYPE% Paddle Solutions, Round : %build_times%

echo msbuild /m /p:Configuration=Release paddle.sln ^>^> build_%build_times%.log
msbuild /m /p:Configuration=Release paddle.sln >> build_%build_times%.log

IF %ERRORLEVEL% NEQ 0 (
    echo Build %BUILD_TYPE% Paddle Solutions, Round : %build_times% Failed!
    set /a build_times=%build_times%+1

    if %build_times% GTR %RETRY_TIMES% (
      goto :FAILURE
  ) else (
      goto :build_paddle
  )
)
goto:eof


:FAILURE
echo BUILD FAILED
exit /b 1

:END
echo BUILD SUCCESSFULLY

ENDLOCAL