Skip to content

sxlllslgh/tensorflow-windows

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

189,920 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
TensorFlow Windows CUDA Patch Build banner

TensorFlow Python Windows CUDA cuDNN License

TensorFlow 2.21.0 for Native Windows CUDA

This repository is a Windows-focused release branch based on upstream TensorFlow v2.21.0. It carries local build fixes for producing TensorFlow artifacts on native Windows x86-64 with CPython 3.14, CUDA 13.3, and cuDNN 9.

This is not an official TensorFlow PyPI release. The release artifacts are intended to be downloaded from this fork's GitHub Releases page.

Supported Configuration

Component Version or layout
TensorFlow base 2.21.0
Platform Native Windows x86-64
Python ABI CPython 3.14, cp314-win_amd64
CUDA 13.3
cuDNN 9.23.2
GPU code sm_75, sm_80, sm_86, sm_87, sm_88, sm_89, sm_90, sm_100, sm_103, sm_110, sm_120, sm_121, compute_121
C API tensorflow.dll and tensorflow.lib
C++ API tensorflow_cc.dll and tensorflow_cc.lib

The C++ release ships one public C++ DLL: tensorflow_cc.dll.

What Changed

This branch keeps the upstream TensorFlow source layout and adds the Windows build support needed by this release:

  • CPython 3.14 toolchain and wheel dependency support.
  • Native Windows CUDA 13.3 and cuDNN 9 configuration fixes.
  • MSVC and NVCC compatibility fixes across TensorFlow, XLA, MLIR, and selected third-party dependencies.
  • Curated Windows DEF exports for user-facing C and C++ symbols, avoiding the MSVC import-library limit while keeping common TensorFlow C++ graph/session programs linkable.
  • Final artifact targets for the Python wheel, C API DLL/import library, C++ DLL/import library, and installable headers.
  • Runtime DLL discovery for CUDA, CUPTI, and cuDNN through TF_CUDA_DLL_DIRECTORIES, CUDA_PATH, LOCAL_CUDA_PATH, CUDNN_PATH, and LOCAL_CUDNN_PATH, with defaults for D:\CUDA and D:\CUDNN.
  • Native Windows CUDA test/build configs, including optional oneDNN/MKL configs and the Windows NUMA noop test path.

Install the Python Wheel

Install CPython 3.14 first. A normal installation can be as simple as:

py -3.14 -m venv .venv
.\.venv\Scripts\python.exe -m pip install --upgrade pip
.\.venv\Scripts\python.exe -m pip install .\wheel\tensorflow-2.21.0-cp314-cp314-win_amd64.whl

The wheel metadata uses a Python 3.14-compatible h5py dependency, so users should not need --no-deps for the normal release wheel install path.

Run a quick import test:

.\.venv\Scripts\python.exe -c "import tensorflow as tf; print(tf.__version__); print(tf.matmul([[1.,2.],[3.,4.]], [[5.,6.],[7.,8.]]).numpy().tolist())"

Use the C API

Add the C API DLL directory to PATH, include the release headers, and link the import library:

$Release = "C:\path\to\release"
$env:PATH = "$Release\c_api\bin;$env:PATH"

cl /nologo /MD /O2 /I"$Release\include" app.c /Fe:app_c.exe /link /LIBPATH:"$Release\c_api\lib" tensorflow.lib

Use the C++ API

The C++ API uses tensorflow_cc.dll and tensorflow_cc.lib:

$Release = "C:\path\to\release"
$env:PATH = "$Release\cxx_api\bin;$Release\c_api\bin;$env:PATH"

cl /nologo /MD /EHsc /std:c++17 /O2 /I"$Release\include" app.cc /Fe:app_cc.exe /link /LIBPATH:"$Release\cxx_api\lib" tensorflow_cc.lib

The smoke-tested C++ path covers common graph/session symbols such as tensorflow::Scope, tensorflow::ClientSession, tensorflow::Input, tensorflow::ops::Const, and tensorflow::ops::MatMul.

Build from Source

The release branch is intended to be built from the upstream v2.21.0 tag plus this patch set. The default local configuration expects:

  • Python at C:\Python314\python.exe.
  • CUDA at D:\CUDA.
  • cuDNN at D:\CUDNN.
  • Bazel available on PATH.
  • An MSVC x64 developer toolchain.

Set temporary directories and build outputs outside the source tree:

$Desktop = [Environment]::GetFolderPath("Desktop")
$Tmp = Join-Path $Desktop "tmp"
New-Item -ItemType Directory -Force $Tmp | Out-Null

$env:TEMP = $Tmp
$env:TMP = $Tmp
$env:TMPDIR = $Tmp
$env:TEMP_DIR = $Tmp
$env:TMP_DIR = $Tmp
$env:TMEP_DIR = $Tmp

$env:PYTHON_BIN_PATH = "C:\Python314\python.exe"
$env:CUDA_PATH = "D:\CUDA"
$env:CUDNN_PATH = "D:\CUDNN"
$env:TF_ENABLE_WIN_CUDA = "1"
$env:HERMETIC_CUDA_COMPUTE_CAPABILITIES = "sm_75,sm_80,sm_86,sm_87,sm_88,sm_89,sm_90,sm_100,sm_103,sm_110,sm_120,sm_121,compute_121"

Configure and build:

.\configure.py

bazel `
  --output_user_root="$Desktop\bazel_user_root" `
  --output_base="$Desktop\bazel_output_base" `
  build `
  --config=opt `
  --config=cuda `
  --config=nonccl `
  --dynamic_mode=off `
  --@local_config_cuda//cuda:override_include_cuda_libs=true `
  //tensorflow/tools/pip_package:wheel `
  //tensorflow:tensorflow.dll `
  //tensorflow:tensorflow_dll_import_lib `
  //tensorflow:tensorflow_cc.dll `
  //tensorflow:tensorflow_cc_dll_import_lib `
  //tensorflow:install_headers

Optional Windows CUDA test configs are also available:

bazel test --config=windows_x86_cuda_2022_pycpp_test
bazel test --config=windows_x86_cuda_2022_wheel_test
bazel test --config=windows_x86_cuda_2022_numa_noop_test

Validation

The release artifacts were smoke-tested with:

  • C API import-library link and MatMul execution.
  • C++ tensorflow_cc.lib link and graph/session MatMul execution.
  • Python wheel import and tf.matmul.
  • Runtime log scanning to ensure no local username or source/build path is printed by the tested runtime paths.

Known Behavior

Upstream TensorFlow 2.11 and newer prints a native Windows GPU support warning in Python and may report tf.config.list_physical_devices("GPU") == [] on native Windows. This branch focuses on producing CUDA-linked native Windows artifacts from TensorFlow 2.21.0; it does not claim to change upstream's Python GPU device registration policy.

The full upstream TensorFlow Bazel test matrix is not claimed for this release. Use the release smoke tests and the Windows CUDA configs above for this fork's validated paths.

Upstream TensorFlow Resources

License

Apache License 2.0

About

Tensorflow with patches enabling running on Windows.

Resources

License

Code of conduct

Contributing

Security policy

Stars

0 stars

Watchers

0 watching

Forks

Packages

 
 
 

Contributors

Languages

  • C++ 55.7%
  • Python 25.5%
  • MLIR 6.3%
  • HTML 4.2%
  • Starlark 4.1%
  • Go 1.2%
  • Other 3.0%