In order to use GPU with TensorFlow, it is necessary to use compatible versions of CUDA and cuDNN, and as of August 9, 2020, the latest TensorFlow 2.3.0 also supports CUDA 11 and cuDNN 8. Is not ... Therefore, building from source code will fail due to compatibility issues.
… But for those who are using “CUDA 11 + cuDNN 8” and still want to use the GPU with TensorFlow, “force” TensorFlow 2.3.0 to be built for CUDA 11 + cuDNN 8 I will leave the method. Since it is a combination of "normally not supported" versions, there is no guarantee that everything will work properly. It works fine as far as I've tried learning and inferring a simple CNN model, but it's a good idea to keep it experimental. (Temporary measures until official support for CUDA11 + cuDNN8)
This is the environment used for the build. It is in a state where the path is passed in advance, such as the CUDA and cuDNN folders.
pacman -S git patch unzip
)This time, the TensorFlow source code is downloaded and built under the S: \ build \ build_tf230
folder. A Python virtual environment is also prepared for the TensorFlow build.
S:/build/build_tf230 #Working folder Root
+ tensorflow #Source code obtained by git
+ venv #Python virtual environment
+ wheelhouse #Folder to store the created whl file
Start x64 Native Tools Command Prompt for VS 2019
and follow the steps below to build.
#Create and activate a virtual environment
python -m venv s:\build\build_tf230\venv
cd /d s:\build\build_tf230
.\venv\Scripts\activate.bat
#Installation of required packages
#Note: Latest 1.19.Note that building will fail if you use x-series NumPy
python -m pip install --upgrade pip
pip install numpy==1.18.5
pip install six wheel
pip install keras_applications==1.0.8 --no-deps
pip install keras_preprocessing==1.1.2 --no-deps
#Source code acquisition (v2.3.0 tag specification)
git clone -b v2.3.0 https://github.com/tensorflow/tensorflow.git
cd tensorflow
#In some environments, command parameters become too long and an error occurs, so delete unnecessary environment variables.
set _OLD_VIRTUAL_PATH=
#Build configuration settings
# CUDA support: Y
# CUDA compute capabilities: 7.5 (Change according to the usage environment)
# Optimization: /arch:AVX2 (changed according to usage environment)
#Other than that, the default setting (Enter)
python ./configure.py
#When using CUDA 11, the following config.An error occurs at the 78th line of h.
# C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.0\include\thrust\system\cuda\config.h
#The compatibility check part of the CUB version, but this check is "THRUST"_IGNORE_CUB_VERSION_You can skip it by defining "CHECK".
#THRUST with bazel parameters_IGNORE_CUB_VERSION_Build TensorFlow with CHECK enabled.
bazel build --config=opt --config=avx2_win --config=short_logs --config=cuda --define=no_tensorflow_py_deps=true --copt=-DTHRUST_IGNORE_CUB_VERSION_CHECK --copt=-nvcc_options=disable-warnings //tensorflow/tools/pip_package:build_pip_package
#Create package (create package in wheelhouse folder)
#I'm worried that the screen won't refresh for a few minutes, but it's being processed properly so let's wait for a while.
bazel-bin\tensorflow\tools\pip_package\build_pip_package ..\wheelhouse
That's it.
The point is to add --copt = -DTHRUST_IGNORE_CUB_VERSION_CHECK
to the bazel build parameter to skip the CUDA 11 CUB compatibility check.
Recommended Posts