Environemt


Setup

  • Open Visual Studio command Prompt (2017 / Win64).

  • Start “Anaconda Prompt 3” from the VS command prompt.

  • Set path:

    set Path=<CMake folder>\bin;<SWIG folder>;<Portable git folder>\bin;%Path%
    
  • Modify CMakeLists.txt (GPU version only):

    • Insert appropriate CUDA compute capability into arch=compute_XX,code="sm_XX,compute_XX" and -DTF_EXTRA_CUDA_CAPABILITIES=X.X

    • Go to https://developer.nvidia.com/cuda-gpus to look up Compute Capability.

    set(CUDA_NVCC_FLAGS ${CUDA_NVCC_FLAGS};-gencode arch=compute_61,code=\"sm_61,compute_61\";)
    
    ...
    
    if (WIN32)
      add_definitions(-DGOOGLE_CUDA=1 -DTF_EXTRA_CUDA_CAPABILITIES=6.1)
    else (WIN32)
    
  • Go to output directory.

  • Configuration:

    • GPU version:

      • Change “Visual Studio 15 2017 Win64” according to the compiler you are using.
    cmake ^
    <TF source>\tensorflow\contrib\cmake ^
    -G"Visual Studio 15 2017 Win64" ^
    -DCMAKE_BUILD_TYPE=Release ^
    -Dtensorflow_DISABLE_EIGEN_FORCEINLINE=ON ^
    -Dtensorflow_BUILD_CC_TESTS=OFF ^
    -Dtensorflow_BUILD_MORE_PYTHON_TESTS=OFF ^
    -Dtensorflow_ENABLE_GPU=OFF
    
    • CPU-only version

      • Change “tensorflow_CUDA_VERSION=9.2” according to your CUDA environment.
      • “CUDA_HOST_COMPILER” must be specified when using Visual Studio 2017; otherwise compilation will not complete.
    cmake ^
    <TF source>\tensorflow\contrib\cmake ^
    -G"Visual Studio 15 2017 Win64" ^
    -DCUDA_HOST_COMPILER="C:/Program Files (x86)/Microsoft Visual Studio/2017/Community/VC/Tools/MSVC/14.11.25503/bin/Hostx64/x64" ^
    -DCMAKE_BUILD_TYPE=Release ^
    -Dtensorflow_DISABLE_EIGEN_FORCEINLINE=ON ^
    -Dtensorflow_BUILD_CC_TESTS=OFF ^
    -Dtensorflow_BUILD_MORE_PYTHON_TESTS=OFF ^
    -Dtensorflow_ENABLE_GPU=ON ^
    -Dtensorflow_CUDA_VERSION=9.2
    
  • Apply patch:

  • Build Python wheel:

    cmake --build . --config Release --target tf_python_build_pip_package
    

Install

  • GPU version:

    pip install tensorflow_gpu-1.10.0-cp36-cp36m-win_amd64.whl
    
  • CPU-only version:

    pip install tensorflow-1.10.0-cp36-cp36m-win_amd64.whl