- 查看你电脑是否有英伟达的显卡
sudo lshw -numeric -c display
*-display
description: 3D controller
product: NVIDIA Corporation [10DE:1C20]
vendor: NVIDIA Corporation [10DE]
physical id: 0
bus info: pci@0000:01:00.0
version: a1
width: 64 bits
clock: 33MHz
capabilities: pm msi pciexpress bus_master cap_list rom
configuration: driver=nvidia latency=0
resources: irq:137 memory:93000000-93ffffff memory:50000000-5fffffff memory:60000000-61ffffff ioport:4000(size=128) memory:94000000-9407ffff
*-display
description: VGA compatible controller
product: Intel Corporation [8086:591B]
vendor: Intel Corporation [8086]
physical id: 2
bus info: pci@0000:00:02.0
version: 04
width: 64 bits
clock: 33MHz
capabilities: pciexpress msi pm vga_controller bus_master cap_list rom
configuration: driver=i915_bpo latency=0
resources: irq:126 memory:92000000-92ffffff memory:a0000000-afffffff ioport:5000(size=64)
- 找出你的系统应该安装的英伟达显卡驱动
ubuntu-drivers devices
== /sys/devices/pci0000:00/0000:00:01.0/0000:01:00.0 ==
vendor : NVIDIA Corporation
modalias : pci:v000010DEd00001C20sv00001025sd0000120Cbc03sc02i00
driver : xserver-xorg-video-nouveau - distro free builtin
driver : nvidia-384 - third-party non-free recommended
- 安装该驱动
sudo apt install nvidia-384
正在读取软件包列表… 完成
正在分析软件包的依赖关系树
正在读取状态信息… 完成
nvidia-384 已经是最新版 (384.130-0ubuntu0.16.04.1)。
升级了 0 个软件包,新安装了 0 个软件包,要卸载 0 个软件包,有 2 个软件包未被升级。
- 验证是否安装成功
nvidia-smi
- 安装cuda并验证
wget https://developer.nvidia.com/compute/cuda/8.0/Prod2/local_installers/cuda-repo-ubuntu1604-8-0-local-ga2_8.0.61-1_amd64-deb
sudo dpkg -i cuda-repo-ubuntu1604-8-0-local-ga2_8.0.61-1_amd64.deb
sudo apt-get update
sudo apt-get install cuda
- 配置环境变量
gedit ~/.bashrc
export PATH=/usr/local/cuda-8.0/bin{PATH:+:{PATH}}
export LD_LIBRARY_PATH=/usr/local/cuda-8.0/lib64{LD_LIBRARY_PATH:+:{LD_LIBRARY_PATH}}
source ~/.bashrc
nvcc -V
nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2016 NVIDIA Corporation
Built on Tue_Jan_10_13:22:03_CST_2017
Cuda compilation tools, release 8.0, V8.0.61
- 安装cudnn
wget https://developer.nvidia.com/compute/machine-learning/cudnn/secure/v5.1/prod_20161129/8.0/cudnn-8.0-linux-x64-v5.1-tgz
tar -xzvf cudnn-8.0-linux-x64-v5.1-tgz
sudo cp cuda/include/cudnn.h /usr/local/cuda/include
sudo cp cuda/lib64/libcudnn* /usr/local/cuda/lib64
sudo chmod a+r /usr/local/cuda/include/cudnn.h /usr/local/cuda/lib64/libcudnn*
- 下载安装gpu版本的tensorflow
conda install tensorflow-gpu
python model.py
gpu_options = tf.GPUOptions(per_process_gpu_memory_fraction=0.333)
sess = tf.Session(config=tf.ConfigProto(gpu_options=gpu_options))
2018-11-29 17:58:25.345884: I tensorflow/core/common_runtime/gpu/gpu_device.cc:955] Found device 0 with properties:
name: GeForce GTX 1060
major: 6 minor: 1 memoryClockRate (GHz) 1.733
pciBusID 0000:01:00.0
Total memory: 5.93GiB
Free memory: 5.46GiB