Skip to content

Commit ec3a1b3

Browse files
Merge pull request #2297 from Intel-tensorflow:mraunak/tf_win_clang
PiperOrigin-RevId: 621404590
2 parents ff989f0 + b69d741 commit ec3a1b3

File tree

1 file changed

+75
-43
lines changed

1 file changed

+75
-43
lines changed

site/en/install/source_windows.md

Lines changed: 75 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Build from source on Windows
22

3-
Build a TensorFlow *pip* package from source and install it on Windows.
3+
Build a TensorFlow *pip* package from the source and install it on Windows.
44

55
Note: We already provide well-tested, pre-built
66
[TensorFlow packages](./pip.md) for Windows systems.
@@ -20,6 +20,7 @@ variable.
2020
Install the TensorFlow *pip* package dependencies:
2121

2222
<pre class="devsite-click-to-copy">
23+
<code class="devsite-terminal tfo-terminal-windows">pip3 install -U pip</code>
2324
<code class="devsite-terminal tfo-terminal-windows">pip3 install -U six numpy wheel packaging</code>
2425
<code class="devsite-terminal tfo-terminal-windows">pip3 install -U keras_preprocessing --no-deps</code>
2526
</pre>
@@ -47,22 +48,35 @@ build TensorFlow. If MSYS2 is installed to `C:\msys64`, add
4748
run:
4849

4950
<pre class="devsite-terminal tfo-terminal-windows devsite-click-to-copy">
51+
pacman -Syu (requires a console restart)
5052
pacman -S git patch unzip
53+
pacman -S git patch unzip rsync
5154
</pre>
5255

53-
### Install Visual C++ Build Tools 2019
56+
Note: Clang will be the preferred compiler to build TensorFlow CPU wheels on the Windows Platform starting with TF 2.16.1 The currently supported version is LLVM/clang 17.0.6.
5457

55-
Install the *Visual C++ build tools 2019*. This comes with *Visual Studio 2019*
58+
Note: To build with Clang on Windows, it is required to install both LLVM and Visual C++ Build tools as although Windows uses clang-cl.exe as the compiler, Visual C++ Build tools are needed to link to Visual C++ libraries
59+
60+
### Install Visual C++ Build Tools 2022
61+
62+
Install the *Visual C++ build tools 2022*. This comes with *Visual Studio Community 2022*
5663
but can be installed separately:
5764

5865
1. Go to the
5966
[Visual Studio downloads](https://visualstudio.microsoft.com/downloads/){:.external},
60-
2. Select *Redistributables and Build Tools*,
67+
2. Select *Tools for Visual Studio or Other Tools, Framework and Redistributables*,
6168
3. Download and install:
62-
- *Microsoft Visual C++ 2019 Redistributable*
63-
- *Microsoft Build Tools 2019*
69+
- *Build Tools for Visual Studio 2022*
70+
- *Microsoft Visual C++ Redistributables for Visual Studio 2022*
71+
72+
Note: TensorFlow is tested against the *Visual Studio Community 2022*.
73+
74+
### Install LLVM
75+
76+
1. Go to the
77+
[LLVM downloads](https://github.com/llvm/llvm-project/releases/){:.external},
78+
2. Download and install Windows-compatible LLVM in C:/Program Files/LLVM e.g., LLVM-17.0.6-win64.exe
6479

65-
Note: TensorFlow is tested against the *Visual Studio 2019*.
6680

6781
### Install GPU support (optional)
6882

@@ -94,31 +108,32 @@ Key Point: If you're having build problems on the latest development branch, try
94108
a release branch that is known to work.
95109

96110
## Optional: Environmental Variable Set Up
97-
Run following commands before running build command to avoid issue with package creation:
98-
(If the below commands were set up while installing the packages, please ignore them). Run `set` check if all the paths were set correctly, run `echo %Environmental Variable%` e.g., `echo %BAZEL_VC%` to check path set up for a specific Environmental Variable
111+
Run the following commands before running the build command to avoid issues with package creation:
112+
(If the below commands were set up while installing the packages, please ignore them). Run `set` to check if all the paths were set correctly, run `echo %Environmental Variable%` e.g., `echo %BAZEL_VC%` to check the path set up for a specific Environmental Variable
99113

100114
Python path set up issue [tensorflow:issue#59943](https://github.com/tensorflow/tensorflow/issues/59943),[tensorflow:issue#9436](https://github.com/tensorflow/tensorflow/issues/9436),[tensorflow:issue#60083](https://github.com/tensorflow/tensorflow/issues/60083)
101115

102116
<pre class="devsite-terminal tfo-terminal-windows devsite-click-to-copy">
103-
set PATH=path/to/python # [e.g. (C:/Python310)]
104-
set PATH=path/to/python/Scripts # [e.g. (C:/Python310/Scripts)]
117+
set PATH=path/to/python;%PATH% # [e.g. (C:/Python311)]
118+
set PATH=path/to/python/Scripts;%PATH% # [e.g. (C:/Python311/Scripts)]
105119
set PYTHON_BIN_PATH=path/to/python_virtualenv/Scripts/python.exe
106120
set PYTHON_LIB_PATH=path/to/python virtualenv/lib/site-packages
107121
set PYTHON_DIRECTORY=path/to/python_virtualenv/Scripts
108122
</pre>
109123

110-
Bazel/MSVC path set up issue [tensorflow:issue#54578](https://github.com/tensorflow/tensorflow/issues/54578)
124+
Bazel/MSVC/CLANG path set up issue [tensorflow:issue#54578](https://github.com/tensorflow/tensorflow/issues/54578)
111125

112126
<pre class="devsite-terminal tfo-terminal-windows devsite-click-to-copy">
113127
set BAZEL_SH=C:/msys64/usr/bin/bash.exe
114-
set BAZEL_VS=C:/Program Files(x86)/Microsoft Visual Studio/2019/BuildTools
115-
set BAZEL_VC=C:/Program Files(x86)/Microsoft Visual Studio/2019/BuildTools/VC
128+
set BAZEL_VS=C:/Program Files/Microsoft Visual Studio/2022/BuildTools
129+
set BAZEL_VC=C:/Program Files/Microsoft Visual Studio/2022/BuildTools/VC
130+
set Bazel_LLVM=C:/Program Files/LLVM (explicitly tell Bazel where LLVM is installed by BAZEL_LLVM, needed while using CLANG)
131+
set PATH=C:/Program Files/LLVM/bin;%PATH% (Optional, needed while using CLANG as Compiler)
116132
</pre>
117133

118-
119134
## Optional: Configure the build
120135

121-
TensorFlow builds are configured by the `.bazelrc` file in the respoitory's
136+
TensorFlow builds are configured by the `.bazelrc` file in the repository's
122137
root directory. The `./configure` or `./configure.py` scripts can be used to
123138
adjust common settings.
124139

@@ -138,21 +153,27 @@ differ):
138153
<h4 class="showalways">View sample configuration session</h4>
139154
<pre class="devsite-terminal tfo-terminal-windows">
140155
python ./configure.py
141-
You have bazel 5.3.0 installed.
142-
Please specify the location of python. [Default is C:\Python310\python.exe]:
156+
You have bazel 6.5.0 installed.
157+
Please specify the location of python. [Default is C:\Python311\python.exe]:
158+
143159
Found possible Python library paths:
144-
C:\Python310\lib\site-packages
145-
Please input the desired Python library path to use. Default is [C:\Python310\lib\site-packages]
160+
C:\Python311\lib\site-packages
161+
Please input the desired Python library path to use. Default is [C:\Python311\lib\site-packages]
146162

147163
Do you wish to build TensorFlow with ROCm support? [y/N]:
148164
No ROCm support will be enabled for TensorFlow.
149165

150-
151166
WARNING: Cannot build with CUDA support on Windows.
152-
Starting in TF 2.11, CUDA build is not supported for Windows. For using TensorFlow GPU on Windows, you will need to build/install TensorFlow in WSL2.
167+
Starting in TF 2.11, CUDA build is not supported for Windows. To use TensorFlow GPU on Windows, you will need to build/install TensorFlow in WSL2.
153168

154-
Please specify optimization flags to use during compilation when bazel option "--config=opt" is specified [Default is /arch:AVX]:
169+
Do you want to use Clang to build TensorFlow? [Y/n]:
170+
Add "--config=win_clang" to compile TensorFlow with CLANG.
155171

172+
Please specify the path to clang executable. [Default is C:\Program Files\LLVM\bin\clang.EXE]:
173+
174+
You have Clang 17.0.6 installed.
175+
176+
Please specify optimization flags to use during compilation when bazel option "--config=opt" is specified [Default is /arch:AVX]:
156177

157178
Would you like to override eigen strong inline for some C++ compilation to reduce the compilation time? [Y/n]:
158179
Eigen strong inline overridden.
@@ -170,13 +191,12 @@ Preconfigured Bazel build configs. You can use any of the below by adding "--con
170191
Preconfigured Bazel build configs to DISABLE default on features:
171192
--config=nogcp # Disable GCP support.
172193
--config=nonccl # Disable NVIDIA NCCL support.
173-
174194
</pre>
175195
</section>
176196

177197
## Build and install the pip package
178198

179-
The pip package gets built in two steps. A `bazel build` commands creates a
199+
The pip package is built in two steps. A `bazel build` command creates a
180200
"package-builder" program. You then run the package-builder to create the
181201
package.
182202

@@ -187,15 +207,23 @@ tensorflow:master repo has been updated to build 2.x by default.
187207
`bazel build ` to create the TensorFlow package-builder.
188208

189209
<pre class="devsite-terminal tfo-terminal-windows devsite-click-to-copy">
190-
bazel build //tensorflow/tools/pip_package:build_pip_package
210+
bazel build //tensorflow/tools/pip_package:wheel
191211
</pre>
192212

193213
#### CPU-only
194214

195215
Use `bazel` to make the TensorFlow package builder with CPU-only support:
196216

217+
##### Build with MSVC
218+
<pre class="devsite-terminal tfo-terminal-windows devsite-click-to-copy">
219+
bazel build --config=opt --repo_env=TF_PYTHON_VERSION=3.11 //tensorflow/tools/pip_package:wheel --repo_env=WHEEL_NAME=tensorflow_cpu
220+
</pre>
221+
222+
##### Build with CLANG
223+
Use --config=`win_clang` to build TenorFlow with the CLANG Compiler:
224+
197225
<pre class="devsite-terminal tfo-terminal-windows devsite-click-to-copy">
198-
bazel build --config=opt //tensorflow/tools/pip_package:build_pip_package
226+
bazel build --config=win_clang --repo_env=TF_PYTHON_VERSION=3.11 //tensorflow/tools/pip_package:wheel --repo_env=WHEEL_NAME=tensorflow_cpu
199227
</pre>
200228

201229
#### GPU support
@@ -217,7 +245,7 @@ bazel clean --expunge
217245

218246
#### Bazel build options
219247

220-
Use this option when building to avoid issue with package creation:
248+
Use this option when building to avoid issues with package creation:
221249
[tensorflow:issue#22390](https://github.com/tensorflow/tensorflow/issues/22390)
222250

223251
<pre class="devsite-terminal tfo-terminal-windows devsite-click-to-copy">
@@ -236,33 +264,37 @@ to suppress nvcc warning messages.
236264

237265
### Build the package
238266

239-
The `bazel build` command creates an executable named `build_pip_package`—this
240-
is the program that builds the `pip` package. For example, the following builds
241-
a `.whl` package in the `C:/tmp/tensorflow_pkg` directory:
267+
To build a pip package, you need to specify the --repo_env=WHEEL_NAME flag.
268+
Depending on the provided name, the package will be created. For example:
242269

243-
<pre class="devsite-terminal tfo-terminal-windows devsite-click-to-copy">
244-
bazel-bin\tensorflow\tools\pip_package\build_pip_package C:/tmp/tensorflow_pkg
270+
To build tensorflow CPU package:
271+
<pre class="devsite-terminal devsite-click-to-copy">
272+
bazel build //tensorflow/tools/pip_package:wheel --repo_env=WHEEL_NAME=tensorflow_cpu
245273
</pre>
246274

247-
Although it is possible to build both CUDA and non-CUDA configs under the
248-
same source tree, we recommend running `bazel clean` when switching between
249-
these two configurations in the same source tree.
275+
To build nightly package, set `tf_nightly` instead of `tensorflow`, e.g.
276+
to build CPU nightly package:
277+
<pre class="devsite-terminal devsite-click-to-copy">
278+
bazel build //tensorflow/tools/pip_package:wheel --repo_env=WHEEL_NAME=tf_nightly_cpu
279+
</pre>
280+
281+
As a result, generated wheel will be located in
282+
<pre class="devsite-terminal devsite-click-to-copy">
283+
bazel-bin/tensorflow/tools/pip_package/wheel_house/
284+
</pre>
250285

251286

252287
### Install the package
253288

254289
The filename of the generated `.whl` file depends on the TensorFlow version and
255-
your platform. Use `pip3 install` to install the package, for example:
290+
your platform. Use `pip install` to install the package, for example:
256291

257-
<pre class="devsite-terminal tfo-terminal-windows prettyprint lang-bsh">
258-
pip3 install C:/tmp/tensorflow_pkg/tensorflow-<var>version</var>-<var>tags</var>.whl
259-
260-
e.g., pip3 install C:/tmp/tensorflow_pkg/tensorflow-2.12.0-cp310-cp310-win_amd64.whl
292+
<pre class="devsite-terminal prettyprint lang-bsh">
293+
pip install bazel-bin/tensorflow/tools/pip_package/wheel_house/tensorflow-<var>version</var>-<var>tags</var>.whl
261294
</pre>
262295

263296
Success: TensorFlow is now installed.
264297

265-
266298
## Build using the MSYS shell
267299

268300
TensorFlow can also be built using the MSYS shell. Make the changes listed
@@ -309,7 +341,7 @@ Note: Starting in TF 2.11, CUDA build is not supported for Windows. For using Te
309341

310342
<table>
311343
<tr><th>Version</th><th>Python version</th><th>Compiler</th><th>Build tools</th></tr>
312-
<tr><td>tensorflow-2.16.1</td><td>3.9-3.12</td><td>MSVC 2019</td><td>Bazel 6.5.0</td></tr>
344+
<tr><td>tensorflow-2.16.1</td><td>3.9-3.12</td><td>CLANG 17.0.6</td><td>Bazel 6.5.0</td></tr>
313345
<tr><td>tensorflow-2.15.0</td><td>3.9-3.11</td><td>MSVC 2019</td><td>Bazel 6.1.0</td></tr>
314346
<tr><td>tensorflow-2.14.0</td><td>3.9-3.11</td><td>MSVC 2019</td><td>Bazel 6.1.0</td></tr>
315347
<tr><td>tensorflow-2.12.0</td><td>3.8-3.11</td><td>MSVC 2019</td><td>Bazel 5.3.0</td></tr>

0 commit comments

Comments
 (0)