Advertisement
Guest User

Untitled

a guest
Jan 23rd, 2017
140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.20 KB | None | 0 0
  1. @echo off
  2. @setlocal EnableDelayedExpansion
  3. ::Deeplearning.ir
  4. ::Sample config for compiling caffe on windows using cmake
  5. ::This is configured to get compiled with cudnn5.1 and cuda8
  6. ::It is tested under windows 10 x64 ver1607
  7. ::Contact: Coderx7@gmail.com
  8.  
  9. :: Default values
  10. if DEFINED APPVEYOR (
  11. echo Setting Appveyor defaults
  12. if NOT DEFINED MSVC_VERSION set MSVC_VERSION=14
  13. if NOT DEFINED WITH_NINJA set WITH_NINJA=1
  14. if NOT DEFINED CPU_ONLY set CPU_ONLY=1
  15. if NOT DEFINED CMAKE_CONFIG set CMAKE_CONFIG=Release
  16. if NOT DEFINED CMAKE_BUILD_SHARED_LIBS set CMAKE_BUILD_SHARED_LIBS=0
  17. if NOT DEFINED BUILD_PYTHON set BUILD_PYTHON=1
  18. if NOT DEFINED BUILD_PYTHON_LAYER set BUILD_PYTHON_LAYER=1
  19. if NOT DEFINED BUILD_MATLAB set BUILD_MATLAB=0
  20. if NOT DEFINED PYTHON_EXE set PYTHON_EXE=python
  21. if NOT DEFINED RUN_TESTS set RUN_TESTS=1
  22. if NOT DEFINED RUN_LINT set RUN_LINT=1
  23. if NOT DEFINED RUN_INSTALL set RUN_INSTALL=1
  24.  
  25. :: Set python 2.7 with conda as the default python
  26. set PATH=C:\Anaconda2;C:\Anaconda2\Scripts;C:\Anaconda2\Library\bin;!PATH!
  27. :: Check that we have the right python version
  28. !PYTHON_EXE! --version
  29. :: Add the required channels
  30. conda config --add channels conda-forge
  31. conda config --add channels willyd
  32. :: Update conda
  33. conda update conda -y
  34. :: Create an environment
  35. :: Todo create protobuf package for vc14
  36. conda install --yes cmake ninja numpy scipy protobuf==3.1.0.vc12 six scikit-image
  37.  
  38. if ERRORLEVEL 1 (
  39. echo ERROR: Conda update or install failed
  40. exit /b 1
  41. )
  42.  
  43. :: Disable the tests in debug config
  44. if "%CMAKE_CONFIG%" == "Debug" (
  45. echo Disabling tests on appveyor with config == %CMAKE_CONFIG%
  46. set RUN_TESTS=0
  47. )
  48.  
  49. ) else (
  50. :: Change the settings here to match your setup
  51. :: Change MSVC_VERSION to 12 to use VS 2013 /14 dor 2015
  52. if NOT DEFINED MSVC_VERSION set MSVC_VERSION=12
  53. :: Change to 1 to use Ninja generator (builds much faster)
  54. if NOT DEFINED WITH_NINJA set WITH_NINJA=0
  55. :: Change to 1 to build caffe without CUDA support
  56. if NOT DEFINED CPU_ONLY set CPU_ONLY=0
  57. :: Change to Debug to build Debug. This is only relevant for the Ninja generator the Visual Studio generator will generate both Debug and Release configs
  58. if NOT DEFINED CMAKE_CONFIG set CMAKE_CONFIG=Release
  59. :: Change to 1 to build a caffe.dll
  60. if NOT DEFINED CMAKE_BUILD_SHARED_LIBS set CMAKE_BUILD_SHARED_LIBS=0
  61. :: Change these options for your needs.
  62. if NOT DEFINED BUILD_PYTHON set BUILD_PYTHON=1
  63. if NOT DEFINED BUILD_PYTHON_LAYER set BUILD_PYTHON_LAYER=1
  64. if NOT DEFINED BUILD_MATLAB set BUILD_MATLAB=0
  65. :: If python is on your path leave this alone
  66. if NOT DEFINED PYTHON_EXE set PYTHON_EXE=python
  67. :: Run the tests
  68. if NOT DEFINED RUN_TESTS set RUN_TESTS=1
  69. :: Run lint
  70. if NOT DEFINED RUN_LINT set RUN_LINT=0
  71. :: Build the install target
  72. if NOT DEFINED RUN_INSTALL set RUN_INSTALL=1
  73. )
  74.  
  75. :: Set the appropriate CMake generator
  76. :: Use the exclamation mark ! below to delay the
  77. :: expansion of CMAKE_GENERATOR
  78. if %WITH_NINJA% EQU 0 (
  79. if "%MSVC_VERSION%"=="14" (
  80. set CMAKE_GENERATOR=Visual Studio 14 2015 Win64
  81. )
  82. if "%MSVC_VERSION%"=="12" (
  83. set CMAKE_GENERATOR=Visual Studio 12 2013 Win64
  84. )
  85. if "!CMAKE_GENERATOR!"=="12" (
  86. echo ERROR: Unsupported MSVC version
  87. exit /B 1
  88. )
  89. ) else (
  90. set CMAKE_GENERATOR=Ninja
  91. )
  92.  
  93. echo INFO: ============================================================
  94. echo INFO: Summary:
  95. echo INFO: ============================================================
  96. echo INFO: MSVC_VERSION = !MSVC_VERSION!
  97. echo INFO: WITH_NINJA = !WITH_NINJA!
  98. echo INFO: CMAKE_GENERATOR = "!CMAKE_GENERATOR!"
  99. echo INFO: CPU_ONLY = !CPU_ONLY!
  100. echo INFO: CMAKE_CONFIG = !CMAKE_CONFIG!
  101. echo INFO: CMAKE_BUILD_SHARED_LIBS = !CMAKE_BUILD_SHARED_LIBS!
  102. echo INFO: BUILD_PYTHON = !BUILD_PYTHON!
  103. echo INFO: BUILD_PYTHON_LAYER = !BUILD_PYTHON_LAYER!
  104. echo INFO: BUILD_MATLAB = !BUILD_MATLAB!
  105. echo INFO: PYTHON_EXE = "!PYTHON_EXE!"
  106. echo INFO: RUN_TESTS = !RUN_TESTS!
  107. echo INFO: RUN_LINT = !RUN_LINT!
  108. echo INFO: RUN_INSTALL = !RUN_INSTALL!
  109. echo INFO: ============================================================
  110.  
  111. :: Build and exectute the tests
  112. :: Do not run the tests with shared library
  113. if !RUN_TESTS! EQU 1 (
  114. if %CMAKE_BUILD_SHARED_LIBS% EQU 1 (
  115. echo WARNING: Disabling tests with shared library build
  116. set RUN_TESTS=0
  117. )
  118. )
  119.  
  120. :: Create build directory and configure cmake
  121. if EXIST build (
  122. echo ERROR: build directory already exists in %cd%\build please remove it and start over.
  123. exit /b 1
  124. )
  125.  
  126. mkdir build
  127. pushd build
  128.  
  129. :: Download dependencies from VS x64
  130. echo INFO: Downloading dependencies
  131. "%PYTHON_EXE%" "%~dp0\download_prebuilt_dependencies.py" --msvc_version v%MSVC_VERSION%0
  132.  
  133. if ERRORLEVEL 1 (
  134. echo ERROR: Downloading dependencies failed
  135. exit /b 1
  136. )
  137.  
  138.  
  139. :: Add the dependencies to the PATH
  140. if EXIST "%cd%\libraries\prependpath.bat" (
  141. call "%cd%\libraries\prependpath.bat"
  142. )
  143.  
  144. :: Setup the environement for VS x64
  145. set batch_file=!VS%MSVC_VERSION%0COMNTOOLS!..\..\VC\vcvarsall.bat
  146. call "%batch_file%" amd64
  147.  
  148. :: Configure using cmake and using the caffe-builder dependencies
  149. :: Add -DCUDNN_ROOT=C:/Projects/caffe/cudnn-8.0-windows10-x64-v5.1/cuda ^
  150. :: below to use cuDNN
  151. cmake -G"!CMAKE_GENERATOR!" ^
  152. -DBLAS=Open ^
  153. -DCMAKE_BUILD_TYPE:STRING=%CMAKE_CONFIG% ^
  154. -DBUILD_SHARED_LIBS:BOOL=%CMAKE_BUILD_SHARED_LIBS% ^
  155. -DBUILD_python:BOOL=%BUILD_PYTHON% ^
  156. -DBUILD_python_layer:BOOL=%BUILD_PYTHON_LAYER% ^
  157. -DBUILD_matlab:BOOL=%BUILD_MATLAB% ^
  158. -DCPU_ONLY:BOOL=%CPU_ONLY% ^
  159. -DCUDNN_ROOT="C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v8.0\cuda" ^
  160. -C "%cd%\libraries\caffe-builder-config.cmake" ^
  161. "%~dp0\.."
  162.  
  163. if ERRORLEVEL 1 (
  164. echo ERROR: Configure failed
  165. exit /b 1
  166. )
  167.  
  168. :: Lint
  169. if %RUN_LINT% EQU 1 (
  170. cmake --build . --target lint --config %CMAKE_CONFIG%
  171. )
  172.  
  173. if ERRORLEVEL 1 (
  174. echo ERROR: Lint failed
  175. exit /b 1
  176. )
  177.  
  178. :: Build the library and tools
  179. cmake --build . --config %CMAKE_CONFIG%
  180.  
  181. if ERRORLEVEL 1 (
  182. echo ERROR: Build failed
  183. exit /b 1
  184. )
  185.  
  186. :: Build and exectute the tests
  187. if !RUN_TESTS! EQU 1 (
  188. cmake --build . --target runtest --config %CMAKE_CONFIG%
  189.  
  190. if ERRORLEVEL 1 (
  191. echo ERROR: Tests failed
  192. exit /b 1
  193. )
  194.  
  195. if %BUILD_PYTHON% EQU 1 (
  196. if %BUILD_PYTHON_LAYER% EQU 1 (
  197. :: Run python tests only in Release build since
  198. :: the _caffe module is _caffe-d is debug
  199. if "%CMAKE_CONFIG%"=="Release" (
  200. :: Run the python tests
  201. cmake --build . --target pytest
  202.  
  203. if ERRORLEVEL 1 (
  204. echo ERROR: Python tests failed
  205. exit /b 1
  206. )
  207. )
  208. )
  209. )
  210. )
  211.  
  212. if %RUN_INSTALL% EQU 1 (
  213. cmake --build . --target install --config %CMAKE_CONFIG%
  214. )
  215.  
  216. popd
  217. @endlocal
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement