terryzhao127 / tensorflow-windows-build-script

A script to automate building Tensorflow on Windows and solve some problems
GNU General Public License v3.0
103 stars 35 forks source link

Updated script and dependencies to successfully compile 1.15.3 on Windows 10 #44

Open fperezgamonal opened 4 years ago

fperezgamonal commented 4 years ago

Hello there,

Just to help anyone trying to compile 1.15.3 (or any version > 1.13.1), I leave here a link to my fork of this repo so it may be helpful to you.

Basically, I updated the required dependencies and included the missing symbols in patches/def_file_filter.py.tpl instead of patches/tf_exported_symbols_msvc.lds. Then, before building Tensorflow with bazel, I simply overwrite the default def_file_filter with mine (just like @guikarist did with the .lds file). By doing so, Tensorflow will be built with those symbols, avoiding any linking errors. In my case I had to add some symbols, build, check, add new symbols, and so on.

Just to sum up, the key changes to make this work can be found in this commit.

If anyone has any doubts, please do not hesitate to reply to this issue.

Hope it helps,

PS: one will also need to update the helpful script https://gist.github.com/guikarist/e10dff3a4e777856cf40e44713fc2cb7 to account for name changes between versions. I attach mine just as a guide as your needs may vary (fewer or more needed includes, etc.) extract-built-tensorflow-cpp-api.txt. Change the extension back to ps1 before modifying and running it!

Cheers!

omatai commented 3 years ago

Is there any likelihood I will get anywhere if I follow this script for a recent TF version - 2.2, 2.3? So far I cannot find any build support for Windows/C++ for TF V2.0+ :-(

fperezgamonal commented 3 years ago

Hello!

I really don't know. I guess it depends on how they define the optional symbols to be included in the dll for these versions (probably with the file patches/def_file_filter.py.tpl).

Isn't there any walkthrough on how to do it for 2.0? It should be similar if they haven't changed anything major...

Sorry I cannot be more helpful 😑

cocoyen1995 commented 3 years ago

Hi @fperezgamonal ,

Thanks for your sharing! I'm trying to build tf1.15.3 dll with your script, but I failed 😢 Could you take a look for me if possible?

The error message shows like this:

ERROR: C:/users/coco/_bazel_coco/n4m5kibl/external/com_google_protobuf/BUILD:294:1: C++ compilation of rule '@com_google_protobuf//:protoc_lib' failed (Exit 2): cl.exe failed: error executing command
  cd C:/users/coco/_bazel_coco/n4m5kibl/execroot/org_tensorflow
  SET INCLUDE=C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.16.27023\ATLMFC\include;C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.16.27023\include;C:\Program Files (x86)\Windows Kits\NETFXSDK\4.6.1\include\um;C:\Program Files (x86)\Windows Kits\10\include\10.0.19041.0\ucrt;C:\Program Files (x86)\Windows Kits\10\include\10.0.19041.0\shared;C:\Program Files (x86)\Windows Kits\10\include\10.0.19041.0\um;C:\Program Files (x86)\Windows Kits\10\include\10.0.19041.0\winrt;C:\Program Files (x86)\Windows Kits\10\include\10.0.19041.0\cppwinrt
    SET PATH=C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.16.27023\bin\HostX64\x64;C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\Common7\IDE\VC\VCPackages;C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\Common7\IDE\CommonExtensions\Microsoft\TestWindow;C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\Common7\IDE\CommonExtensions\Microsoft\TeamFoundation\Team Explorer;C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\MSBuild\15.0\bin\Roslyn;C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\Team Tools\Performance Tools\x64;C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\Team Tools\Performance Tools;C:\Program Files (x86)\Microsoft Visual Studio\Shared\Common\VSPerfCollectionTools\\x64;C:\Program Files (x86)\Microsoft Visual Studio\Shared\Common\VSPerfCollectionTools\;C:\Program Files (x86)\Microsoft SDKs\Windows\v10.0A\bin\NETFX 4.6.1 Tools\x64\;C:\Program Files (x86)\Windows Kits\10\bin\10.0.19041.0\x64;C:\Program Files (x86)\Windows Kits\10\bin\x64;C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\\MSBuild\15.0\bin;C:\WINDOWS\Microsoft.NET\Framework64\v4.0.30319;C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\Common7\IDE\;C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\Common7\Tools\;;C:\WINDOWS\system32;C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\Common7\IDE\CommonExtensions\Microsoft\CMake\CMake\bin;C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\Common7\IDE\CommonExtensions\Microsoft\CMake\Ninja
    SET PWD=/proc/self/cwd
    SET PYTHON_BIN_PATH=D:/Coco/Libs/tensorflow_1.15.3_script/build_dll/venv/Scripts/python.exe
    SET PYTHON_LIB_PATH=D:/Coco/Libs/tensorflow_1.15.3_script/build_dll/venv/lib/site-packages
    SET RUNFILES_MANIFEST_ONLY=1
    SET TEMP=C:\Users\Coco\AppData\Local\Temp
    SET TF2_BEHAVIOR=0
    SET TF_CONFIGURE_IOS=0
    SET TMP=C:\Users\Coco\AppData\Local\Temp
  C:/Program Files (x86)/Microsoft Visual Studio/2017/Community/VC/Tools/MSVC/14.14.26428/bin/HostX64/x64/cl.exe /nologo /DCOMPILER_MSVC /DNOMINMAX /D_WIN32_WINNT=0x0601 /D_CRT_SECURE_NO_DEPRECATE /D_CRT_SECURE_NO_WARNINGS /bigobj /Zm500 /EHsc /wd4351 /wd4291 /wd4250 /wd4996 /Iexternal/com_google_protobuf /Ibazel-out/x64_windows-opt/bin/external/com_google_protobuf /Iexternal/com_google_protobuf/src /Ibazel-out/x64_windows-opt/bin/external/com_google_protobuf/src /showIncludes /MD /O2 /Oy- /DNDEBUG /wd4117 -D__DATE__="redacted" -D__TIMESTAMP__="redacted" -D__TIME__="redacted" /Gy /Gw -w -w -DWIN32_LEAN_AND_MEAN -DNOGDI /arch:AVX2 /DHAVE_PTHREAD /wd4018 /wd4065 /wd4146 /wd4244 /wd4251 /wd4267 /wd4305 /wd4307 /wd4309 /wd4334 /wd4355 /wd4506 /wd4514 /wd4800 /wd4996 /Fobazel-out/x64_windows-opt/bin/external/com_google_protobuf/_objs/protoc_lib/cpp_extension.obj /c external/com_google_protobuf/src/google/protobuf/compiler/cpp/cpp_extension.cc
Execution platform: @bazel_tools//platforms:host_platform
C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.16.27023\include\yvals_core.h(298): fatal error C1189: #error:  STL1001: Unexpected compiler version, expected MSVC 19.15 or newer.

I found this issue's discussion here it seems like they use a newer version of bazel (0.27.0), but if I change the bazel version to 0.27.0, another error occur:

ERROR: C:/users/coco/_bazel_coco/n4m5kibl/external/snappy/BUILD.bazel:85:1: Executing genrule @snappy//:snappy_stubs_public_h failed (Exit 256): bash.exe failed: error executing command
  cd C:/users/coco/_bazel_coco/n4m5kibl/execroot/org_tensorflow
  SET PATH=C:\msys64\usr\bin;C:\msys64\bin;C:\WINDOWS;C:\WINDOWS\System32;C:\WINDOWS\System32\WindowsPowerShell\v1.0;D:\Coco\Libs\tensorflow_1.15.3\build_dll\venv\Scripts;C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.1\bin;C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.1\libnvvp;D:\Coco\Libs\TensorRT-7.2.3.4\lib;C:\Program Files (x86)\Common Files\MVS\Runtime\Win64_x64;C:\Program Files (x86)\Common Files\Intel\Shared Libraries\redist\intel64_win\compiler;C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v10.22\bin;C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v10.22\libnvvp;C:\Program Files\Cognex\CVL\bin\win64\cvl;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\iCLS\;C:\Program Files\Intel\Intel(R) Management Engine Components\iCLS\;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\IPT;C:\Program Files\Intel\Intel(R) Management Engine Components\IPT;C:\Program Files\Git\cmd;C:\Program Files (x86)\Windows Kits\8.1\Windows Performance Toolkit\;C:\Program Files (x86)\Windows Kits\10\Windows Performance Toolkit\;D:\Coco\Tools\cmake\cmake-3.17.4-win64-x64\bin;C:\WINDOWS;C:\WINDOWS\system32;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;C:\WINDOWS\System32\OpenSSH\;C:\msys64;C:\msys64\usr\bin;C:\msys64\usr\bin\bash.exe;C:\mysys64\usr\bin\bazel.exe;C:\Program Files\LLVM\bin;C:\Program Files\NVIDIA Corporation\NVIDIA NGX;C:\Program Files\MVTec\HALCON-13.0\bin\x64-win64;C:\Program Files\PuTTY\;C:\Program Files\Cognex\VisionPro\bin;C:\Program Files (x86)\Microsoft ASP.NET\ASP.NET Web Pages\v1.0\;C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.16.27023\bin;C:\Program Files\NVIDIA Corporation\NVIDIA NvDLISR;C:\Program Files\dotnet\;C:\Program Files\Docker\Docker\resources\bin;C:\ProgramData\DockerDesktop\version-bin;%USERPROFILE%\.dnx\bin;C:\Program Files\Microsoft DNX\Dnvm\;C:\Program Files\TortoiseGit\bin;C:\Program Files\nodejs\;C:\ProgramData\chocolatey\bin;C:\Program Files\NVIDIA Corporation\Nsight Compute 2020.2.0\;C:\Program Files\Microsoft SQL Server\Client SDK\ODBC\170\Tools\Binn\;D:\Coco\Libs\libtorch-win-1.6.0\libtorch\lib;C:\Users\Coco\AppData\Local\Programs\Python\Python37\Scripts\;C:\Users\Coco\AppData\Local\Programs\Python\Python37\;C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v10.0\\bin;C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v10.0\lib\x64;C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v10.11\bin;C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v10.11\lib\x64;C:\Users\Coco\AppData\Local\Programs\Python\Python36;C:\Users\Coco\AppData\Local\Programs\Python\Python36\Scripts;C:\Users\Coco\AppData\Local\Continuum\anaconda3;C:\Users\Coco\AppData\Local\Continuum\anaconda3\Library\mingw-w64\bin;C:\Users\Coco\AppData\Local\Continuum\anaconda3\Library\usr\bin;C:\Users\Coco\AppData\Local\Continuum\anaconda3\Library\bin;C:\Users\Coco\AppData\Local\Continuum\anaconda3\Scripts;C:\Users\Coco\AppData\Local\Microsoft\WindowsApps;C:\tools\cuda\bin;C:\Users\Coco\AppData\Local\Programs\Microsoft VS Code\bin;C:\Program Files\wget-1.20.3-win64;C:\MinGW\bin;C:\Program Files\mingw-w64\x86_64-8.1.0-posix-seh-rt_v6-rev0\mingw64\bin;C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\bin;C:\Users\Coco\Downloads\cmake-3.15.0-win64-x64\cmake-3.15.0-win64-x64\bin;C:\Users\Coco\AppData\Local\Microsoft\WindowsApps;C:\Users\Coco\.dotnet\tools;C:\Users\Coco\AppData\Roaming\npm;C:\msys64\usr\bin
    SET PYTHON_BIN_PATH=D:/Coco/Libs/tensorflow_1.15.3_script/build_dll/venv/Scripts/python.exe
    SET PYTHON_LIB_PATH=D:/Coco/Libs/tensorflow_1.15.3_script/build_dll/venv/lib/site-packages
    SET RUNFILES_MANIFEST_ONLY=1
    SET TF2_BEHAVIOR=0
    SET TF_CONFIGURE_IOS=0
  C:/msys64/usr/bin/bash.exe -c source external/bazel_tools/tools/genrule/genrule-setup.sh; sed -e 's/${\(.*\)_01}/\1/g' -e 's/${SNAPPY_MAJOR}/1/g' -e 's/${SNAPPY_MINOR}/1/g' -e 's/${SNAPPY_PATCHLEVEL}/4/g' external/snappy/snappy-stubs-public.h.in >bazel-out/x64_windows-opt/bin/external/snappy/snappy-stubs-public.h
Execution platform: @bazel_tools//platforms:host_platform
      0 [main] bash (17788) C:\msys64\usr\bin\bash.exe: *** fatal error - add_item ("\??\C:\msys64", "/", ...) failed, errno 1

So I'm wondering how did you build this version's dll successfully?

My environment list:

I only try to build with CPU, so my command line goes like:

$parameterString = "--config=opt --define=no_tensorflow_py_deps=true //tensorflow:libtensorflow_cc.so --verbose_failures"
.\build.ps1 `
    -BazelBuildParameters $parameterString `
    -BuildCppAPI -ReserveSource -ReserveVenv

Thanks in advance for any help or advice! Hope can hear from you soon 👋

cocoyen1995 commented 3 years ago

【update】 I successfully built dll without this script today, I've updated msys64, using VS2019's compiler, and the version of bazel is 0.27.0. I used the same environment condition to run the script, and the dll came out successfully. (Although I haven't validated yet) To sum up, I finally built tensorflow 1.15.3 with VS2019 and bazel 0.27.0. (in Windows powershell)

fperezgamonal commented 3 years ago

Hello @cocoyen1995

I'm very sorry, I didn't get your message. I'm glad you managed to compile it (it's not an easy task!). I'm currently trying to compile Tensorflow 2.6.0 for Windows and I've been following TensorFlow's guide but I may update the script. If I do so successfully, I'll attach it here :)

Cheers!

fperezgamonal commented 3 years ago

Hi again,

I've successfully compiled TF 2.6.0 with the following configuration:

I have updated everything in this Gist. It includes the build script, an extraction script (DLL, lib and includes) and an auxiliary script which basically calls the other 2).

Hope it helps someone :)

Cheers!