TensorFlow公式のチュートリアルを進める(3)
POSTED BY
2023-01-12
2023-01-12
Google TensorFlowバージョン2 の公式チュートリアルをすすめるメモ(2)
【Windows10】Python統合開発環境Anaconda3メモ
【Anaconda3】指定した仮想環境でJupyter Notebookを動かす
【Windows10】NVIDIAグラフィックカードのGPUをTensorFlowに認識させて動かす
続きです。TensorFlowでGPUを認識した集大成として、TensorFlow公式チュートリアルサンプル
●テンソルと演算
https://www.tensorflow.org/tutorials/customization/basics?hl=ja
をすすめてみます。Anaconda3 64-bit Jupyter Notebook(64bit)を起動し、前回のGPU仮想環境カーネルNew→Environment「conda_tf-gpu」にて新規作成します。
★出現したエラー:なし
無事エラー無く実行できました。Jupyter Notebook(Anaconda3)コンソールログではGPU利用の痕跡が見えます。本記事の最後に貼付します。
上記チュートリアルの「GPUによる高速化」「明示的デバイス配置」にて、GPUのチェックと同一の処理をCPUとGPUで明示的に指定して行ってテストできています。
GPUのチェック
x = tf.random.uniform([3, 3]) print("利用できるGPUはあるか: "), print(tf.config.experimental.list_physical_devices("GPU")) print("テンソルはGPU #0にあるか: "), print(x.device.endswith('GPU:0'))
結果
利用できるGPUはあるか: [PhysicalDevice(name='/physical_device:GPU:0', device_type='GPU')] テンソルはGPU #0にあるか: True
CPUとGPUの比較
import time def time_matmul(x): start = time.time() for loop in range(10): tf.matmul(x, x) result = time.time()-start print("10 loops: {:0.2f}ms".format(1000*result)) # CPUでの実行を強制 print("On CPU:") with tf.device("CPU:0"): x = tf.random.uniform([1000, 1000]) assert x.device.endswith("CPU:0") time_matmul(x) # GPU #0があればその上での実行を強制 if tf.config.experimental.list_physical_devices("GPU"): print("On GPU:") with tf.device("GPU:0"): # 2番めのGPUなら GPU:1, 3番目なら GPU:2 など x = tf.random.uniform([1000, 1000]) assert x.device.endswith("GPU:0") time_matmul(x)
結果
On CPU: 10 loops: 49.87ms On GPU: 10 loops: 1.00ms
初回の実行こそライブラリのロードなどでGPUは時間がかかりCPUより遅いようでしたが、2度目以降はCPUよりはるかに速いという結果が得られました。
以下、Jupyter Notebookコンソールのログです。
[I 13:58:00.211 NotebookApp] Creating new notebook in [I 13:58:03.410 NotebookApp] Kernel started: e0dfc74e-0ef6-4c37-b3a7-ffbf06a3d37d, name: conda_tf-gpu [I 14:00:02.993 NotebookApp] Saving file at /Untitled4.ipynb 2021-01-12 14:54:44.132264: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library cudart64_101.dll 2021-01-12 14:54:58.697013: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library nvcuda.dll 2021-01-12 14:54:58.725958: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1561] Found device 0 with properties: pciBusID: 0000:01:00.0 name: GeForce GTX 1050 Ti computeCapability: 6.1 coreClock: 1.455GHz coreCount: 6 deviceMemorySize: 4.00GiB deviceMemoryBandwidth: 104.43GiB/s 2021-01-12 14:54:58.726091: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library cudart64_101.dll 2021-01-12 14:54:59.476740: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library cublas64_10.dll 2021-01-12 14:54:59.956291: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library cufft64_10.dll 2021-01-12 14:55:00.030618: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library curand64_10.dll 2021-01-12 14:55:00.345922: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library cusolver64_10.dll 2021-01-12 14:55:00.654046: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library cusparse64_10.dll 2021-01-12 14:55:01.215301: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library cudnn64_7.dll 2021-01-12 14:55:01.215529: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1703] Adding visible gpu devices: 0 2021-01-12 14:55:01.217412: I tensorflow/core/platform/cpu_feature_guard.cc:143] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2 2021-01-12 14:55:01.224931: I tensorflow/compiler/xla/service/service.cc:168] XLA service 0x1dd92508e20 initialized for platform Host (this does not guarantee that XLA will be used). Devices: 2021-01-12 14:55:01.225021: I tensorflow/compiler/xla/service/service.cc:176] StreamExecutor device (0): Host, Default Version 2021-01-12 14:55:01.225609: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1561] Found device 0 with properties: pciBusID: 0000:01:00.0 name: GeForce GTX 1050 Ti computeCapability: 6.1 coreClock: 1.455GHz coreCount: 6 deviceMemorySize: 4.00GiB deviceMemoryBandwidth: 104.43GiB/s 2021-01-12 14:55:01.226249: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library cudart64_101.dll 2021-01-12 14:55:01.226679: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library cublas64_10.dll 2021-01-12 14:55:01.227056: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library cufft64_10.dll 2021-01-12 14:55:01.227449: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library curand64_10.dll 2021-01-12 14:55:01.227813: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library cusolver64_10.dll 2021-01-12 14:55:01.228172: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library cusparse64_10.dll 2021-01-12 14:55:01.228506: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library cudnn64_7.dll 2021-01-12 14:55:01.228872: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1703] Adding visible gpu devices: 0 2021-01-12 14:55:01.675882: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1102] Device interconnect StreamExecutor with strength 1 edge matrix: 2021-01-12 14:55:01.675991: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1108] 0 2021-01-12 14:55:01.676978: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1121] 0: N 2021-01-12 14:55:01.677505: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1247] Created TensorFlow device (/job:localhost/replica:0/task:0/device:GPU:0 with 2988 MB memory) -> physical GPU (device: 0, name: GeForce GTX 1050 Ti, pci bus id: 0000:01:00.0, compute capability: 6.1) 2021-01-12 14:55:01.680267: I tensorflow/compiler/xla/service/service.cc:168] XLA service 0x1dda93e8fe0 initialized for platform CUDA (this does not guarantee that XLA will be used). Devices: 2021-01-12 14:55:01.680383: I tensorflow/compiler/xla/service/service.cc:176] StreamExecutor device (0): GeForce GTX 1050 Ti, Compute Capability 6.1 [I 14:56:02.981 NotebookApp] Saving file at /Untitled4.ipynb 2021-01-12 14:56:56.632067: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library cublas64_10.dll [I 14:58:02.977 NotebookApp] Saving file at /Untitled4.ipynb [I 15:00:03.824 NotebookApp] Saving file at /Untitled4.ipynb
Android
iPhone/iPad
Flutter
MacOS
Windows
Debian
Ubuntu
CentOS
FreeBSD
RaspberryPI
HTML/CSS
C/C++
PHP
Java
JavaScript
Node.js
Swift
Python
Amazon/AWS
CORESERVER
Google
仮想通貨
LINE
OpenAI/ChatGPT
IBM Watson
Microsoft Azure
Xcode
VMware
MySQL
PostgreSQL
Redis
Groonga
Git/GitHub
Apache
nginx
Postfix
SendGrid
Hackintosh
Hardware
Fate/Grand Order
ウマ娘
将棋
ドラレコ
※本記事は当サイト管理人の個人的な備忘録です。本記事の参照又は付随ソースコード利用後にいかなる損害が発生しても当サイト及び管理人は一切責任を負いません。
※本記事内容の無断転載を禁じます。
※本記事内容の無断転載を禁じます。
【WEBMASTER/管理人】
自営業プログラマーです。お仕事ください!ご連絡は以下アドレスまでお願いします★
☆ServerNote.NETショッピング↓
ShoppingNote / Amazon.co.jp
☆お仲間ブログ↓
一人社長の不動産業務日誌
【キーワード検索】
【最近の記事】【全部の記事】
nvidia-smiを1秒ごとに実行してGPU使用率をモニタリングTSUKUMOのマルチGPUパソコンWA9J-X211/XTのUbuntu Server 22.04でMYCOEIROINK作成コードを実行し音声合成モデルをトレーニングする
TSUKUMOのマルチGPUパソコンWA9J-X211/XTにUbuntu Server 22.04とCOEIROINK Engineを導入する
Python venv(仮想環境作成)でError: Command returned non-zero exit status 1のエラー対処法
【Ubuntu】プロジェクトごとに複数のPythonバージョンを使い分ける
【PHP】フォーム入力を受け取り出力する
【Ubuntu】aptでインストールしたapache2にソースコンパイルしたphpをマルチスレッドモードで組み込む
【PHP】HTMLファイルを読み込んで文字列変換して出力する
TSUKUMOのマルチGPUパソコンWA9J-X211/XTにUbuntu Server 22.04とVOICEVOX Engineを導入する
【VOICEBOX Engine】403 Forbidden Origin not allowedの対処法
【人気の記事】【全部の記事】
進研ゼミチャレンジタッチをAndroid端末化する【Windows10】リモートデスクトップ間のコピー&ペーストができなくなった場合の対処法
Windows版Google Driveが使用中と言われアンインストールできない場合
Googleファミリーリンクで子供の端末の現在地がエラーで取得できない場合
【C/C++】小数点以下の切り捨て・切り上げ・四捨五入
Windows11+WSL2でUbuntuを使う【2】ブリッジ接続+固定IPの設定
Androidホームで左にスワイプすると出てくるニュース共を一切表示させない方法
Googleスプレッドシートを編集したら自動で更新日時を入れる
【Javascript】JSON配列内にある特定要素の取得法【Node.js】
【PHP】Mail/mimeDecodeを使ってメールの中身を解析(準備編)
【カテゴリーリンク】
Android
iPhone/iPad
Flutter
MacOS
Windows
Debian
Ubuntu
CentOS
FreeBSD
RaspberryPI
HTML/CSS
C/C++
PHP
Java
JavaScript
Node.js
Swift
Python
Amazon/AWS
CORESERVER
Google
仮想通貨
LINE
OpenAI/ChatGPT
IBM Watson
Microsoft Azure
Xcode
VMware
MySQL
PostgreSQL
Redis
Groonga
Git/GitHub
Apache
nginx
Postfix
SendGrid
Hackintosh
Hardware
Fate/Grand Order
ウマ娘
将棋
ドラレコ