tensorflow / runtime

A performant and modular runtime for TensorFlow
Apache License 2.0
756 stars 123 forks source link

Is there way to compile TFRT on windows? #80

Closed Honya2000 closed 3 years ago

Honya2000 commented 3 years ago

Is there way to compile TFRT using windows toolsets? For example VS 2019 compiler? I tried to run this from command prompt: bazel build //tools:bef_executor

But it throws error that at least VS 2017 is required. I have VS 2019 installed but seems like bazel doesn't recognize it.

tlemo commented 3 years ago

First, please see the Bazel install instructions on Windows. Bazelisk is the recommended (and the easiest) way to make sure you have the right Bazel version.

Windows support is experimental. TFRT should build and pass most test cases, but not everything works yet. Here's a list of known issues

Honya2000 commented 3 years ago

According to readme file bazel sould be at least verion 4.0.0.

I'm using version 4.2.1:

Build label: 4.2.1 Build target: bazel-out/x64_windows-opt/bin/src/main/java/com/google/devtools/build/lib/bazel/BazelServer_deploy.jar Build time: Mon Aug 30 15:19:20 2021 (1630336760) Build timestamp: 1630336760 Build timestamp as int: 1630336760

Honya2000 commented 3 years ago

And yes, i checked those issues.... But noone reports it is not compilable on windows at all?

That;s why i'm asking, what i'm doing wrong. There is no any instructions how to compile it on windows.

So is command: bazel build //tools:bef_executor suppose to work on windows after bazel installation? Or should i do something additional?

tlemo commented 3 years ago

Are you able to build any other C++ projects with Bazel, on the same machine? (try https://github.com/bazelbuild/examples/tree/main/cpp-tutorial or Abseil C++)

Honya2000 commented 3 years ago

The only project where I used bazel - was WebRTC. But … First - WebRTC used special depot toolsets. And second - it didn’t compile anything but just generated visual studio project. Compilation happened inside visual studio..

In TFRT it tries to compile the project and fails, because cannot find visual studio compiler. How to specify the path to visual studio for bazel?

Honya2000 commented 3 years ago

Ok, just found how to tell bazel visual studio location

set BAZEL_VC=C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\VC

Will try tomorrow…

tlemo commented 3 years ago

Once you can verify that you can build simple C++ apps with Bazel, the instructions for building on Windows are fairly straightforward:

Prerequisites

  1. Install Bazelisk (or the right version of Bazel)
  2. Install Visual Studio 2017+
  3. Install LLVM 11.1+
  4. (Optional) Use a Python virtual environment, ex. miniconda (conda create -n tfrt python=3.8)
  5. pip install clang==11.0

Building & running tests

  1. (Optional) Activate the right Python virtual environment
  2. (Optional) Cleanup: bazel --noworkspace_rc clean --expunge
  3. bazel build //tools:bef_executor
  4. bazel build //tools:tfrt_translate
  5. bazel test -c dbg //mlir_tests/bef_executor/...
Honya2000 commented 3 years ago

Still not able to build. Tried to set BAZEL_VC=C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\VC

But seems like it is ignored by bazel. ERROR: C:/users/andrey/_bazel_andrey/o2svxzdq/external/llvm-project/llvm/BUILD.bazel:170:11: Compiling llvm/lib/Support/TypeSize.cpp [for host] failed: (Exit 2): cl.exe failed: error executing command C:/Program Files (x86)/Microsoft Visual Studio 14.0/VC/bin/amd64/cl.exe /nologo /DCOMPILER_MSVC /DNOMINMAX /D_WIN32_WINNT=0x0601 /D_CRT_SECURE_NO_DEPRECATE /D_CRT_SECURE_NO_WARNINGS /bigobj /Zm500 ... (remaining 45 argument(s) skipped) external/llvm-project/llvm/include\llvm/Support/Compiler.h(88): fatal error C1189: #error: LLVM requires at least MSVC 2017.ERROR: C:/users/andrey/_bazel_andrey/o2svxzdq/external/llvm-project/llvm/BUILD.bazel:170:11: Compiling llvm/lib/Support/TypeSize.cpp [for host] failed: (Exit 2): cl.exe failed: error executing command C:/Program Files (x86)/Microsoft Visual Studio 14.0/VC/bin/amd64/cl.exe /nologo /DCOMPILER_MSVC /DNOMINMAX /D_WIN32_WINNT=0x0601 /D_CRT_SECURE_NO_DEPRECATE /D_CRT_SECURE_NO_WARNINGS /bigobj /Zm500 ... (remaining 45 argument(s) skipped) external/llvm-project/llvm/include\llvm/Support/Compiler.h(88): fatal error C1189: #error: LLVM requires at least MSVC 2017.

Not sure why bazel tries to use old visual studio.

Honya2000 commented 3 years ago

Ok, finally was able to build bef_executor. An it took over 7000 secs. )

tlemo commented 3 years ago

I'm glad to hear that you're able to work out the Bazel / MSVC setup problem. What was the solution?

Regarding build times, it's a known issue that optimized builds take a long time (it used to be even worse, see https://github.com/tensorflow/runtime/issues/65). During development, debug builds (-c dbg) are much faster.

chsigg commented 3 years ago

Thanks a lot Leonard for helping out!

@Honya2000, it would be great if you could post here what you changed to make it work. Thanks!