Skip to content

Commit

Permalink
TensorFlow 1.3, L4T 28.1
Browse files Browse the repository at this point in the history
  • Loading branch information
jetsonhacks committed Sep 11, 2017
1 parent 594db37 commit 8f2357f
Show file tree
Hide file tree
Showing 14 changed files with 249 additions and 85 deletions.
97 changes: 78 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,50 +1,109 @@
# installTensorFlowTX2
April 1, 2017
Install TensorFlow v1.0.1 on NVIDIA Jetson TX2 Development Kit
September 11, 2017
JetsonHacks

Jetson TX2 is flashed with JetPack 3.0 which installs:
* L4T 27.1 an Ubuntu 16.04 64-bit variant (aarch64)
Install TensorFlow v1.3 on NVIDIA Jetson TX2 Development Kit

Jetson TX2 is flashed with JetPack 3.1 which installs:
* L4T 28.1 an Ubuntu 16.04 64-bit variant (aarch64)
* CUDA 8.0
* cuDNN 5.1.10
* cuDNN 6.0

### Installation
Before installing TensorFlow, a swap file should be created (minimum of 8GB recommended). The Jetson TX2 does not have enough physical memory to compile TensorFlow. The swap file may be located on the internal eMMC, and may be removed after the build.

Note: This procedure was derived from these discussion threads:
There is a convenience script for building a swap file. To build a 8GB swapfile on the eMMC in the home directory:

$ ./createSwapfile.sh -d ~/ -s 8

After TensorFlow has finished building, the swap file is no longer needed and may be removed.

<ul>
<li>https://github.com/tensorflow/tensorflow/issues/851</li>
<li>http://stackoverflow.com/questions/39783919/tensorflow-on-nvidia-tx1/</li>
<li>https://devtalk.nvidia.com/default/topic/1000717/tensorflow-on-jetson-tx2/</li>
</ul>

These scripts support either Python 2.7 or Python 3.5.
TensorFlow should be built in the following order:

#### installPrerequisites.sh
Installs Java and other dependencies needed. Also builds:
## For Python 2.7

##### Bazel
Builds version 0.4.5. Includes patches for compiling under aarch64.
#### installPrerequisites.sh
Installs Java and other dependencies needed. Also builds Bazel version 0.5.2.

#### cloneTensorFlow.sh
Git clones v1.0.1 from the TensorFlow repository and patches the source code for aarch64
Git clones v1.3.0 from the TensorFlow repository and patches the source code for aarch64

#### setTensorFlowEV.sh
Sets up the TensorFlow environment variables. This script will ask for the default python library path. There are many settings to chose from, the script picks the usual suspects. Uses python 2.7.

## For Python 3.5

#### installPrerequisitesPy3.sh
Installs Java and other dependencies needed. Also builds Bazel version 0.5.2.

#### cloneTensorFlow.sh
Git clones v1.3.0 from the TensorFlow repository and patches the source code for aarch64

#### setTensorFlowEVPy3.sh
Sets up the TensorFlow environment variables. This script will ask for the default python library path. There are many settings to chose from, the script picks the usual suspects. Uses python 3.5.

## Build TensorFlow
Once the prerequisites have been installed and the environment configured, it is time to build TensorFlow itself.

#### buildTensorFlow.sh
Builds TensorFlow.

#### packageTensorFlow.sh
Once TensorFlow has finished building, this script may be used to create a 'wheel' file, a package for installing with Python. The wheel file will be in the $HOME directory.

#### Install wheel file
For Python 2.X

$ pip install $HOME/<em>wheel file</em>

For Python 3.X

$ pip3 install $HOME/<em>wheel file</em>


### Notes
This TensorFlow installation procedure was derived from these discussion threads:

<ul>
<li>https://github.com/tensorflow/tensorflow/issues/851</li>
<li>http://stackoverflow.com/questions/39783919/tensorflow-on-nvidia-tx1/</li>
<li>https://devtalk.nvidia.com/default/topic/1000717/tensorflow-on-jetson-tx2/</li>
<li>https://github.com/tensorflow/tensorflow/issues/9697</li>
</ul>

### Release Notes
September 2017
* L4T 28.1 (JetPack 3.1)
* TensorFlow 1.3

April 2017
* Initial Release
* L4T 27.1 (JetPack 3.0)
* TensorFlow 1.0



## License
MIT License

#### Build Issues
Copyright (c) 2017 Jetsonhacks

For various reasons, the build may fail. The 'debug' folder contains a version of the buildTensorFlow.sh script which is more verbose in the way that it describes both what it is doing and errors it encounters. See the debug directory for more details.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

#### Notes
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
4 changes: 2 additions & 2 deletions buildTensorFlow.sh
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
#!/bin/bash
# NVIDIA Jetson TX1
# NVIDIA Jetson TX2
# TensorFlow Installation
# Export TensorFlow GPU environment variables
# WARNING This needs to match setTensorFlowEV.sh settings
export TF_NEED_CUDA=1
export TF_CUDA_VERSION=8.0
export CUDA_TOOLKIT_PATH=/usr/local/cuda
export TF_CUDNN_VERSION=5.1.10
export TF_CUDNN_VERSION=6.0.21
export CUDNN_INSTALL_PATH=/usr/lib/aarch64-linux-gnu/
export TF_CUDA_COMPUTE_CAPABILITIES=6.2

Expand Down
4 changes: 2 additions & 2 deletions cloneTensorFlow.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/bin/bash
# NVIDIA Jetson TX1
# NVIDIA Jetson TX2
# TensorFlow Installation
# Install Tensorflow repository then
# setup for compilation
Expand All @@ -8,7 +8,7 @@ INSTALL_DIR=$PWD
cd $HOME
git clone https://github.com/tensorflow/tensorflow.git
cd tensorflow
git checkout v1.0.1
git checkout v1.3.0
patch -p1 < $INSTALL_DIR/patches/tensorflow.patch


Expand Down
62 changes: 62 additions & 0 deletions createSwapfile.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
#!/bin/bash
#NVIDIA Jetson TX1
# Create a swap file and set up permissions
# If a parameter is passed, it should be the place to create the swapfile
SWAPDIRECTORY=$PWD
SWAPSIZE=8
AUTOMOUNT="N"
function usage
{
echo "usage: createSwapFile [[[-d directory ] [-s size] -a] | [-h]]"
echo "-d | --dir <directoryname> Directory to place swapfile"
echo "-s | --size <gigabytes>"
echo "-a | --auto Enable swap on boot in /etc/fstab "
echo "-h | --help This message"
}

while [ "$1" != "" ]; do
case $1 in
-d | --dir ) shift
SWAPDIRECTORY=$1
;;
-s | --size ) shift
SWAPSIZE=$1
;;
-a | --auto ) AUTOMOUNT="Y"
;;
-h | --help ) usage
exit
;;
* ) usage
exit 1
esac
shift
done

echo "Creating Swapfile at: " $SWAPDIRECTORY
echo "Swapfile Size: " $SWAPSIZE"G"
echo "Automount: " $AUTOMOUNT

#Create a swapfile for Ubuntu at the current directory location
fallocate -l $SWAPSIZE"G" $SWAPDIRECTORY"/swapfile"
cd $SWAPDIRECTORY
#List out the file
ls -lh swapfile
# Change permissions so that only root can use it
sudo chmod 600 swapfile
#List out the file
ls -lh swapfile
#Set up the Linux swap area
sudo mkswap swapfile
#Now start using the swapfile
sudo swapon swapfile
#Show that it's now being used
swapon -s

if [ "$AUTOMOUNT" = "Y" ]; then
echo "Modifying /etc/fstab to enable on boot"
SWAPLOCATION=$SWAPDIRECTORY"/swapfile"
echo $SWAPLOCATION
sudo sh -c 'echo "'$SWAPLOCATION' none swap sw 0 0" >> /etc/fstab'
fi

8 changes: 8 additions & 0 deletions installPrerequisitesPy3.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/bin/bash
# NVIDIA Jetson TX2
# Install TensorFlow dependencies and prerequisites
# Install Java and other dependencies by apt-get
./scripts/installDependenciesPy3.sh
./scripts/installBazel.sh


4 changes: 2 additions & 2 deletions packageTensorFlow.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/bash
# NVIDIA Jetson TX1
# NVIDIA Jetson TX2
cd $HOME/tensorflow
bazel-bin/tensorflow/tools/pip_package/build_pip_package /tmp/tensorflow_pkg
mv /tmp/tensorflow_pkg/tensorflow-1.0.1-cp27-cp27mu-linux_aarch64.whl $HOME/
mv /tmp/tensorflow_pkg/tensorflow-*.whl $HOME/

13 changes: 0 additions & 13 deletions patches/bazel.patch

This file was deleted.

58 changes: 20 additions & 38 deletions patches/tensorflow.patch
Original file line number Diff line number Diff line change
@@ -1,16 +1,3 @@
diff --git a/tensorflow/core/kernels/BUILD b/tensorflow/core/kernels/BUILD
index 2e04827..9d81923 100644
--- a/tensorflow/core/kernels/BUILD
+++ b/tensorflow/core/kernels/BUILD
@@ -1184,7 +1184,7 @@ tf_kernel_libraries(
"segment_reduction_ops",
"scan_ops",
"sequence_ops",
- "sparse_matmul_op",
+ #DC "sparse_matmul_op",
],
deps = [
":bounds_check",
diff --git a/tensorflow/core/kernels/cwise_op_gpu_select.cu.cc b/tensorflow/core/kernels/cwise_op_gpu_select.cu.cc
index 02058a8..880a0c3 100644
--- a/tensorflow/core/kernels/cwise_op_gpu_select.cu.cc
Expand All @@ -32,31 +19,7 @@ index 02058a8..880a0c3 100644
#else
Eigen::IndexList<Eigen::type2index<1>, int> broadcast_dims;
broadcast_dims.set(1, all_but_batch);
diff --git a/tensorflow/core/kernels/sparse_tensor_dense_matmul_op_gpu.cu.cc b/tensorflow/core/kernels/sparse_tensor_dense_matmul_op_gpu.cu.cc
index a177696..28d2f59 100644
--- a/tensorflow/core/kernels/sparse_tensor_dense_matmul_op_gpu.cu.cc
+++ b/tensorflow/core/kernels/sparse_tensor_dense_matmul_op_gpu.cu.cc
@@ -104,9 +104,17 @@ struct SparseTensorDenseMatMulFunctor<GPUDevice, T, ADJ_A, ADJ_B> {
int n = (ADJ_B) ? b.dimension(0) : b.dimension(1);

#if !defined(EIGEN_HAS_INDEX_LIST)
- Eigen::Tensor<int, 2>::Dimensions matrix_1_by_nnz{{ 1, nnz }};
- Eigen::array<int, 2> n_by_1{{ n, 1 }};
- Eigen::array<int, 1> reduce_on_rows{{ 0 }};
+ // Eigen::Tensor<int, 2>::Dimensions matrix_1_by_nnz{{ 1, nnz }};
+ Eigen::Tensor<int, 2>::Dimensions matrix_1_by_nnz;
+ matrix_1_by_nnz[0] = 1;
+ matrix_1_by_nnz[1] = nnz;
+ // Eigen::array<int, 2> n_by_1{{ n, 1 }};
+ Eigen::array<int, 2> n_by_1;
+ n_by_1[0] = n;
+ n_by_1[1] = 1;
+ // Eigen::array<int, 1> reduce_on_rows{{ 0 }};
+ Eigen::array<int, 1> reduce_on_rows;
+ reduce_on_rows[0]= 0;
#else
Eigen::IndexList<Eigen::type2index<1>, int> matrix_1_by_nnz;
matrix_1_by_nnz.set(1, nnz);
diff --git a/tensorflow/stream_executor/cuda/cuda_gpu_executor.cc b/tensorflow/stream_executor/cuda/cuda_gpu_executor.cc
index b2da109..8ee1f3a 100644
--- a/tensorflow/stream_executor/cuda/cuda_gpu_executor.cc
Expand All @@ -71,5 +34,24 @@ index b2da109..8ee1f3a 100644
+ return 0;
+#elif defined(__APPLE__)
LOG(INFO) << "OS X does not support NUMA - returning NUMA node zero";
return 0;
return 0;N
#elif defined(PLATFORM_WINDOWS)
diff --git aa/tensorflow/workspace.bzl b/tensorflow/workspace.bzl
index 2a206b0..d785473 100644
--- a/tensorflow/workspace.bzl
+++ b/tensorflow/workspace.bzl
@@ -150,11 +150,11 @@ def tf_workspace(path_prefix="", tf_repo_name=""):
native.new_http_archive(
name = "eigen_archive",
urls = [
- "http://mirror.bazel.build/bitbucket.org/eigen/eigen/get/f3a22f35b044.tar.gz",
- "https://bitbucket.org/eigen/eigen/get/f3a22f35b044.tar.gz",
+ "http://mirror.bazel.build/bitbucket.org/eigen/eigen/get/d781c1de9834.tar.gz",
+ "https://bitbucket.org/eigen/eigen/get/d781c1de9834.tar.gz",
],
- sha256 = "ca7beac153d4059c02c8fc59816c82d54ea47fe58365e8aded4082ded0b820c4",
- strip_prefix = "eigen-eigen-f3a22f35b044",
+ sha256 = "a34b208da6ec18fa8da963369e166e4a368612c14d956dd2f9d7072904675d9b",
+ strip_prefix = "eigen-eigen-d781c1de9834",
build_file = str(Label("//third_party:eigen.BUILD")),
)
12 changes: 6 additions & 6 deletions scripts/installBazel.sh
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
#!/bin/bash
# NVIDIA Jetson TX1
# NVIDIA Jetson TX2
# TensorFlow Installation
# Install Bazel
# Version 0.5.2 - v0.5.3 apparently has issues
# We use the release distribution so that we don't have to build protobuf
#
INSTALL_DIR=$PWD
cd $HOME
wget --no-check-certificate https://github.com/bazelbuild/bazel/releases/download/0.4.5/bazel-0.4.5-dist.zip
unzip bazel-0.4.5-dist.zip -d bazel-0.4.5-dist
sudo chmod -R ug+rwx $HOME/bazel-0.4.5-dist
wget --no-check-certificate https://github.com/bazelbuild/bazel/releases/download/0.5.2/bazel-0.5.2-dist.zip
unzip bazel-0.5.2-dist.zip -d bazel-0.5.2-dist
sudo chmod -R ug+rwx $HOME/bazel-0.5.2-dist
# git clone https://github.com/bazelbuild/bazel.git
cd bazel-0.4.5-dist
patch -p0 < $INSTALL_DIR/patches/bazel.patch
cd bazel-0.5.2-dist
./compile.sh
sudo cp output/bazel /usr/local/bin
3 changes: 2 additions & 1 deletion scripts/installDependencies.sh
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
#!/bin/bash
# NVIDIA Jetson TX1
# NVIDIA Jetson TX2
# Install TensorFlow dependencies
# Install Java
sudo add-apt-repository ppa:webupd8team/java
sudo apt-get update
sudo apt-get install oracle-java8-installer -y
# Install other dependencies
sudo apt-get install zip unzip autoconf automake libtool curl zlib1g-dev maven -y
# Install Python 2.x
sudo apt-get install python-numpy swig python-dev python-pip python-wheel -y
11 changes: 11 additions & 0 deletions scripts/installDependenciesPy3.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/bin/bash
# NVIDIA Jetson TX2
# Install TensorFlow dependencies
# Install Java
sudo add-apt-repository ppa:webupd8team/java
sudo apt-get update
sudo apt-get install oracle-java8-installer -y
# Install other dependencies
sudo apt-get install zip unzip autoconf automake libtool curl zlib1g-dev maven -y
# Install Python 3.x
sudo apt-get install python3-numpy swig python3-dev python3-pip python3-wheel -y
2 changes: 1 addition & 1 deletion setLocalLib.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/bin/bash
# NVIDIA Jetson TX1
# NVIDIA Jetson TX2
# TensorFlow Installation
# Useful setup command to set library path
sudo sh -c 'echo /usr/local/lib >> /etc/ld.so.conf'
Expand Down
Loading

0 comments on commit 8f2357f

Please sign in to comment.