@@ -15,6 +15,7 @@ cmake_policy(SET CMP0022 NEW)
1515
1616# Options
1717option (tensorflow_VERBOSE "Enable for verbose output" OFF )
18+ option (tensorflow_ENABLE_GPU "Enable GPU support" OFF )
1819option (tensorflow_ENABLE_SSL_SUPPORT "Enable boringssl support" OFF )
1920option (tensorflow_ENABLE_GRPC_SUPPORT "Enable gRPC support" ON )
2021option (tensorflow_BUILD_CC_EXAMPLE "Build the C++ tutorial example" ON )
@@ -48,8 +49,13 @@ set(CMAKE_POSITION_INDEPENDENT_CODE ON)
4849add_definitions (-DEIGEN_AVOID_STL_ARRAY )
4950if (WIN32 )
5051 add_definitions (-DNOMINMAX -D_WIN32_WINNT=0x0A00 -DLANG_CXX11 -DCOMPILER_MSVC -D__VERSION__= \"MSVC\" )
52+ add_definitions(-DWIN32 -DOS_WIN -D_MBCS -DWIN64 -DWIN32_LEAN_AND_MEAN -DNOGDI -DPLATFORM_WINDOWS)
53+ add_definitions(-DTENSORFLOW_USE_EIGEN_THREADPOOL -DEIGEN_HAS_C99_MATH -D_ITERATOR_DEBUG_LEVEL=0)
54+ add_definitions(/bigobj /nologo /EHsc /GF /FC /MP /Gm-)
5155 # Suppress warnings to reduce build log size.
5256 add_definitions(/wd4267 /wd4244 /wd4800 /wd4503 /wd4554 /wd4996 /wd4348 /wd4018)
57+ add_definitions(/wd4099 /wd4146 /wd4267 /wd4305 /wd4307)
58+ add_definitions(/wd4715 /wd4722 /wd4723 /wd4838 /wd4309 /wd4334)
5359 set(CMAKE_CXX_FLAGS " ${CMAKE_CXX_FLAGS} /MP ")
5460endif()
5561
@@ -80,7 +86,16 @@ set(tensorflow_EXTERNAL_LIBRARIES
8086 ${protobuf_STATIC_LIBRARIES}
8187)
8288set(tensorflow_EXTERNAL_DEPENDENCIES
83- gif_copy_headers_to_destination png_copy_headers_to_destination jpeg_copy_headers_to_destination jsoncpp farmhash_copy_headers_to_destination highwayhash_copy_headers_to_destination protobuf eigen)
89+ zlib_copy_headers_to_destination
90+ gif_copy_headers_to_destination
91+ png_copy_headers_to_destination
92+ jpeg_copy_headers_to_destination
93+ jsoncpp
94+ farmhash_copy_headers_to_destination
95+ highwayhash_copy_headers_to_destination
96+ protobuf
97+ eigen
98+ )
8499
85100include_directories(
86101 # Source and generated code.
@@ -118,19 +133,67 @@ if(UNIX)
118133 list(APPEND tensorflow_EXTERNAL_LIBRARIES ${CMAKE_THREAD_LIBS_INIT} ${CMAKE_DL_LIBS} )
119134endif()
120135
136+ if (tensorflow_ENABLE_GPU)
137+ if (WIN32)
138+ find_package(CUDA 8.0 REQUIRED)
139+
140+ # by default we assume compute cabability 3.5 and 5.2. If you change this change it in
141+ # CUDA_NVCC_FLAGS and cuda_config.h below
142+ set(CUDA_NVCC_FLAGS ${CUDA_NVCC_FLAGS} ;-gencode arch=compute_35,code=\" sm_35,compute_35\" ;-gencode arch=compute_52,code=\" sm_52,compute_52\" )
143+ set(CUDA_NVCC_FLAGS ${CUDA_NVCC_FLAGS} ;--include-path ${PROJECT_BINARY_DIR} /$\{ build_configuration\} ;--expt-relaxed-constexpr)
144+ set(CUDA_INCLUDE ${CUDA_TOOLKIT_TARGET_DIR} ${CUDA_TOOLKIT_TARGET_DIR} /extras/CUPTI/include)
145+ include_directories(${CUDA_INCLUDE} )
146+ add_definitions(-DGOOGLE_CUDA=1 -DTF_EXTRA_CUDA_CAPABILITIES=3.5,5.2)
147+
148+ # add cudnn
149+ include_directories(${CUDNN_HOME} )
150+ set(CUDA_LIBRARIES ${CUDA_LIBRARIES} ${CUDNN_HOME} /lib/x64/cudnn.lib)
151+
152+ # create cuda_config.h
153+ FILE(WRITE ${tensorflow_source_dir} /third_party/gpus/cuda/cuda_config.h
154+ " #ifndef CUDA_CUDA_CONFIG_H_\n"
155+ "#define CUDA_CUDA_CONFIG_H_\n "
156+ "#define TF_CUDA_CAPABILITIES CudaVersion(\" 3.5\" ),CudaVersion(\" 5.2\" )\n "
157+ "#define TF_CUDA_VERSION \" 64_80\"\n "
158+ "#define TF_CUDNN_VERSION \" 64_5\"\n "
159+ "#endif // CUDA_CUDA_CONFIG_H_\n "
160+ )
161+
162+ # tf assumes in various places header files to be in cuda/include. On windows the cuda sdk
163+ # installs them under cuda/version/include and to avoid that we need to change tf we copy a
164+ # few files to cuda/include
165+ FILE (COPY
166+ ${CUDA_TOOLKIT_TARGET_DIR} /include/cuda.h ${CUDA_TOOLKIT_TARGET_DIR} /include/cuComplex.h
167+ ${CUDA_TOOLKIT_TARGET_DIR} /include/cublas_v2.h ${CUDNN_HOME} /include/cudnn.h
168+ ${CUDA_TOOLKIT_TARGET_DIR} /include/cufft.h ${CUDA_TOOLKIT_TARGET_DIR} /include/curand.h
169+ DESTINATION ${tensorflow_source_dir} /third_party/gpus/cuda/include
170+ )
171+ include_directories (${tensorflow_source_dir} /third_party/gpus )
172+ # add cuda libraries to tensorflow_EXTERNAL_LIBRARIES
173+ list (APPEND tensorflow_EXTERNAL_LIBRARIES ${CUDA_LIBRARIES} )
174+ endif ()
175+ endif ()
176+
121177# Let's get to work!
122178include (tf_core_framework.cmake )
123179include (tf_tools.cmake )
124180# NOTE: Disabled until issue #3996 is fixed.
125181# include(tf_stream_executor.cmake)
182+ if (tensorflow_ENABLE_GPU)
183+ if (WIN32 )
184+ include (tf_stream_executor.cmake )
185+ endif ()
186+ endif ()
187+
126188include (tf_core_cpu.cmake )
127189include (tf_models.cmake )
128190include (tf_core_ops.cmake )
129191include (tf_core_direct_session.cmake )
192+ include (tf_core_kernels.cmake )
130193if (tensorflow_ENABLE_GRPC_SUPPORT)
131194 include (tf_core_distributed_runtime.cmake )
132195endif ()
133- include(tf_core_kernels.cmake)
196+
134197include (tf_cc_ops.cmake )
135198if (tensorflow_BUILD_CC_EXAMPLE)
136199 include (tf_tutorials.cmake )
0 commit comments