id: 12387    nodeId: 12387    type: General    point: 638.0    linkPoint: 7.0    maker: cella    permission: linkable    made at: 2017.12.14 00:26    edited at: 2017.12.27 10:44
how to install Tensorflow on Beagleboard-X15: failures
#### how to start

# connect X15 to the USB port of a PC and turn on X15.
# on mac os x:

$ ifconfig
# inet 192.168.6.1 appears.

$ ssh debian@192.168.6.2
# password is "temppwd"

debian@BeagleBoard-X15:~$ df
Filesystem 1K-blocks Used Available Use% Mounted on
udev 820472 0 820472 0% /dev
tmpfs 186072 9112 176960 5% /run
/dev/mmcblk1p1 3574972 2884536 489120 86% /
tmpfs 930356 8 930348 1% /dev/shm
tmpfs 5120 4 5116 1% /run/lock
tmpfs 930356 0 930356 0% /sys/fs/cgroup
tmpfs 186068 4 186064 1% /run/user/1000


# now let's mount micro sd card
# https://hifiduino.wordpress.com/2014/03/19/beaglebone-black-accessing-usd-and-usb-storage/

debian@BeagleBoard-X15:/media$ sudo fdisk -l
[sudo] password for debian:
Disk /dev/mmcblk1: 3.5 GiB, 3791650816 bytes, 7405568 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0x03fe2796

Device Boot Start End Sectors Size Id Type
/dev/mmcblk1p1 * 8192 7405567 7397376 3.5G 83 Linux


Disk /dev/mmcblk1boot1: 2 MiB, 2097152 bytes, 4096 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes


Disk /dev/mmcblk1boot0: 2 MiB, 2097152 bytes, 4096 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes


Disk /dev/mmcblk0: 29.8 GiB, 32010928128 bytes, 62521344 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0x00000000

Device Boot Start End Sectors Size Id Type
/dev/mmcblk0p1 8192 62521343 62513152 29.8G c W95 FAT32 (LBA)


# how to mount the micro SD card after booting from eMMC

debian@BeagleBoard-X15:/media$ sudo mkdir sd
debian@BeagleBoard-X15:~$ sudo mount -v /dev/mmcblk0p1 /media/sd
mount: /dev/mmcblk0p1 mounted on /media/sd.





#### how to make a bootable micro SD card

# https://elinux.org/BeagleBoardDebian#BeagleBoard-X15
# don't confuse with flasher image

# in a PC with the micro SD card inserted:
$ wget https://rcn-ee.com/rootfs/2017-12-08/microsd/bbx15-debian-9.2-console-armhf-2017-12-08-2gb.img.xz
$ xzcat bbx15-debian-9.2-console-armhf-2017-12-08-2gb.img.xz | sudo dd of=/dev/mmcblk0
# confirm the disk name by lsblk and don't use mmcblk0p1

# and insert the SD card into X15 and just press the power button (don't confuse with pressing and holding boot-select button for flasher)
# now X15 is booted by micro SD card

# to resize the 1.7GB file system to the full 32GB
# in X15:
$ cd /opt/scripts/tools
$ git pull
$ sudo ./grow_partition.sh
$ sudo reboot

debian@arm:~$ df
Filesystem 1K-blocks Used Available Use% Mounted on
udev 820656 0 820656 0% /dev
tmpfs 186068 9124 176944 5% /run
/dev/mmcblk0p1 30758104 823608 28654448 3% /
tmpfs 930340 0 930340 0% /dev/shm
tmpfs 5120 4 5116 1% /run/lock
tmpfs 930340 0 930340 0% /sys/fs/cgroup
tmpfs 186068 0 186068 0% /run/user/1000

# just for more detailed steps refer to
# https://eewiki.net/display/linuxonarm/BeagleBoard-X15#BeagleBoard-X15-SetupmicroSDcard







# select ubuntu 16.04 image instead of debian when wget
ubuntu@arm:~$ uname -a
Linux arm 4.9.67-ti-r82 #1 SMP PREEMPT Fri Dec 8 03:58:51 UTC 2017 armv7l armv7l armv7l GNU/Linux
ubuntu@arm:~$ df
Filesystem 1K-blocks Used Available Use% Mounted on
udev 820384 0 820384 0% /dev
tmpfs 186068 6792 179276 4% /run
/dev/mmcblk0p1 30758104 888212 28589844 4% /
tmpfs 930340 0 930340 0% /dev/shm
tmpfs 5120 4 5116 1% /run/lock
tmpfs 930340 0 930340 0% /sys/fs/cgroup
tmpfs 186068 0 186068 0% /run/user/1000

ubuntu@arm:~$ ll /usr/bin/python3.5
-rwxr-xr-x 2 root root 3189712 Nov 28 17:52 /usr/bin/python3.5*
ubuntu@arm:~$ gcc --version
gcc (Ubuntu/Linaro 5.4.0-6ubuntu1~16.04.5) 5.4.0 20160609
Copyright (C) 2015 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

ubuntu@arm:~$ g++ --version
g++ (Ubuntu/Linaro 5.4.0-6ubuntu1~16.04.5) 5.4.0 20160609
Copyright (C) 2015 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

ubuntu@arm:~$ sudo apt-get update

# for bazel
ubuntu@arm:~$ sudo apt-get install pkg-config zip g++ zlib1g-dev unzip

# for tensorflow
ubuntu@arm:~$ sudo apt-get install python3-pip python3-numpy swig python3-dev
ubuntu@arm:~$ export LC_ALL=C
ubuntu@arm:~$ sudo pip3 install wheel

# for bazel
ubuntu@arm:~$ sudo apt-get install openjdk-8-jdk
ubuntu@arm:~$ mkdir tfbuild
ubuntu@arm:~$ cd tfbuild
ubuntu@arm:~/tfbuild$ wget https://github.com/bazelbuild/bazel/releases/download/0.9.0/bazel-0.9.0-dist.zip
ubuntu@arm:~/tfbuild$ unzip -d bazel bazel-0.9.0-dist.zip
ubuntu@arm:~/tfbuild$ cd bazel
ubuntu@arm:~/tfbuild/bazel$ vi scripts/bootstrap/compile.sh
run "${JAVAC}" -classpath "${classpath}" -sourcepath "${sourcepath}" \
-d "${output}/classes" -source "$JAVA_VERSION" -target "$JAVA_VERSION" \
-encoding UTF-8 "@${paramfile}" -J-Xmx500M

ubuntu@arm:~/tfbuild/bazel$ vi tools/cpp/cc_configure.bzl
# at about line 25, change
cpu_value = get_cpu_value(repository_ctx)
# to
cpu_value = "arm"

ubuntu@arm:~/tfbuild/bazel$ ./compile.sh
# needs heat sink or fan, or x15 will shutdown due to CPU heat; about 50 min. taken
ubuntu@arm:~/tfbuild/bazel$ sudo cp output/bazel /usr/local/bin/bazel
ubuntu@arm:~/tfbuild/bazel$ cd ..

ubuntu@arm:~/tfbuild$ git clone --recurse-submodules https://github.com/tensorflow/tensorflow.git
ubuntu@arm:~/tfbuild$ cd tensorflow
ubuntu@arm:~/tfbuild/tensorflow$ grep -Rl 'lib64' | xargs sed -i 's/lib64/lib/g'

ubuntu@arm:~/tfbuild/tensorflow$ ./configure
# select /usr/bin/python3.5 and its default lib path; select jemalloc Yes and the others are all No or defaults
ubuntu@arm:~/tfbuild/tensorflow$ bazel build --config=opt --local_resources 1024,1.0,1.0 --verbose_failures //tensorflow/tools/pip_package:build_pip_package --cxxopt="-D_GLIBCXX_USE_CXX11_ABI=0"
ubuntu@arm:~/tfbuild/tensorflow$ bazel-bin/tensorflow/tools/pip_package/build_pip_package /tmp/tensorflow_pkg
ubuntu@arm:~/tfbuild/tensorflow$ sudo pip3 install /tmp/tensorflow_pkg/tensorflow-1.4.0-cp35-cp35m-linux_armv7l.whl





#### how to install Tensorflow from source

# https://github.com/samjabrahams/tensorflow-on-raspberry-pi

debian@arm:~$ sudo apt-get update

debian@arm:~$ which python3
/usr/bin/python3
debian@arm:~$ ls -l /usr/bin/python3
lrwxrwxrwx 1 root root 9 Jan 20 2017 /usr/bin/python3 -> python3.5

# for Bazel
debian@arm:~$ sudo apt-get install pkg-config zip g++ zlib1g-dev unzip

# for Tensorflow
debian@arm:~$ sudo apt-get install python3-pip python3-numpy swig python3-dev
debian@arm:~$ sudo pip3 install wheel
Requirement already satisfied: wheel in /usr/lib/python3/dist-packages

# just to check gcc, g++
debian@arm:~$ gcc --version
gcc (Debian 6.3.0-18) 6.3.0 20170516
Copyright (C) 2016 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

debian@arm:~$ g++ --version
g++ (Debian 6.3.0-18) 6.3.0 20170516
Copyright (C) 2016 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.


# build bazel
# 0.9.0 instead of 0.4.5 (which is used in the Samjabrahams's guide), as Tensorflow 1.4 needs >= 0.5.4

debian@arm:~$ sudo apt-get install openjdk-8-jdk
# java is used in building bazel
debian@arm:~$ mkdir /media/sd/tf
debian@arm:~$ cd /media/sd/tf
debian@arm:~/tf$ wget https://github.com/bazelbuild/bazel/releases/download/0.9.0/bazel-0.9.0-dist.zip
debian@arm:~/tf$ unzip -d bazel bazel-0.9.0-dist.zip
debian@arm:~/tf$ cd bazel

debian@arm:~/tf/bazel$ vi scripts/bootstrap/compile.sh
run "${JAVAC}" -classpath "${classpath}" -sourcepath "${sourcepath}" \
-d "${output}/classes" -source "$JAVA_VERSION" -target "$JAVA_VERSION" \
-encoding UTF-8 "@${paramfile}" -J-Xmx500M

debian@arm:~/tf/bazel$ vi tools/cpp/cc_configure.bzl
# at about line 25, change
cpu_value = get_cpu_value(repository_ctx)
# to
cpu_value = "arm"

debian@arm:~/tf/bazel$ ./compile.sh
# needs heat sink or fan, or x15 will shutdown due to CPU heat; about 50 min. taken

debian@arm:~/tf/bazel$ cd

debian@arm:~/tf$ git clone --recurse-submodules https://github.com/tensorflow/tensorflow.git
debian@arm:~/tf$ cd tensorflow
debian@arm:~/tf/tensorflow$ grep -Rl 'lib64' | xargs sed -i 's/lib64/lib/g'
debian@arm:~/tf/tensorflow$ ./configure
# select /usr/bin/python3.5 and its default lib path; select jemalloc Yes and the others are all No or defaults

# X15 has 2GB RAM and there is gcc-6 installed
debian@arm:~/tf$ bazel build -c opt --copt="-mfpu=neon-vfpv4" --copt="-funsafe-math-optimizations" --copt="-ftree-vectorize" --copt="-fomit-frame-pointer" --local_resources 1024,1.0,1.0 --verbose_failures tensorflow/tools/pip_package:build_pip_package --cxxopt="-D_GLIBCXX_USE_CXX11_ABI=0"
# about 220 min. taken

debian@arm:~/tf/tensorflow$ bazel-bin/tensorflow/tools/pip_package/build_pip_package /tmp/tensorflow_pkg

debian@arm:~/tf/tensorflow$ sudo pip3 install /tmp/tensorflow_pkg/tensorflow-1.4.0-cp35-cp35m-linux_armv7l.whl









debian@BeagleBoard-X15:~/tf/bazel$ vi tools/cpp/cc_configure.bzl
...
"""Compute the cpu_value based on the OS name."""
return "arm"
...

debian@BeagleBoard-X15:/media/sd/tf/bazel$ ./compile.sh
# error:
Message from syslogd@BeagleBoard-X15 at Dec 17 12:04:24 ...
kernel:[ 4707.812620] thermal thermal_zone0: critical temperature reached(90 C),shutting down

# success in the next try with a fan; 30 min
debian@arm:~/tf$ df
Filesystem 1K-blocks Used Available Use% Mounted on
udev 820656 0 820656 0% /dev
tmpfs 186068 9116 176952 5% /run
/dev/mmcblk0p1 30758104 1887432 27590624 7% /
tmpfs 930340 0 930340 0% /dev/shm
tmpfs 5120 4 5116 1% /run/lock
tmpfs 930340 0 930340 0% /sys/fs/cgroup
tmpfs 186068 0 186068 0% /run/user/1000








# SD card with original FAT32 (vfat) invokes many probems:
# chown, chmod are not working;
# shell script is not excutalbe by "./some.sh"
# I decided to format SD card as ext4, the native file system of debian.

debian@BeagleBoard-X15:~$ sudo parted /dev/mmcblk0
GNU Parted 3.2
Using /dev/mmcblk0
Welcome to GNU Parted! Type 'help' to view a list of commands.
(parted) mklabel gpt
Warning: The existing disk label on /dev/mmcblk0 will be destroyed and all data
on this disk will be lost. Do you want to continue?
Yes/No? Yes
(parted) mkpart P1 ext4 1MiB 100%
(parted) quit
Information: You may need to update /etc/fstab.

debian@BeagleBoard-X15:~$ sudo mke2fs -t ext4 /dev/mmcblk0p1

debian@BeagleBoard-X15:~$ sudo fdisk -l /dev/mmcblk0
Disk /dev/mmcblk0: 29.8 GiB, 32010928128 bytes, 62521344 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: gpt
Disk identifier: 33E97224-DC0C-44C4-8839-42F84F93E47F

Device Start End Sectors Size Type
/dev/mmcblk0p1 2048 62519295 62517248 29.8G Linux filesystem

debian@BeagleBoard-X15:~$ sudo mount -v /dev/mmcblk0p1 /media/sd
mount: /dev/mmcblk0p1 mounted on /media/sd.
debian@BeagleBoard-X15:~$ df
Filesystem 1K-blocks Used Available Use% Mounted on
udev 820472 0 820472 0% /dev
tmpfs 186072 9156 176916 5% /run
/dev/mmcblk1p1 3574972 3108108 265548 93% /
tmpfs 930356 8 930348 1% /dev/shm
tmpfs 5120 4 5116 1% /run/lock
tmpfs 930356 0 930356 0% /sys/fs/cgroup
tmpfs 186068 4 186064 1% /run/user/1000
/dev/mmcblk0p1 30636904 45080 29012512 1% /media/sd

# when uid=1000 and gid=1000 for debian
# (without these options, /media/sd is owned by root
# and sudo-chown or sudo-chmod is not working in /media/sd. I don't know why.
debian@BeagleBoard-X15:/media$ sudo vi /etc/fstab
/dev/mmcblk0p1 /media/sd auto auto,rw,exec,async,user,uid=1000,gid=1000,umask=000,nofail 0 0

Return to how to install Tensorflow on Beagleboard-X15: failures