How to install Tensorflow GPU with CUDA 9.2 for python on Ubuntu

This is going to be a tutorial on how to install tensorflow 1.8.0 GPU version. We will also be installing CUDA 9.2 and cuDNN 7.1.4 along with the GPU version of tensorflow 1.8.0. At the time of writing this blog post, the latest version of tensorflow is 1.8.0.This tutorial is for building tensorflow from source. If you want to use the official pre-built pip package instead, I recommend another post, How to install Tensorflow 1.7.0 using official pip package.

Update: We have a released a new article on How to install Tensorflow GPU with CUDA 10.0 for python on Ubuntu.

Tensorflow is an open source software library developed and used by Google that is fairly common among students, researchers, and developers for deep learning applications such as neural networks. It has both the CPU as well as GPU version available and although the CPU version works quite well, realistically, if you are going for deep learning, you will need GPU. In order to use the GPU version of TensorFlow, you will need an NVIDIA GPU with a compute capability > 3.0. While it is technically possible to install tensorflow GPU version in a virtual machine, you cannot access the full power of your GPU via a virtual machine. So, I recommend doing a fresh install of Ubuntu if you don’t have Ubuntu before starting with the tutorial.

Tensorflow 1.8 with CUDA 9.2 and cuDNN 7.1.4 performs up to 37% faster when compared to earlier versions of Tensorflow. View full results here.

There must be 64-bit python installed tensorflow does not work on 32-bit python installation.

Step 1: Update and Upgrade your system:

sudo apt-get update 
sudo apt-get upgrade

Step 2: Verify You Have a CUDA-Capable GPU:

lspci | grep -i nvidia

Note GPU model. eg. GeForce 840M

If you do not see any settings, update the PCI hardware database that Linux maintains by entering update-pciids (generally found in /sbin) at the command line and rerun the previous lspci command.

If your graphics card is from NVIDIA then goto http://developer.nvidia.com/cuda-gpus and verify if listed in CUDA enabled gpu list.

Note down its Compute Capability. eg. GeForce 840M 5.0

Step 3: Verify You Have a Supported Version of Linux:

To determine which distribution and release number you’re running, type the following at the command line:

uname -m && cat /etc/*release

The x86_64 line indicates you are running on a 64-bit system which is supported by cuda 9.1

Step 4: Install Dependencies:

Required to compile from source:

sudo apt-get install build-essential 
sudo apt-get install cmake git unzip zip
sudo add-apt-repository ppa:deadsnakes/ppa
sudo apt-get update
sudo apt-get install python2.7-dev python3.5-dev python3.6-dev pylint

Step 5: Install linux kernel header:

Goto terminal and type:

uname -r

You can get like “4.10.0-42-generic”. Note down linux kernel version.

To install linux header supported by your linux kernel do following:

sudo apt-get install linux-headers-$(uname -r)

Step 6: Install NVIDIA CUDA 9.2:

Remove previous cuda installation:

sudo apt-get purge nvidia*
sudo apt-get autoremove
sudo apt-get autoclean
sudo rm -rf /usr/local/cuda*

Install cuda :

For Ubuntu 16.04 :

sudo apt-key adv --fetch-keys http://developer.download.nvidia.com/compute/cuda/repos/ubuntu1604/x86_64/7fa2af80.pub
echo "deb https://developer.download.nvidia.com/compute/cuda/repos/ubuntu1604/x86_64 /" | sudo tee /etc/apt/sources.list.d/cuda.list

For Ubuntu 17.10 and Ubuntu 18.04 :

sudo apt-key adv --fetch-keys http://developer.download.nvidia.com/compute/cuda/repos/ubuntu1710/x86_64/7fa2af80.pub
echo "deb https://developer.download.nvidia.com/compute/cuda/repos/ubuntu1710/x86_64 /" | sudo tee /etc/apt/sources.list.d/cuda.list

For Both Options:

sudo apt-get update 
sudo apt-get -o Dpkg::Options::="--force-overwrite" install cuda-9-2 cuda-drivers

Step 7: Reboot the system to load the NVIDIA drivers.

Step 8: Go to terminal and type:

echo 'export PATH=/usr/local/cuda-9.2/bin${PATH:+:${PATH}}' >> ~/.bashrc
echo 'export LD_LIBRARY_PATH=/usr/local/cuda-9.2/lib64${LD_LIBRARY_PATH:+:${LD_LIBRARY_PATH}}' >> ~/.bashrc
source ~/.bashrc
sudo ldconfig
nvidia-smi

Check driver version probably Driver Version: 396.26

(not likely) If you got nvidia-smi is not found then you have unsupported linux kernel installed. Comment your linux kernel version noted in step 5.

12 Comments on How to install Tensorflow GPU with CUDA 9.2 for python on Ubuntu

  1. i followed all your tutorial but at this point I get an error
    source ~/.bashrc
    I get this error
    bash: /lib64:/usr/local/cuda/extras/CUPTI: No such file or directory
    I get to the file /usr/local/cuda/extras/CUPTI/lib64 and I have all those 3 files
    libcupti.so libcupti.so.9.2 libcupti.so.9.2.148 x86_64-linux-gnu

  2. Thank you, I managed to compile & install tensorflow with cuda 9.2. I suppose that the same instructions apply also for cuda 10, but I am not going to attempt.

  3. Hi

    I tried this procedure and am running into the following issue!

    INFO: From Compiling tensorflow/contrib/lite/toco/graph_transformations/remove_unused_op.cc:
    In file included from ./tensorflow/contrib/lite/kernels/internal/common.h:42:0,
    from ./tensorflow/contrib/lite/toco/runtime/types.h:18,
    from ./tensorflow/contrib/lite/toco/model.h:26,
    from ./tensorflow/contrib/lite/toco/graph_transformations/graph_transformations.h:23,
    from tensorflow/contrib/lite/toco/graph_transformations/remove_unused_op.cc:20:
    external/arm_neon_2_x86_sse/NEON_2_SSE.h: In function ‘void vst1q_lane_f32(float32_t*, float32x4_t, int)’:
    external/arm_neon_2_x86_sse/NEON_2_SSE.h:9673:31: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing]
    *(ptr) = *((float*)&ilane);
    ^
    external/arm_neon_2_x86_sse/NEON_2_SSE.h: In function ‘float32_t vgetq_lane_f32(float32x4_t, int)’:
    external/arm_neon_2_x86_sse/NEON_2_SSE.h:11912:22: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing]
    return *(float*)&ilane;
    ^
    INFO: From Compiling tensorflow/contrib/lite/toco/graph_transformations/resolve_slice_attributes.cc:
    In file included from ./tensorflow/contrib/lite/kernels/internal/common.h:42:0,
    from ./tensorflow/contrib/lite/toco/runtime/types.h:18,
    from ./tensorflow/contrib/lite/toco/model.h:26,
    from ./tensorflow/contrib/lite/toco/graph_transformations/graph_transformations.h:23,
    from tensorflow/contrib/lite/toco/graph_transformations/resolve_slice_attributes.cc:20:
    external/arm_neon_2_x86_sse/NEON_2_SSE.h: In function ‘void vst1q_lane_f32(float32_t*, float32x4_t, int)’:
    external/arm_neon_2_x86_sse/NEON_2_SSE.h:9673:31: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing]
    *(ptr) = *((float*)&ilane);
    ^
    external/arm_neon_2_x86_sse/NEON_2_SSE.h: In function ‘float32_t vgetq_lane_f32(float32x4_t, int)’:
    external/arm_neon_2_x86_sse/NEON_2_SSE.h:11912:22: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing]
    return *(float*)&ilane;
    ^
    INFO: From Compiling tensorflow/contrib/lite/toco/graph_transformations/fuse_activation_functions.cc:
    In file included from ./tensorflow/contrib/lite/kernels/internal/common.h:42:0,
    from ./tensorflow/contrib/lite/toco/runtime/types.h:18,
    from ./tensorflow/contrib/lite/toco/model.h:26,
    from ./tensorflow/contrib/lite/toco/graph_transformations/graph_transformations.h:23,
    from tensorflow/contrib/lite/toco/graph_transformations/fuse_activation_functions.cc:20:
    external/arm_neon_2_x86_sse/NEON_2_SSE.h: In function ‘void vst1q_lane_f32(float32_t*, float32x4_t, int)’:
    external/arm_neon_2_x86_sse/NEON_2_SSE.h:9673:31: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing]
    *(ptr) = *((float*)&ilane);
    ^
    external/arm_neon_2_x86_sse/NEON_2_SSE.h: In function ‘float32_t vgetq_lane_f32(float32x4_t, int)’:
    external/arm_neon_2_x86_sse/NEON_2_SSE.h:11912:22: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing]
    return *(float*)&ilane;
    ^
    INFO: From Compiling tensorflow/contrib/lite/toco/graph_transformations/quantize.cc:
    In file included from ./tensorflow/contrib/lite/kernels/internal/common.h:42:0,
    from ./tensorflow/contrib/lite/toco/runtime/types.h:18,
    from ./tensorflow/contrib/lite/toco/model.h:26,
    from ./tensorflow/contrib/lite/toco/graph_transformations/graph_transformations.h:23,
    from tensorflow/contrib/lite/toco/graph_transformations/quantize.cc:23:
    external/arm_neon_2_x86_sse/NEON_2_SSE.h: In function ‘void vst1q_lane_f32(float32_t*, float32x4_t, int)’:
    external/arm_neon_2_x86_sse/NEON_2_SSE.h:9673:31: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing]
    *(ptr) = *((float*)&ilane);
    ^
    external/arm_neon_2_x86_sse/NEON_2_SSE.h: In function ‘float32_t vgetq_lane_f32(float32x4_t, int)’:
    external/arm_neon_2_x86_sse/NEON_2_SSE.h:11912:22: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing]
    return *(float*)&ilane;
    ^
    INFO: From Compiling tensorflow/contrib/lite/toco/graph_transformations/propagate_fixed_sizes.cc:
    In file included from ./tensorflow/contrib/lite/kernels/internal/common.h:42:0,
    from ./tensorflow/contrib/lite/toco/runtime/types.h:18,
    from ./tensorflow/contrib/lite/toco/model.h:26,
    from ./tensorflow/contrib/lite/toco/graph_transformations/graph_transformations.h:23,
    from tensorflow/contrib/lite/toco/graph_transformations/propagate_fixed_sizes.cc:23:
    external/arm_neon_2_x86_sse/NEON_2_SSE.h: In function ‘void vst1q_lane_f32(float32_t*, float32x4_t, int)’:
    external/arm_neon_2_x86_sse/NEON_2_SSE.h:9673:31: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing]
    *(ptr) = *((float*)&ilane);
    ^
    external/arm_neon_2_x86_sse/NEON_2_SSE.h: In function ‘float32_t vgetq_lane_f32(float32x4_t, int)’:
    external/arm_neon_2_x86_sse/NEON_2_SSE.h:11912:22: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing]
    return *(float*)&ilane;
    ^
    tensorflow/contrib/lite/toco/graph_transformations/propagate_fixed_sizes.cc: In function ‘void toco::{anonymous}::ProcessTensorFlowReshapeOperator(toco::Model*, toco::TensorFlowReshapeOperator*)’:
    tensorflow/contrib/lite/toco/graph_transformations/propagate_fixed_sizes.cc:500:21: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
    for (int i = 0; i < shape_data.size(); i++) {
    ^
    tensorflow/contrib/lite/toco/graph_transformations/propagate_fixed_sizes.cc: In function 'void toco::{anonymous}::ProcessSliceOperator(toco::Model*, toco::SliceOperator*)':
    tensorflow/contrib/lite/toco/graph_transformations/propagate_fixed_sizes.cc:658:21: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
    for (int i = 0; i begin.size(); ++i) {
    ^
    tensorflow/contrib/lite/toco/graph_transformations/propagate_fixed_sizes.cc: In function ‘void toco::{anonymous}::ProcessPadOperator(toco::Model*, toco::PadOperator*)’:
    tensorflow/contrib/lite/toco/graph_transformations/propagate_fixed_sizes.cc:1168:21: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
    for (int i = 0; i left_padding.size(); ++i) {
    ^
    In file included from ./tensorflow/core/platform/default/logging.h:24:0,
    from ./tensorflow/core/platform/logging.h:25,
    from ./tensorflow/contrib/lite/toco/model.h:28,
    from ./tensorflow/contrib/lite/toco/graph_transformations/graph_transformations.h:23,
    from tensorflow/contrib/lite/toco/graph_transformations/propagate_fixed_sizes.cc:23:
    tensorflow/contrib/lite/toco/graph_transformations/propagate_fixed_sizes.cc: In function ‘void toco::{anonymous}::ProcessStridedSliceOperator(toco::Model*, toco::StridedSliceOperator*)’:
    tensorflow/contrib/lite/toco/graph_transformations/propagate_fixed_sizes.cc:1296:34: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
    CHECK(op->start_indices.size() == dim_count)
    ^
    ./tensorflow/core/platform/macros.h:82:47: note: in definition of macro ‘TF_PREDICT_FALSE’
    #define TF_PREDICT_FALSE(x) (__builtin_expect(x, 0))
    ^
    tensorflow/contrib/lite/toco/graph_transformations/propagate_fixed_sizes.cc:1296:3: note: in expansion of macro ‘CHECK’
    CHECK(op->start_indices.size() == dim_count)
    ^
    tensorflow/contrib/lite/toco/graph_transformations/propagate_fixed_sizes.cc:1300:33: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
    CHECK(op->stop_indices.size() == dim_count)
    ^
    ./tensorflow/core/platform/macros.h:82:47: note: in definition of macro ‘TF_PREDICT_FALSE’
    #define TF_PREDICT_FALSE(x) (__builtin_expect(x, 0))
    ^
    tensorflow/contrib/lite/toco/graph_transformations/propagate_fixed_sizes.cc:1300:3: note: in expansion of macro ‘CHECK’
    CHECK(op->stop_indices.size() == dim_count)
    ^
    tensorflow/contrib/lite/toco/graph_transformations/propagate_fixed_sizes.cc:1304:28: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
    CHECK(op->strides.size() == dim_count)
    ^
    ./tensorflow/core/platform/macros.h:82:47: note: in definition of macro ‘TF_PREDICT_FALSE’
    #define TF_PREDICT_FALSE(x) (__builtin_expect(x, 0))
    ^
    tensorflow/contrib/lite/toco/graph_transformations/propagate_fixed_sizes.cc:1304:3: note: in expansion of macro ‘CHECK’
    CHECK(op->strides.size() == dim_count)
    ^
    tensorflow/contrib/lite/toco/graph_transformations/propagate_fixed_sizes.cc: In function ‘void toco::{anonymous}::ProcessSqueezeOperator(toco::Model*, toco::SqueezeOperator*)’:
    tensorflow/contrib/lite/toco/graph_transformations/propagate_fixed_sizes.cc:1353:21: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
    for (int i = 0; i < input_dims.size(); ++i) {
    ^
    tensorflow/contrib/lite/toco/graph_transformations/propagate_fixed_sizes.cc: In function 'void toco::{anonymous}::ProcessTransposeOperator(toco::Model*, toco::TransposeOperator*)':
    tensorflow/contrib/lite/toco/graph_transformations/propagate_fixed_sizes.cc:1425:21: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
    for (int i = 0; i < perm.size(); i++) {
    ^
    tensorflow/contrib/lite/toco/graph_transformations/propagate_fixed_sizes.cc: In function 'void toco::{anonymous}::ProcessArgMaxOperator(toco::Model*, toco::ArgMaxOperator*)':
    tensorflow/contrib/lite/toco/graph_transformations/propagate_fixed_sizes.cc:1448:21: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
    for (int i = 0; i < input_dims.size() – 1; ++i) {
    ^
    INFO: From Compiling tensorflow/contrib/lite/toco/graph_transformations/resolve_constant_concatenation.cc:
    In file included from ./tensorflow/contrib/lite/kernels/internal/common.h:42:0,
    from ./tensorflow/contrib/lite/toco/runtime/types.h:18,
    from ./tensorflow/contrib/lite/toco/model.h:26,
    from ./tensorflow/contrib/lite/toco/graph_transformations/graph_transformations.h:23,
    from tensorflow/contrib/lite/toco/graph_transformations/resolve_constant_concatenation.cc:21:
    external/arm_neon_2_x86_sse/NEON_2_SSE.h: In function 'void vst1q_lane_f32(float32_t*, float32x4_t, int)':
    external/arm_neon_2_x86_sse/NEON_2_SSE.h:9673:31: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing]
    *(ptr) = *((float*)&ilane);
    ^
    external/arm_neon_2_x86_sse/NEON_2_SSE.h: In function 'float32_t vgetq_lane_f32(float32x4_t, int)':
    external/arm_neon_2_x86_sse/NEON_2_SSE.h:11912:22: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing]
    return *(float*)&ilane;
    ^
    tensorflow/contrib/lite/toco/graph_transformations/resolve_constant_concatenation.cc: In instantiation of 'void toco::{anonymous}::CopyTensorSegments(const std::vector&, const std::vector&, int, toco::Array*) [with toco::ArrayDataType A = (toco::ArrayDataType)2; T = float]’:
    tensorflow/contrib/lite/toco/graph_transformations/resolve_constant_concatenation.cc:99:37: required from ‘void toco::{anonymous}::ConcatenateTensorBuffers(const std::vector&, int, toco::Array*) [with toco::ArrayDataType A = (toco::ArrayDataType)2]’
    tensorflow/contrib/lite/toco/graph_transformations/resolve_constant_concatenation.cc:167:64: required from here
    tensorflow/contrib/lite/toco/graph_transformations/resolve_constant_concatenation.cc:66:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
    for (int i = 0; i < input_arrays.size(); i++) {
    ^
    tensorflow/contrib/lite/toco/graph_transformations/resolve_constant_concatenation.cc: In instantiation of 'void toco::{anonymous}::CopyTensorSegments(const std::vector&, const std::vector&, int, toco::Array*) [with toco::ArrayDataType A = (toco::ArrayDataType)4; T = unsigned char]’:
    tensorflow/contrib/lite/toco/graph_transformations/resolve_constant_concatenation.cc:99:37: required from ‘void toco::{anonymous}::ConcatenateTensorBuffers(const std::vector&, int, toco::Array*) [with toco::ArrayDataType A = (toco::ArrayDataType)4]’
    tensorflow/contrib/lite/toco/graph_transformations/resolve_constant_concatenation.cc:172:64: required from here
    tensorflow/contrib/lite/toco/graph_transformations/resolve_constant_concatenation.cc:66:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
    tensorflow/contrib/lite/toco/graph_transformations/resolve_constant_concatenation.cc: In instantiation of ‘void toco::{anonymous}::CopyTensorSegments(const std::vector&, const std::vector&, int, toco::Array*) [with toco::ArrayDataType A = (toco::ArrayDataType)7; T = int]’:
    tensorflow/contrib/lite/toco/graph_transformations/resolve_constant_concatenation.cc:99:37: required from ‘void toco::{anonymous}::ConcatenateTensorBuffers(const std::vector&, int, toco::Array*) [with toco::ArrayDataType A = (toco::ArrayDataType)7]’
    tensorflow/contrib/lite/toco/graph_transformations/resolve_constant_concatenation.cc:176:64: required from here
    tensorflow/contrib/lite/toco/graph_transformations/resolve_constant_concatenation.cc:66:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
    tensorflow/contrib/lite/toco/graph_transformations/resolve_constant_concatenation.cc: In instantiation of ‘void toco::{anonymous}::CopyTensorSegments(const std::vector&, const std::vector&, int, toco::Array*) [with toco::ArrayDataType A = (toco::ArrayDataType)9; T = long long int]’:
    tensorflow/contrib/lite/toco/graph_transformations/resolve_constant_concatenation.cc:99:37: required from ‘void toco::{anonymous}::ConcatenateTensorBuffers(const std::vector&, int, toco::Array*) [with toco::ArrayDataType A = (toco::ArrayDataType)9]’
    tensorflow/contrib/lite/toco/graph_transformations/resolve_constant_concatenation.cc:180:64: required from here
    tensorflow/contrib/lite/toco/graph_transformations/resolve_constant_concatenation.cc:66:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
    tensorflow/contrib/lite/toco/graph_transformations/resolve_constant_concatenation.cc: In instantiation of ‘void toco::{anonymous}::CopyTensorSegments(const std::vector&, const std::vector&, int, toco::Array*) [with toco::ArrayDataType A = (toco::ArrayDataType)11; T = std::__cxx11::basic_string]’:
    tensorflow/contrib/lite/toco/graph_transformations/resolve_constant_concatenation.cc:99:37: required from ‘void toco::{anonymous}::ConcatenateTensorBuffers(const std::vector&, int, toco::Array*) [with toco::ArrayDataType A = (toco::ArrayDataType)11]’
    tensorflow/contrib/lite/toco/graph_transformations/resolve_constant_concatenation.cc:184:64: required from here
    tensorflow/contrib/lite/toco/graph_transformations/resolve_constant_concatenation.cc:66:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
    INFO: From Compiling tensorflow/contrib/lite/toco/graph_transformations/convert_trivial_addn_to_add.cc:
    In file included from ./tensorflow/contrib/lite/kernels/internal/common.h:42:0,
    from ./tensorflow/contrib/lite/toco/runtime/types.h:18,
    from ./tensorflow/contrib/lite/toco/model.h:26,
    from ./tensorflow/contrib/lite/toco/graph_transformations/graph_transformations.h:23,
    from tensorflow/contrib/lite/toco/graph_transformations/convert_trivial_addn_to_add.cc:15:
    external/arm_neon_2_x86_sse/NEON_2_SSE.h: In function ‘void vst1q_lane_f32(float32_t*, float32x4_t, int)’:
    external/arm_neon_2_x86_sse/NEON_2_SSE.h:9673:31: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing]
    *(ptr) = *((float*)&ilane);
    ^
    external/arm_neon_2_x86_sse/NEON_2_SSE.h: In function ‘float32_t vgetq_lane_f32(float32x4_t, int)’:
    external/arm_neon_2_x86_sse/NEON_2_SSE.h:11912:22: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing]
    return *(float*)&ilane;
    ^
    INFO: From Compiling tensorflow/contrib/lite/toco/graph_transformations/propagate_array_data_types.cc:
    In file included from ./tensorflow/contrib/lite/kernels/internal/common.h:42:0,
    from ./tensorflow/contrib/lite/toco/runtime/types.h:18,
    from ./tensorflow/contrib/lite/toco/model.h:26,
    from ./tensorflow/contrib/lite/toco/graph_transformations/graph_transformations.h:23,
    from tensorflow/contrib/lite/toco/graph_transformations/propagate_array_data_types.cc:20:
    external/arm_neon_2_x86_sse/NEON_2_SSE.h: In function ‘void vst1q_lane_f32(float32_t*, float32x4_t, int)’:
    external/arm_neon_2_x86_sse/NEON_2_SSE.h:9673:31: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing]
    *(ptr) = *((float*)&ilane);
    ^
    external/arm_neon_2_x86_sse/NEON_2_SSE.h: In function ‘float32_t vgetq_lane_f32(float32x4_t, int)’:
    external/arm_neon_2_x86_sse/NEON_2_SSE.h:11912:22: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing]
    return *(float*)&ilane;
    ^
    tensorflow/contrib/lite/toco/graph_transformations/propagate_array_data_types.cc: In member function ‘virtual bool toco::PropagateArrayDataTypes::Run(toco::Model*, std::size_t)’:
    tensorflow/contrib/lite/toco/graph_transformations/propagate_array_data_types.cc:135:25: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
    for (int i = 0; i outputs.size(); ++i) {
    ^
    INFO: From Compiling tensorflow/contrib/lite/toco/graph_transformations/hardcode_min_max.cc:
    In file included from ./tensorflow/contrib/lite/kernels/internal/common.h:42:0,
    from ./tensorflow/contrib/lite/toco/runtime/types.h:18,
    from ./tensorflow/contrib/lite/toco/model.h:26,
    from ./tensorflow/contrib/lite/toco/graph_transformations/graph_transformations.h:23,
    from tensorflow/contrib/lite/toco/graph_transformations/hardcode_min_max.cc:20:
    external/arm_neon_2_x86_sse/NEON_2_SSE.h: In function ‘void vst1q_lane_f32(float32_t*, float32x4_t, int)’:
    external/arm_neon_2_x86_sse/NEON_2_SSE.h:9673:31: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing]
    *(ptr) = *((float*)&ilane);
    ^
    external/arm_neon_2_x86_sse/NEON_2_SSE.h: In function ‘float32_t vgetq_lane_f32(float32x4_t, int)’:
    external/arm_neon_2_x86_sse/NEON_2_SSE.h:11912:22: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing]
    return *(float*)&ilane;
    ^
    INFO: From Compiling tensorflow/contrib/lite/toco/graph_transformations/dequantize.cc:
    In file included from ./tensorflow/contrib/lite/kernels/internal/common.h:42:0,
    from ./tensorflow/contrib/lite/toco/runtime/types.h:18,
    from ./tensorflow/contrib/lite/toco/model.h:26,
    from ./tensorflow/contrib/lite/toco/graph_transformations/graph_transformations.h:23,
    from tensorflow/contrib/lite/toco/graph_transformations/dequantize.cc:20:
    external/arm_neon_2_x86_sse/NEON_2_SSE.h: In function ‘void vst1q_lane_f32(float32_t*, float32x4_t, int)’:
    external/arm_neon_2_x86_sse/NEON_2_SSE.h:9673:31: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing]
    *(ptr) = *((float*)&ilane);
    ^
    external/arm_neon_2_x86_sse/NEON_2_SSE.h: In function ‘float32_t vgetq_lane_f32(float32x4_t, int)’:
    external/arm_neon_2_x86_sse/NEON_2_SSE.h:11912:22: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing]
    return *(float*)&ilane;
    ^
    tensorflow/contrib/lite/toco/graph_transformations/dequantize.cc: In instantiation of ‘void toco::{anonymous}::DequantizeBuffer(toco::Array*) [with toco::ArrayDataType A = (toco::ArrayDataType)4]’:
    tensorflow/contrib/lite/toco/graph_transformations/dequantize.cc:89:52: required from here
    tensorflow/contrib/lite/toco/graph_transformations/dequantize.cc:38:21: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
    for (int i = 0; i < old_data.size(); i++) {
    ^
    tensorflow/contrib/lite/toco/graph_transformations/dequantize.cc: In instantiation of 'void toco::{anonymous}::DequantizeBuffer(toco::Array*) [with toco::ArrayDataType A = (toco::ArrayDataType)7]':
    tensorflow/contrib/lite/toco/graph_transformations/dequantize.cc:91:52: required from here
    tensorflow/contrib/lite/toco/graph_transformations/dequantize.cc:38:21: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
    INFO: From Compiling tensorflow/contrib/lite/toco/tensorflow_graph_matching/resolve_svdf.cc:
    In file included from ./tensorflow/contrib/lite/kernels/internal/common.h:42:0,
    from ./tensorflow/contrib/lite/toco/runtime/types.h:18,
    from ./tensorflow/contrib/lite/toco/model.h:26,
    from ./tensorflow/contrib/lite/toco/tensorflow_graph_matching/resolve_svdf.h:21,
    from tensorflow/contrib/lite/toco/tensorflow_graph_matching/resolve_svdf.cc:15:
    external/arm_neon_2_x86_sse/NEON_2_SSE.h: In function 'void vst1q_lane_f32(float32_t*, float32x4_t, int)':
    external/arm_neon_2_x86_sse/NEON_2_SSE.h:9673:31: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing]
    *(ptr) = *((float*)&ilane);
    ^
    external/arm_neon_2_x86_sse/NEON_2_SSE.h: In function 'float32_t vgetq_lane_f32(float32x4_t, int)':
    external/arm_neon_2_x86_sse/NEON_2_SSE.h:11912:22: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing]
    return *(float*)&ilane;
    ^
    tensorflow/contrib/lite/toco/tensorflow_graph_matching/resolve_svdf.cc: In member function 'void toco::SvdfCluster::MaybeMergeConstNodes(const std::vector&, bool, const std::unique_ptr&)’:
    tensorflow/contrib/lite/toco/tensorflow_graph_matching/resolve_svdf.cc:189:21: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
    for (int i = 0; i < const_node_parts.size(); i++) {
    ^
    tensorflow/contrib/lite/toco/tensorflow_graph_matching/resolve_svdf.cc:217:21: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
    for (int i = 0; i < const_node_parts.size(); i++) {
    ^
    ERROR: /home/narayan/tensorflow/tensorflow/tools/api/generator/BUILD:27:1: Executing genrule //tensorflow/tools/api/generator:python_api_gen failed (Exit 1)
    Traceback (most recent call last):
    File "/home/narayan/.cache/bazel/_bazel_narayan/a82f839cc2517c10479f03b429cbad81/execroot/org_tensorflow/bazel-out/host/bin/tensorflow/tools/api/generator/create_python_api.runfiles/org_tensorflow/tensorflow/tools/api/generator/create_python_api.py", line 26, in
    from tensorflow.python.util import tf_decorator
    File “/home/narayan/.cache/bazel/_bazel_narayan/a82f839cc2517c10479f03b429cbad81/execroot/org_tensorflow/bazel-out/host/bin/tensorflow/tools/api/generator/create_python_api.runfiles/org_tensorflow/tensorflow/python/__init__.py”, line 52, in
    from tensorflow.core.framework.graph_pb2 import *
    File “/home/narayan/.cache/bazel/_bazel_narayan/a82f839cc2517c10479f03b429cbad81/execroot/org_tensorflow/bazel-out/host/bin/tensorflow/tools/api/generator/create_python_api.runfiles/org_tensorflow/tensorflow/core/framework/graph_pb2.py”, line 6, in
    from google.protobuf import descriptor as _descriptor
    File “/home/narayan/.local/lib/python3.5/site-packages/google/protobuf/__init__.py”, line 37, in
    __import__(‘pkg_resources’).declare_namespace(__name__)
    File “/usr/lib/python3/dist-packages/pkg_resources/__init__.py”, line 2927, in
    @_call_aside
    File “/usr/lib/python3/dist-packages/pkg_resources/__init__.py”, line 2913, in _call_aside
    f(*args, **kwargs)
    File “/usr/lib/python3/dist-packages/pkg_resources/__init__.py”, line 2952, in _initialize_master_working_set
    add_activation_listener(lambda dist: dist.activate())
    File “/usr/lib/python3/dist-packages/pkg_resources/__init__.py”, line 956, in subscribe
    callback(dist)
    File “/usr/lib/python3/dist-packages/pkg_resources/__init__.py”, line 2952, in
    add_activation_listener(lambda dist: dist.activate())
    File “/usr/lib/python3/dist-packages/pkg_resources/__init__.py”, line 2515, in activate
    declare_namespace(pkg)
    File “/usr/lib/python3/dist-packages/pkg_resources/__init__.py”, line 2097, in declare_namespace
    _handle_ns(packageName, path_item)
    File “/usr/lib/python3/dist-packages/pkg_resources/__init__.py”, line 2047, in _handle_ns
    _rebuild_mod_path(path, packageName, module)
    File “/usr/lib/python3/dist-packages/pkg_resources/__init__.py”, line 2066, in _rebuild_mod_path
    orig_path.sort(key=position_in_sys_path)
    AttributeError: ‘_NamespacePath’ object has no attribute ‘sort’
    Target //tensorflow/tools/pip_package:build_pip_package failed to build
    Use –verbose_failures to see the command lines of failed build steps.
    INFO: Elapsed time: 3273.853s, Critical Path: 188.71s
    INFO: 11182 processes, local.
    FAILED: Build did NOT complete successfully

    Please help!

    Narayan

  4. When I run “nvidia-smi”
    I’m getting error
    “NVIDIA-SMI has failed because it couldn’t communicate with the NVIDIA driver. Make sure that the latest NVIDIA driver is installed and running.”

    My Linux kernal version is “4.15.0-33-generic”

    • You can try by switching to linux kernel 4.13 or 4.10 from the boot screen -> advanced options. Then follow the steps from step 1.

  5. after following all steps
    I got the following error
    Traceback (most recent call last):
    File “/home/anas/.local/lib/python3.6/site-packages/tensorflow/python/pywrap_tensorflow.py”, line 58, in
    from tensorflow.python.pywrap_tensorflow_internal import *
    File “/home/anas/.local/lib/python3.6/site-packages/tensorflow/python/pywrap_tensorflow_internal.py”, line 28, in
    _pywrap_tensorflow_internal = swig_import_helper()
    File “/home/anas/.local/lib/python3.6/site-packages/tensorflow/python/pywrap_tensorflow_internal.py”, line 24, in swig_import_helper
    _mod = imp.load_module(‘_pywrap_tensorflow_internal’, fp, pathname, description)
    File “/usr/lib/python3.6/imp.py”, line 243, in load_module
    return load_dynamic(name, filename, file)
    File “/usr/lib/python3.6/imp.py”, line 343, in load_dynamic
    return _load(spec)
    ImportError: libcublas.so.9.0: cannot open shared object file: No such file or directory

    During handling of the above exception, another exception occurred:

    Traceback (most recent call last):
    File “”, line 1, in
    File “/home/anas/.local/lib/python3.6/site-packages/tensorflow/__init__.py”, line 22, in
    from tensorflow.python import pywrap_tensorflow # pylint: disable=unused-import
    File “/home/anas/.local/lib/python3.6/site-packages/tensorflow/python/__init__.py”, line 49, in
    from tensorflow.python import pywrap_tensorflow
    File “/home/anas/.local/lib/python3.6/site-packages/tensorflow/python/pywrap_tensorflow.py”, line 74, in
    raise ImportError(msg)
    ImportError: Traceback (most recent call last):
    File “/home/anas/.local/lib/python3.6/site-packages/tensorflow/python/pywrap_tensorflow.py”, line 58, in
    from tensorflow.python.pywrap_tensorflow_internal import *
    File “/home/anas/.local/lib/python3.6/site-packages/tensorflow/python/pywrap_tensorflow_internal.py”, line 28, in
    _pywrap_tensorflow_internal = swig_import_helper()
    File “/home/anas/.local/lib/python3.6/site-packages/tensorflow/python/pywrap_tensorflow_internal.py”, line 24, in swig_import_helper
    _mod = imp.load_module(‘_pywrap_tensorflow_internal’, fp, pathname, description)
    File “/usr/lib/python3.6/imp.py”, line 243, in load_module
    return load_dynamic(name, filename, file)
    File “/usr/lib/python3.6/imp.py”, line 343, in load_dynamic
    return _load(spec)
    ImportError: libcublas.so.9.0: cannot open shared object file: No such file or directory

    • Seems like you have cuda 9.2 installed but you have not installed tensorflow in a clean virtual environment. Ary you able to build wheel?

  6. Excellent guide to help folks get TF working with CUDAs above 9.0. Also, I just used these instructions successfully with r1.9, driver 396.37, and CuDNN 7.1.4 – slightly different from what’s listed here.

Leave a Reply

Your email address will not be published.




This site uses Akismet to reduce spam. Learn how your comment data is processed.