As per
TensorFlow installation manual, TensorFlow can be installed with either CPU or GPU support.
In order to check if we can install TensorFlow with GPU support we have to check if we have NVIDIA graphics card:
$ lspci
...
01:00.0 VGA compatible controller: NVIDIA Corporation GK107 [GeForce GT 640 OEM] (rev a1)
...
We do have it so we can go forward with installation of GPU-accelerated version of TensorFlow.
Installing TensorFlow Dependencies
1) CUDA Toolkit 8.0
If CUDA is installed on local machine, we should be able to find the location of NVIDIA CUDA compiler (nvcc) and check its version (which matches the version of CUDA package):
$ which nvcc
/usr/local/cuda-8.0/bin/nvcc
$ nvcc --version
nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2016 NVIDIA Corporation
Built on Sun_Sep__4_22:14:01_CDT_2016
Cuda compilation tools, release 8.0, V8.0.44
If CUDA is not installed, download Ubuntu installer from
CUDA Downloads page and follow Installation instructions in
CUDA Quick start Guide.
In our case, CUDA 8.0 was installed so no upgrade was necessary.
2) NVIDIA drivers associated with CUDA Toolkit 8.0
They get installed within CUDA Installation and get loaded upon the next system boot.
Installed NVIDIA driver files have names with pattern nvidia-XXX where XXX is a number so we can use:
$ sudo apt list | grep -P 'nvidia-[0-9]+'
nvidia-304/xenial-updates,xenial-security 304.134-0ubuntu0.16.04.1 amd64
nvidia-304-dev/xenial-updates,xenial-security 304.134-0ubuntu0.16.04.1 amd64
nvidia-304-updates/xenial-updates,xenial-security 304.134-0ubuntu0.16.04.1 amd64
nvidia-304-updates-dev/xenial-updates,xenial-security 304.134-0ubuntu0.16.04.1 amd64
nvidia-331/xenial-updates,xenial-security 340.101-0ubuntu0.16.04.1 amd64
nvidia-331-dev/xenial-updates,xenial-security 340.101-0ubuntu0.16.04.1 amd64
nvidia-331-updates/xenial-updates,xenial-security 340.101-0ubuntu0.16.04.1 amd64
nvidia-331-updates-dev/xenial-updates,xenial-security 340.101-0ubuntu0.16.04.1 amd64
nvidia-331-updates-uvm/xenial-updates,xenial-security 340.101-0ubuntu0.16.04.1 amd64
nvidia-331-uvm/xenial-updates,xenial-security 340.101-0ubuntu0.16.04.1 amd64
nvidia-340/xenial-updates,xenial-security 340.101-0ubuntu0.16.04.1 amd64
nvidia-340-dev/xenial-updates,xenial-security 340.101-0ubuntu0.16.04.1 amd64
nvidia-340-updates/xenial-updates,xenial-security 340.101-0ubuntu0.16.04.1 amd64
nvidia-340-updates-dev/xenial-updates,xenial-security 340.101-0ubuntu0.16.04.1 amd64
nvidia-340-updates-uvm/xenial 340.96-0ubuntu2 amd64
nvidia-340-uvm/xenial-updates,xenial-security 340.101-0ubuntu0.16.04.1 amd64
nvidia-346/xenial 352.63-0ubuntu3 amd64
nvidia-346-dev/xenial 352.63-0ubuntu3 amd64
nvidia-346-updates/xenial 352.63-0ubuntu3 amd64
nvidia-346-updates-dev/xenial 352.63-0ubuntu3 amd64
nvidia-352/xenial 361.42-0ubuntu2 i386
nvidia-352-dev/xenial 361.42-0ubuntu2 i386
nvidia-352-updates/xenial 361.42-0ubuntu2 i386
nvidia-352-updates-dev/xenial 361.42-0ubuntu2 i386
nvidia-361/xenial-updates,xenial-security 367.57-0ubuntu0.16.04.1 amd64
nvidia-361-dev/xenial-updates,xenial-security 367.57-0ubuntu0.16.04.1 amd64
nvidia-361-updates/xenial 361.42-0ubuntu2 i386
nvidia-361-updates-dev/xenial 361.42-0ubuntu2 i386
nvidia-367/xenial-updates,xenial-security,now 367.57-0ubuntu0.16.04.1 amd64 [installed,automatic]
nvidia-367-dev/xenial-updates,xenial-security,now 367.57-0ubuntu0.16.04.1 amd64 [installed,automatic]
Driver in use is the latest one, with version 367.57.
We can also run NVIDIA System Management Interface:
$ nvidia-smi
Sun Mar 19 18:24:12 2017
+-----------------------------------------------------------------------------+
| NVIDIA-SMI 367.57 Driver Version: 367.57 |
|-------------------------------+----------------------+----------------------+
| 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 GT 640 Off | 0000:01:00.0 N/A | N/A |
| 40% 32C P8 N/A / N/A | 528MiB / 1990MiB | N/A Default |
+-------------------------------+----------------------+----------------------+
+-----------------------------------------------------------------------------+
| Processes: GPU Memory |
| GPU PID Type Process name Usage |
|=============================================================================|
| 0 Not Supported |
+-----------------------------------------------------------------------------+
...or query NVIDIA settings for NvidiaDriverVersion:
$ nvidia-settings -q NvidiaDriverVersion
Attribute 'NvidiaDriverVersion' (my-PC:0.0): 367.57
Attribute 'NvidiaDriverVersion' (my-PC:0[gpu:0]): 367.57
...or open NVIDIA settings GUI (we have to open it from Terminal) and check driver version there:
$ nvidia-settings
3) cuDNN v5.1
Installation of cuDNN is a matter of downloading its package, uncompressing it and copying header file and a library into CUDA installation directories.
We detected earlier that CUDA root directory is /usr/local/cuda-8.0/. We have to check that /usr/local/cuda-8.0/include and /usr/local/cuda-8.0/lib64 directories contain cuDNN. In our case they do as I already had cuDNN installed:
/usr/local/cuda-8.0/include$ ls cudnn*
cudnn.h
/usr/local/cuda-8.0/lib64$ ls libcudnn*
libcudnn.so libcudnn.so.5 libcudnn.so.5.1.5 libcudnn_static.a
Header file contains version information:
/usr/local/cuda-8.0/include$ cat cudnn.h | grep CUDNN_MAJOR -A 2
#define CUDNN_MAJOR 5
#define CUDNN_MINOR 1
#define CUDNN_PATCHLEVEL 5
We verified that have cuDNN v5.1 installed.
4) GPU card with CUDA Compute Capability 3.0 or higher
Compute Capability is a version of GPU's architecture generation.
NVIDIA's
CUDA GPUs page lists two versions of GeForce GT 640:
GeForce GT 640 (GDDR5) 3.5
GeForce GT 640 (GDDR3) 2.1
We have to find out if GeForce GT 640 OEM has GDDR5 or GDDR3.
GeForce GT 640 OEM Specification does not mention Computing Capability.
I tried various tools with no success:
$ nvidia-smi
Sun Mar 19 22:52:36 2017
+-----------------------------------------------------------------------------+
| NVIDIA-SMI 367.57 Driver Version: 367.57 |
|-------------------------------+----------------------+----------------------+
| 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 GT 640 Off | 0000:01:00.0 N/A | N/A |
| 40% 33C P8 N/A / N/A | 721MiB / 1990MiB | N/A Default |
+-------------------------------+----------------------+----------------------+
+-----------------------------------------------------------------------------+
| Processes: GPU Memory |
| GPU PID Type Process name Usage |
|=============================================================================|
| 0 Not Supported |
+-----------------------------------------------------------------------------+
$ nvidia-smi --query
==============NVSMI LOG==============
Timestamp : Sun Mar 19 22:50:19 2017
Driver Version : 367.57
Attached GPUs : 1
GPU 0000:01:00.0
Product Name : GeForce GT 640
Product Brand : GeForce
Display Mode : N/A
Display Active : N/A
Persistence Mode : Disabled
Accounting Mode : N/A
Accounting Mode Buffer Size : N/A
Driver Model
Current : N/A
Pending : N/A
Serial Number : N/A
GPU UUID : GPU-f2583df9-404d-2564-d332-e7878a94d087
Minor Number : 0
VBIOS Version : 80.07.53.00.21
MultiGPU Board : N/A
Board ID : N/A
GPU Part Number : N/A
Inforom Version
Image Version : N/A
OEM Object : N/A
ECC Object : N/A
Power Management Object : N/A
GPU Operation Mode
Current : N/A
Pending : N/A
GPU Virtualization Mode
Virtualization mode : N/A
PCI
Bus : 0x01
Device : 0x00
Domain : 0x0000
Device Id : 0x0FC010DE
Bus Id : 0000:01:00.0
Sub System Id : 0x3B861642
GPU Link Info
PCIe Generation
Max : N/A
Current : N/A
Link Width
Max : N/A
Current : N/A
Bridge Chip
Type : N/A
Firmware : N/A
Replays since reset : 0
Tx Throughput : N/A
Rx Throughput : N/A
Fan Speed : 40 %
Performance State : P0
Clocks Throttle Reasons : N/A
FB Memory Usage
Total : 1990 MiB
Used : 733 MiB
Free : 1257 MiB
BAR1 Memory Usage
Total : N/A
Used : N/A
Free : N/A
Compute Mode : Default
Utilization
Gpu : N/A
Memory : N/A
Encoder : N/A
Decoder : N/A
Ecc Mode
Current : N/A
Pending : N/A
ECC Errors
Volatile
Single Bit
Device Memory : N/A
Register File : N/A
L1 Cache : N/A
L2 Cache : N/A
Texture Memory : N/A
Texture Shared : N/A
Total : N/A
Double Bit
Device Memory : N/A
Register File : N/A
L1 Cache : N/A
L2 Cache : N/A
Texture Memory : N/A
Texture Shared : N/A
Total : N/A
Aggregate
Single Bit
Device Memory : N/A
Register File : N/A
L1 Cache : N/A
L2 Cache : N/A
Texture Memory : N/A
Texture Shared : N/A
Total : N/A
Double Bit
Device Memory : N/A
Register File : N/A
L1 Cache : N/A
L2 Cache : N/A
Texture Memory : N/A
Texture Shared : N/A
Total : N/A
Retired Pages
Single Bit ECC : N/A
Double Bit ECC : N/A
Pending : N/A
Temperature
GPU Current Temp : 38 C
GPU Shutdown Temp : N/A
GPU Slowdown Temp : N/A
Power Readings
Power Management : N/A
Power Draw : N/A
Power Limit : N/A
Default Power Limit : N/A
Enforced Power Limit : N/A
Min Power Limit : N/A
Max Power Limit : N/A
Clocks
Graphics : N/A
SM : N/A
Memory : N/A
Video : N/A
Applications Clocks
Graphics : N/A
Memory : N/A
Default Applications Clocks
Graphics : N/A
Memory : N/A
Max Clocks
Graphics : N/A
SM : N/A
Memory : N/A
Video : N/A
Clock Policy
Auto Boost : N/A
Auto Boost Default : N/A
Processes : N/A
$ sudo dmidecode -t memory
# dmidecode 3.0
Getting SMBIOS data from sysfs.
SMBIOS 2.7 present.
Handle 0x000F, DMI type 16, 23 bytes
Physical Memory Array
Location: System Board Or Motherboard
Use: System Memory
Error Correction Type: None
Maximum Capacity: 32 GB
Error Information Handle: Not Provided
Number Of Devices: 4
Handle 0x0011, DMI type 17, 34 bytes
Memory Device
Array Handle: 0x000F
Error Information Handle: Not Provided
Total Width: 64 bits
Data Width: 64 bits
Size: 4096 MB
Form Factor: DIMM
Set: None
Locator: ChannelA-DIMM0
Bank Locator: BANK 0
Type: DDR3
Type Detail: Synchronous
Speed: 1600 MHz
Manufacturer: 0443
Serial Number: 42718838
Asset Tag: 9876543210
Part Number: RMR5040ED58E9W1600
Rank: 2
Configured Clock Speed: 1600 MHz
Handle 0x0013, DMI type 17, 34 bytes
Memory Device
Array Handle: 0x000F
Error Information Handle: Not Provided
Total Width: 64 bits
Data Width: 64 bits
Size: 4096 MB
Form Factor: DIMM
Set: None
Locator: ChannelA-DIMM1
Bank Locator: BANK 1
Type: DDR3
Type Detail: Synchronous
Speed: 1600 MHz
Manufacturer: 0443
Serial Number: 42218738
Asset Tag: 9876543210
Part Number: RMR5040ED58E9W1600
Rank: 2
Configured Clock Speed: 1600 MHz
Handle 0x0015, DMI type 17, 34 bytes
Memory Device
Array Handle: 0x000F
Error Information Handle: Not Provided
Total Width: 64 bits
Data Width: 64 bits
Size: 4096 MB
Form Factor: DIMM
Set: None
Locator: ChannelB-DIMM0
Bank Locator: BANK 2
Type: DDR3
Type Detail: Synchronous
Speed: 1600 MHz
Manufacturer: 0443
Serial Number: 42508938
Asset Tag: 9876543210
Part Number: RMR5040ED58E9W1600
Rank: 2
Configured Clock Speed: 1600 MHz
Handle 0x0017, DMI type 17, 34 bytes
Memory Device
Array Handle: 0x000F
Error Information Handle: Not Provided
Total Width: 64 bits
Data Width: 64 bits
Size: 4096 MB
Form Factor: DIMM
Set: None
Locator: ChannelB-DIMM1
Bank Locator: BANK 3
Type: DDR3
Type Detail: Synchronous
Speed: 1600 MHz
Manufacturer: 0443
Serial Number: 42B3C138
Asset Tag: 9876543210
Part Number: RMR5040ED58E9W1600
Rank: 2
Configured Clock Speed: 1600 MHz
$ sudo lshw -short -C memory
H/W path Device Class Description
====================================================================
/0/0 memory 64KiB BIOS
/0/c memory 1MiB L2 cache
/0/d memory 256KiB L1 cache
/0/e memory 8MiB L3 cache
/0/f memory 16GiB System Memory
/0/f/0 memory 4GiB DIMM DDR3 Synchron
/0/f/1 memory 4GiB DIMM DDR3 Synchron
/0/f/2 memory 4GiB DIMM DDR3 Synchron
/0/f/3 memory 4GiB DIMM DDR3 Synchron
$ sudo lshw -C video
*-display
description: VGA compatible controller
product: GK107 [GeForce GT 640 OEM]
vendor: NVIDIA Corporation
physical id: 0
bus info: pci@0000:01:00.0
version: a1
width: 64 bits
clock: 33MHz
capabilities: pm msi pciexpress vga_controller bus_master cap_list rom
configuration: driver=nvidia latency=0
resources: irq:31 memory:f6000000-f6ffffff memory:e0000000-efffffff memory:f0000000-f1ffffff ioport:e000(size=128) memory:f7000000-f707ffff
$ lspci
...
01:00.0 VGA compatible controller: NVIDIA Corporation GK107 [GeForce GT 640 OEM] (rev a1)
...
$ sudo lspci -v -s 01:00.0
01:00.0 VGA compatible controller: NVIDIA Corporation GK107 [GeForce GT 640 OEM] (rev a1) (prog-if 00 [VGA controller])
Subsystem: Bitland(ShenZhen) Information Technology Co., Ltd. GK107 [GeForce GT 640 OEM]
Flags: bus master, fast devsel, latency 0, IRQ 31
Memory at f6000000 (32-bit, non-prefetchable) [size=16M]
Memory at e0000000 (64-bit, prefetchable) [size=256M]
Memory at f0000000 (64-bit, prefetchable) [size=32M]
I/O ports at e000 [size=128]
[virtual] Expansion ROM at f7000000 [disabled] [size=512K]
Capabilities: [60] Power Management version 3
Capabilities: [68] MSI: Enable+ Count=1/1 Maskable- 64bit+
Capabilities: [78] Express Endpoint, MSI 00
Capabilities: [b4] Vendor Specific Information: Len=14
Capabilities: [100] Virtual Channel
Capabilities: [128] Power Budgeting
Capabilities: [600] Vendor Specific Information: ID=0001 Rev=1 Len=024
Capabilities: [900] #19
Kernel driver in use: nvidia
Kernel modules: nvidiafb, nouveau, nvidia_367, nvidia_367_drm
None of these tools gave me the answer. I found on Wikipedia's page
List of Nvidia graphics processing units that "The GeForce GT 640 (OEM) card is a rebranded GeForce GT 545 (DDR3)." That would mean that Compute Capability is 2.1.
Nevertheless, I decided to try to use CUDA's API
cudaGetDeviceProperties which populates structure cudaDeviceProp. This structure has fields major and minor which actually denote Compute Capability. Example's code is
here and after I compiled it and ran, I got:
$ ./CudaDeviceInfo.out
Device Number: 0
Device name: GeForce GT 640
Memory Clock Rate (KHz): 891000
Memory Bus Width (bits): 128
Peak Memory Bandwidth (GB/s): 28.512000
Compute Capability: 3.0
Hooray! Compute Capability is 3.0, we can use this GPU!
5) libcupti-dev library
This library is NVIDIA CUDA Profile Tools Interface. It can be installed like here:
$ sudo apt-get install libcupti-dev
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following packages were automatically installed and are no longer required:
linux-headers-4.4.0-31 linux-headers-4.4.0-31-generic linux-headers-4.4.0-62 linux-headers-4.4.0-62-generic linux-image-4.4.0-31-generic
linux-image-4.4.0-62-generic linux-image-extra-4.4.0-31-generic linux-image-extra-4.4.0-62-generic
Use 'sudo apt autoremove' to remove them.
The following additional packages will be installed:
libcupti-doc libcupti7.5
The following NEW packages will be installed
libcupti-dev libcupti-doc libcupti7.5
0 to upgrade, 3 to newly install, 0 to remove and 131 not to upgrade.
Need to get 1,113 kB of archives.
After this operation, 4,915 kB of additional disk space will be used.
Do you want to continue? [Y/n] y
Get:1 http://gb.archive.ubuntu.com/ubuntu xenial/multiverse amd64 libcupti7.5 amd64 7.5.18-0ubuntu1 [993 kB]
Get:2 http://gb.archive.ubuntu.com/ubuntu xenial/multiverse amd64 libcupti-dev amd64 7.5.18-0ubuntu1 [65.3 kB]
Get:3 http://gb.archive.ubuntu.com/ubuntu xenial/multiverse amd64 libcupti-doc all 7.5.18-0ubuntu1 [55.2 kB]
Fetched 1,113 kB in 4s (257 kB/s)
Selecting previously unselected package libcupti7.5:amd64.
(Reading database ... 369041 files and directories currently installed.)
Preparing to unpack .../libcupti7.5_7.5.18-0ubuntu1_amd64.deb ...
Unpacking libcupti7.5:amd64 (7.5.18-0ubuntu1) ...
Selecting previously unselected package libcupti-dev:amd64.
Preparing to unpack .../libcupti-dev_7.5.18-0ubuntu1_amd64.deb ...
Unpacking libcupti-dev:amd64 (7.5.18-0ubuntu1) ...
Selecting previously unselected package libcupti-doc.
Preparing to unpack .../libcupti-doc_7.5.18-0ubuntu1_all.deb ...
Unpacking libcupti-doc (7.5.18-0ubuntu1) ...
Processing triggers for libc-bin (2.23-0ubuntu5) ...
/sbin/ldconfig.real: /usr/local/cuda-8.0/targets/x86_64-linux/lib/libcudnn.so.5 is not a symbolic link
Setting up libcupti7.5:amd64 (7.5.18-0ubuntu1) ...
Setting up libcupti-dev:amd64 (7.5.18-0ubuntu1) ...
Setting up libcupti-doc (7.5.18-0ubuntu1) ...
Processing triggers for libc-bin (2.23-0ubuntu5) ...
/sbin/ldconfig.real: /usr/local/cuda-8.0/targets/x86_64-linux/lib/libcudnn.so.5 is not a symbolic link
TensorFlow Installation
There are four options how to install TensorFlow: using virtualenv, native pip, Docker or Anaconda. Official documentation recommends
virtualenv and we'll go this way.
I haven't used virtualenv before so let's install it (with verifying if other required packages are present):
$ sudo apt-get install python-pip python-dev python-virtualenv
Reading package lists... Done
Building dependency tree
Reading state information... Done
python-dev is already the newest version (2.7.11-1).
python-dev set to manually installed.
The following additional packages will be installed:
libpython-all-dev python-all python-all-dev python-setuptools python-wheel
python3-virtualenv virtualenv
Suggested packages:
python-setuptools-doc
The following NEW packages will be installed
libpython-all-dev python-all python-all-dev python-pip python-setuptools
python-virtualenv python-wheel python3-virtualenv virtualenv
0 to upgrade, 9 to newly install, 0 to remove and 0 not to upgrade.
Need to get 459 kB of archives.
After this operation, 1,711 kB of additional disk space will be used.
Do you want to continue? [Y/n] y
Get:1 http://gb.archive.ubuntu.com/ubuntu xenial/main amd64 libpython-all-dev amd64 2.7.11-1 [992 B]
Get:2 http://gb.archive.ubuntu.com/ubuntu xenial/main amd64 python-all amd64 2.7.11-1 [978 B]
Get:3 http://gb.archive.ubuntu.com/ubuntu xenial/main amd64 python-all-dev amd64 2.7.11-1 [1,000 B]
Get:4 http://gb.archive.ubuntu.com/ubuntu xenial-updates/universe amd64 python-pip all 8.1.1-2ubuntu0.4 [144 kB]
Get:5 http://gb.archive.ubuntu.com/ubuntu xenial/main amd64 python-setuptools all 20.7.0-1 [169 kB]
Get:6 http://gb.archive.ubuntu.com/ubuntu xenial-updates/universe amd64 python-virtualenv all 15.0.1+ds-3ubuntu1 [46.6 kB]
Get:7 http://gb.archive.ubuntu.com/ubuntu xenial/universe amd64 python-wheel all 0.29.0-1 [48.0 kB]
Get:8 http://gb.archive.ubuntu.com/ubuntu xenial-updates/universe amd64 python3-virtualenv all 15.0.1+ds-3ubuntu1 [43.2 kB]
Get:9 http://gb.archive.ubuntu.com/ubuntu xenial-updates/universe amd64 virtualenv all 15.0.1+ds-3ubuntu1 [4,342 B]
Fetched 459 kB in 21s (20.9 kB/s)
Selecting previously unselected package libpython-all-dev:amd64.
(Reading database ... 304681 files and directories currently installed.)
Preparing to unpack .../libpython-all-dev_2.7.11-1_amd64.deb ...
Unpacking libpython-all-dev:amd64 (2.7.11-1) ...
Selecting previously unselected package python-all.
Preparing to unpack .../python-all_2.7.11-1_amd64.deb ...
Unpacking python-all (2.7.11-1) ...
Selecting previously unselected package python-all-dev.
Preparing to unpack .../python-all-dev_2.7.11-1_amd64.deb ...
Unpacking python-all-dev (2.7.11-1) ...
Selecting previously unselected package python-pip.
Preparing to unpack .../python-pip_8.1.1-2ubuntu0.4_all.deb ...
Unpacking python-pip (8.1.1-2ubuntu0.4) ...
Selecting previously unselected package python-setuptools.
Preparing to unpack .../python-setuptools_20.7.0-1_all.deb ...
Unpacking python-setuptools (20.7.0-1) ...
Selecting previously unselected package python-virtualenv.
Preparing to unpack .../python-virtualenv_15.0.1+ds-3ubuntu1_all.deb ...
Unpacking python-virtualenv (15.0.1+ds-3ubuntu1) ...
Selecting previously unselected package python-wheel.
Preparing to unpack .../python-wheel_0.29.0-1_all.deb ...
Unpacking python-wheel (0.29.0-1) ...
Selecting previously unselected package python3-virtualenv.
Preparing to unpack .../python3-virtualenv_15.0.1+ds-3ubuntu1_all.deb ...
Unpacking python3-virtualenv (15.0.1+ds-3ubuntu1) ...
Selecting previously unselected package virtualenv.
Preparing to unpack .../virtualenv_15.0.1+ds-3ubuntu1_all.deb ...
Unpacking virtualenv (15.0.1+ds-3ubuntu1) ...
Processing triggers for man-db (2.7.5-1) ...
Setting up libpython-all-dev:amd64 (2.7.11-1) ...
Setting up python-all (2.7.11-1) ...
Setting up python-all-dev (2.7.11-1) ...
Setting up python-pip (8.1.1-2ubuntu0.4) ...
Setting up python-setuptools (20.7.0-1) ...
Setting up python-virtualenv (15.0.1+ds-3ubuntu1) ...
Setting up python-wheel (0.29.0-1) ...
Setting up python3-virtualenv (15.0.1+ds-3ubuntu1) ...
Setting up virtualenv (15.0.1+ds-3ubuntu1) ...
We can verify that virtualenv has been properly installed by querying its version:
$ virtualenv --version
15.0.1
or simply call it to get usage help:
$ virtualenv
Running virtualenv with interpreter /usr/bin/python2
You must provide a DEST_DIR
Usage: virtualenv.py [OPTIONS] DEST_DIR
Options:
--version show program's version number and exit
-h, --help show this help message and exit
-v, --verbose Increase verbosity.
-q, --quiet Decrease verbosity.
-p PYTHON_EXE, --python=PYTHON_EXE
The Python interpreter to use, e.g.,
--python=python2.5 will use the python2.5 interpreter
to create the new environment. The default is the
python2 interpreter on your path (e.g.
/usr/bin/python2)
--clear Clear out the non-root install and start from scratch.
--no-site-packages DEPRECATED. Retained only for backward compatibility.
Not having access to global site-packages is now the
default behavior.
--system-site-packages
Give the virtual environment access to the global
site-packages.
--always-copy Always copy files rather than symlinking.
--unzip-setuptools Unzip Setuptools when installing it.
--relocatable Make an EXISTING virtualenv environment relocatable.
This fixes up scripts and makes all .pth files
relative.
--no-setuptools Do not install setuptools in the new virtualenv.
--no-pip Do not install pip in the new virtualenv.
--no-wheel Do not install wheel in the new virtualenv.
--extra-search-dir=DIR
Directory to look for setuptools/pip distributions in.
This option can be used multiple times.
--download Download preinstalled packages from PyPI.
--no-download, --never-download
Do not download preinstalled packages from PyPI.
--prompt=PROMPT Provides an alternative prompt prefix for this
environment.
--setuptools DEPRECATED. Retained only for backward compatibility.
This option has no effect.
--distribute DEPRECATED. Retained only for backward compatibility.
This option has no effect.
We can now create virtualenv for Tensorflow, in directory "tensorflow":
$ virtualenv --python=python3 --system-site-packages tensorflow
Already using interpreter /usr/bin/python3
Using base prefix '/usr'
New python executable in /home/user_name/dev/tensorflow/bin/python3
Also creating executable in /home/user_name/dev/tensorflow/bin/python
Installing setuptools, pkg_resources, pip, wheel...done.
After activating virtual environment, prompt will be prepended with the name of the folder where we created it (e.g. (tensorflow)):
tensorflow/bin$ source activate
(tensorflow) user@user-machine:~/tensorflow/bin$
We want to install GPU-enabled TensorFlow for Python3:
$ pip3 install --upgrade tensorflow-gpu
Collecting tensorflow-gpu
Downloading tensorflow_gpu-1.0.1-cp35-cp35m-manylinux1_x86_64.whl (94.8MB)
100% |████████████████████████████████| 94.8MB 18kB/s
Requirement already up-to-date: wheel>=0.26 in /home/bojan/dev/tensorflow/lib/python3.5/site-packages (from tensorflow-gpu)
Requirement already up-to-date: protobuf>=3.1.0 in /usr/local/lib/python3.5/dist-packages (from tensorflow-gpu)
Collecting numpy>=1.11.0 (from tensorflow-gpu)
Downloading numpy-1.12.1-cp35-cp35m-manylinux1_x86_64.whl (16.8MB)
100% |████████████████████████████████| 16.8MB 87kB/s
Requirement already up-to-date: six>=1.10.0 in /home/bojan/dev/tensorflow/lib/python3.5/site-packages (from tensorflow-gpu)
Requirement already up-to-date: setuptools in /home/bojan/dev/tensorflow/lib/python3.5/site-packages (from protobuf>=3.1.0->tensorflow-gpu)
Requirement already up-to-date: appdirs>=1.4.0 in /home/bojan/dev/tensorflow/lib/python3.5/site-packages (from setuptools->protobuf>=3.1.0->tensorflow-gpu)
Requirement already up-to-date: packaging>=16.8 in /home/bojan/dev/tensorflow/lib/python3.5/site-packages (from setuptools->protobuf>=3.1.0->tensorflow-gpu)
Requirement already up-to-date: pyparsing in /home/bojan/dev/tensorflow/lib/python3.5/site-packages (from packaging>=16.8->setuptools->protobuf>=3.1.0->tensorflow-gpu)
Installing collected packages: numpy, tensorflow-gpu
Found existing installation: numpy 1.12.0
Not uninstalling numpy at /usr/local/lib/python3.5/dist-packages, outside environment /home/bojan/dev/tensorflow
Successfully installed numpy-1.12.1 tensorflow-gpu-1.0.1
TensorFlow Installation Verification
We can run a short program within Python interactive shell:
$ python
Python 3.5.2 (default, Nov 17 2016, 17:05:23)
[GCC 5.4.0 20160609] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import tensorflow as tf
I tensorflow/stream_executor/dso_loader.cc:135] successfully opened CUDA library libcublas.so.8.0 locally
I tensorflow/stream_executor/dso_loader.cc:135] successfully opened CUDA library libcudnn.so.5 locally
I tensorflow/stream_executor/dso_loader.cc:135] successfully opened CUDA library libcufft.so.8.0 locally
I tensorflow/stream_executor/dso_loader.cc:135] successfully opened CUDA library libcuda.so.1 locally
I tensorflow/stream_executor/dso_loader.cc:135] successfully opened CUDA library libcurand.so.8.0 locally
>>> hello = tf.constant('Hello, TensorFlow!')
>>> sess = tf.Session()
W tensorflow/core/platform/cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use SSE3 instructions, but these are available on your machine and could speed up CPU computations.
W tensorflow/core/platform/cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use SSE4.1 instructions, but these are available on your machine and could speed up CPU computations.
W tensorflow/core/platform/cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use SSE4.2 instructions, but these are available on your machine and could speed up CPU computations.
W tensorflow/core/platform/cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use AVX instructions, but these are available on your machine and could speed up CPU computations.
I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:910] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero
I tensorflow/core/common_runtime/gpu/gpu_device.cc:885] Found device 0 with properties:
name: GeForce GT 640
major: 3 minor: 0 memoryClockRate (GHz) 0.797
pciBusID 0000:01:00.0
Total memory: 1.94GiB
Free memory: 1.46GiB
I tensorflow/core/common_runtime/gpu/gpu_device.cc:906] DMA: 0
I tensorflow/core/common_runtime/gpu/gpu_device.cc:916] 0: Y
I tensorflow/core/common_runtime/gpu/gpu_device.cc:975] Creating TensorFlow device (/gpu:0) -> (device: 0, name: GeForce GT 640, pci bus id: 0000:01:00.0)
>>> print(sess.run(hello))
b'Hello, TensorFlow!'
>>>
Yay! We're ready to use TensorFlow!
Once we're done working with TensorFlow, we should deactivate its virtualenv:
$ deactivate
To remove virtualenv completely, simply delete its directory:
$ rm -rf tensorflow
References:
TensorFlow Manual: Installing TensorFlow on Ubuntu