公式サイト の手順通りにやったものです。
公式サイトより詳しくないのでご了承ください。自分の覚書みたいなものです。
環境
- Windows 10 Home 21H2 19044.1526
- Python 3.9.6
- pip 21.1.3
- TensorFlow 2.8.0
- CUDA 11.2
- cuDNN SDK 8.1.0
準備
Microsoft Visual C++ 再頒布可能パッケージ
このパッケージに含まれる msvcp140_1.dll が必要のためインストールする。
うちのPCは 64ビットOS なので、アーキテクチャX64 の実行ファイルをダウンロードしてインストールした。


ロングパスの有効化
Windows だと 256文字以上のフォルダ名+ファイル名の場合エラーとなるため、ロングパスを有効にさせます。
スタートメニューに「regedit」と入力し、レジストリエディッターを起動させます。

レジストリエディター で「HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\FileSystem」に移動します。
「FileSystem」フォルダ内に「LongPathsEnabled」が無い場合は追加します。
右クリックメニューから「新規 -> DWORD (32ビット) 値」を選択し、新しく追加します。

- キー: LongPathsEnabled
- 値: 1

設定後

TensorFlow のインストール
次のコマンドで TensorFlow がインストールできます。
pip install --upgrade tensorflow

動作確認
次のコマンドで TensorFlow のインストールに成功したか確認することができます。
python -c "import tensorflow as tf;print(tf.reduce_sum(tf.random.normal([1000, 1000])))"

GPUを使うためのDLLが無いのでエラーになってますが、動いてはいそうです。
C:\WINDOWS\system32>python -c "import tensorflow as tf;print(tf.reduce_sum(tf.random.normal([1000, 1000])))"
2022-03-06 16:59:24.092377: W tensorflow/stream_executor/platform/default/dso_loader.cc:64] Could not load dynamic library 'cudart64_110.dll'; dlerror: cudart64_110.dll not found
2022-03-06 16:59:24.092624: I tensorflow/stream_executor/cuda/cudart_stub.cc:29] Ignore above cudart dlerror if you do not have a GPU set up on your machine.
2022-03-06 16:59:27.917585: W tensorflow/stream_executor/platform/default/dso_loader.cc:64] Could not load dynamic library 'cudart64_110.dll'; dlerror: cudart64_110.dll not found
2022-03-06 16:59:27.918185: W tensorflow/stream_executor/platform/default/dso_loader.cc:64] Could not load dynamic library 'cublas64_11.dll'; dlerror: cublas64_11.dll not found
2022-03-06 16:59:27.919028: W tensorflow/stream_executor/platform/default/dso_loader.cc:64] Could not load dynamic library 'cublasLt64_11.dll'; dlerror: cublasLt64_11.dll not found
2022-03-06 16:59:27.919546: W tensorflow/stream_executor/platform/default/dso_loader.cc:64] Could not load dynamic library 'cufft64_10.dll'; dlerror: cufft64_10.dll not found
2022-03-06 16:59:27.920028: W tensorflow/stream_executor/platform/default/dso_loader.cc:64] Could not load dynamic library 'curand64_10.dll'; dlerror: curand64_10.dll not found
2022-03-06 16:59:27.920502: W tensorflow/stream_executor/platform/default/dso_loader.cc:64] Could not load dynamic library 'cusolver64_11.dll'; dlerror: cusolver64_11.dll not found
2022-03-06 16:59:27.920977: W tensorflow/stream_executor/platform/default/dso_loader.cc:64] Could not load dynamic library 'cusparse64_11.dll'; dlerror: cusparse64_11.dll not found
2022-03-06 16:59:27.921440: W tensorflow/stream_executor/platform/default/dso_loader.cc:64] Could not load dynamic library 'cudnn64_8.dll'; dlerror: cudnn64_8.dll not found
2022-03-06 16:59:27.921521: W tensorflow/core/common_runtime/gpu/gpu_device.cc:1850] Cannot dlopen some GPU libraries. Please make sure the missing libraries mentioned above are installed properly if you would like to use GPU. Follow the guide at https://www.tensorflow.org/install/gpu for how to download and setup the required libraries for your platform.
Skipping registering GPU devices...
2022-03-06 16:59:27.922366: I tensorflow/core/platform/cpu_feature_guard.cc:151] This TensorFlow binary is optimized with oneAPI Deep Neural Network Library (oneDNN) to use the following CPU instructions in performance-critical operations: AVX AVX2
To enable them in other operations, rebuild TensorFlow with the appropriate compiler flags.
tf.Tensor(93.55823, shape=(), dtype=float32)
GPU サポート
CPUだけでも機械学習できますが、GPUを使えるようにします。
GPU サポートの設定方法も 公式サイト を参考にしました。
NVIDIA GPU ドライバー v450.80.02 以降
使ってるグラボ用の GPUドライバー をダウンロードしてインストールします。

v450.80.02 以降でないと正常に動作しないらしいです。
今回は「NVIDIAグラフィックスドライバー」にチェックを入れてインストールしました。

CUDA 11.2
TensorFlow 2.8.0 は CUDA 11.2 に対応しています。
CUDA Toolkit Archive よりダウンロードできます。

ダウンロードが出来たので実行したところ、インストールできませんでした。
You already have a newer version of the NVIDIA Frameview SDK installed.

Frameview というアプリが既にインストールされていたので、一度アンインストールして再度実行したところ、無事にインストールすることができました。

カスタムインストールを選択して、CUDA のみをインストールしました。

cuDNN SDK 8.1.0
cuDNN Archive から cuDNN SDK v8.1.0 をダウンロードします。
CUDA 11.2 対応版をダウンロードします。cuDNN v8.1.1 でも問題ありませんでした。

x64 が無かったので「cuDNN Library for Windows (x86)」をダウンロードして、

Cドライブの直下に新規フォルダー「tools」を作って、そこに展開して置いておきます。

環境変数
最後に今インストールしたディレクトリを、環境変数に登録します。
C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.2\bin
C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.2\extras\CUPTI\lib64
C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.2\include
C:\tools\cuda\bin

動作確認
動作確認をします。
python -c "import tensorflow as tf;print(tf.reduce_sum(tf.random.normal([1000, 1000])))"

正常に GPU が認識されているので、問題なさそうです。
C:\WINDOWS\system32>python -c "import tensorflow as tf;print(tf.reduce_sum(tf.random.normal([1000, 1000])))"
2022-03-06 19:34:12.714818: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1900] Ignoring visible gpu device (device: 0, name: NVIDIA GeForce GTX 760, pci bus id: 0000:01:00.0, compute capability: 3.0) with Cuda compute capability 3.0. The minimum required Cuda capability is 3.5.
2022-03-06 19:34:12.718506: I tensorflow/core/platform/cpu_feature_guard.cc:151] This TensorFlow binary is optimized with oneAPI Deep Neural Network Library (oneDNN) to use the following CPU instructions in performance-critical operations: AVX AVX2
To enable them in other operations, rebuild TensorFlow with the appropriate compiler flags.
tf.Tensor(392.52243, shape=(), dtype=float32)
今回のオチ
よく読んでみると NVIDIA GeForce GTX 760 は計算能力が低いから使わないって書いてありますね。
せっかく設定したのに、無駄に終わりました。