簡體   English   中英

Kebuntu上的keras(-gpu)+ tensorflow-gpu + anaconda

[英]keras(-gpu) + tensorflow-gpu + anaconda on Kubuntu

我有Kubuntu 18.04和Anaconda 5.264。我安裝了CUDA驅動程序以及keras-gpu和tensorflow-gpu(也自動安裝了tensorflow)。

以下代碼

from tensorflow.python.client import device_lib
print(device_lib.list_local_devices())

import keras
from keras.datasets import mnist
from keras.models import Sequential
from keras.layers import Dense, Dropout, Flatten
from keras.layers import Conv2D, MaxPooling2D
from keras import backend as K

import tensorflow as tf
print('Tensorflow: ', tf.__version__)

給出輸出

2018-07-29 12:14:06.821996: I tensorflow/core/platform/cpu_feature_guard.cc:141] Your CPU supports instructions that this TensorFlow binary was not compiled to use: SSE4.1 SSE4.2 AVX AVX2 FMA
2018-07-29 12:14:06.880569: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:897] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero
2018-07-29 12:14:06.880910: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1392] Found device 0 with properties:
name: GeForce GTX 980 major: 5 minor: 2 memoryClockRate(GHz): 1.2155
pciBusID: 0000:01:00.0
totalMemory: 3.95GiB freeMemory: 2.72GiB
2018-07-29 12:14:06.880924: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1471] Adding visible gpu devices: 0
2018-07-29 12:14:07.058984: I tensorflow/core/common_runtime/gpu/gpu_device.cc:952] Device interconnect StreamExecutor with strength 1 edge matrix:
2018-07-29 12:14:07.059012: I tensorflow/core/common_runtime/gpu/gpu_device.cc:958]      0
2018-07-29 12:14:07.059017: I tensorflow/core/common_runtime/gpu/gpu_device.cc:971] 0:   N
2018-07-29 12:14:07.059114: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1084] Created TensorFlow device (/device:GPU:0 with 2430 MB memory) -> physical GPU (device: 0, name: GeForce GTX 980, pci bus id: 0000:01:00.0, compute capability: 5.2)
[name: "/device:CPU:0"
device_type: "CPU"
memory_limit: 268435456
locality {
}
incarnation: 18195666940796676435
, name: "/device:GPU:0"
device_type: "GPU"
memory_limit: 2548367360
locality {
  bus_id: 1
  links {
  }
}
incarnation: 7016427886680347829
physical_device_desc: "device: 0, name: GeForce GTX 980, pci bus id: 0000:01:00.0, compute capability: 5.2"
]
Using TensorFlow backend.
Tensorflow:  1.9.0

所以看來keras使用的是tensorflow CPU而不是GPU(使用DeepBach,我的CPU內核之一是100%)? 我究竟做錯了什么?

如何確定keras / DeepBach正在使用哪個設備? 在使用keras / DeepBach進行訓練時,nvidia-smi顯示沒有GPU利用率。 如何告訴keras / DeepBach使用GPU而不是CPU?

CUDA似乎已安裝:

$ nvcc -V
nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2017 NVIDIA Corporation
Built on Fri_Sep__1_21:08:03_CDT_2017
Cuda compilation tools, release 9.0, V9.0.176

$ nvidia-smi
Sun Jul 29 12:10:28 2018       
+-----------------------------------------------------------------------------+
| NVIDIA-SMI 390.48                 Driver Version: 390.48                    |
|-------------------------------+----------------------+----------------------+
| GPU  Name        Persistence-M| Bus-Id        Disp.A | Volatile Uncorr. ECC |
| Fan  Temp  Perf  Pwr:Usage/Cap|         Memory-Usage | GPU-Util  Compute M. |
|===============================+======================+======================|
|   0  GeForce GTX 980     Off  | 00000000:01:00.0  On |                  N/A |
|  4%   62C    P0    47W / 180W |   1160MiB /  4040MiB |      1%      Default |
+-------------------------------+----------------------+----------------------+

+-----------------------------------------------------------------------------+
| Processes:                                                       GPU Memory |
|  GPU       PID   Type   Process name                             Usage      |
|=============================================================================|
|    0      1113      G   /usr/lib/xorg/Xorg                           562MiB |
|    0      1385      G   kwin_x11                                     152MiB |
|    0      1395      G   /usr/bin/krunner                               2MiB |
|    0      1399      G   /usr/bin/plasmashell                         167MiB |
|    0     26801      G   ...-token=2DD4BBFEA86302FEC3C179E07D55C897   267MiB |
+-----------------------------------------------------------------------------+

當您運行代碼時,請檢查system-monitor以查看是否涉及GPU。 專門檢查Gpu的內存使用情況

我認為您已經使用CUDA支持編譯了(或安裝了已經編譯的軟件包)tensorflow,但不支持所有適用於CPU的指令(您的CPU支持tensorflow可以使用的SSE4.1,SSE4.2,AVX,AVX2和FMA指令)采用)。

這意味着tensorflow可以正常工作(具有完整的GPU支持),但是您不能滿負荷使用處理器。

嘗試使用以下示例比較時間(GPU與CPU): https : //stackoverflow.com/a/54661896/10418812

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM